source: trunk/third/gstreamer/testsuite/debug/global.c @ 21005

Revision 21005, 3.5 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21004, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
3 *
4 * global.c: Test global parameter setting/getting
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
24
25#include <gst/gst.h>
26
27#define THREAD_COUNT    5
28#define ITERATIONS      20
29
30/* stupid logging functions */
31static void
32gst_debug_log_one (GstDebugCategory * category,
33    GstDebugLevel level,
34    const gchar * file,
35    const gchar * function,
36    gint line, GObject * object, GstDebugMessage * message, gpointer data)
37    G_GNUC_NO_INSTRUMENT;
38     static void gst_debug_log_two (GstDebugCategory * category,
39    GstDebugLevel level,
40    const gchar * file,
41    const gchar * function,
42    gint line, GObject * object, GstDebugMessage * message, gpointer thread)
43  G_GNUC_NO_INSTRUMENT;
44
45     static void
46         gst_debug_log_one (GstDebugCategory * category, GstDebugLevel level,
47    const gchar * file, const gchar * function, gint line, GObject * object,
48    GstDebugMessage * message, gpointer data)
49{
50}
51static void
52gst_debug_log_two (GstDebugCategory * category, GstDebugLevel level,
53    const gchar * file, const gchar * function, gint line, GObject * object,
54    GstDebugMessage * message, gpointer data)
55{
56}
57
58static gpointer
59thread_main (gpointer threadnum)
60{
61  gint num;
62  gint i;
63
64  num = GPOINTER_TO_INT (threadnum);
65  for (i = 0; i < ITERATIONS; i++) {
66    g_print ("iteration %d of thread %d starting\n", i, num);
67    /* do some stuff with global settings */
68    gst_debug_set_default_threshold (GST_LEVEL_DEBUG);
69    gst_debug_add_log_function (gst_debug_log_one, g_thread_self ());
70    gst_debug_add_log_function (gst_debug_log_two, NULL);
71
72    /* reset all the stuff we did */
73    gst_debug_set_default_threshold (GST_LEVEL_DEFAULT);
74    g_assert (gst_debug_remove_log_function_by_data (g_thread_self ()) == 1);
75  }
76
77  g_print ("Thread %d is done.\n", num);
78  return threadnum;
79}
80
81gint
82main (gint argc, gchar * argv[])
83{
84  gint i;
85  GThread *threads[THREAD_COUNT];
86
87  g_print ("initializing GStreamer\n");
88  gst_init (&argc, &argv);
89  g_assert (gst_debug_remove_log_function (gst_debug_log_default) == 1);
90
91  /* some checks for defaults */
92  g_print ("Doing startup checks\n");
93  g_assert (gst_debug_get_default_threshold () == GST_LEVEL_DEFAULT);
94
95  g_print ("creating %d threads\n", THREAD_COUNT);
96  for (i = 0; i < THREAD_COUNT; i++) {
97    g_assert ((threads[i] =
98            g_thread_create (thread_main, GINT_TO_POINTER (i), TRUE, NULL)));
99  }
100  g_print ("joining %d threads\n", THREAD_COUNT);
101  for (i = 0; i < THREAD_COUNT; i++) {
102    g_assert (GPOINTER_TO_INT (g_thread_join (threads[i])) == i);
103  }
104
105  /* some checks if everything worked */
106  g_print ("Doing shutdown checks\n");
107  g_assert (gst_debug_get_default_threshold () == GST_LEVEL_DEFAULT);
108  g_assert (gst_debug_remove_log_function (gst_debug_log_two) ==
109      THREAD_COUNT * ITERATIONS);
110
111  return 0;
112}
Note: See TracBrowser for help on using the repository browser.