blob: 4ee1e8de7698da9d89788c2b5b3d44de1bb17cb4 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
Benny Prijono32177c02008-06-20 22:44:47 +00003 * Copyright (C)2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono5dcb38d2005-11-21 01:55:47 +00004 *
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
47int atomic_test(void)
48{
49 pj_pool_t *pool;
50 pj_atomic_t *atomic_var;
51 pj_status_t rc;
52
53 pool = pj_pool_create(mem, NULL, 4096, 0, NULL);
54 if (!pool)
55 return -10;
56
57 /* create() */
58 rc = pj_atomic_create(pool, 111, &atomic_var);
59 if (rc != 0) {
60 return -20;
61 }
62
63 /* get: check the value. */
64 if (pj_atomic_get(atomic_var) != 111)
65 return -30;
66
67 /* increment. */
68 pj_atomic_inc(atomic_var);
69 if (pj_atomic_get(atomic_var) != 112)
70 return -40;
71
72 /* decrement. */
73 pj_atomic_dec(atomic_var);
74 if (pj_atomic_get(atomic_var) != 111)
75 return -50;
76
77 /* set */
78 pj_atomic_set(atomic_var, 211);
79 if (pj_atomic_get(atomic_var) != 211)
80 return -60;
81
82 /* add */
83 pj_atomic_add(atomic_var, 10);
84 if (pj_atomic_get(atomic_var) != 221)
85 return -60;
86
87 /* check the value again. */
88 if (pj_atomic_get(atomic_var) != 221)
89 return -70;
90
91 /* destroy */
92 rc = pj_atomic_destroy(atomic_var);
93 if (rc != 0)
94 return -80;
95
96 pj_pool_release(pool);
97
98 return 0;
99}
100
101
102#else
103/* To prevent warning about "translation unit is empty"
104 * when this test is disabled.
105 */
106int dummy_atomic_test;
107#endif /* INCLUDE_ATOMIC_TEST */
108