|
GnuCash 2.4.99
|
00001 /******************************************************************** 00002 * test-kvp_frame.c: GLib g_test test suite for kvp_frame.c. * 00003 * Copyright 2011 John Ralls <jralls@ceridwen.us> * 00004 * * 00005 * This program is free software; you can redistribute it and/or * 00006 * modify it under the terms of the GNU General Public License as * 00007 * published by the Free Software Foundation; either version 2 of * 00008 * the License, or (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License* 00016 * along with this program; if not, contact: * 00017 * * 00018 * Free Software Foundation Voice: +1-617-542-5942 * 00019 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * 00020 * Boston, MA 02110-1301, USA gnu@gnu.org * 00021 ********************************************************************/ 00022 #include "config.h" 00023 #include <string.h> 00024 #include <glib.h> 00025 #include "unittest-support.h" 00026 #include "qof.h" 00027 00028 static const gchar *suitename = "/qof/kvp_frame"; 00029 void test_suite_kvp_frame ( void ); 00030 00031 typedef struct 00032 { 00033 KvpFrame *frame; 00034 } Fixture; 00035 00036 static void 00037 setup( Fixture *fixture, gconstpointer pData ) 00038 { 00039 fixture->frame = kvp_frame_new(); 00040 } 00041 00042 static void 00043 teardown( Fixture *fixture, gconstpointer pData ) 00044 { 00045 kvp_frame_delete( fixture->frame ); 00046 } 00047 00048 extern KvpFrame* ( *p_get_trailer_make )( KvpFrame *frame, const char *key_path, char **end_key ); 00049 extern gchar* ( *p_kvp_value_glist_to_string )( const GList *list ); 00050 extern KvpFrame* ( *p_get_or_make )( KvpFrame *fr, const char * key ); 00051 extern const KvpFrame* ( *p_kvp_frame_get_frame_or_null_slash_trash )( const KvpFrame *frame, char *key_path ); 00052 extern const KvpFrame* ( *p_get_trailer_or_null )( const KvpFrame * frame, const char * key_path, char **end_key ); 00053 00054 extern void init_static_test_pointers( void ); 00055 00056 static void 00057 setup_static( Fixture *fixture, gconstpointer pData ) 00058 { 00059 fixture->frame = kvp_frame_new(); 00060 init_static_test_pointers(); 00061 g_assert( p_get_trailer_make && p_kvp_value_glist_to_string && 00062 p_get_or_make && p_kvp_frame_get_frame_or_null_slash_trash && 00063 p_get_trailer_or_null ); 00064 } 00065 00066 static void 00067 teardown_static( Fixture *fixture, gconstpointer pData ) 00068 { 00069 kvp_frame_delete( fixture->frame ); 00070 p_get_trailer_make = NULL; 00071 p_kvp_value_glist_to_string = NULL; 00072 p_get_or_make = NULL; 00073 p_kvp_frame_get_frame_or_null_slash_trash = NULL; 00074 p_get_trailer_or_null = NULL; 00075 } 00076 00077 static void 00078 test_kvp_frame_new_delete( void ) 00079 { 00080 KvpFrame *frame; 00081 Timespec ts; 00082 GncGUID *guid; 00083 00084 ts.tv_sec = 1; 00085 ts.tv_nsec = 1; 00086 guid = guid_malloc(); 00087 guid_new( guid ); 00088 00089 frame = kvp_frame_new(); 00090 g_assert( frame ); 00091 g_assert( kvp_frame_is_empty( frame ) ); 00092 00093 kvp_frame_set_gint64( frame, "gint64-type", 100 ); 00094 kvp_frame_set_double( frame, "double-type", 3.14159 ); 00095 kvp_frame_set_numeric( frame, "numeric-type", gnc_numeric_zero() ); 00096 kvp_frame_set_timespec( frame, "timespec-type", ts ); 00097 kvp_frame_set_string( frame, "string-type", "abcdefghijklmnop" ); 00098 kvp_frame_set_guid( frame, "guid-type", guid ); 00099 kvp_frame_set_frame( frame, "frame-type", kvp_frame_new() ); 00100 00101 g_assert( !kvp_frame_is_empty( frame ) ); 00102 00103 kvp_frame_delete( frame ); 00104 g_assert( frame ); 00105 00106 guid_free( guid ); 00107 } 00108 00109 static void 00110 test_kvp_frame_copy( Fixture *fixture, gconstpointer pData ) 00111 { 00112 KvpFrame *to_copy = NULL; 00113 gint64 test_gint64, copy_gint64; 00114 double test_double, copy_double; 00115 gnc_numeric test_gnc_numeric, copy_gnc_numeric; 00116 Timespec test_ts, copy_ts; 00117 const char* test_str, *copy_str; 00118 GncGUID *test_guid, *copy_guid; 00119 KvpFrame *test_frame, *copy_frame; 00120 00121 /* init data in source frame */ 00122 test_gint64 = 111; 00123 test_double = 1.1; 00124 test_gnc_numeric = gnc_numeric_zero(); 00125 test_ts.tv_sec = 1; 00126 test_ts.tv_nsec = 1; 00127 test_str = "abcdefghijklmnop"; 00128 test_guid = guid_malloc(); 00129 guid_new( test_guid ); 00130 test_frame = kvp_frame_new(); 00131 00132 g_assert( fixture->frame ); 00133 kvp_frame_set_gint64( fixture->frame, "gint64-type", test_gint64 ); 00134 kvp_frame_set_double( fixture->frame, "double-type", test_double ); 00135 kvp_frame_set_numeric( fixture->frame, "numeric-type", test_gnc_numeric ); 00136 kvp_frame_set_timespec( fixture->frame, "timespec-type", test_ts ); 00137 kvp_frame_set_string( fixture->frame, "string-type", test_str ); 00138 kvp_frame_set_guid( fixture->frame, "guid-type", test_guid ); 00139 kvp_frame_set_frame( fixture->frame, "frame-type", test_frame ); 00140 g_assert( !kvp_frame_is_empty( fixture->frame ) ); 00141 00142 g_test_message( "Test frame copy" ); 00143 to_copy = kvp_frame_copy( fixture->frame ); 00144 g_assert( to_copy ); 00145 g_assert( !kvp_frame_is_empty( to_copy ) ); 00146 g_assert( to_copy != fixture->frame ); 00147 g_assert_cmpint( kvp_frame_compare( fixture->frame, to_copy ), == , 0 ); 00148 copy_gint64 = kvp_frame_get_gint64( to_copy, "gint64-type" ); 00149 g_assert( ©_gint64 != &test_gint64 ); 00150 g_assert_cmpint( copy_gint64, == , test_gint64 ); 00151 copy_double = kvp_frame_get_double( to_copy, "double-type" ); 00152 g_assert( ©_double != &test_double ); 00153 g_assert_cmpfloat( copy_double, == , test_double ); 00154 copy_gnc_numeric = kvp_frame_get_numeric( to_copy, "numeric-type" ); 00155 g_assert( ©_gnc_numeric != &test_gnc_numeric ); 00156 g_assert_cmpfloat( copy_gnc_numeric.num, == , test_gnc_numeric.num ); 00157 g_assert_cmpfloat( copy_gnc_numeric.denom, == , test_gnc_numeric.denom ); 00158 copy_ts = kvp_frame_get_timespec( to_copy, "timespec-type" ); 00159 g_assert( ©_ts != &test_ts ); 00160 g_assert_cmpfloat( copy_ts.tv_sec, == , test_ts.tv_sec ); 00161 g_assert_cmpfloat( copy_ts.tv_nsec, == , test_ts.tv_nsec ); 00162 copy_str = kvp_frame_get_string( to_copy, "string-type" ); 00163 g_assert( copy_str != test_str ); 00164 g_assert_cmpstr( copy_str, == , test_str ); 00165 copy_guid = kvp_frame_get_guid( to_copy, "guid-type" ); 00166 g_assert( copy_guid != test_guid ); 00167 g_assert( guid_equal( copy_guid, test_guid ) ); 00168 copy_frame = kvp_frame_get_frame( to_copy, "frame-type"); 00169 g_assert( copy_frame ); 00170 g_assert( kvp_frame_is_empty( copy_frame ) ); 00171 g_assert( copy_frame != test_frame ); 00172 g_assert_cmpint( kvp_frame_compare( copy_frame, test_frame ), == , 0 ); 00173 00174 kvp_frame_delete( to_copy ); 00175 guid_free( test_guid ); 00176 } 00177 00178 static void 00179 test_kvp_frame_set_foo( Fixture *fixture, gconstpointer pData ) 00180 { 00181 gnc_numeric test_gnc_numeric, copy_gnc_numeric; 00182 Timespec test_ts, copy_ts; 00183 GncGUID *test_guid, *copy_guid; 00184 00185 test_gnc_numeric = gnc_numeric_zero(); 00186 test_ts.tv_sec = 1; 00187 test_ts.tv_nsec = 1; 00188 test_guid = guid_malloc(); 00189 guid_new( test_guid ); 00190 00191 g_assert( fixture->frame ); 00192 g_assert( kvp_frame_is_empty( fixture->frame ) ); 00193 00194 g_test_message( "Test gint64 setup and replace, test frame is created" ); 00195 g_assert( kvp_frame_get_frame( fixture->frame, "/test" ) == NULL ); 00196 kvp_frame_set_gint64( fixture->frame, "/test/gint64", 1 ); 00197 g_assert( kvp_frame_get_frame( fixture->frame, "/test" ) != NULL ); 00198 g_assert_cmpint( kvp_frame_get_gint64( fixture->frame, "/test/gint64" ), == , 1 ); 00199 kvp_frame_set_gint64( fixture->frame, "/test/gint64", 5 ); 00200 g_assert_cmpint( kvp_frame_get_gint64( fixture->frame, "/test/gint64" ), == , 5 ); 00201 00202 g_test_message( "Test double setup and replace, test2 frame is created" ); 00203 g_assert( kvp_frame_get_frame( fixture->frame, "/test2" ) == NULL ); 00204 kvp_frame_set_double( fixture->frame, "/test2/double", 1.1 ); 00205 g_assert( kvp_frame_get_frame( fixture->frame, "/test2" ) != NULL ); 00206 g_assert_cmpfloat( kvp_frame_get_double( fixture->frame, "/test2/double" ), == , 1.1 ); 00207 kvp_frame_set_double( fixture->frame, "/test2/double", 5.5 ); 00208 g_assert_cmpfloat( kvp_frame_get_double( fixture->frame, "/test2/double" ), == , 5.5 ); 00209 00210 g_test_message( "Test double setup and replace, test3 frame is created" ); 00211 g_assert( kvp_frame_get_frame( fixture->frame, "/test3" ) == NULL ); 00212 kvp_frame_set_numeric( fixture->frame, "/test3/numeric", test_gnc_numeric ); 00213 g_assert( kvp_frame_get_frame( fixture->frame, "/test3" ) != NULL ); 00214 copy_gnc_numeric = kvp_frame_get_numeric( fixture->frame, "/test3/numeric" ); 00215 g_assert_cmpint( copy_gnc_numeric.num, == , 0 ); 00216 g_assert_cmpint( copy_gnc_numeric.denom, == , 1 ); 00217 test_gnc_numeric.num = 2; 00218 test_gnc_numeric.denom = 3; 00219 kvp_frame_set_numeric( fixture->frame, "/test3/numeric", test_gnc_numeric ); 00220 copy_gnc_numeric = kvp_frame_get_numeric( fixture->frame, "/test3/numeric" ); 00221 g_assert_cmpint( copy_gnc_numeric.num, == , 2 ); 00222 g_assert_cmpint( copy_gnc_numeric.denom, == , 3 ); 00223 00224 g_test_message( "Test timespec setup and replace, test4 frame is created" ); 00225 g_assert( kvp_frame_get_frame( fixture->frame, "/test4" ) == NULL ); 00226 kvp_frame_set_timespec( fixture->frame, "/test4/timespec", test_ts ); 00227 g_assert( kvp_frame_get_frame( fixture->frame, "/test4" ) != NULL ); 00228 copy_ts = kvp_frame_get_timespec( fixture->frame, "/test4/timespec" ); 00229 g_assert_cmpint( copy_ts.tv_sec, == , 1 ); 00230 g_assert_cmpint( copy_ts.tv_nsec, == , 1 ); 00231 test_ts.tv_sec = 7; 00232 test_ts.tv_nsec = 13; 00233 kvp_frame_set_timespec( fixture->frame, "/test4/timespec", test_ts ); 00234 copy_ts = kvp_frame_get_timespec( fixture->frame, "/test4/timespec" ); 00235 g_assert_cmpint( copy_ts.tv_sec, == , 7 ); 00236 g_assert_cmpint( copy_ts.tv_nsec, == , 13 ); 00237 00238 g_test_message( "Test string setup and replace, test5 frame is created" ); 00239 g_assert( kvp_frame_get_frame( fixture->frame, "/test5" ) == NULL ); 00240 kvp_frame_set_string( fixture->frame, "/test5/string", "one string" ); 00241 g_assert( kvp_frame_get_frame( fixture->frame, "/test5" ) != NULL ); 00242 g_assert_cmpstr( kvp_frame_get_string( fixture->frame, "/test5/string" ), == , "one string" ); 00243 kvp_frame_set_string( fixture->frame, "/test5/string", "another string" ); 00244 g_assert_cmpstr( kvp_frame_get_string( fixture->frame, "/test5/string" ), == , "another string" ); 00245 00246 g_test_message( "Test guid setup and replace, test6 frame is created" ); 00247 g_assert( kvp_frame_get_frame( fixture->frame, "/test6" ) == NULL ); 00248 kvp_frame_set_guid( fixture->frame, "/test6/guid", test_guid ); 00249 g_assert( kvp_frame_get_frame( fixture->frame, "/test6" ) != NULL ); 00250 copy_guid = kvp_frame_get_guid( fixture->frame, "/test6/guid" ); 00251 g_assert( guid_equal( copy_guid, test_guid ) ); 00252 kvp_frame_set_guid( fixture->frame, "/test6/guid", guid_null() ); 00253 copy_guid = kvp_frame_get_guid( fixture->frame, "/test6/guid" ); 00254 g_assert( guid_equal( copy_guid, guid_null() ) ); 00255 00256 g_test_message( "Test frame setup and replace, test7 frame is created" ); 00257 g_assert( kvp_frame_get_frame( fixture->frame, "/test7" ) == NULL ); 00258 kvp_frame_set_frame( fixture->frame, "/test7", kvp_frame_new() ); 00259 g_assert( kvp_frame_get_frame( fixture->frame, "/test7" ) != NULL ); 00260 kvp_frame_set_frame( fixture->frame, "/test7", NULL ); 00261 g_assert( kvp_frame_get_frame( fixture->frame, "/test7" ) == NULL ); 00262 } 00263 00264 static void 00265 test_kvp_frame_get_frame_slash( Fixture *fixture, gconstpointer pData ) 00266 { 00267 KvpFrame *result_frame = NULL; 00268 /* Mostly testing static routine kvp_frmae_get_frame_slash_trash */ 00269 g_assert( fixture->frame ); 00270 00271 g_test_message( "Test path with one slash same frame should be returned" ); 00272 result_frame = kvp_frame_get_frame_slash( fixture->frame, "/" ); 00273 g_assert( result_frame ); 00274 g_assert( result_frame == fixture->frame ); 00275 00276 g_test_message( "Test path with trailing slash same frame should be returned" ); 00277 result_frame = kvp_frame_get_frame_slash( fixture->frame, "/////" ); 00278 g_assert( result_frame ); 00279 g_assert( result_frame == fixture->frame ); 00280 00281 g_test_message( "Test new frame is created" ); 00282 result_frame = kvp_frame_get_frame_slash( fixture->frame, "/test" ); 00283 g_assert( result_frame ); 00284 g_assert( result_frame != fixture->frame ); 00285 g_assert( result_frame == kvp_frame_get_frame( fixture->frame, "/test" ) ); 00286 00287 g_test_message( "Test trailing slashes are ignored and frame created" ); 00288 result_frame = kvp_frame_get_frame_slash( fixture->frame, "////test2/////" ); 00289 g_assert( result_frame ); 00290 g_assert( result_frame != fixture->frame ); 00291 g_assert( result_frame == kvp_frame_get_frame( fixture->frame, "/test2" ) ); 00292 g_assert( result_frame != kvp_frame_get_frame( fixture->frame, "/test" ) ); 00293 00294 g_test_message( "Test frames are created along the path if not exist and last frame is returned" ); 00295 result_frame = kvp_frame_get_frame_slash( fixture->frame, "////test3/////test4//////" ); 00296 g_assert( result_frame ); 00297 g_assert( result_frame != fixture->frame ); 00298 g_assert( result_frame != kvp_frame_get_frame( fixture->frame, "/test2" ) ); 00299 g_assert( result_frame != kvp_frame_get_frame( fixture->frame, "/test" ) ); 00300 g_assert( kvp_frame_get_frame( fixture->frame, "/test3" ) != NULL ); 00301 g_assert( result_frame != kvp_frame_get_frame( fixture->frame, "/test3" ) ); 00302 g_assert( result_frame == kvp_frame_get_frame( fixture->frame, "/test3/test4" ) ); 00303 00304 g_test_message( "Test existing frame is returned" ); 00305 g_assert( result_frame == kvp_frame_get_frame_slash( fixture->frame, "////test3/////test4//////" ) ); 00306 } 00307 00308 static void 00309 test_kvp_frame_get_slot_path( Fixture *fixture, gconstpointer pData ) 00310 { 00311 KvpValue *result_value = NULL ; 00312 00313 g_assert( fixture->frame ); 00314 g_assert( kvp_frame_is_empty( fixture->frame ) ); 00315 00316 g_test_message( "Test with non existing path should return NULL" ); 00317 result_value = kvp_frame_get_slot_path( fixture->frame, "test", "test2", NULL ); 00318 g_assert( !result_value ); 00319 00320 g_test_message( "Test with existing value set to current frame" ); 00321 kvp_frame_set_gint64( fixture->frame, "/test", 1 ); 00322 result_value = kvp_frame_get_slot_path( fixture->frame, "test", NULL ); 00323 g_assert( result_value ); 00324 g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_GINT64 ); 00325 g_assert_cmpint( kvp_value_get_gint64( result_value ), == , 1 ); 00326 00327 g_test_message( "Test should return null as test is not a frame" ); 00328 kvp_frame_set_gint64( fixture->frame, "/test/test2", 2 ); 00329 result_value = kvp_frame_get_slot_path( fixture->frame, "test", "test2", NULL ); 00330 g_assert( !result_value ); 00331 00332 g_test_message( "Test should return last value in the path" ); 00333 kvp_frame_set_gint64( fixture->frame, "/test2/test3", 2 ); 00334 result_value = kvp_frame_get_slot_path( fixture->frame, "test2", "test3", NULL ); 00335 g_assert( result_value ); 00336 g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_GINT64 ); 00337 g_assert_cmpint( kvp_value_get_gint64( result_value ), == , 2 ); 00338 00339 g_test_message( "Test should return null as last value in the path does not exist" ); 00340 result_value = kvp_frame_get_slot_path( fixture->frame, "test2", "test3", "test4", NULL ); 00341 g_assert( !result_value ); 00342 } 00343 00344 static void 00345 test_kvp_frame_get_slot_path_gslist( Fixture *fixture, gconstpointer pData ) 00346 { 00347 /* similar to previous test except path is passed as GSList*/ 00348 GSList *path_list = NULL; 00349 KvpValue *result_value = NULL ; 00350 00351 g_assert( fixture->frame ); 00352 g_assert( kvp_frame_is_empty( fixture->frame ) ); 00353 00354 g_test_message( "Test with non existing path should return NULL" ); 00355 path_list = g_slist_append (path_list, "test"); 00356 path_list = g_slist_append (path_list, "test2"); 00357 result_value = kvp_frame_get_slot_path_gslist( fixture->frame, path_list ); 00358 g_assert( !result_value ); 00359 00360 g_test_message( "Test with existing value set to current frame" ); 00361 path_list = g_slist_remove( path_list, "test2" ); 00362 kvp_frame_set_gint64( fixture->frame, "/test", 1 ); 00363 result_value = kvp_frame_get_slot_path_gslist( fixture->frame, path_list ); 00364 g_assert( result_value ); 00365 g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_GINT64 ); 00366 g_assert_cmpint( kvp_value_get_gint64( result_value ), == , 1 ); 00367 00368 g_test_message( "Test should return null as test is not a frame" ); 00369 path_list = g_slist_append (path_list, "test2"); 00370 kvp_frame_set_gint64( fixture->frame, "/test/test2", 2 ); 00371 result_value = kvp_frame_get_slot_path_gslist( fixture->frame, path_list ); 00372 g_assert( !result_value ); 00373 00374 g_test_message( "Test should return last value in the path" ); 00375 path_list = g_slist_remove( path_list, "test" ); 00376 path_list = g_slist_append (path_list, "test3"); 00377 kvp_frame_set_gint64( fixture->frame, "/test2/test3", 2 ); 00378 result_value = kvp_frame_get_slot_path_gslist( fixture->frame, path_list ); 00379 g_assert( result_value ); 00380 g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_GINT64 ); 00381 g_assert_cmpint( kvp_value_get_gint64( result_value ), == , 2 ); 00382 00383 g_test_message( "Test should return null as last value in the path does not exist" ); 00384 path_list = g_slist_append (path_list, "test4"); 00385 result_value = kvp_frame_get_slot_path_gslist( fixture->frame, path_list ); 00386 g_assert( !result_value ); 00387 g_slist_free( path_list ); 00388 } 00389 00390 static void 00391 test_kvp_frame_add_frame_nc( Fixture *fixture, gconstpointer pData ) 00392 { 00393 /* basically we test static function kvp_frame_add_value_nc 00394 * if path not exist it's created 00395 * if gslist exist on the path new value added to the list 00396 * if any other value exist it's converted to gslist and newvalue added 00397 */ 00398 KvpFrame *test_frame = NULL, 00399 *test_frame2 = NULL, 00400 *test_frame3 = NULL, 00401 *result_frame = NULL; 00402 KvpValue *result_value = NULL; 00403 GList *result_list = NULL; 00404 00405 g_assert( fixture->frame ); 00406 g_assert( kvp_frame_is_empty( fixture->frame ) ); 00407 00408 g_test_message( "Test when path does not exist it is created" ); 00409 result_frame = kvp_frame_get_frame( fixture->frame, "/test/test2/test3" ); 00410 g_assert( !result_frame ); 00411 test_frame = kvp_frame_new(); 00412 kvp_frame_add_frame_nc( fixture->frame, "/test/test2/test3", test_frame ); 00413 result_frame = kvp_frame_get_frame( fixture->frame, "/test/test2/test3" ); 00414 g_assert( result_frame ); 00415 g_assert( result_frame == test_frame ); /* no copying done */ 00416 result_frame = kvp_frame_get_frame( fixture->frame, "/test/test2" ); 00417 g_assert( result_frame != test_frame ); 00418 result_frame = kvp_frame_get_frame( fixture->frame, "/test" ); 00419 g_assert( result_frame != test_frame ); 00420 00421 g_test_message( "Test when value exist on the path it's converted to bag and new value added" ); 00422 test_frame2 = kvp_frame_new(); 00423 kvp_frame_add_frame_nc( fixture->frame, "/test/test2/test3", test_frame2 ); 00424 result_value = kvp_frame_get_value( fixture->frame, "/test/test2/test3" ); 00425 result_list = kvp_value_get_glist( result_value ); 00426 g_assert( result_list ); 00427 g_assert_cmpint( g_list_length( result_list ), == , 2 ); 00428 result_value = g_list_first( result_list )->data; 00429 g_assert( result_value ); 00430 g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_FRAME ); 00431 g_assert( kvp_value_get_frame( result_value ) == test_frame ); 00432 result_value = g_list_next( result_list )->data; 00433 g_assert( result_value ); 00434 g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_FRAME ); 00435 g_assert( kvp_value_get_frame( result_value ) == test_frame2 ); 00436 00437 g_test_message( "Test when bag exists on the path new values are added to it" ); 00438 test_frame3 = kvp_frame_new(); 00439 kvp_frame_add_frame_nc( fixture->frame, "/test/test2/test3", test_frame3 ); 00440 result_value = kvp_frame_get_value( fixture->frame, "/test/test2/test3" ); 00441 g_assert( result_list == kvp_value_get_glist( result_value ) ); /* same list used */ 00442 g_assert_cmpint( g_list_length( result_list ), == , 3 ); 00443 result_value = g_list_first( result_list )->data; 00444 g_assert( result_value ); 00445 g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_FRAME ); 00446 g_assert( kvp_value_get_frame( result_value ) == test_frame ); 00447 result_value = g_list_next( result_list )->data; 00448 g_assert( result_value ); 00449 g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_FRAME ); 00450 g_assert( kvp_value_get_frame( result_value ) == test_frame2 ); 00451 result_value = g_list_last( result_list )->data; 00452 g_assert( result_value ); 00453 g_assert( kvp_value_get_type( result_value ) == KVP_TYPE_FRAME ); 00454 g_assert( kvp_value_get_frame( result_value ) == test_frame3 ); 00455 } 00456 00457 static void 00458 test_kvp_value_copy( void ) 00459 { 00460 KvpValue *gint64_orig_value, *gint64_copy_value; 00461 KvpValue *double_orig_value, *double_copy_value; 00462 KvpValue *numeric_orig_value, *numeric_copy_value; 00463 KvpValue *string_orig_value, *string_copy_value; 00464 KvpValue *guid_orig_value, *guid_copy_value; 00465 KvpValue *timespec_orig_value, *timespec_copy_value; 00466 KvpValue *glist_orig_value, *glist_copy_value; 00467 KvpValue *frame_orig_value, *frame_copy_value; 00468 00469 /* data init */ 00470 gnc_numeric gnc_numeric_orig, gnc_numeric_copy; 00471 GncGUID *guid_orig, *guid_copy; 00472 Timespec ts_orig, ts_copy; 00473 GList *list_orig, *list_copy; 00474 KvpFrame *frame_orig, *frame_copy; 00475 00476 gnc_numeric_orig = gnc_numeric_zero(); 00477 guid_orig = guid_malloc(); 00478 guid_new( guid_orig ); 00479 ts_orig.tv_sec = 1; 00480 ts_orig.tv_nsec = 1; 00481 list_orig = NULL; 00482 list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); 00483 frame_orig = kvp_frame_new(); 00484 00485 g_test_message( "Test creates original values and checks copies of them" ); 00486 gint64_orig_value = kvp_value_new_gint64( 2 ); 00487 double_orig_value = kvp_value_new_double( 3.3 ); 00488 numeric_orig_value = kvp_value_new_gnc_numeric( gnc_numeric_orig ); 00489 string_orig_value = kvp_value_new_string( "abcdefghijklmnop" ); 00490 guid_orig_value = kvp_value_new_guid( guid_orig ); 00491 timespec_orig_value = kvp_value_new_timespec( ts_orig ); 00492 glist_orig_value = kvp_value_new_glist( list_orig ); 00493 frame_orig_value = kvp_value_new_frame( frame_orig ); 00494 g_assert( gint64_orig_value && double_orig_value && numeric_orig_value && string_orig_value 00495 && guid_orig_value && timespec_orig_value && glist_orig_value && frame_orig_value ); 00496 00497 /* copy values */ 00498 gint64_copy_value = kvp_value_copy( gint64_orig_value ); 00499 g_assert( gint64_copy_value ); 00500 g_assert( gint64_copy_value != gint64_orig_value ); 00501 g_assert( kvp_value_get_type( gint64_copy_value ) == KVP_TYPE_GINT64 ); 00502 g_assert_cmpint( kvp_value_get_gint64( gint64_copy_value ), == , 2 ); 00503 00504 double_copy_value = kvp_value_copy( double_orig_value ); 00505 g_assert( double_copy_value ); 00506 g_assert( double_copy_value != double_orig_value ); 00507 g_assert( kvp_value_get_type( double_copy_value ) == KVP_TYPE_DOUBLE ); 00508 g_assert_cmpfloat( kvp_value_get_double( double_copy_value ), == , 3.3 ); 00509 00510 numeric_copy_value = kvp_value_copy( numeric_orig_value ); 00511 g_assert( numeric_copy_value ); 00512 g_assert( numeric_copy_value != numeric_orig_value ); 00513 g_assert( kvp_value_get_type( numeric_copy_value ) == KVP_TYPE_NUMERIC ); 00514 gnc_numeric_copy = kvp_value_get_numeric( numeric_copy_value ); 00515 g_assert_cmpfloat( gnc_numeric_copy.num, == , gnc_numeric_orig.num ); 00516 g_assert_cmpfloat( gnc_numeric_copy.denom, == , gnc_numeric_orig.denom ); 00517 00518 string_copy_value = kvp_value_copy( string_orig_value ); 00519 g_assert( string_copy_value ); 00520 g_assert( string_copy_value != string_orig_value ); 00521 g_assert( kvp_value_get_type( string_copy_value ) == KVP_TYPE_STRING ); 00522 g_assert_cmpstr( kvp_value_get_string( string_copy_value ), == , "abcdefghijklmnop" ); 00523 00524 guid_copy_value = kvp_value_copy( guid_orig_value ); 00525 g_assert( guid_copy_value ); 00526 g_assert( guid_copy_value != guid_orig_value ); 00527 g_assert( kvp_value_get_type( guid_copy_value ) == KVP_TYPE_GUID ); 00528 guid_copy = kvp_value_get_guid( guid_copy_value ); 00529 g_assert( guid_orig != guid_copy ); 00530 g_assert( guid_equal( guid_orig, guid_copy ) ); 00531 00532 timespec_copy_value = kvp_value_copy( timespec_orig_value ); 00533 g_assert( timespec_copy_value ); 00534 g_assert( timespec_copy_value != timespec_orig_value ); 00535 g_assert( kvp_value_get_type( timespec_copy_value ) == KVP_TYPE_TIMESPEC ); 00536 ts_copy = kvp_value_get_timespec( timespec_copy_value ); 00537 g_assert_cmpfloat( ts_copy.tv_sec, == , ts_orig.tv_sec ); 00538 g_assert_cmpfloat( ts_copy.tv_nsec, == , ts_orig.tv_nsec ); 00539 00540 glist_copy_value = kvp_value_copy( glist_orig_value ); 00541 g_assert( glist_copy_value ); 00542 g_assert( glist_copy_value != glist_orig_value ); 00543 g_assert( kvp_value_get_type( glist_copy_value ) == KVP_TYPE_GLIST ); 00544 list_copy = kvp_value_get_glist( glist_copy_value ); 00545 g_assert( list_copy != list_orig ); 00546 g_assert_cmpint( g_list_length( list_copy ), == , g_list_length( list_orig ) ); 00547 g_assert_cmpint( kvp_glist_compare( list_orig, list_copy ), == , 0 ); 00548 00549 frame_copy_value = kvp_value_copy( frame_orig_value ); 00550 g_assert( frame_copy_value ); 00551 g_assert( frame_copy_value != frame_orig_value ); 00552 g_assert( kvp_value_get_type( frame_copy_value ) == KVP_TYPE_FRAME ); 00553 frame_copy = kvp_value_get_frame( frame_copy_value ); 00554 g_assert_cmpint( kvp_frame_compare( frame_orig, frame_copy ), == , 0 ); 00555 00556 /* destroy objects */ 00557 kvp_value_delete( gint64_orig_value ); 00558 kvp_value_delete( double_orig_value ); 00559 kvp_value_delete( numeric_orig_value ); 00560 kvp_value_delete( string_orig_value ); 00561 kvp_value_delete( guid_orig_value ); 00562 kvp_value_delete( timespec_orig_value ); 00563 kvp_value_delete( glist_orig_value ); 00564 kvp_value_delete( frame_orig_value ); 00565 00566 kvp_value_delete( gint64_copy_value ); 00567 kvp_value_delete( double_copy_value ); 00568 kvp_value_delete( numeric_copy_value ); 00569 kvp_value_delete( string_copy_value ); 00570 kvp_value_delete( guid_copy_value ); 00571 kvp_value_delete( timespec_copy_value ); 00572 kvp_value_delete( glist_copy_value ); 00573 kvp_value_delete( frame_copy_value ); 00574 } 00575 00576 static void 00577 test_kvp_glist_copy( void ) 00578 { 00579 GList *value_list = NULL, *copy_list = NULL, *lp1 = NULL, *lp2 = NULL; 00580 KvpValue *gint64_value; 00581 KvpValue *double_value; 00582 KvpValue *numeric_value; 00583 KvpValue *string_value; 00584 KvpValue *guid_value; 00585 KvpValue *timespec_value; 00586 KvpValue *glist_value; 00587 KvpValue *frame_value; 00588 00589 gnc_numeric gnc_numeric_orig; 00590 GncGUID *guid_orig; 00591 Timespec ts_orig; 00592 GList *list_orig; 00593 KvpFrame *frame_orig; 00594 00595 gnc_numeric_orig = gnc_numeric_zero(); 00596 guid_orig = guid_malloc(); 00597 guid_new( guid_orig ); 00598 ts_orig.tv_sec = 1; 00599 ts_orig.tv_nsec = 1; 00600 list_orig = NULL; 00601 list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); 00602 frame_orig = kvp_frame_new(); 00603 00604 gint64_value = kvp_value_new_gint64( 2 ); 00605 double_value = kvp_value_new_double( 3.3 ); 00606 numeric_value = kvp_value_new_gnc_numeric( gnc_numeric_orig ); 00607 string_value = kvp_value_new_string( "abcdefghijklmnop" ); 00608 guid_value = kvp_value_new_guid( guid_orig ); 00609 timespec_value = kvp_value_new_timespec( ts_orig ); 00610 glist_value = kvp_value_new_glist( list_orig ); 00611 frame_value = kvp_value_new_frame( frame_orig ); 00612 00613 value_list = g_list_append( value_list, gint64_value ); 00614 value_list = g_list_append( value_list, double_value ); 00615 value_list = g_list_append( value_list, numeric_value ); 00616 value_list = g_list_append( value_list, string_value ); 00617 value_list = g_list_append( value_list, guid_value ); 00618 value_list = g_list_append( value_list, timespec_value ); 00619 value_list = g_list_append( value_list, glist_value ); 00620 value_list = g_list_append( value_list, frame_value ); 00621 g_assert( value_list ); 00622 g_assert_cmpint( g_list_length( value_list ), == , 8 ); 00623 00624 g_test_message( "Test list and all values are copied to new list" ); 00625 copy_list = kvp_glist_copy( value_list ); 00626 g_assert( copy_list ); 00627 g_assert( copy_list != value_list ); 00628 g_assert_cmpint( g_list_length( copy_list ), == , 8 ); 00629 lp1 = value_list; 00630 lp2 = copy_list; 00631 while (lp1 && lp2) 00632 { 00633 KvpValue *v1 = (KvpValue *) lp1->data; 00634 KvpValue *v2 = (KvpValue *) lp2->data; 00635 g_assert( v1 != v2 ); 00636 g_assert_cmpint( kvp_value_compare(v1, v2), == , 0 ); 00637 lp1 = lp1->next; 00638 lp2 = lp2->next; 00639 } 00640 g_assert_cmpint( kvp_glist_compare( value_list, copy_list ), == , 0 ); 00641 00642 /* destroy */ 00643 kvp_glist_delete( value_list ); 00644 kvp_glist_delete( copy_list ); 00645 } 00646 00647 static void 00648 test_kvp_glist_compare( void ) 00649 { 00650 GList *list1 = NULL, *list2 = NULL; 00651 00652 KvpValue *gint64_value; 00653 KvpValue *double_value; 00654 KvpValue *numeric_value; 00655 KvpValue *string_value; 00656 KvpValue *guid_value; 00657 KvpValue *timespec_value; 00658 KvpValue *glist_value; 00659 KvpValue *frame_value; 00660 00661 gnc_numeric gnc_numeric_orig; 00662 GncGUID *guid_orig; 00663 Timespec ts_orig; 00664 GList *list_orig; 00665 KvpFrame *frame_orig; 00666 00667 gnc_numeric_orig = gnc_numeric_zero(); 00668 guid_orig = guid_malloc(); 00669 guid_new( guid_orig ); 00670 ts_orig.tv_sec = 1; 00671 ts_orig.tv_nsec = 1; 00672 list_orig = NULL; 00673 list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); 00674 frame_orig = kvp_frame_new(); 00675 00676 gint64_value = kvp_value_new_gint64( 2 ); 00677 double_value = kvp_value_new_double( 3.3 ); 00678 numeric_value = kvp_value_new_gnc_numeric( gnc_numeric_orig ); 00679 string_value = kvp_value_new_string( "abcdefghijklmnop" ); 00680 guid_value = kvp_value_new_guid( guid_orig ); 00681 timespec_value = kvp_value_new_timespec( ts_orig ); 00682 glist_value = kvp_value_new_glist( list_orig ); 00683 frame_value = kvp_value_new_frame( frame_orig ); 00684 00685 /* init list 1 */ 00686 list1 = g_list_append( list1, gint64_value ); 00687 list1 = g_list_append( list1, double_value ); 00688 list1 = g_list_append( list1, numeric_value ); 00689 list1 = g_list_append( list1, string_value ); 00690 list1 = g_list_append( list1, guid_value ); 00691 list1 = g_list_append( list1, timespec_value ); 00692 list1 = g_list_append( list1, glist_value ); 00693 list1 = g_list_append( list1, frame_value ); 00694 g_assert( list1 ); 00695 g_assert_cmpint( g_list_length( list1 ), == , 8 ); 00696 00697 g_test_message( "Test when list is the same" ); 00698 list2 = list1; 00699 g_assert_cmpint( kvp_glist_compare( list1, list2 ), == , 0 ); 00700 00701 g_test_message( "Test when list1 is null" ); 00702 g_assert_cmpint( kvp_glist_compare( NULL, list2 ), == , -1 ); 00703 00704 g_test_message( "Test when list2 is null" ); 00705 g_assert_cmpint( kvp_glist_compare( list1, NULL ), == , 1 ); 00706 00707 g_test_message( "Copy list and test they are equal" ); 00708 list2 = kvp_glist_copy( list1 ); 00709 g_assert( list1 != list2 ); 00710 g_assert_cmpint( g_list_length( list1 ), == , g_list_length( list2 ) ); 00711 g_assert_cmpint( kvp_glist_compare( list1, list2 ), == , 0 ); 00712 00713 g_test_message( "Test when list 1 is shorter lists are not equal" ); 00714 list1 = g_list_remove( list1, frame_value ); 00715 g_assert_cmpint( g_list_length( list1 ), == , 7 ); 00716 g_assert_cmpint( g_list_length( list2 ), == , 8 ); 00717 g_assert_cmpint( kvp_glist_compare( list1, list2 ), == , -1 ); 00718 00719 g_test_message( "Test when list 2 is shorter lists are not equal" ); 00720 list1 = g_list_append( list1, frame_value ); 00721 list1 = g_list_append( list1, frame_value ); 00722 g_assert_cmpint( g_list_length( list1 ), == , 9 ); 00723 g_assert_cmpint( g_list_length( list2 ), == , 8 ); 00724 g_assert_cmpint( kvp_glist_compare( list1, list2 ), == , 1 ); 00725 00726 g_test_message( "Test when data is not equal lists are not equal" ); 00727 list1 = g_list_remove( list1, frame_value ); 00728 g_assert_cmpint( g_list_length( list1 ), == , g_list_length( list2 ) ); 00729 g_assert_cmpint( kvp_glist_compare( list1, list2 ), == , 0 ); 00730 list1 = g_list_remove( list1, gint64_value ); 00731 kvp_value_delete( gint64_value ); 00732 list1 = g_list_prepend( list1, kvp_value_new_gint64( 5 ) ); 00733 g_assert_cmpint( g_list_length( list1 ), == , g_list_length( list2 ) ); 00734 g_assert_cmpint( kvp_glist_compare( list1, list2 ), != , 0 ); 00735 00736 /* delete lists */ 00737 kvp_glist_delete( list1 ); 00738 kvp_glist_delete( list2 ); 00739 } 00740 00741 static void 00742 test_kvp_value_compare( void ) 00743 { 00744 KvpValue *gint64_orig_value, *gint64_copy_value; 00745 KvpValue *double_orig_value, *double_copy_value; 00746 KvpValue *numeric_orig_value, *numeric_copy_value; 00747 KvpValue *string_orig_value, *string_copy_value; 00748 KvpValue *guid_orig_value, *guid_copy_value; 00749 KvpValue *timespec_orig_value, *timespec_copy_value; 00750 KvpValue *glist_orig_value, *glist_copy_value; 00751 KvpValue *frame_orig_value, *frame_copy_value; 00752 00753 /* data init */ 00754 gnc_numeric gnc_numeric_orig, gnc_numeric_copy; 00755 GncGUID *guid_orig, *guid_copy; 00756 Timespec ts_orig, ts_copy; 00757 GList *list_orig, *list_copy; 00758 KvpFrame *frame_orig, *frame_copy; 00759 00760 gnc_numeric_orig = gnc_numeric_zero(); 00761 gnc_numeric_copy = gnc_numeric_zero(); 00762 guid_orig = guid_malloc(); 00763 guid_new( guid_orig ); 00764 guid_copy = guid_malloc(); 00765 guid_new( guid_copy ); 00766 ts_orig.tv_sec = 1; 00767 ts_orig.tv_nsec = 1; 00768 ts_copy.tv_sec = 2; 00769 ts_copy.tv_nsec = 2; 00770 list_orig = NULL; 00771 list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); 00772 list_copy = NULL; 00773 list_copy = g_list_append( list_copy, kvp_value_new_string( "abcdefg" ) ); 00774 frame_orig = kvp_frame_new(); 00775 frame_copy = kvp_frame_new(); 00776 00777 gint64_orig_value = kvp_value_new_gint64( 2 ); 00778 gint64_copy_value = kvp_value_new_gint64( 5 ); 00779 double_orig_value = kvp_value_new_double( 3.3 ); 00780 double_copy_value = kvp_value_new_double( 3.5 ); 00781 numeric_orig_value = kvp_value_new_gnc_numeric( gnc_numeric_orig ); 00782 numeric_copy_value = kvp_value_new_gnc_numeric( gnc_numeric_copy ); 00783 string_orig_value = kvp_value_new_string( "abcdefghijklmnop" ); 00784 string_copy_value = kvp_value_new_string( "abcdefghijklmnop" ); 00785 guid_orig_value = kvp_value_new_guid( guid_orig ); 00786 guid_copy_value = kvp_value_new_guid( guid_copy ); 00787 timespec_orig_value = kvp_value_new_timespec( ts_orig ); 00788 timespec_copy_value = kvp_value_new_timespec( ts_copy ); 00789 glist_orig_value = kvp_value_new_glist( list_orig ); 00790 glist_copy_value = kvp_value_new_glist( list_copy ); 00791 frame_orig_value = kvp_value_new_frame( frame_orig ); 00792 frame_copy_value = kvp_value_new_frame( frame_copy ); 00793 00794 g_test_message( "Test the same kvpvalue is equal" ); 00795 g_assert_cmpint( kvp_value_compare( gint64_orig_value, gint64_orig_value ), == , 0 ); 00796 00797 g_test_message( "Test first value is null" ); 00798 g_assert_cmpint( kvp_value_compare( NULL, gint64_orig_value ), == , -1 ); 00799 00800 g_test_message( "Test second value is null" ); 00801 g_assert_cmpint( kvp_value_compare( gint64_orig_value, NULL ), == , 1 ); 00802 00803 g_test_message( "Test diffrent data types first is lesser" ); 00804 g_assert_cmpint( kvp_value_compare( gint64_orig_value, double_orig_value ), == , -1 ); 00805 00806 g_test_message( "Test diffrent data types second is lesser" ); 00807 g_assert_cmpint( kvp_value_compare( double_orig_value, gint64_orig_value ), == , 1 ); 00808 00809 /* testing all different cases of data equality is not the aim 00810 * of this test. Rather we check that all data types are being compared. 00811 */ 00812 g_test_message( "Test different kvpvalues of all the types" ); 00813 g_assert_cmpint( kvp_value_compare( gint64_orig_value, gint64_copy_value ), == , -1 ); 00814 g_assert_cmpint( kvp_value_compare( gint64_copy_value, gint64_orig_value ), == , 1 ); 00815 g_assert_cmpint( kvp_value_compare( double_orig_value, double_copy_value ), == , double_compare( 3.3, 3.5 ) ); 00816 g_assert_cmpint( kvp_value_compare( numeric_orig_value, numeric_copy_value ), == , gnc_numeric_compare( gnc_numeric_orig, gnc_numeric_copy ) ); 00817 g_assert_cmpint( kvp_value_compare( string_orig_value, string_copy_value ), == , strcmp( "abcdefghijklmnop", "abcdefghijklmnop" ) ); 00818 g_assert_cmpint( kvp_value_compare( guid_orig_value, guid_copy_value ), == , guid_compare( guid_orig, guid_copy ) ); 00819 g_assert_cmpint( kvp_value_compare( timespec_orig_value, timespec_copy_value ), == , timespec_cmp( &ts_orig, &ts_copy ) ); 00820 g_assert_cmpint( kvp_value_compare( glist_orig_value, glist_copy_value ), == , kvp_glist_compare( list_orig, list_copy ) ); 00821 g_assert_cmpint( kvp_value_compare( frame_orig_value, frame_copy_value ), == , kvp_frame_compare( frame_orig, frame_copy ) ); 00822 00823 /* destroy objects */ 00824 kvp_value_delete( gint64_orig_value ); 00825 kvp_value_delete( double_orig_value ); 00826 kvp_value_delete( numeric_orig_value ); 00827 kvp_value_delete( string_orig_value ); 00828 kvp_value_delete( guid_orig_value ); 00829 kvp_value_delete( timespec_orig_value ); 00830 kvp_value_delete( glist_orig_value ); 00831 kvp_value_delete( frame_orig_value ); 00832 00833 kvp_value_delete( gint64_copy_value ); 00834 kvp_value_delete( double_copy_value ); 00835 kvp_value_delete( numeric_copy_value ); 00836 kvp_value_delete( string_copy_value ); 00837 kvp_value_delete( guid_copy_value ); 00838 kvp_value_delete( timespec_copy_value ); 00839 kvp_value_delete( glist_copy_value ); 00840 kvp_value_delete( frame_copy_value ); 00841 } 00842 00843 static void 00844 test_kvp_value_new_foo_nc( void ) 00845 { 00846 KvpValue *binary_value_nc, *glist_value_nc, *frame_value_nc; 00847 void *val; 00848 guint64 size; 00849 GList *list = NULL; 00850 KvpFrame *frame = NULL; 00851 00852 g_test_message( "Test new binary values are not copied" ); 00853 val = g_new0( char, 5 ); 00854 size = sizeof( val ); 00855 binary_value_nc = kvp_value_new_binary_nc( val, size ); 00856 g_assert( binary_value_nc ); 00857 g_assert( kvp_value_get_type( binary_value_nc ) == KVP_TYPE_BINARY ); 00858 g_assert( kvp_value_get_binary( binary_value_nc, &size ) == val ); 00859 00860 g_test_message( "Test new glist is not copied" ); 00861 list = g_list_append( list, kvp_value_new_gint64( 2 ) ); 00862 g_assert_cmpint( g_list_length( list ), == , 1 ); 00863 glist_value_nc = kvp_value_new_glist_nc( list ); 00864 g_assert( glist_value_nc ); 00865 g_assert( kvp_value_get_type( glist_value_nc ) == KVP_TYPE_GLIST ); 00866 g_assert( kvp_value_get_glist( glist_value_nc ) == list ); 00867 00868 g_test_message( "Test new frame is not copied" ); 00869 frame = kvp_frame_new(); 00870 frame_value_nc = kvp_value_new_frame_nc( frame ); 00871 g_assert( frame_value_nc ); 00872 g_assert( kvp_value_get_type( frame_value_nc ) == KVP_TYPE_FRAME ); 00873 g_assert( kvp_value_get_frame( frame_value_nc ) == frame ); 00874 00875 kvp_value_delete( binary_value_nc ); 00876 kvp_value_delete( glist_value_nc ); 00877 kvp_value_delete( frame_value_nc ); 00878 } 00879 00880 static void 00881 test_kvp_frame_compare( Fixture *fixture, gconstpointer pData ) 00882 { 00883 KvpFrame *cmp_frame = NULL; 00884 00885 cmp_frame = kvp_frame_new(); 00886 g_assert( cmp_frame ); 00887 00888 g_test_message( "Test the same frame is equal with itself" ); 00889 g_assert_cmpint( kvp_frame_compare( fixture->frame, fixture->frame ), == , 0 ); 00890 00891 g_test_message( "Test first frame null second not null" ); 00892 g_assert_cmpint( kvp_frame_compare( NULL, fixture->frame ), == , -1 ); 00893 00894 g_test_message( "Test first frame not null second null" ); 00895 g_assert_cmpint( kvp_frame_compare( fixture->frame, NULL ), == , 1 ); 00896 00897 g_test_message( "Test first frame is empty second not empty" ); 00898 kvp_frame_set_gint64( fixture->frame, "/test/test2", 64 ); 00899 g_assert( !kvp_frame_is_empty( fixture->frame ) ); 00900 g_assert( kvp_frame_is_empty( cmp_frame ) ); 00901 g_assert_cmpint( kvp_frame_compare( cmp_frame, fixture->frame ), == , -1 ); 00902 00903 g_test_message( "Test first frame is not empty second is empty" ); 00904 g_assert_cmpint( kvp_frame_compare( fixture->frame, cmp_frame ), == , 1 ); 00905 00906 g_test_message( "Test when frames are equal" ); 00907 kvp_frame_set_gint64( cmp_frame, "/test/test2", 64 ); 00908 g_assert( !kvp_frame_is_empty( cmp_frame ) ); 00909 g_assert_cmpint( kvp_frame_compare( fixture->frame, cmp_frame ), == , 0 ); 00910 00911 g_test_message( "Test when frames have equal data but second frame has additional slot set" ); 00912 kvp_frame_set_string( fixture->frame, "/test/test3", "abcdefghijklmnop" ); 00913 g_assert_cmpint( kvp_frame_compare( cmp_frame, fixture->frame ), == , -1 ); 00914 00915 g_test_message( "Test when frames have equal data but first frame has additional slot set" ); 00916 g_assert_cmpint( kvp_frame_compare( fixture->frame, cmp_frame ), == , 1 ); 00917 00918 g_test_message( "Test when frames have equal number of slots second frame has different data in one slot" ); 00919 kvp_frame_set_string( cmp_frame, "/test/test3", "abcdefg" ); 00920 g_assert_cmpint( kvp_frame_compare( cmp_frame, fixture->frame ), < , 0 ); 00921 00922 g_test_message( "Test when frames have equal number of slots second frame has different data in one slot" ); 00923 g_assert_cmpint( kvp_frame_compare( fixture->frame, cmp_frame ), > , 0 ); 00924 00925 kvp_frame_delete( cmp_frame ); 00926 } 00927 00928 static void 00929 test_binary_to_string( void ) 00930 { 00931 gchar *result; 00932 guchar *val; 00933 guint32 size; 00934 val = g_new0( guchar, 5 ); 00935 size = 5 * sizeof( guchar ); 00936 val[0] = (guchar) 0; 00937 val[1] = (guchar) 9; 00938 val[2] = (guchar) 10; 00939 val[3] = (guchar) 255; 00940 val[4] = (guchar) 256; 00941 00942 result = binary_to_string( val, size ); 00943 g_assert( result ); 00944 g_assert_cmpstr( result, == , "00090aff00" ); 00945 00946 g_free( val ); 00947 g_free( result ); 00948 } 00949 00950 static void 00951 test_kvp_value_to_string( void ) 00952 { 00953 const gchar *str_tmp; 00954 gchar *str_tmp2, *str_tmp3; 00955 gchar *result; 00956 KvpValue *gint64_value; 00957 KvpValue *double_value; 00958 KvpValue *numeric_value; 00959 KvpValue *string_value; 00960 KvpValue *guid_value; 00961 KvpValue *timespec_value; 00962 KvpValue *glist_value; 00963 KvpValue *frame_value; 00964 00965 gnc_numeric gnc_numeric_orig; 00966 GncGUID *guid_orig; 00967 Timespec ts_orig; 00968 GList *list_orig; 00969 KvpFrame *frame_orig; 00970 00971 gnc_numeric_orig = gnc_numeric_zero(); 00972 guid_orig = guid_malloc(); 00973 guid_new( guid_orig ); 00974 ts_orig.tv_sec = 1; 00975 ts_orig.tv_nsec = 1; 00976 list_orig = NULL; 00977 list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); 00978 frame_orig = kvp_frame_new(); 00979 00980 gint64_value = kvp_value_new_gint64( 2 ); 00981 double_value = kvp_value_new_double( 3.3 ); 00982 numeric_value = kvp_value_new_gnc_numeric( gnc_numeric_orig ); 00983 string_value = kvp_value_new_string( "abcdefghijklmnop" ); 00984 guid_value = kvp_value_new_guid( guid_orig ); 00985 timespec_value = kvp_value_new_timespec( ts_orig ); 00986 glist_value = kvp_value_new_glist( list_orig ); 00987 frame_value = kvp_value_new_frame( frame_orig ); 00988 00989 g_test_message( "Test value string representation with different data types" ); 00990 result = kvp_value_to_string( gint64_value ); 00991 g_assert( result ); 00992 g_assert_cmpstr( result, == , "KVP_VALUE_GINT64(2)" ); 00993 g_free( result ); 00994 00995 result = kvp_value_to_string( double_value ); 00996 g_assert( result ); 00997 g_assert_cmpstr( result, == , "KVP_VALUE_DOUBLE(3.3)" ); 00998 g_free( result ); 00999 01000 result = kvp_value_to_string( numeric_value ); 01001 g_assert( result ); 01002 g_assert_cmpstr( result, == , "KVP_VALUE_NUMERIC(0/1)" ); 01003 g_free( result ); 01004 01005 result = kvp_value_to_string( string_value ); 01006 g_assert( result ); 01007 g_assert_cmpstr( result, == , "KVP_VALUE_STRING(abcdefghijklmnop)" ); 01008 g_free( result ); 01009 01010 result = kvp_value_to_string( guid_value ); 01011 g_assert( result ); 01012 str_tmp = guid_to_string( kvp_value_get_guid( guid_value ) ); 01013 str_tmp2 = g_strdup_printf("KVP_VALUE_GUID(%s)", str_tmp ? str_tmp : ""); 01014 g_assert_cmpstr( result, == , str_tmp2 ); 01015 g_free( result ); 01016 g_free( str_tmp2 ); 01017 01018 result = kvp_value_to_string( timespec_value ); 01019 g_assert( result ); 01020 str_tmp2 = g_new0 (char, 40); 01021 gnc_timespec_to_iso8601_buff( kvp_value_get_timespec( timespec_value ), str_tmp2 ); 01022 str_tmp3 = g_strdup_printf("KVP_VALUE_TIMESPEC(%s)", str_tmp2); 01023 g_assert_cmpstr( result, == , str_tmp3 ); 01024 g_free( result ); 01025 g_free( str_tmp2 ); 01026 g_free( str_tmp3 ); 01027 01028 result = kvp_value_to_string( glist_value ); 01029 g_assert( result ); 01030 g_assert_cmpstr( result, == , "KVP_VALUE_GLIST([ KVP_VALUE_STRING(abcdefghijklmnop), ])" ); 01031 g_free( result ); 01032 01033 result = kvp_value_to_string( frame_value ); 01034 g_assert( result ); 01035 g_assert_cmpstr( result, == , "KVP_VALUE_FRAME({\n}\n)" ); 01036 g_free( result ); 01037 01038 kvp_value_delete( gint64_value ); 01039 kvp_value_delete( double_value ); 01040 kvp_value_delete( numeric_value ); 01041 kvp_value_delete( string_value ); 01042 kvp_value_delete( guid_value ); 01043 kvp_value_delete( timespec_value ); 01044 kvp_value_delete( glist_value ); 01045 kvp_value_delete( frame_value ); 01046 } 01047 01048 static void 01049 test_kvp_frame_to_string( Fixture *fixture, gconstpointer pData ) 01050 { 01051 gchar *result; 01052 gnc_numeric test_gnc_numeric; 01053 GncGUID *test_guid; 01054 Timespec test_ts; 01055 KvpFrame *test_frame; 01056 01057 test_gnc_numeric = gnc_numeric_zero(); 01058 test_guid = guid_malloc(); 01059 guid_new( test_guid ); 01060 test_ts.tv_sec = 1; 01061 test_ts.tv_nsec = 1; 01062 test_frame = kvp_frame_new(); 01063 01064 g_assert( fixture->frame ); 01065 g_assert( kvp_frame_is_empty( fixture->frame ) ); 01066 01067 g_test_message( "Test empty frame" ); 01068 result = kvp_frame_to_string( fixture->frame ); 01069 g_assert_cmpstr( result, == , "{\n}\n" ); 01070 g_free( result ); 01071 01072 /* slots can be randomly distributed in hash table 01073 * instead of checking the whole return string we rather check if certain entries exist in it 01074 */ 01075 g_test_message( "Test with all data types and nested frames" ); 01076 kvp_frame_set_gint64( fixture->frame, "/gint64-type", 2 ); 01077 result = kvp_frame_to_string( fixture->frame ); 01078 g_assert( g_strrstr( result, " gint64-type => KVP_VALUE_GINT64(2),\n" ) != NULL ); 01079 g_free( result ); 01080 01081 kvp_frame_set_double( fixture->frame, "/double-type", 3.3 ); 01082 result = kvp_frame_to_string( fixture->frame ); 01083 g_assert( g_strrstr( result, " double-type => KVP_VALUE_DOUBLE(3.3),\n" ) != NULL ); 01084 g_free( result ); 01085 01086 kvp_frame_set_numeric( fixture->frame, "/numeric-type", test_gnc_numeric ); 01087 result = kvp_frame_to_string( fixture->frame ); 01088 g_assert( g_strrstr( result, " numeric-type => KVP_VALUE_NUMERIC(0/1),\n" ) != NULL ); 01089 g_free( result ); 01090 01091 kvp_frame_set_timespec( fixture->frame, "/timespec-type", test_ts ); 01092 result = kvp_frame_to_string( fixture->frame ); 01093 g_assert( g_strrstr( result, " timespec-type => KVP_VALUE_TIMESPEC" ) != NULL ); 01094 g_free( result ); 01095 01096 kvp_frame_set_string( fixture->frame, "/string-type", "abcdefghijklmnop" ); 01097 result = kvp_frame_to_string( fixture->frame ); 01098 g_assert( g_strrstr( result, " string-type => KVP_VALUE_STRING(abcdefghijklmnop),\n" ) != NULL ); 01099 g_free( result ); 01100 01101 kvp_frame_set_guid( fixture->frame, "/guid-type", test_guid ); 01102 result = kvp_frame_to_string( fixture->frame ); 01103 g_assert( g_strrstr( result, " guid-type => KVP_VALUE_GUID" ) != NULL ); 01104 g_free( result ); 01105 01106 kvp_frame_set_frame( fixture->frame, "/nested/frame-type", test_frame ); 01107 result = kvp_frame_to_string( fixture->frame ); 01108 g_assert( g_strrstr( result, " nested => KVP_VALUE_FRAME({\n frame-type => KVP_VALUE_FRAME({\n}\n),\n}\n),\n" ) != NULL ); 01109 g_free( result ); 01110 } 01111 01112 static void 01113 test_kvp_frame_set_slot_path( Fixture *fixture, gconstpointer pData ) 01114 { 01115 GHashTable *frame_hash = NULL; 01116 KvpValue *input_value, *output_value; 01117 01118 g_assert( fixture->frame ); 01119 g_assert( kvp_frame_is_empty( fixture->frame ) ); 01120 01121 g_test_message( "Test with a simple value added to the empty frame" ); 01122 input_value = kvp_value_new_gint64( 2 ); 01123 kvp_frame_set_slot_path( fixture->frame, input_value, "test", NULL ); 01124 output_value = kvp_frame_get_slot_path( fixture->frame, "test", NULL ); 01125 g_assert( output_value ); 01126 g_assert( input_value != output_value ); /* copied */ 01127 g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); 01128 kvp_value_delete( input_value ); 01129 01130 g_test_message( "Test when value is being replaced" ); 01131 input_value = kvp_value_new_double( 3.3 ); 01132 kvp_frame_set_slot_path( fixture->frame, input_value, "test", NULL ); 01133 output_value = kvp_frame_get_slot_path( fixture->frame, "test", NULL ); 01134 g_assert( output_value ); 01135 g_assert( input_value != output_value ); /* copied */ 01136 g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); /* old value removed */ 01137 frame_hash = kvp_frame_get_hash( fixture->frame ); 01138 g_assert( frame_hash ); 01139 g_assert_cmpint( g_hash_table_size( frame_hash ), == , 1 ); /* be sure it was replaced */ 01140 kvp_value_delete( input_value ); 01141 01142 g_test_message( "Test when existing path elements are not frames" ); 01143 input_value = kvp_value_new_string( "abcdefghijklmnop" ); 01144 kvp_frame_set_slot_path( fixture->frame, input_value, "test", "test2", NULL ); 01145 g_assert( kvp_frame_get_slot_path( fixture->frame, "test2", NULL ) == NULL );/* was not added */ 01146 g_assert_cmpint( kvp_value_compare( output_value, kvp_frame_get_slot_path( fixture->frame, "test", NULL ) ), == , 0 ); /* nothing changed */ 01147 g_assert_cmpint( g_hash_table_size( frame_hash ), == , 1 ); /* didn't change */ 01148 kvp_value_delete( input_value ); 01149 01150 g_test_message( "Test frames are created along the path when needed" ); 01151 input_value = kvp_value_new_string( "abcdefghijklmnop" ); 01152 kvp_frame_set_slot_path( fixture->frame, input_value, "test2", "test3", NULL ); 01153 output_value = kvp_frame_get_slot_path( fixture->frame, "test2", NULL ); 01154 g_assert( output_value ); 01155 g_assert( kvp_value_get_type( output_value ) == KVP_TYPE_FRAME ); 01156 output_value = kvp_frame_get_slot_path( fixture->frame, "test2", "test3", NULL ); 01157 g_assert( output_value ); 01158 g_assert( input_value != output_value ); /* copied */ 01159 g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); 01160 g_assert_cmpint( g_hash_table_size( frame_hash ), == , 2 ); 01161 kvp_value_delete( input_value ); 01162 } 01163 01164 static void 01165 test_kvp_frame_set_slot_path_gslist( Fixture *fixture, gconstpointer pData ) 01166 { 01167 /* similar to previous test except path is passed as GSList*/ 01168 GSList *path_list = NULL; 01169 GHashTable *frame_hash = NULL; 01170 KvpValue *input_value, *output_value; 01171 01172 g_assert( fixture->frame ); 01173 g_assert( kvp_frame_is_empty( fixture->frame ) ); 01174 01175 g_test_message( "Test with a simple value added to the empty frame" ); 01176 path_list = g_slist_append( path_list, "test" ); 01177 input_value = kvp_value_new_gint64( 2 ); 01178 kvp_frame_set_slot_path_gslist( fixture->frame, input_value, path_list ); 01179 output_value = kvp_frame_get_slot_path( fixture->frame, "test", NULL ); 01180 g_assert( output_value ); 01181 g_assert( input_value != output_value ); /* copied */ 01182 g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); 01183 kvp_value_delete( input_value ); 01184 01185 g_test_message( "Test when value is being replaced" ); 01186 input_value = kvp_value_new_double( 3.3 ); 01187 kvp_frame_set_slot_path_gslist( fixture->frame, input_value, path_list ); 01188 output_value = kvp_frame_get_slot_path( fixture->frame, "test", NULL ); 01189 g_assert( output_value ); 01190 g_assert( input_value != output_value ); /* copied */ 01191 g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); /* old value removed */ 01192 frame_hash = kvp_frame_get_hash( fixture->frame ); 01193 g_assert( frame_hash ); 01194 g_assert_cmpint( g_hash_table_size( frame_hash ), == , 1 ); /* be sure it was replaced */ 01195 kvp_value_delete( input_value ); 01196 01197 g_test_message( "Test when existing path elements are not frames" ); 01198 path_list = g_slist_append( path_list, "test2"); 01199 input_value = kvp_value_new_string( "abcdefghijklmnop" ); 01200 kvp_frame_set_slot_path_gslist( fixture->frame, input_value, path_list ); 01201 g_assert( kvp_frame_get_slot_path( fixture->frame, "test2", NULL ) == NULL );/* was not added */ 01202 g_assert_cmpint( kvp_value_compare( output_value, kvp_frame_get_slot_path( fixture->frame, "test", NULL ) ), == , 0 ); /* nothing changed */ 01203 g_assert_cmpint( g_hash_table_size( frame_hash ), == , 1 ); /* didn't change */ 01204 kvp_value_delete( input_value ); 01205 01206 g_test_message( "Test frames are created along the path when needed" ); 01207 path_list = g_slist_remove( path_list, "test" ); 01208 path_list = g_slist_append( path_list, "test3"); 01209 input_value = kvp_value_new_string( "abcdefghijklmnop" ); 01210 kvp_frame_set_slot_path_gslist( fixture->frame, input_value, path_list ); 01211 output_value = kvp_frame_get_slot_path( fixture->frame, "test2", NULL ); 01212 g_assert( output_value ); 01213 g_assert( kvp_value_get_type( output_value ) == KVP_TYPE_FRAME ); 01214 output_value = kvp_frame_get_slot_path( fixture->frame, "test2", "test3", NULL ); 01215 g_assert( output_value ); 01216 g_assert( input_value != output_value ); /* copied */ 01217 g_assert_cmpint( kvp_value_compare( output_value, input_value ), == , 0 ); 01218 g_assert_cmpint( g_hash_table_size( frame_hash ), == , 2 ); 01219 kvp_value_delete( input_value ); 01220 01221 g_slist_free( path_list ); 01222 } 01223 01224 static void 01225 test_kvp_frame_replace_slot_nc( Fixture *fixture, gconstpointer pData ) 01226 { 01227 GHashTable *frame_hash; 01228 KvpValue *orig_value, *orig_value2, *copy_value; 01229 /* test indirectly static function kvp_frame_replace_slot_nc */ 01230 g_assert( fixture->frame ); 01231 g_assert( kvp_frame_is_empty( fixture->frame ) ); 01232 01233 g_test_message( "Test when new value is created frame hash init and value stored in hash" ); 01234 orig_value = kvp_value_new_gint64( 2 ); 01235 kvp_frame_set_slot( fixture->frame, "test", orig_value ); 01236 g_assert( !kvp_frame_is_empty( fixture->frame ) ); 01237 frame_hash = kvp_frame_get_hash( fixture->frame ); 01238 g_assert( frame_hash ); 01239 g_assert_cmpint( g_hash_table_size( frame_hash ), == , 1 ); 01240 copy_value = g_hash_table_lookup( frame_hash, "test" ); 01241 g_assert( orig_value != copy_value ); 01242 g_assert_cmpint( kvp_value_compare( orig_value, copy_value ), == , 0 ); 01243 01244 g_test_message( "Test when value is replaced" ); 01245 orig_value2 = kvp_value_new_gint64( 5 ); 01246 kvp_frame_set_slot( fixture->frame, "test", orig_value2 ); 01247 frame_hash = kvp_frame_get_hash( fixture->frame ); 01248 g_assert( frame_hash ); 01249 g_assert_cmpint( g_hash_table_size( frame_hash ), == , 1 ); 01250 copy_value = g_hash_table_lookup( frame_hash, "test" ); 01251 g_assert( orig_value2 != copy_value ); 01252 g_assert_cmpint( kvp_value_compare( orig_value2, copy_value ), == , 0 ); 01253 g_assert_cmpint( kvp_value_compare( orig_value, copy_value ), != , 0 ); 01254 01255 kvp_value_delete( orig_value ); 01256 kvp_value_delete( orig_value2 ); 01257 } 01258 01259 static void 01260 test_get_trailer_make( Fixture *fixture, gconstpointer pData ) 01261 { 01262 char *last_key = NULL; 01263 KvpValue *frame_value = NULL; 01264 KvpFrame *frame = NULL, *frame2 = NULL; 01265 01266 g_test_message( "Test null frame and empty string checks" ); 01267 g_assert( p_get_trailer_make( NULL, "test", &last_key ) == NULL ); 01268 g_assert( !last_key ); 01269 g_assert( p_get_trailer_make( fixture->frame, NULL, &last_key ) == NULL ); 01270 g_assert( !last_key ); 01271 g_assert( p_get_trailer_make( fixture->frame, "", &last_key ) == NULL ); 01272 g_assert( !last_key ); 01273 01274 g_test_message( "Test single frame on the path with no slash" ); 01275 g_assert( p_get_trailer_make( fixture->frame, "test", &last_key ) == fixture->frame ); 01276 g_assert_cmpstr( last_key, == , "test" ); 01277 01278 g_test_message( "Test single frame on the path with slash" ); 01279 last_key = NULL; 01280 g_assert( p_get_trailer_make( fixture->frame, "/test", &last_key ) == fixture->frame ); 01281 g_assert_cmpstr( last_key, == , "test" ); 01282 01283 g_test_message( "Test path of trailing slash" ); 01284 last_key = NULL; 01285 g_assert( p_get_trailer_make( fixture->frame, "test/", &last_key ) == NULL ); 01286 g_assert( !last_key ); 01287 01288 g_test_message( "Test path of two entries: frame for test should be created" ); 01289 /* test is considered to be last frame on the path 01290 * and it is returned. Currently it doesn't exist and will be created 01291 * test2 is stripped away and returned as last entry of the path 01292 */ 01293 last_key = NULL; 01294 frame = p_get_trailer_make( fixture->frame, "/test/test2", &last_key ); 01295 g_assert( frame ); 01296 g_assert( frame != fixture->frame ); 01297 frame_value = kvp_frame_get_slot( fixture->frame, "test" ); 01298 g_assert( frame_value ); 01299 g_assert( kvp_value_get_frame( frame_value ) == frame ); 01300 frame_value = kvp_frame_get_slot( frame, "test2" ); 01301 g_assert( !frame_value ); 01302 g_assert_cmpstr( last_key, == , "test2" ); 01303 01304 g_test_message( "Test path of two entries: test frame already exist" ); 01305 /* here test frame already exist and should be returned 01306 */ 01307 last_key = NULL; 01308 g_assert( frame == p_get_trailer_make( fixture->frame, "/test/test2", &last_key ) ); 01309 g_assert_cmpstr( last_key, == , "test2" ); 01310 01311 g_test_message( "Test path of three entries: neither frame exist" ); 01312 /* test3 and test4 frames will be created. test4 will be created inside test3 frame 01313 * while test3 inside fixture->frame. test4 will be returned 01314 * test5 stripped away and returned in last_key 01315 */ 01316 last_key = NULL; 01317 frame = p_get_trailer_make( fixture->frame, "/test3/test4/test5", &last_key ); 01318 g_assert( frame ); 01319 g_assert( frame != fixture->frame ); 01320 frame_value = kvp_frame_get_slot( fixture->frame, "test3" ); 01321 g_assert( frame_value ); 01322 frame2 = kvp_value_get_frame( frame_value ); 01323 g_assert( frame2 != frame ); 01324 g_assert( frame2 != fixture->frame ); 01325 frame_value = kvp_frame_get_slot( frame2, "test4" ); 01326 g_assert( frame_value ); 01327 g_assert( kvp_value_get_frame( frame_value ) == frame ); 01328 frame_value = kvp_frame_get_slot( frame, "test5" ); 01329 g_assert( !frame_value ); 01330 g_assert_cmpstr( last_key, == , "test5" ); 01331 } 01332 01333 static void 01334 test_kvp_value_glist_to_string( Fixture *fixture, gconstpointer pData ) 01335 { 01336 /* 01337 * kvp_value_glist_to_string and kvp_value_to_string call each other 01338 */ 01339 GList *value_list = NULL; 01340 gchar *result; 01341 01342 gnc_numeric gnc_numeric_orig; 01343 GList *list_orig; 01344 KvpFrame *frame_orig; 01345 01346 gnc_numeric_orig = gnc_numeric_zero(); 01347 list_orig = NULL; 01348 list_orig = g_list_append( list_orig, kvp_value_new_string( "abcdefghijklmnop" ) ); 01349 frame_orig = kvp_frame_new(); 01350 01351 g_test_message( "Test empty list" ); 01352 result = p_kvp_value_glist_to_string( value_list ); 01353 g_assert_cmpstr( result, == , "[ ]" ); 01354 g_free( result ); 01355 01356 g_test_message( "Test list with simple and complex values" ); 01357 value_list = g_list_append( value_list, kvp_value_new_gint64( 2 ) ); 01358 value_list = g_list_append( value_list, kvp_value_new_double( 3.3 ) ); 01359 value_list = g_list_append( value_list, kvp_value_new_gnc_numeric( gnc_numeric_orig ) ); 01360 value_list = g_list_append( value_list, kvp_value_new_string( "abcdefghijklmnop" ) ); 01361 value_list = g_list_append( value_list, kvp_value_new_glist( list_orig ) ); 01362 value_list = g_list_append( value_list, kvp_value_new_frame( frame_orig ) ); 01363 g_assert( value_list ); 01364 g_assert_cmpint( g_list_length( value_list ), == , 6 ); 01365 result = p_kvp_value_glist_to_string( value_list ); 01366 01367 g_assert_cmpstr( result, == , "[ KVP_VALUE_GINT64(2), KVP_VALUE_DOUBLE(3.3), KVP_VALUE_NUMERIC(0/1), KVP_VALUE_STRING(abcdefghijklmnop), KVP_VALUE_GLIST([ KVP_VALUE_STRING(abcdefghijklmnop), ]), KVP_VALUE_FRAME({\n}\n), ]" ); 01368 g_free( result ); 01369 01370 kvp_glist_delete( value_list ); 01371 } 01372 01373 static void 01374 test_get_or_make( Fixture *fixture, gconstpointer pData ) 01375 { 01376 KvpFrame *test_frame = NULL; 01377 01378 g_assert( fixture->frame ); 01379 g_assert( kvp_frame_is_empty( fixture->frame ) ); 01380 01381 g_test_message( "Test new frame is created" ); 01382 test_frame = p_get_or_make( fixture->frame, "test" ); 01383 g_assert( test_frame ); 01384 g_assert( test_frame != fixture->frame ); 01385 g_assert( kvp_frame_get_frame( fixture->frame, "test" ) == test_frame ); 01386 01387 g_test_message( "Test existing frame is returned" ); 01388 g_assert( test_frame == p_get_or_make( fixture->frame, "test" ) ); 01389 g_assert( kvp_frame_get_frame( fixture->frame, "test" ) == test_frame ); 01390 } 01391 01392 static void 01393 test_kvp_frame_get_frame_or_null_slash_trash( Fixture *fixture, gconstpointer pData ) 01394 { 01395 g_test_message( "Test null checks" ); 01396 g_assert( p_kvp_frame_get_frame_or_null_slash_trash( NULL, "test" ) == NULL ); 01397 g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, NULL ) == NULL ); 01398 01399 g_test_message( "Test single slash and trailing slash path" ); 01400 g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, "/" ) == fixture->frame ); 01401 g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, "////" ) == fixture->frame ); 01402 01403 g_test_message( "Test non existing path" ); 01404 g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, "/test" ) == NULL ); 01405 01406 g_test_message( "Test existing path when value is not frame" ); 01407 kvp_frame_set_gint64( fixture->frame, "/test", 2 ); 01408 g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, "/test" ) == NULL ); 01409 01410 g_test_message( "Test existing path when value is frame" ); 01411 kvp_frame_set_frame( fixture->frame, "/test2", kvp_frame_new() ); 01412 g_assert( p_kvp_frame_get_frame_or_null_slash_trash( fixture->frame, "/test2" ) != NULL ); 01413 } 01414 01415 static void 01416 test_get_trailer_or_null( Fixture *fixture, gconstpointer pData ) 01417 { 01418 char *last_key = NULL; 01419 KvpFrame *frame = NULL; 01420 const KvpFrame* frame2 = NULL; 01421 01422 g_test_message( "Test null frame and empty string checks" ); 01423 g_assert( p_get_trailer_or_null( NULL, "test", &last_key ) == NULL ); 01424 g_assert( !last_key ); 01425 g_assert( p_get_trailer_or_null( fixture->frame, NULL, &last_key ) == NULL ); 01426 g_assert( !last_key ); 01427 g_assert( p_get_trailer_or_null( fixture->frame, "", &last_key ) == NULL ); 01428 g_assert( !last_key ); 01429 01430 g_test_message( "Test single frame on the path with no slash" ); 01431 g_assert( p_get_trailer_or_null( fixture->frame, "test", &last_key ) == fixture->frame ); 01432 g_assert_cmpstr( last_key, == , "test" ); 01433 01434 g_test_message( "Test single frame on the path with slash" ); 01435 last_key = NULL; 01436 g_assert( p_get_trailer_or_null( fixture->frame, "/test", &last_key ) == fixture->frame ); 01437 g_assert_cmpstr( last_key, == , "test" ); 01438 01439 g_test_message( "Test path of trailing slash" ); 01440 last_key = NULL; 01441 g_assert( p_get_trailer_or_null( fixture->frame, "test/", &last_key ) == NULL ); 01442 g_assert( !last_key ); 01443 01444 g_test_message( "Test with non existing path" ); 01445 last_key = NULL; 01446 g_assert( p_get_trailer_or_null( fixture->frame, "/test/test2", &last_key ) == NULL ); 01447 g_assert_cmpstr( last_key, == , "test2" ); 01448 01449 g_test_message( "Test with existing path" ); 01450 last_key = NULL; 01451 frame = kvp_frame_new(); 01452 kvp_frame_set_frame( fixture->frame, "/test/test2", frame ); 01453 frame2 = p_get_trailer_or_null( fixture->frame, "/test/test2", &last_key ); 01454 g_assert( kvp_frame_get_frame( fixture->frame, "/test") == frame2 ); 01455 g_assert_cmpstr( last_key, == , "test2" ); 01456 } 01457 01458 void 01459 test_suite_kvp_frame( void ) 01460 { 01461 GNC_TEST_ADD_FUNC( suitename, "kvp frame new and delete", test_kvp_frame_new_delete ); 01462 GNC_TEST_ADD( suitename, "kvp frame copy", Fixture, NULL, setup, test_kvp_frame_copy, teardown ); 01463 GNC_TEST_ADD( suitename, "kvp frame set foo", Fixture, NULL, setup, test_kvp_frame_set_foo, teardown ); 01464 GNC_TEST_ADD( suitename, "kvp frame get frame slash", Fixture, NULL, setup, test_kvp_frame_get_frame_slash, teardown ); 01465 GNC_TEST_ADD( suitename, "kvp frame get slot path", Fixture, NULL, setup, test_kvp_frame_get_slot_path, teardown ); 01466 GNC_TEST_ADD( suitename, "kvp frame get slot path gslist", Fixture, NULL, setup, test_kvp_frame_get_slot_path_gslist, teardown ); 01467 GNC_TEST_ADD( suitename, "kvp frame add frame nc", Fixture, NULL, setup, test_kvp_frame_add_frame_nc, teardown ); 01468 GNC_TEST_ADD_FUNC( suitename, "kvp value copy", test_kvp_value_copy ); 01469 GNC_TEST_ADD_FUNC( suitename, "kvp glist copy", test_kvp_glist_copy ); 01470 GNC_TEST_ADD_FUNC( suitename, "kvp glist compare", test_kvp_glist_compare ); 01471 GNC_TEST_ADD_FUNC( suitename, "kvp value compare", test_kvp_value_compare ); 01472 GNC_TEST_ADD_FUNC( suitename, "kvp value new foo no copy", test_kvp_value_new_foo_nc ); 01473 GNC_TEST_ADD( suitename, "kvp frame compare", Fixture, NULL, setup, test_kvp_frame_compare, teardown ); 01474 GNC_TEST_ADD_FUNC( suitename, "binary to string", test_binary_to_string ); 01475 GNC_TEST_ADD_FUNC( suitename, "kvp value to string", test_kvp_value_to_string ); 01476 GNC_TEST_ADD( suitename, "kvp frame to string", Fixture, NULL, setup, test_kvp_frame_to_string, teardown ); 01477 GNC_TEST_ADD( suitename, "kvp frame set slot path", Fixture, NULL, setup, test_kvp_frame_set_slot_path, teardown ); 01478 GNC_TEST_ADD( suitename, "kvp frame set slot path gslist", Fixture, NULL, setup, test_kvp_frame_set_slot_path_gslist, teardown ); 01479 GNC_TEST_ADD( suitename, "kvp frame replace slot nc", Fixture, NULL, setup, test_kvp_frame_replace_slot_nc, teardown ); 01480 GNC_TEST_ADD( suitename, "get trailer make", Fixture, NULL, setup_static, test_get_trailer_make, teardown_static ); 01481 GNC_TEST_ADD( suitename, "kvp value glist to string", Fixture, NULL, setup_static, test_kvp_value_glist_to_string, teardown_static ); 01482 GNC_TEST_ADD( suitename, "get or make", Fixture, NULL, setup_static, test_get_or_make, teardown_static ); 01483 GNC_TEST_ADD( suitename, "kvp frame get frame or null slash trash", Fixture, NULL, setup_static, test_kvp_frame_get_frame_or_null_slash_trash, teardown_static ); 01484 GNC_TEST_ADD( suitename, "get trailer or null", Fixture, NULL, setup_static, test_get_trailer_or_null, teardown_static ); 01485 }
1.7.4