1 : /*
2 : * This file is part of MIN Test Framework. Copyright © 2008 Nokia Corporation
3 : * and/or its subsidiary(-ies).
4 : * Contact: Marko Hyyppä
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 scripter_dsa.tests
22 : * @version 0.1
23 : * @brief This file contains unit tests for MIN Scripter DSA interface.
24 : */
25 :
26 : /* ------------------------------------------------------------------------- */
27 : /* INCLUDE FILES */
28 : #include <check.h>
29 : #include <min_common.h>
30 : #include <dllist.h>
31 : #include <scripter_dsa.h>
32 :
33 : /* ------------------------------------------------------------------------- */
34 : /* EXTERNAL DATA STRUCTURES */
35 : /* None */
36 :
37 : /* ------------------------------------------------------------------------- */
38 : /* EXTERNAL FUNCTION PROTOTYPES */
39 : /* None */
40 :
41 : /* ------------------------------------------------------------------------- */
42 : /* CONSTANTS */
43 : /* None */
44 :
45 : /* ------------------------------------------------------------------------- */
46 : /* MACROS */
47 : /* None */
48 :
49 : /* ------------------------------------------------------------------------- */
50 : /* LOCAL CONSTANTS AND MACROS */
51 : /* None */
52 :
53 : /* ------------------------------------------------------------------------- */
54 : /* MODULE DATA STRUCTURES */
55 : /* None */
56 :
57 : /* ------------------------------------------------------------------------- */
58 : /* LOCAL FUNCTION PROTOTYPES */
59 : /* None */
60 :
61 : /* ------------------------------------------------------------------------- */
62 : /* FORWARD DECLARATIONS */
63 : /* None */
64 :
65 : /* ==================== LOCAL FUNCTIONS ==================================== */
66 1 : START_TEST(test_scripter_dsa_create_and_remove)
67 : {
68 1 : ScripterDataItem* scr_data = INITPTR;
69 1 : TSChar DLL_name[] = "Test DLL";
70 1 : TSChar Class_name[] = "foo";
71 1 : TDLLType DLL_type = EDLLTypeNormal;
72 1 : int result = 0;
73 :
74 1 : scr_data = scripter_dsa_create( DLL_name,Class_name, DLL_type );
75 1 : fail_unless( scr_data != INITPTR,
76 : "Scripter Data Item creation failed." );
77 :
78 1 : result = strncmp( DLL_name, scr_data->DLL_name_, strlen( DLL_name ) );
79 1 : fail_unless( result == 0,
80 : "DLL name of Scripter Data Item is invalid." );
81 1 : fail_unless( scr_data->DLL_type_ == EDLLTypeNormal,
82 : "DLL type of Scripter Data Item is invalid." );
83 1 : fail_unless( scr_data->symbol_list_ != INITPTR,
84 : "Symbol list of Scripter Data Item is not created." );
85 :
86 1 : scripter_dsa_free( &scr_data );
87 1 : fail_unless( scr_data == INITPTR,
88 : "Scripter Data Item removing failed." );
89 : }
90 1 : END_TEST
91 : /* ------------------------------------------------------------------------- */
92 1 : START_TEST(test_scripter_dsa_add_data)
93 : {
94 1 : ScripterDataItem* scr_data = INITPTR;
95 1 : TSChar DLL_name[] = "Test DLL";
96 1 : TSChar Class_name[] = "foo";
97 1 : TDLLType DLL_type = EDLLTypeNormal;
98 1 : DLList* scr_list = INITPTR;
99 1 : DLListIterator data_item = INITPTR;
100 1 : int result = 0;
101 :
102 1 : scr_data = scripter_dsa_create( DLL_name, Class_name, DLL_type );
103 1 : fail_unless( scr_data != INITPTR,
104 : "Scripter Data Item creation failed." );
105 :
106 1 : scr_list = dl_list_create();
107 1 : fail_unless( scr_list != INITPTR,
108 : "Scripter Data linked list creation failed." );
109 :
110 1 : data_item = scripter_dsa_add( scr_list, scr_data );
111 1 : fail_unless( data_item != INITPTR,
112 : "Scripter Data Item adding failed." );
113 :
114 1 : result = strncmp( DLL_name, ( ( ScripterDataItem* ) dl_list_data( data_item ) )->DLL_name_,
115 : strlen( DLL_name ) );
116 1 : fail_unless( result == 0,
117 : "DLL name of Scripter Data Item is invalid." );
118 1 : fail_unless( ( ( ScripterDataItem* ) dl_list_data( data_item ) )->DLL_type_ == EDLLTypeNormal,
119 : "DLL type of Scripter Data Item is invalid." );
120 1 : fail_unless( ( ( ScripterDataItem* ) dl_list_data( data_item ) )->symbol_list_ != INITPTR,
121 : "Symbol list of Scripter Data Item is not created." );
122 :
123 1 : scripter_dsa_free( &scr_data );
124 1 : fail_unless( scr_data == INITPTR,
125 : "Scripter Data Item removing failed." );
126 : }
127 1 : END_TEST
128 : /* ------------------------------------------------------------------------- */
129 1 : START_TEST(test_scripter_dsa_remove)
130 : {
131 1 : ScripterDataItem* scr_data = INITPTR;
132 1 : TSChar DLL_name[] = "Test DLL";
133 1 : TSChar Class_name[] = "foo";
134 1 : TDLLType DLL_type = EDLLTypeNormal;
135 1 : DLList* scr_list = INITPTR;
136 1 : DLListIterator data_item = INITPTR;
137 1 : int result = 0;
138 1 : int retval = 0;
139 :
140 1 : scr_data = scripter_dsa_create( DLL_name, Class_name, DLL_type );
141 1 : fail_unless( scr_data != INITPTR,
142 : "Scripter Data Item creation failed." );
143 :
144 1 : scr_list = dl_list_create();
145 1 : fail_unless( scr_list != INITPTR,
146 : "Scripter Data linked list creation failed." );
147 :
148 1 : data_item = scripter_dsa_add( scr_list, scr_data );
149 1 : fail_unless( data_item != INITPTR,
150 : "Scripter Data Item adding failed." );
151 :
152 1 : result = strncmp( DLL_name, ( ( ScripterDataItem* ) dl_list_data( data_item ) )->DLL_name_,
153 : strlen( DLL_name ) );
154 1 : fail_unless( result == 0,
155 : "DLL name of Scripter Data Item is invalid." );
156 1 : fail_unless( ( ( ScripterDataItem* ) dl_list_data( data_item ) )->DLL_type_ == EDLLTypeNormal,
157 : "DLL type of Scripter Data Item is invalid." );
158 1 : fail_unless( ( ( ScripterDataItem* ) dl_list_data( data_item ) )->symbol_list_ != INITPTR,
159 : "Symbol list of Scripter Data Item is not created." );
160 :
161 1 : retval = scripter_dsa_remove( data_item );
162 1 : fail_unless( retval == 0,
163 : "Scripter Data Item removing failed." );
164 :
165 : /* This is only code coverage test, no functionality */
166 1 : retval = scripter_dsa_remove( INITPTR );
167 1 : fail_unless( retval == -1,
168 : "Scripter Data Item removing by INITPTR pointer expection failed." );
169 :
170 : }
171 1 : END_TEST
172 : /* ------------------------------------------------------------------------- */
173 1 : START_TEST(test_scripter_dsa_add_symbol)
174 : {
175 1 : ScripterDataItem* scr_data = INITPTR;
176 1 : TSChar DLL_name[] = "Test DLL";
177 1 : TSChar Class_name[] = "foo";
178 1 : TDLLType DLL_type = EDLLTypeNormal;
179 1 : DLList* scr_list = INITPTR;
180 1 : DLListIterator data_item = INITPTR;
181 : char *symbol_name;
182 1 : int retval = 0;
183 1 : DLListIterator first_symbol = INITPTR;
184 :
185 1 : scr_data = scripter_dsa_create( DLL_name, Class_name, DLL_type );
186 1 : fail_unless( scr_data != INITPTR,
187 : "Scripter Data Item creation failed." );
188 :
189 1 : scr_list = dl_list_create();
190 1 : fail_unless( scr_list != INITPTR,
191 : "Scripter Data linked list creation failed." );
192 :
193 1 : data_item = scripter_dsa_add( scr_list, scr_data );
194 1 : fail_unless( data_item != INITPTR,
195 : "Scripter Data Item adding failed." );
196 :
197 1 : symbol_name = NEW2 (char, strlen ("TestSymbol") + 1 );
198 1 : strcpy (symbol_name, "TestSymbol");
199 1 : retval = scripter_dsa_add_symbol( data_item, symbol_name );
200 1 : fail_unless( retval == 0,
201 : "Scripter symbol name adding failed." );
202 :
203 1 : first_symbol = dl_list_head( ( ( ScripterDataItem* ) dl_list_data( data_item ) )->symbol_list_ );
204 1 : fail_unless( first_symbol != INITPTR,
205 : "Scripter first symbol data item not exists." );
206 :
207 1 : retval = strncmp( symbol_name, dl_list_data( first_symbol ), strlen( symbol_name ) );
208 1 : fail_unless( retval == 0,
209 : "Scripter symbol name is invalid." );
210 :
211 : /* This is only code coverage test, no functionality */
212 1 : symbol_name = NEW2 (char, strlen ("TestSymbol2") + 1 );
213 1 : strcpy (symbol_name, "TestSymbol2");
214 :
215 1 : retval = scripter_dsa_add_symbol( INITPTR, symbol_name );
216 1 : fail_unless( retval == -1,
217 : "Scripter symbol name adding by INITPTR data item pointer expection failed." );
218 :
219 1 : scripter_dsa_free( &scr_data );
220 1 : fail_unless( scr_data == INITPTR,
221 : "Scripter Data Item removing with INITPTR failed." );
222 : }
223 1 : END_TEST
224 : /* ------------------------------------------------------------------------- */
225 : Suite *scripter_dsa_suite (void)
226 5 : {
227 5 : Suite *s = suite_create( "scripter_dsa" );
228 :
229 : /* Core test case */
230 5 : TCase *tc_core = tcase_create( "Core" );
231 :
232 : /* Scripter data handling tests */
233 5 : tcase_add_test( tc_core, test_scripter_dsa_create_and_remove );
234 5 : tcase_add_test( tc_core, test_scripter_dsa_add_data );
235 5 : tcase_add_test( tc_core, test_scripter_dsa_remove );
236 :
237 : /* Scripter symbol name data handling */
238 5 : tcase_add_test( tc_core, test_scripter_dsa_add_symbol );
239 :
240 5 : suite_add_tcase( s, tc_core );
241 :
242 5 : return s;
243 : }
244 : /* ======================== FUNCTIONS ====================================== */
245 : int scripter_dsa_tests()
246 5 : {
247 5 : int number_failed = 0;
248 5 : Suite * s = scripter_dsa_suite();
249 5 : SRunner * sr = srunner_create( s );
250 : // srunner_set_fork_status( sr, CK_NOFORK );
251 5 : srunner_run_all( sr, CK_NORMAL );
252 1 : number_failed = srunner_ntests_failed( sr );
253 1 : srunner_free( sr );
254 1 : return number_failed;
255 : }
256 : /* ------------------------------------------------------------------------- */
257 :
258 : /* ------------------------------------------------------------------------- */
259 :
260 : /* ================= OTHER EXPORTED FUNCTIONS ============================== */
261 : /* None */
262 : /* End of file */
|