Add headers
[platform/upstream/glib.git] / glib / tests / rec-mutex.c
1 /* Unit tests for GRecMutex
2  * Copyright (C) 2011 Red Hat, Inc
3  * Author: Matthias Clasen
4  *
5  * This work is provided "as is"; redistribution and modification
6  * in whole or in part, in any medium, physical or electronic is
7  * permitted without restriction.
8  *
9  * This work is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * In no event shall the authors or contributors be liable for any
14  * direct, indirect, incidental, special, exemplary, or consequential
15  * damages (including, but not limited to, procurement of substitute
16  * goods or services; loss of use, data, or profits; or business
17  * interruption) however caused and on any theory of liability, whether
18  * in contract, strict liability, or tort (including negligence or
19  * otherwise) arising in any way out of the use of this software, even
20  * if advised of the possibility of such damage.
21  */
22
23 #include <glib.h>
24
25 static void
26 test_rec_mutex1 (void)
27 {
28   GRecMutex mutex;
29
30   g_rec_mutex_init (&mutex);
31   g_rec_mutex_lock (&mutex);
32   g_rec_mutex_unlock (&mutex);
33   g_rec_mutex_lock (&mutex);
34   g_rec_mutex_unlock (&mutex);
35   g_rec_mutex_clear (&mutex);
36 }
37
38 static void
39 test_rec_mutex2 (void)
40 {
41   GRecMutex mutex = G_REC_MUTEX_INIT;
42
43   g_rec_mutex_lock (&mutex);
44   g_rec_mutex_unlock (&mutex);
45   g_rec_mutex_lock (&mutex);
46   g_rec_mutex_unlock (&mutex);
47   g_rec_mutex_clear (&mutex);
48 }
49
50 static void
51 test_rec_mutex3 (void)
52 {
53   GRecMutex mutex = G_REC_MUTEX_INIT;
54   gboolean ret;
55
56   ret = g_rec_mutex_trylock (&mutex);
57   g_assert (ret);
58
59   ret = g_rec_mutex_trylock (&mutex);
60   g_assert (ret);
61
62   g_rec_mutex_unlock (&mutex);
63   g_rec_mutex_unlock (&mutex);
64   g_rec_mutex_clear (&mutex);
65 }
66
67
68 int
69 main (int argc, char *argv[])
70 {
71   g_test_init (&argc, &argv, NULL);
72
73   g_test_add_func ("/thread/rec-mutex1", test_rec_mutex1);
74   g_test_add_func ("/thread/rec-mutex2", test_rec_mutex2);
75   g_test_add_func ("/thread/rec-mutex3", test_rec_mutex3);
76
77   return g_test_run ();
78 }