@@ -239,3 +239,52 @@ void Test_dictionary_dump(CuTest *tc)
239
239
240
240
dictionary_del (dic );
241
241
}
242
+
243
+ void Test_dictionary_get (CuTest * tc )
244
+ {
245
+ dictionary * dic ;
246
+ int i , j ;
247
+ char sec_name [32 ];
248
+ char key_name [64 ];
249
+
250
+ /*NULL test*/
251
+ CuAssertPtrEquals (tc , NULL , dictionary_get (NULL , NULL , NULL ));
252
+ CuAssertPtrEquals (tc , NULL , dictionary_get (NULL , "string" , NULL ));
253
+
254
+ /*Check the def return element*/
255
+ dic = dictionary_new (DICTMINSZ );
256
+ CuAssertPtrNotNull (tc , dic );
257
+ CuAssertPtrEquals (tc , NULL , dictionary_get (dic , "dummy" , NULL ));
258
+ CuAssertStrEquals (tc , "def" , dictionary_get (dic , NULL , "def" ));
259
+ CuAssertStrEquals (tc , "def" , dictionary_get (dic , "dummy" , "def" ));
260
+
261
+ /*Populate the dictionary*/
262
+ for (i = 1 ; i < 3 ; ++ i )
263
+ {
264
+ sprintf (sec_name , "sec%d" , i );
265
+ dictionary_set (dic , sec_name , "" );
266
+ for (j = 1 ; j < 5 ; ++ j )
267
+ {
268
+ sprintf (key_name , "%s:key%d" , sec_name , j );
269
+ dictionary_set (dic , key_name , "dummy_value" );
270
+ CuAssertStrEquals (tc , "dummy_value" ,
271
+ dictionary_get (dic , key_name , "string" ));
272
+ }
273
+ }
274
+
275
+ /*Test get dictionary section value*/
276
+ CuAssertStrEquals (tc , "" ,
277
+ dictionary_get (dic , "sec1" , NULL ));
278
+ CuAssertStrEquals (tc , "" ,
279
+ dictionary_get (dic , "sec1" , "def" ));
280
+
281
+ /*delete and set a key in a dictionary*/
282
+ dictionary_unset (dic , "sec1:key4" );
283
+ CuAssertStrEquals (tc , "def" ,
284
+ dictionary_get (dic , "sec1:key4" , "def" ));
285
+ dictionary_set (dic , "sec1:key4" , "dummy_value" );
286
+ CuAssertStrEquals (tc , "dummy_value" ,
287
+ dictionary_get (dic , "sec1:key4" , "def" ));
288
+
289
+ dictionary_del (dic );
290
+ }
0 commit comments