]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/cunit/examples/simple_test/main.c
Update
[l4.git] / l4 / pkg / cunit / examples / simple_test / main.c
1 /*!
2  * \file   examples/simple_test/main.c
3  * \brief  
4  *
5  * \date   01/30/2007
6  * \author Bjoern Doebel <doebel@os.inf.tu-dresden.de
7  *
8  */
9 /*
10  * (c) 2007-2009 Technische Universität Dresden
11  * This file is part of TUD:OS and distributed under the terms of the
12  * GNU General Public License 2.
13  * Please see the COPYING-GPL-2 file for details.
14  */
15 #include <CUnit.h>
16 #include <Basic.h>
17 #include <l4/log/macros.h>
18 #include <l4/util/util.h>
19
20 // tested functions
21 int maxi(int, int);
22 int mini(int, int);
23
24 // test suite
25 int init_test_suite(void);
26 int cleanup_test_suite(void);
27 // tests
28 void test_maxi(void);
29 void test_mini(void);
30
31 int maxi(int i1, int i2)
32 {
33   return (i1 > i2) ? i1 : i2;
34 }
35
36 int mini(int i, int j)
37 {
38         return maxi(i,j);
39 }
40
41 void test_maxi(void)
42 {
43   CU_ASSERT(maxi(0,2) == 2);
44   CU_ASSERT(maxi(0,-2) == 0);
45   CU_ASSERT(maxi(2,2) == 2);
46 }
47
48 void test_mini(void)
49 {
50   CU_ASSERT(mini(0,2) == 0);
51   CU_ASSERT(mini(0,0) == 0);
52   CU_ASSERT(mini(2,-2) == -2);
53 }
54
55 int init_test_suite(void)
56 {
57         LOG("test suite initialization.");
58         return 0;
59 }
60
61 int cleanup_test_suite(void)
62 {
63         LOG("test suite cleanup");
64         return 0;
65 }
66
67 int main(void)
68 {
69         CU_pSuite suite = NULL;
70
71         int error = CU_initialize_registry();
72         if (error == CUE_SUCCESS)
73                 LOG("Intialized test registry.");
74         else
75                 LOG("Registry initialization failed.");
76
77         suite = CU_add_suite("cunit_simple", init_test_suite, cleanup_test_suite);
78         if (suite)
79                 LOG("Test suite initialized.");
80         else {
81                 CU_ErrorCode e = CU_get_error();
82                 LOG("Error initializing test suite.");
83                 LOG("Error was: %d", e);
84         }
85
86         CU_ADD_TEST(suite, test_maxi);
87         LOG("added test_maxi to suite.");
88         CU_ADD_TEST(suite, test_mini);
89         LOG("added test_mini to suite.");
90
91         LOG("Running tests in NORMAL mode.");
92         CU_basic_set_mode(CU_BRM_NORMAL);
93         CU_basic_run_tests();
94
95         LOG("Running tests in SILENT mode.");
96         CU_basic_set_mode(CU_BRM_SILENT);
97         CU_basic_run_tests();
98
99         LOG("Running tests in VERBOSE mode.");
100         CU_basic_set_mode(CU_BRM_VERBOSE);
101         CU_basic_run_tests();
102
103         CU_cleanup_registry();
104         LOG("Registry cleaned up.");
105
106         l4_sleep_forever();
107
108         return 0;
109 }