void DictionarySuite_TestMerge( DictionarySuiteData* data ) { Dictionary_Entry_Value* testStruct2=NULL; Dictionary_Entry_Value* testGeomStruct2=NULL; Dictionary_Entry_Value* mergedStruct=NULL; Dictionary_Entry_Value* expectedMergedStruct=NULL; testStruct2 = Dictionary_Entry_Value_NewStruct( ); Dictionary_Entry_Value_AddMember( testStruct2, (Dictionary_Entry_Key)"height", Dictionary_Entry_Value_FromDouble( data->testDD->testStruct->height ) ); Dictionary_Entry_Value_AddMember( testStruct2, (Dictionary_Entry_Key)"anisotropic", Dictionary_Entry_Value_FromBool( False ) ); Dictionary_Entry_Value_AddMember( testStruct2, (Dictionary_Entry_Key)"new_person", Dictionary_Entry_Value_FromString( "Luke" ) ); testGeomStruct2 = Dictionary_Entry_Value_NewStruct( ); Dictionary_Entry_Value_AddMember( testStruct2, (Dictionary_Entry_Key)"geom", testGeomStruct2 ); Dictionary_Entry_Value_AddMember( testGeomStruct2, (Dictionary_Entry_Key)"startx", Dictionary_Entry_Value_FromUnsignedInt( data->testDD->testStruct->geom.startx ) ); Dictionary_Entry_Value_AddMember( testGeomStruct2, (Dictionary_Entry_Key)"startz", Dictionary_Entry_Value_FromUnsignedInt( 222 ) ); /* Testing Merge_Append */ DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD ); /* Do a copy of the DEV during merge, since we don't want it being deleted */ Dictionary_AddMerge( data->dict, "test_struct", Dictionary_Entry_Value_Copy( testStruct2, True ), Dictionary_MergeType_Append ); /* OK: since this was an append, we expect _two_ entries called "test_struct", * one preceding the other, one with the orig data, one with new data */ pcu_check_true( (data->testDD->testEntriesCount+1) == data->dict->count ); pcu_check_true( Dictionary_Entry_Value_Compare( data->testDD->testValues[8], Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_struct" ) ) ); pcu_check_true( Dictionary_Entry_Value_Compare( testStruct2, data->dict->entryPtr[9]->value ) ); Dictionary_Empty( data->dict ); /* Testing Merge_Merge */ DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD ); /* The nicest way for this test I think is to manually build a merged struct * to compare against */ expectedMergedStruct = Dictionary_Entry_Value_Copy( data->testDD->testValues[8], True ); Dictionary_Set( expectedMergedStruct->as.typeStruct, (Dictionary_Entry_Key)"anisotropic", Dictionary_Entry_Value_FromBool( False ) ); Dictionary_Add( expectedMergedStruct->as.typeStruct, (Dictionary_Entry_Key)"new_person", Dictionary_Entry_Value_FromString( "Luke" ) ); Dictionary_Set( (Dictionary_Get( expectedMergedStruct->as.typeStruct, (Dictionary_Entry_Key)"geom" ) )->as.typeStruct, "startz", Dictionary_Entry_Value_FromUnsignedInt( 222 ) ); Dictionary_AddMerge( data->dict, "test_struct", Dictionary_Entry_Value_Copy( testStruct2, True ), Dictionary_MergeType_Merge ); /* This time, the new struct should be merged into the existing one */ pcu_check_true( data->testDD->testEntriesCount == data->dict->count ); mergedStruct = Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_struct" ); pcu_check_true( Dictionary_Entry_Value_Compare( mergedStruct, expectedMergedStruct ) ); Dictionary_Empty( data->dict ); Dictionary_Entry_Value_Delete( expectedMergedStruct ); /* Testing Merge_Replace */ DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD ); Dictionary_AddMerge( data->dict, "test_struct", Dictionary_Entry_Value_Copy( testStruct2, True ), Dictionary_MergeType_Replace ); pcu_check_true( data->testDD->testEntriesCount == data->dict->count ); pcu_check_true( Dictionary_Entry_Value_Compare( testStruct2, Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_struct" ) ) ); Dictionary_Empty( data->dict ); Dictionary_Entry_Value_Delete( testStruct2 ); }
int main( int argc, char* argv[] ) { Stream* stream = NULL; Dictionary* dictionary; Dictionary_Entry_Value* tmpVal0; Dictionary_Entry_Value* tmpVal1; MPI_Init( &argc, &argv ); BaseFoundation_Init( &argc, &argv ); BaseIO_Init( &argc, &argv ); stream = Journal_Register (Info_Type, "myStream"); dictionary = Dictionary_New(); tmpVal0 = Dictionary_Entry_Value_NewStruct(); tmpVal1 = Dictionary_Entry_Value_NewStruct(); Dictionary_Entry_Value_AddMember( tmpVal1, "name", Dictionary_Entry_Value_FromString( "bill" ) ); Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 1.0f ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 ); tmpVal1 = Dictionary_Entry_Value_NewList(); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "bottom" ) ); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "top" ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 ); Dictionary_Add( dictionary, "one", tmpVal0 ); tmpVal0 = Dictionary_Entry_Value_NewStruct(); tmpVal1 = Dictionary_Entry_Value_NewStruct(); Dictionary_Entry_Value_AddMember( tmpVal1, "new_name", Dictionary_Entry_Value_FromString( "frank" ) ); Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 2.0f ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 ); tmpVal1 = Dictionary_Entry_Value_NewList(); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "left" ) ); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "right" ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 ); Dictionary_AddMerge( dictionary, "one", tmpVal0, Dictionary_MergeType_Append ); Print( dictionary, stream ); Stg_Class_Delete( dictionary ); dictionary = Dictionary_New(); tmpVal0 = Dictionary_Entry_Value_NewStruct(); tmpVal1 = Dictionary_Entry_Value_NewStruct(); Dictionary_Entry_Value_AddMember( tmpVal1, "name", Dictionary_Entry_Value_FromString( "bill" ) ); Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 1.0f ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 ); tmpVal1 = Dictionary_Entry_Value_NewList(); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "bottom" ) ); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "top" ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 ); Dictionary_Add( dictionary, "one", tmpVal0 ); tmpVal0 = Dictionary_Entry_Value_NewStruct(); tmpVal1 = Dictionary_Entry_Value_NewStruct(); Dictionary_Entry_Value_AddMember( tmpVal1, "new_name", Dictionary_Entry_Value_FromString( "frank" ) ); Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 2.0f ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 ); tmpVal1 = Dictionary_Entry_Value_NewList(); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "left" ) ); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "right" ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 ); Dictionary_AddMerge( dictionary, "one", tmpVal0, Dictionary_MergeType_Merge ); Print( dictionary, stream ); Stg_Class_Delete( dictionary ); dictionary = Dictionary_New(); tmpVal0 = Dictionary_Entry_Value_NewStruct(); tmpVal1 = Dictionary_Entry_Value_NewStruct(); Dictionary_Entry_Value_AddMember( tmpVal1, "name", Dictionary_Entry_Value_FromString( "bill" ) ); Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 1.0f ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 ); tmpVal1 = Dictionary_Entry_Value_NewList(); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "bottom" ) ); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "top" ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 ); Dictionary_Add( dictionary, "one", tmpVal0 ); tmpVal0 = Dictionary_Entry_Value_NewStruct(); tmpVal1 = Dictionary_Entry_Value_NewStruct(); Dictionary_Entry_Value_AddMember( tmpVal1, "new_name", Dictionary_Entry_Value_FromString( "frank" ) ); Dictionary_Entry_Value_AddMember( tmpVal1, "value", Dictionary_Entry_Value_FromDouble( 2.0f ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "inside", tmpVal1 ); tmpVal1 = Dictionary_Entry_Value_NewList(); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "left" ) ); Dictionary_Entry_Value_AddElement( tmpVal1, Dictionary_Entry_Value_FromString( "right" ) ); Dictionary_Entry_Value_AddMember( tmpVal0, "list_one", tmpVal1 ); Dictionary_AddMerge( dictionary, "one", tmpVal0, Dictionary_MergeType_Replace ); Print( dictionary, stream ); Stg_Class_Delete( dictionary ); BaseIO_Finalise(); BaseFoundation_Finalise(); MPI_Finalize(); return EXIT_SUCCESS; }