Debian Codegraph @

Xpjproject/pjlib/src/pjlib-test/atomic.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #include "test.h"
20 #include <pjlib.h>
21
22 /**
23 * \page page_pjlib_atomic_test Test: Atomic Variable
24 *
25 * This file provides implementation of \b atomic_test(). It tests the
26 * functionality of the atomic variable API.
27 *
28 * \section atomic_test_sec Scope of the Test
29 *
30 * API tested:
31 * - pj_atomic_create()
32 * - pj_atomic_get()
33 * - pj_atomic_inc()
34 * - pj_atomic_dec()
35 * - pj_atomic_set()
36 * - pj_atomic_destroy()
37 *
38 *
39 * This file is <b>pjlib-test/atomic.c</b>
40 *
41 * \include pjlib-test/atomic.c
42 */
43
44
45 #if INCLUDE_ATOMIC_TEST
46
47 #define THIS_FILE "atomic.c"
48 #define ERR(r__) { rc=r__; goto on_return; }
49
50 int atomic_test(void)
51 {
52 pj_pool_t *pool;
53 pj_atomic_t *atomic_var;
54 int rc=0;
55
56 PJ_TEST_NOT_NULL( (pool=pj_pool_create(mem, NULL, 4096, 0, NULL)),
57 NULL, ERR(-10));
58 /* create() */
59 PJ_TEST_SUCCESS( pj_atomic_create(pool, 111, &atomic_var), NULL, ERR(-20));
60
61 /* get: check the value. */
62 PJ_TEST_EQ( pj_atomic_get(atomic_var), 111, NULL, ERR(-30));
63
64 /* increment. */
65 pj_atomic_inc(atomic_var);
66 PJ_TEST_EQ( pj_atomic_get(atomic_var), 112, NULL, ERR(-40));
67
68 /* decrement. */
69 pj_atomic_dec(atomic_var);
70 PJ_TEST_EQ( pj_atomic_get(atomic_var), 111, NULL, ERR(-50));
71
72 /* set */
73 pj_atomic_set(atomic_var, 211);
74 PJ_TEST_EQ( pj_atomic_get(atomic_var), 211, NULL, ERR(-60));
75
76 /* add */
77 pj_atomic_add(atomic_var, 10);
78 PJ_TEST_EQ( pj_atomic_get(atomic_var), 221, NULL, ERR(-60));
79
80 /* check the value again. */
81 PJ_TEST_EQ( pj_atomic_get(atomic_var), 221, NULL, ERR(-70));
82
83 /* destroy */
84 PJ_TEST_SUCCESS( pj_atomic_destroy(atomic_var), NULL, ERR(-80));
85
86 on_return:
87 pj_pool_release(pool);
88 return rc;
89 }
90
91
92 #else
93 /* To prevent warning about "translation unit is empty"
94 * when this test is disabled.
95 */
96 int dummy_atomic_test;
97 #endif /* INCLUDE_ATOMIC_TEST */
98