//===========================================================================// // File: resource.tst // // Project: MUNGA Brick: Resource Manager // // Contents: Test methods for Resource Manager classes. // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- ---------------------------------------------------------- // // 01/19/95 GSY Initial coding. // // 01/20/95 GAH Modified in the MUNGA style // //---------------------------------------------------------------------------// // Copyright (C) 1994, Virtual World Entertainment, Inc. All Rights reserved // // PROPRIETARY AND CONFIDENTIAL // //===========================================================================// //GY: Directory (References) stuff wasn't tested so is not reliable yet !!!! Logical ResourceFile::TestClass() { DEBUG_STREAM<<"Starting Resource test....\n"; typedef char ATTRIB[16]; ResourceFile file; // //---------------------------------- // ResourceDescription* // addResource( // ResourceDescription::Name res_name, // ResourceDescription::Type res_type, // unsigned short res_priority, // ResourceDescription::PreloadRequest load_flag, // void* res_address, // size_t res_size, // int res_index=-1 //ResourceDescription::ResourceID res_index=-1 // ); //---------------------------------- // ATTRIB attrib4 = "data4"; ResourceDescription *res = file.AddResource( "The fourth", ResourceDescription::FirstNonListResourceType, // 4(3) 1, ResourceDescription::Preload, attrib4, sizeof(ATTRIB), 3 ); Test(res->resourceID == 3); ATTRIB attrib1 = "data1"; res = file.AddResource( "The first", // 1 ResourceDescription::FirstNonListResourceType, //DirectoryType = 0 0, ResourceDescription::Preload, attrib1, sizeof(ATTRIB) ); Test(res->resourceID == 0); ATTRIB attrib2 = "data2"; res = file.AddResource( // 2 "The second", ResourceDescription::FirstNonListResourceType, //DirectoryType = 0 0, ResourceDescription::Preload, attrib2, sizeof(ATTRIB) ); Test(res->resourceID == 1); // Same data but different memory allocated res = file.AddResource( "The first", // 1.1 ResourceDescription::FirstNonListResourceType, //DirectoryType = 0 0, ResourceDescription::Preload, attrib1, sizeof(ATTRIB) ); Test(res->resourceID == 2); ATTRIB attrib10 = "data10"; res = file.AddResource( "The tenth", // 10 (9) ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib10, sizeof(ATTRIB), 9 ); Test(res->resourceID == 9); ATTRIB attrib6 = "data6"; res = file.AddResource("The sixth", // 6 (5) ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib6, sizeof(ATTRIB), 5 ); Test(res->resourceID == 5); ATTRIB attrib5 = "data5"; // 5 res = file.AddResource("The fifth", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib5, sizeof(ATTRIB) ); Test(res->resourceID == 4); ATTRIB attrib7 = "data7"; // 7 res = file.AddResource("The seventh", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib7, sizeof(ATTRIB) ); Test(res->resourceID == 6); ATTRIB attrib11 = "data11"; // 11 (10) res = file.AddResource("The eleventh", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib11, sizeof(ATTRIB), 10 ); Test(res->resourceID == 10); ATTRIB attrib1001 = "data1001"; // 1001 (1000) res = file.AddResource("The thousand first", //last ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib1001, sizeof(ATTRIB), 1000 ); Test(res->resourceID == 1000); ATTRIB attrib8 = "data8"; // 8 res = file.AddResource("The eighth", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib8, sizeof(ATTRIB) ); Test(res->resourceID == 7); ATTRIB attrib101 = "data101"; // 101 (100) res = file.AddResource("The hundred first", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib101, sizeof(ATTRIB), 100 ); Test(res->resourceID == 100); //------------------------------ // ResourceDescription* // FindResourceDescription( // ResourceDescription::Name res_name, // ResourceDescription::Type res_type) //------------------------------ res = file.FindResourceDescription( "The fourth", ResourceDescription::FirstNonListResourceType ); Test(res); Test(!strcmp(res->resourceName, "The fourth")); Test(res->resourceType == ResourceDescription::FirstNonListResourceType); Test(res->resourceID == 3); res = file.FindResourceDescription( "The hundred first", ResourceDescription::FirstNonListResourceType ); Test(res); Test(!strcmp(res->resourceName, "The hundred first")); Test(res->resourceType == ResourceDescription::FirstNonListResourceType); //-------------------------------------------------- // void // DeleteResource(ResourceDescription *resource); //-------------------------------------------------- //ID=3 file.FindResourceDescription(3)->Unlock(); Unregister_Object(file.FindResourceDescription(3)); file.DeleteResource (file.FindResourceDescription(3)); Test(!file.FindResourceDescription(3)); //ID=4 file.FindResourceDescription(4)->Unlock(); Unregister_Object(file.FindResourceDescription(4)); file.DeleteResource (file.FindResourceDescription(4)); Test(!file.FindResourceDescription(4)); //ID=5 file.FindResourceDescription(5)->Unlock(); Unregister_Object(file.FindResourceDescription(5)); file.DeleteResource (file.FindResourceDescription(5)); Test(!file.FindResourceDescription(5)); //ID=2 file.FindResourceDescription(2)->Unlock(); Unregister_Object(file.FindResourceDescription(2)); file.DeleteResource(file.FindResourceDescription(2)); Test(!file.FindResourceDescription(2)); //ID=0 file.FindResourceDescription(0)->Unlock(); Unregister_Object(file.FindResourceDescription(0)); file.DeleteResource(file.FindResourceDescription(0)); Test(!file.FindResourceDescription(0)); file.FindResourceDescription( "The second", ResourceDescription::FirstNonListResourceType )->Unlock(); Unregister_Object( file.FindResourceDescription( "The second", ResourceDescription::FirstNonListResourceType ) ); file.DeleteResource( file.FindResourceDescription( "The second", ResourceDescription::FirstNonListResourceType ) ); Test( !file.FindResourceDescription( "The second", ResourceDescription::FirstNonListResourceType ) ); file.FindResourceDescription( "The hundred first", ResourceDescription::FirstNonListResourceType )->Unlock(); Unregister_Object( file.FindResourceDescription( "The hundred first", ResourceDescription::FirstNonListResourceType ) ); file.DeleteResource( file.FindResourceDescription( "The hundred first", ResourceDescription::FirstNonListResourceType ) ); Test( !file.FindResourceDescription( "The hundred first", ResourceDescription::FirstNonListResourceType ) ); file.FindResourceDescription( "The thousand first", ResourceDescription::FirstNonListResourceType )->Unlock(); Unregister_Object( file.FindResourceDescription( "The thousand first", ResourceDescription::FirstNonListResourceType ) ); file.DeleteResource( file.FindResourceDescription( "The thousand first", ResourceDescription::FirstNonListResourceType ) ); Test( !file.FindResourceDescription( "The thousand hundred first", ResourceDescription::FirstNonListResourceType ) ); // //------------------------------------------------------------------------------ // ResourceDescription* // AddResourceDirectory( // ResourceDescription::ResourceName name, // int priority, // ResourceDescription::PreloadRequest load_flag, // ResourceDescription::ResourceID* address, // int count, // ResourceDescription::ResourceID index=-1 // ); //------------------------------------------------------------------------------ // //---------------------------------------- // One way of directory describing: // //ResourceDescription::ResourceID // dir[] = { // 7, // 9, // 10 // }; //---------------------------------------- // The other way : ResourceDescription::ResourceID dirRes[10]; res = file.FindResourceDescription( "The eighth", ResourceDescription::FirstNonListResourceType ); Test(res); dirRes[0] = res->resourceID; //7 Test(dirRes[0]==7); res = file.FindResourceDescription( "The tenth", ResourceDescription::FirstNonListResourceType ); Test(res); dirRes[1] = res->resourceID; //9 Test(dirRes[1]==9); res = file.FindResourceDescription( "The eleventh", ResourceDescription::FirstNonListResourceType ); Test(res); dirRes[2] = res->resourceID; //10 Test(dirRes[2]==10); //--------------------------------------------------------- // test Directory assigned to resource "The seventh" // Remember: Directory has to be appended to end of the list // Test(file.maxResourceID==10); Test(!file.FindResourceDescription(file.maxResourceID +1)); res = file.AddResourceList( "first directory", ResourceDescription::ModelListResourceType, 1, ResourceDescription::Preload, dirRes, 3, //count of references file.maxResourceID +1 //Dir. has to be in ); //resourceArray after //resources it references Test(res); res = file.FindResourceDescription( "first directory", ResourceDescription::ModelListResourceType ); Test(res); Test(res->resourceID == 11); Test(res->resourceType == ResourceDescription::ModelListResourceType); ResourceDescription::ResourceID *res_array = (ResourceDescription::ResourceID*)res->resourceAddress; Test(res_array[0] == 3); Test(res_array[1] == 7); Test(res_array[2] == 9); Test(res_array[3] == 10); return True; } // //############################################################################## //################# StreamableResourceFile::TestClass() ####################### //############################################################################## Logical StreamableResourceFile::TestClass() { // ResourceFile::TestClass(); // ????? gives error: //resourceArray[index] !=NULL //in AddResource() DEBUG_STREAM<<"Starting StreamableResource test....\n"; // //------------------------------------------------------------------------------ // StreamableResourceFile(); //------------------------------------------------------------------------------ // ResourceDescription *res; typedef char ATTRIB[16]; { StreamableResourceFile file; ATTRIB attrib4 = "data4"; res = file.AddResource( "The fourth", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib4, sizeof(ATTRIB), 3 ); Test(res->resourceID == 3); ATTRIB attrib1 = "data1"; res = file.AddResource( "The first", ResourceDescription::FirstNonListResourceType, 0, ResourceDescription::Preload, attrib1, sizeof(ATTRIB) ); Test(res->resourceID == 0); ATTRIB attrib2 = "data2"; res = file.AddResource( "The second", ResourceDescription::FirstNonListResourceType, 0, ResourceDescription::Preload, attrib2, sizeof(ATTRIB) ); Test(res->resourceID == 1); // Same data but different memory allocated res = file.AddResource( "The first", ResourceDescription::FirstNonListResourceType, 0, ResourceDescription::Preload, attrib1, sizeof(ATTRIB) ); Test(res->resourceID == 2); ATTRIB attrib10 = "data10"; res = file.AddResource( "The tenth", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib10, sizeof(ATTRIB), 9 ); Test(res->resourceID == 9); ATTRIB attrib6 = "data6"; res = file.AddResource( "The sixth", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib6, sizeof(ATTRIB), 5 ); Test(res->resourceID == 5); ATTRIB attrib5 = "data5"; res = file.AddResource( "The fifth", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib5, sizeof(ATTRIB) ); Test(res->resourceID == 4); ATTRIB attrib7 = "data7"; res = file.AddResource( "The seventh", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib7, sizeof(ATTRIB) ); Test(res->resourceID == 6); ATTRIB attrib11 = "data11"; res = file.AddResource( "The eleventh", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib11, sizeof(ATTRIB), 10 ); Test(res->resourceID == 10); // //------------------------------------------------------------------------------ // int // SaveAs(char* file_name); //------------------------------------------------------------------------------ // file.SaveAs("temp.res"); } // //------------------------------------------------------------------------------ // int // Open(char *file_name); //------------------------------------------------------------------------------ // { StreamableResourceFile file; Test(file.Open("temp.res")); Test(!strcmp(file.FindResourceDescription(0)->resourceName,"The first")); Test( !strcmp( file.FindResourceDescription( "The eleventh", ResourceDescription::FirstNonListResourceType )->resourceName, "The eleventh" ) ); ATTRIB attrib12 = "data12"; res = file.AddResource( "The twelfth", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib12, sizeof(ATTRIB), 11 ); Test(res->resourceID == 11); ATTRIB attrib8 = "data8"; res = file.AddResource( "The eighth", ResourceDescription::FirstNonListResourceType, 1, ResourceDescription::Preload, attrib8, sizeof(ATTRIB) ); Test(res->resourceID == 7); // //------------------------------------------------------------------------------ // int // Save(); //------------------------------------------------------------------------------ // file.Save(); } { StreamableResourceFile file; file.Open("temp.res"); file.FindResourceDescription(2)->Unlock(); Unregister_Object(file.FindResourceDescription(2)); file.DeleteResource(file.FindResourceDescription(2)); file.FindResourceDescription(0)->Unlock(); Unregister_Object(file.FindResourceDescription(0)); file.DeleteResource(file.FindResourceDescription(0)); file.Save(); } { StreamableResourceFile file; file.Open("temp.res"); Test( !file.FindResourceDescription( "The first", ResourceDescription::FirstNonListResourceType ) ); Test(!file.FindResourceDescription(0)); // //------------------------------------------------------------------------------ // ResourceDescription* // AddResourceDirectory( // ResourceDescription::ResourceName name, // int priority, // ResourceDescription::PreloadRequest load_flag, // ResourceDescription::ResourceID* address, // int count, // ResourceDescription::ResourceID index=-1 // ); //------------------------------------------------------------------------------ // //-------------------------- // Test resource descriptions before adding directory // //---------------------------------------- // One way of directory describing: // //ResourceDescription::ResourceID // dir[] = { // 0, // 9, // 11 // }; //---------------------------------------- // The other way : ResourceDescription::ResourceID dirRes[10]; //------------------ // test "The first" // res = file.FindResourceDescription( "The eighth", ResourceDescription::FirstNonListResourceType ); Test(res); dirRes[0] = res->resourceID; Test(dirRes[0]==7); //------------------ // test "The tenth" // res = file.FindResourceDescription( "The tenth", ResourceDescription::FirstNonListResourceType ); Test(res); dirRes[1] = res->resourceID; Test(dirRes[1]==9); //------------------ // test "The twelfth" // res = file.FindResourceDescription( "The twelfth", ResourceDescription::FirstNonListResourceType ); Test(res); dirRes[2] = res->resourceID; Test(dirRes[2]==11); // //---------------- // Add Directory // Test(file.maxResourceID==11); Test(!file.FindResourceDescription(file.maxResourceID+1)); res = file.AddResourceList( "The first list", ResourceDescription::ModelListResourceType, 1, ResourceDescription::Preload, dirRes, 3, file.maxResourceID+1 ); Test(res); Test(res->resourceID == 12); Test(res->resourceType == ResourceDescription::ModelListResourceType); Test(((ResourceDescription::ResourceID*)res->resourceAddress)[0] == 3); Test(((ResourceDescription::ResourceID*)res->resourceAddress)[1] == 7); Test(((ResourceDescription::ResourceID*)res->resourceAddress)[2] == 9); Test(((ResourceDescription::ResourceID*)res->resourceAddress)[3] == 11); file.Save(); } { StreamableResourceFile file; file.Open("temp.res"); res = file.FindResourceDescription( "The first list", ResourceDescription::ModelListResourceType ); Test(res); Test(res->resourceID == 12); Test(res->resourceType == ResourceDescription::ModelListResourceType); res->Lock(); Test(((ResourceDescription::ResourceID*)res->resourceAddress)[0] == 3); Test(((ResourceDescription::ResourceID*)res->resourceAddress)[1] == 7); Test(((ResourceDescription::ResourceID*)res->resourceAddress)[2] == 9); Test(((ResourceDescription::ResourceID*)res->resourceAddress)[3] == 11); res->Unlock(); } return True; }