1 : /*
2 : * This file is part of MIN Test Framework. Copyright © 2008 Nokia Corporation
3 : * and/or its subsidiary(-ies).
4 : * Contact: Konrad Marek Zapalowicz
5 : * Contact e-mail: DG.MIN-Support@nokia.com
6 : *
7 : * This program is free software: you can redistribute it and/or modify it
8 : * under the terms of the GNU General Public License as published by the Free
9 : * Software Foundation, version 2 of the License.
10 : *
11 : * This program is distributed in the hope that it will be useful, but WITHOUT
12 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 : * more details. You should have received a copy of the GNU General Public
15 : * License along with this program. If not, see
16 : * <http://www.gnu.org/licenses/>.
17 : */
18 :
19 :
20 : /**
21 : * @file test_module_api.test
22 : * @version 0.1
23 : * @brief This file contains test for Test Module API
24 : */
25 :
26 : /* ------------------------------------------------------------------------- */
27 : /* INCLUDES */
28 : #include <check.h>
29 :
30 : /* ------------------------------------------------------------------------- */
31 : /* CONSTANTS */
32 : /* None */
33 :
34 : /* ------------------------------------------------------------------------- */
35 : /* MACROS */
36 : /* None */
37 :
38 : /* ------------------------------------------------------------------------- */
39 : /* DATA TYPES */
40 : /* None */
41 :
42 : /* ------------------------------------------------------------------------- */
43 : /* LOCAL FUNCTION PROTOTYPES */
44 : void fun1( TestCaseResult * tcr );
45 : void fun2( TestCaseResult * tcr );
46 : /* ------------------------------------------------------------------------- */
47 : /* FORWARD DECLARATIONS */
48 : /* None */
49 :
50 : /* ------------------------------------------------------------------------- */
51 : /* STRUCTURES */
52 : /* None */
53 :
54 : /* ------------------------------------------------------------------------- */
55 : /* ==================== LOCAL FUNCTIONS ==================================== */
56 : void fun1( TestCaseResult * tcr )
57 0 : {
58 :
59 0 : }
60 : void fun2( TestCaseResult * tcr )
61 0 : {
62 :
63 0 : }
64 : /* ------------------------------------------------------------------------- */
65 : /* ============================= TESTS ===================================== */
66 : /* ------------------------------------------------------------------------- */
67 1 : START_TEST(test_tmapi_entry_macro_1)
68 : {
69 1 : DLList * list = dl_list_create();
70 1 : fail_unless( list != INITPTR, "List creation error" );
71 1 : ENTRY(list,"Test Case 1",fun1);
72 1 : fail_unless( dl_list_size(list) == 1, "Entry macro not working (1)" );
73 1 : ENTRY(list,"Test Case 2",fun2);
74 1 : fail_unless( dl_list_size(list) == 2, "Entry macro not working (2)" );
75 1 : dl_list_free(&list);
76 : }
77 1 : END_TEST
78 : /* ------------------------------------------------------------------------- */
79 1 : START_TEST(test_tmapi_entry_macro_2)
80 : {
81 1 : DLList * list = dl_list_create();
82 1 : DLListIterator it = DLListNULLIterator;
83 1 : TestCaseInfo * tci = INITPTR;
84 1 : fail_unless( list != INITPTR, "List creation error" );
85 1 : ENTRY(list,"Test Case 1",fun1);
86 1 : it = dl_list_head(list);
87 1 : tci = (TestCaseInfo*)dl_list_data(it);
88 1 : fail_unless(strcmp(tci->name_,"Test Case 1")==0,"TC name is wrong");
89 1 : fail_unless(tci->id_ == 1,"TC id is wrong");
90 1 : fail_unless(tci->test_ == fun1,"TC test function is wrong");
91 1 : dl_list_free(&list);
92 : }
93 1 : END_TEST
94 : /* ------------------------------------------------------------------------- */
95 1 : START_TEST(test_tmapi_entry2_macro_1)
96 : {
97 1 : DLList * list = dl_list_create();
98 1 : fail_unless( list != INITPTR, "List creation error" );
99 1 : ENTRY2(list,"Test Case 1",1);
100 1 : fail_unless( dl_list_size(list) == 1, "Entry2 macro not working (1)" );
101 1 : ENTRY2(list,"Test Case 2",2);
102 1 : fail_unless( dl_list_size(list) == 2, "Entry2 macro not working (2)" );
103 1 : dl_list_free(&list);
104 : }
105 1 : END_TEST
106 : /* ------------------------------------------------------------------------- */
107 1 : START_TEST(test_tmapi_entry2_macro_2)
108 : {
109 1 : DLList * list = dl_list_create();
110 1 : DLListIterator it = DLListNULLIterator;
111 1 : TestCaseInfo * tci = INITPTR;
112 1 : fail_unless( list != INITPTR, "List creation error" );
113 1 : ENTRY2(list,"Test Case 1",2);
114 1 : it = dl_list_head(list);
115 1 : tci = (TestCaseInfo*)dl_list_data(it);
116 1 : fail_unless(strcmp(tci->name_,"Test Case 1")==0,"TC name is wrong");
117 1 : fail_unless(tci->id_ == 2,"TC id is wrong");
118 1 : fail_unless(tci->test_ == INITPTR,"TC test function is wrong");
119 1 : dl_list_free(&list);
120 : }
121 1 : END_TEST
122 : /* ------------------------------------------------------------------------- */
123 1 : START_TEST(test_tmapi_result_macro)
124 : {
125 : TestCaseResult tcr;
126 1 : TestCaseResult* tmp = &tcr;
127 1 : RESULT(tmp,10,"Result of a test");
128 : fail_unless(tcr.result_ == 10,"Result value is wrong");
129 : fail_unless( strcmp(tcr.desc_,"Result of a test") == 0
130 : , "Description is wrong" );
131 : }
132 : END_TEST
133 : /* ------------------------------------------------------------------------- */
134 : /* ========================== FUNCTIONS ==================================== */
135 : /* ------------------------------------------------------------------------- */
136 : Suite* tmapi_suite()
137 6 : {
138 6 : Suite * s = suite_create ("test module api");
139 :
140 : /* Core test case */
141 6 : TCase *tc_core = tcase_create ("Core");
142 6 : tcase_add_test (tc_core, test_tmapi_entry_macro_1);
143 6 : tcase_add_test (tc_core, test_tmapi_entry_macro_2);
144 6 : tcase_add_test (tc_core, test_tmapi_entry2_macro_1);
145 6 : tcase_add_test (tc_core, test_tmapi_entry2_macro_2);
146 6 : tcase_add_test (tc_core, test_tmapi_result_macro);
147 6 : suite_add_tcase (s, tc_core);
148 6 : return s;
149 : }
150 : /* ------------------------------------------------------------------------- */
151 : int tmapi_tests()
152 6 : {
153 6 : int number_failed = 0;
154 6 : Suite * s = tmapi_suite ();
155 6 : SRunner * sr = srunner_create (s);
156 6 : srunner_run_all(sr, CK_NORMAL);
157 1 : number_failed = srunner_ntests_failed(sr);
158 1 : srunner_free(sr);
159 1 : return number_failed;
160 : }
161 : /* ------------------------------------------------------------------------- */
162 : /* End of file */
|