void TestKillSelfPointer2(void) { ObjectsInit(); Ptr<CRoot> pRoot; Ptr<CTestNamedObject> pObject; BOOL bResult; pRoot = ORoot(); pObject = OMalloc(CTestNamedObject); pObject->Init(1); pObject->mpNamedTest1 = pObject; pRoot->Add(pObject); AssertInt(1, pRoot->NumObjects()); AssertLongLongInt(3, gcObjects.NumMemoryIndexes()); //pObject should not be destroyed here and not cause a stack overflow. bResult = pRoot->Remove(pObject); AssertTrue(bResult); AssertInt(0, pRoot->NumObjects()); AssertLongLongInt(3, gcObjects.NumMemoryIndexes()); //If there were cyclic pointers then the object cannot tell it should be freed when a stack pointer is removed. pObject = NULL; AssertLongLongInt(2, gcObjects.NumMemoryIndexes()); ObjectsKill(); }
void TestObjectsFlushClearGetByName(void) { CFileUtil cFileUtil; CPointer pObject; Ptr<CTestDoubleNamedString> pDouble; Ptr<CRoot> pRoot; cFileUtil.RemoveDir("Output"); cFileUtil.MakeDir("Output/Dehollowfication"); ObjectsInit("Output/Dehollowfication"); SetupObjectsConstructors(); pRoot = ORoot(); pDouble = ONMalloc(CTestDoubleNamedString, "Double")->Init(); pRoot->Add(pDouble); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(0, gcObjects.NumDatabaseNames()); pObject = gcObjects.Get(3); AssertNotNull(pObject.Object()); AssertString("CTestDoubleNamedString", pObject.ClassName()); gcObjects.Flush(TRUE, TRUE); AssertLongLongInt(3, gcObjects.NumDatabaseObjects()); AssertLongLongInt(2, gcObjects.NumDatabaseNames()); pObject = gcObjects.Get("Double"); AssertNotNull(pObject.Object()); AssertString("CTestDoubleNamedString", pObject.ClassName()); ObjectsKill(); }
void TestObjectsInMemoryIteration() { SIndexesIterator sIter; OIndex oi; ObjectsInit(); SetupObjectsForDehollowfication(); oi = gcObjects.StartMemoryIteration(&sIter); AssertLongLongInt(1LL, oi); oi = gcObjects.IterateMemory(&sIter); AssertLongLongInt(2LL, oi); oi = gcObjects.IterateMemory(&sIter); AssertLongLongInt(3LL, oi); oi = gcObjects.IterateMemory(&sIter); AssertLongLongInt(4LL, oi); oi = gcObjects.IterateMemory(&sIter); AssertLongLongInt(5LL, oi); oi = gcObjects.IterateMemory(&sIter); AssertLongLongInt(6LL, oi); oi = gcObjects.IterateMemory(&sIter); AssertLongLongInt(7LL, oi); oi = gcObjects.IterateMemory(&sIter); AssertLongLongInt(8LL, oi); oi = gcObjects.IterateMemory(&sIter); AssertLongLongInt(9LL, oi); oi = gcObjects.IterateMemory(&sIter); AssertLongLongInt(INVALID_O_INDEX, oi); ObjectsKill(); }
void TestKillSelfPointer1(void) { ObjectsInit(); Ptr<CRoot> pRoot; Ptr<CTestNamedObject> pObject; BOOL bResult; CBaseObject* pvObject; pRoot = ORoot(); pObject = OMalloc(CTestNamedObject); pObject->Init(1); pObject->mpNamedTest1 = pObject; pRoot->Add(pObject); AssertInt(1, pRoot->NumObjects()); AssertLongLongInt(3, gcObjects.NumMemoryIndexes()); pvObject = pObject.BaseObject(); pObject = NULL; //pObject should be destroyed here and not cause a stack overflow. bResult = pRoot->Remove(pvObject); AssertTrue(bResult); AssertInt(0, pRoot->NumObjects()); AssertLongLongInt(2, gcObjects.NumMemoryIndexes()); ObjectsKill(); }
void TestLogFileRead(void) { CLogFile* pcLogFile; CMemoryFile* pcMemoryFile; CFileBasic cFile; BOOL bResult; int iLength; char sz[200]; filePos iRead; pcMemoryFile = MemoryFile(); cFile.Init(pcMemoryFile); cFile.Open(EFM_Write_Create); cFile.WriteString("The suspense is killing me!"); cFile.Close(); pcLogFile = LogFile(pcMemoryFile); cFile.Init(pcLogFile); bResult = cFile.Open(EFM_Read); AssertTrue(bResult); pcLogFile->Begin(); bResult = cFile.ReadStringLength(&iLength); AssertTrue(bResult); AssertInt(28, iLength); AssertFalse(cFile.IsEndOfFile()); bResult = cFile.ReadStringChars(sz, iLength); AssertString("The suspense is killing me!", sz); AssertTrue(cFile.IsEndOfFile()); memset(sz, 0, 200); bResult = cFile.Seek(20); AssertTrue(bResult); bResult = cFile.ReadStringChars(sz, 8); AssertString("killing ", sz); AssertLongLongInt(28, cFile.GetFilePos()); AssertFalse(cFile.IsEndOfFile()); memset(sz, 0, 200); bResult = cFile.ReadStringChars(sz, 4); AssertString("me!", sz); AssertLongLongInt(32, cFile.GetFilePos()); AssertTrue(cFile.IsEndOfFile()); iRead = cFile.Read(sz, 1, 1); AssertLongLongInt(0, iRead); AssertLongLongInt(32, cFile.GetFilePos()); AssertTrue(cFile.IsEndOfFile()); AssertLongLongInt(32, cFile.GetFilePos()); AssertTrue(cFile.IsEndOfFile()); bResult = cFile.Close(); AssertTrue(bResult); cFile.Kill(); }
void TestDehollowficationFromDatabaseOfTwoPointers(void) { CIndexedConfig cConfig; CFileUtil cFileUtil; cConfig.Manual("Output\\Dehollowfication\\Database", FALSE, TRUE, FALSE, 1 MB); cFileUtil.RemoveDir("Output\\Dehollowfication\\Database"); MemoryInit(); ObjectsInit(&cConfig); SetupDehollowficationScene(); gcObjects.Flush(FALSE, FALSE); ObjectsKill(); MemoryKill(); MemoryInit(); ObjectsInit(&cConfig); SetupDehollowficationConstructors(); Ptr<CRoot> pRoot = ORoot(); Ptr<CTestDoubleNamedString> pDouble = pRoot->Get<CTestDoubleNamedString>("Double Start"); Ptr<CTestNamedString> pString1 = pDouble->mpSplit1; Ptr<CTestNamedString> pString2 = pDouble->mpSplit2; pString1->ClassName(); pString2->ClassName(); Ptr<CTestNamedString> pDiamond1 = pString1->mpAnother; Ptr<CTestNamedString> pDiamond2 = pString2->mpAnother; AssertTrue(pDiamond1.IsHollow()); AssertTrue(pDiamond2.IsHollow()); AssertPointer(pDiamond1.Object(), pDiamond2.Object()); AssertPointer(pString1->mpAnother.Object(), pString2->mpAnother.Object()); AssertLongLongInt(3LL, pDiamond1.GetIndex()); AssertLongLongInt(3LL, pDiamond2.GetIndex()); //Dehollofication of pDiamond1 happens here. pString1->mpAnother and pString2->mpAnother are remapped to the dehollowed diamond object. pDiamond1->ClassName(); AssertFalse(pDiamond1.IsHollow()); AssertFalse(pDiamond2.IsHollow()); //This should be false but it's not until I remap local pointers. AssertPointer(pDiamond1.Object(), pDiamond2.Object()); //These should be the same but they're not until I remap local pointers. AssertLongLongInt(3LL, pDiamond1.GetIndex()); AssertFalse(pString1->mpAnother.IsHollow()); AssertFalse(pString2->mpAnother.IsHollow()); AssertPointer(pString1->mpAnother.Object(), pString2->mpAnother.Object()); ObjectsKill(); MemoryKill(); }
void TestObjectDehollowfication(void) { CFileUtil cFileUtil; CPointer pPointer; CTestDoubleNamedString* pcInternal; Ptr<CTestDoubleNamedString> pDouble; Ptr<CTestNamedString> pSingle; int iClassSize; OIndex oiOld; OIndex oiNew; cFileUtil.RemoveDir("Output"); cFileUtil.MakeDir("Output/Dehollowfication"); ObjectsInit("Output/Dehollowfication"); SetupObjectsForDehollowfication(); gcObjects.Flush(TRUE, TRUE); AssertLongLongInt(9, gcObjects.NumDatabaseObjects()); ObjectsKill(); ObjectsInit("Output/Dehollowfication"); SetupObjectsConstructors(); AssertLongLongInt(9, gcObjects.NumDatabaseObjects()); AssertTrue(gcObjects.Contains("Double")); pPointer = gcObjects.Get("Double"); AssertNotNull(pPointer.Object()); AssertString("CTestDoubleNamedString", pPointer.ClassName()); pcInternal = (CTestDoubleNamedString*)pPointer.Object(); AssertTrue(pcInternal->mpSplit1.IsNotNull()); AssertTrue(pcInternal->mpSplit1.IsHollow()); AssertTrue(pcInternal->mpSplit2.IsNotNull()); AssertTrue(pcInternal->mpSplit2.IsHollow()); pDouble = pPointer; oiOld = pDouble->mpSplit1.GetIndex(); AssertTrue(pcInternal->mpSplit1.IsHollow()); //Making sure we haven't de-hollowed the object by calling GetIndex. //Problem - An oi of 1 is briefly assigned to the de-hollowed object and then it is reassigned back to its original value. iClassSize = pDouble->mpSplit1->ClassSize(); //The method call - ClassSize() - is irrelevant as long as the -> operator on mpSplit1 is invoked. AssertTrue(pcInternal->mpSplit1.IsNotNull()); AssertFalse(pcInternal->mpSplit1.IsHollow()); AssertInt(sizeof(CTestNamedString), iClassSize); AssertString("CTestNamedString", pcInternal->mpSplit1.ClassName()); oiNew = pDouble->mpSplit1.GetIndex(); AssertLongLongInt(oiOld, oiNew); pSingle = pDouble->mpSplit2; AssertTrue(pcInternal->mpSplit2.IsNotNull()); AssertTrue(pcInternal->mpSplit2.IsHollow()); ObjectsKill(); }
void TestObjectReaderSimpleDeserialised(void) { WriteObjectReaderSimpleFile(); CObjectReaderSimpleDisk cReader; CObjectGraphDeserialiser cGraphDeserialiser; CPointer cBase; Ptr<CTestNamedString> cNS1; Ptr<CTestNamedString> cNS2; CPointer cTemp; CObjectAllocator cAllocator; CDependentReadObjects cDependentReadObjects; MemoryInit(); ObjectsInit(); gcObjects.AddConstructor<CTestNamedString>(); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(0, gcObjects.NumMemoryIndexes()); cAllocator.Init(&gcObjects); cDependentReadObjects.Init(); cReader.Init("Output\\ObjectReaderSimple\\Test\\"); cGraphDeserialiser.Init(&cReader, FALSE, &cAllocator, &cDependentReadObjects, gcObjects.GetMemory()); cBase = cGraphDeserialiser.Read("Waggy"); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(2, gcObjects.NumMemoryIndexes()); cNS1 = gcObjects.Get("Waggy"); AssertTrue(cNS1.IsNotNull()); AssertString("NS1", cNS1->mszEmbedded.Text()); cNS2 = gcObjects.Get("Dog"); AssertTrue(cNS2.IsNotNull()); AssertString("NS2", cNS2->mszEmbedded.Text()); AssertTrue(cBase.IsNotNull()); AssertString("CTestNamedString", cBase->ClassName()); AssertPointer(&cNS1, &cBase); AssertPointer(&cNS2, &cNS1->mpAnother); AssertPointer(NULL, &cNS2->mpAnother); cGraphDeserialiser.Kill(); cDependentReadObjects.Kill(); cAllocator.Kill(); cReader.Kill(); ObjectsKill(); }
CPointer SetupObjectReaderChunkedChunkFile(void) { Ptr<CTestNamedString> cNS1; Ptr<CTestNamedString> cNS2; Ptr<CTestNamedString> cNS3; Ptr<CTestNamedString> cNS4; Ptr<CTestInteger> cI1; Ptr<CTestInteger> cI2; Ptr<CTestInteger> cI3; Ptr<CTestWithArray> cA1; Ptr<CTestWithArray> cA2; Ptr<CString> sz1; Ptr<CString> sz2; Ptr<CString> sz3; cNS1 = ONMalloc(CTestNamedString, "NamedString 1")->Init(); cNS2 = ONMalloc(CTestNamedString, "NamedString 2")->Init(); cNS3 = ONMalloc(CTestNamedString, "NamedString 3")->Init(); cNS4 = ONMalloc(CTestNamedString, "NamedString 4")->Init(); cI1 = OMalloc(CTestInteger)->Init(3, 2, 1); AssertLongLongInt(5LL, cI1->GetOI()); cI2 = OMalloc(CTestInteger)->Init(543, 3, 4); AssertLongLongInt(6LL, cI2->GetOI()); cI3 = OMalloc(CTestInteger)->Init(10, 8192, 7); AssertLongLongInt(7LL, cI3->GetOI()); cA1 = ONMalloc(CTestWithArray, "Array 1")->Init("Something with One", 1); cA2 = ONMalloc(CTestWithArray, "Array X")->Init("An with 2", 2); sz1 = OMalloc(CString)->Init("String 1"); sz2 = OMalloc(CString)->Init("Ye!"); sz3 = OMalloc(CString)->Init("3"); cNS1->Init(sz1, cNS2, "In Named 1"); cNS2->Init(sz1, cNS3, "Another in 2"); cNS3->Init(sz3, cNS1, "Three"); cNS4->Init(ONull, ONull, "Nulloid!"); cA1->Add(sz2); cA1->Add(cNS1); cA1->Add(cI1); cA1->Add(cNS3); cA1->Add(cI2); cA1->Add(cA2); cA2->Add(cI3); cA2->Add(cNS2); cA2->Add(cI1); cA2->Add(cNS4); return cA1; }
void AssertMapBlock(CMapBlock* pcMapBlock, char* szKey, long long int lliData) { long long int* plli; pcMapBlock->Get(szKey, (void**)&plli, NULL); AssertLongLongInt(lliData, *plli); }
void TestObjectsFlushRemovesStackPointers(void) { CFileUtil cFileUtil; Ptr<CTestDoubleNamedString> pDouble; Ptr<CRoot> pRoot; cFileUtil.RemoveDir("Output"); cFileUtil.MakeDir("Output/ClearPointers"); ObjectsInit("Output/ClearPointers"); SetupObjectsConstructors(); pRoot = ORoot(); gcObjects.Flush(TRUE, TRUE); AssertLongLongInt(2, gcObjects.NumDatabaseObjects()); AssertNull(&pRoot); pDouble = ONMalloc(CTestDoubleNamedString, "Double")->Init(); AssertString("CTestDoubleNamedString", pDouble.ClassName()); pRoot = ORoot(); AssertString("CRoot", pRoot.ClassName()); ObjectsKill(); }
void TestEmbeddedStackPointersEmbeddedDistPassThruPointer(void) { ObjectsInit(); CEmbeddedTest* pcTest; CEmbeddedComplex cComplex; Ptr<CEmbeddedTest> pTest; cComplex.Class(); cComplex.Init(); cComplex.mai[0] = 1234; cComplex.mai[1] = 7890; AssertInt(0, cComplex.GetDistToStack()); AssertInt(0, cComplex.NumStackFroms()); Ptr<CEmbeddedComplex> pComplex; pComplex = &cComplex; AssertInt(1, cComplex.NumStackFroms()); AssertInt(1234, pComplex->mai[0]); AssertInt(7890, pComplex->mai[1]); AssertInt(0, cComplex.GetDistToStack()); pTest = OMalloc(CEmbeddedTest); pcTest = (CEmbeddedTest*)pTest.Object(); pTest->Init(); cComplex.mpTest = pTest; AssertInt(UNKNOWN_DIST_TO_STACK, pcTest->GetDistToStack()); AssertInt(2, pComplex->mpTest->NumStackFroms()); AssertInt(1, cComplex.NumStackFroms()); pTest = NULL; AssertInt(UNKNOWN_DIST_TO_STACK, pcTest->GetDistToStack()); AssertLongLongInt(1, gcObjects.NumMemoryIndexes()); AssertInt(1, pComplex->mpTest->NumStackFroms()); AssertInt(1, cComplex.NumStackFroms()); cComplex.Kill(); AssertLongLongInt(0, gcObjects.NumMemoryIndexes()); ObjectsKill(); }
void TestObjectsFlushNoClear(void) { CFileUtil cFileUtil; BOOL bResult; cFileUtil.RemoveDir("Output"); cFileUtil.MakeDir("Output/Flush1"); ObjectsInit("Output/Flush1"); SetupObjectsForDehollowfication(); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(0, gcObjects.NumDatabaseNames()); AssertLongLongInt(9, gcObjects.NumMemoryIndexes()); AssertLongLongInt(6, gcObjects.NumMemoryNames()); bResult = gcObjects.Flush(FALSE, FALSE); AssertTrue(bResult); AssertLongLongInt(9, gcObjects.NumDatabaseObjects()); AssertLongLongInt(6, gcObjects.NumDatabaseNames()); AssertLongLongInt(9, gcObjects.NumMemoryIndexes()); AssertLongLongInt(6, gcObjects.NumMemoryNames()); ObjectsKill(); CArrayChars aszFileNames; int i; CChars* psz; CChars szOutput; CChars szFileName; aszFileNames.Init(); cFileUtil.FindAllFiles("Input/Dehollowfication", &aszFileNames, FALSE, FALSE); for (i = 0; i < aszFileNames.NumElements(); i++) { psz = aszFileNames.Get(i); szFileName.Init(psz->Text()); cFileUtil.RemovePath(&szFileName); szOutput.Init(); cFileUtil.CurrentDirectory(&szOutput); cFileUtil.AppendToPath(&szOutput, "Output/Flush1"); cFileUtil.AppendToPath(&szOutput, szFileName.Text()); AssertFile(psz->Text(), szOutput.Text()); szOutput.Kill(); szFileName.Kill(); } aszFileNames.Kill(); }
void TestIndexesIteration(void) { CIndexes cIndexes; void* pvMem; void* pvTest; int i; SIndexesIterator sIter; i = 15; pvMem = &i; cIndexes.Init(512); cIndexes.Add(2, pvMem); pvTest = cIndexes.Get(2); AssertPointer(pvMem, pvTest); cIndexes.Add(255, pvMem); cIndexes.Add(256, pvMem); cIndexes.Add(260, pvMem); cIndexes.Add(0x0000708a9bcd5500LL, pvMem); cIndexes.Add(0x0000708a9bcd5501LL, pvMem); cIndexes.Add(0x0000708a9bcd55FFLL, pvMem); cIndexes.Add(0x0000720000000101LL, pvMem); cIndexes.Add(0x0000720000000102LL, pvMem); AssertLongLongInt(2, cIndexes.StartIteration(&sIter)); AssertLongLongInt(255, cIndexes.Iterate(&sIter)); AssertLongLongInt(256, cIndexes.Iterate(&sIter)); AssertLongLongInt(260, cIndexes.Iterate(&sIter)); AssertLongLongInt(0x0000708a9bcd5500LL, cIndexes.Iterate(&sIter)); AssertLongLongInt(0x0000708a9bcd5501LL, cIndexes.Iterate(&sIter)); AssertLongLongInt(0x0000708a9bcd55FFLL, cIndexes.Iterate(&sIter)); AssertLongLongInt(0x0000720000000101LL, cIndexes.Iterate(&sIter)); AssertLongLongInt(0x0000720000000102LL, cIndexes.Iterate(&sIter)); AssertLongLongInt(INVALID_O_INDEX, cIndexes.Iterate(&sIter)); cIndexes.Kill(); }
void TestObjectsObjectKillInGraph(void) { Ptr<CTestNamedString> cNS1; Ptr<CTestNamedString> cNS2; Ptr<CRoot> pRoot; Ptr<CString> cS1; Ptr<CString> cS2; CTestNamedString* pcNS2; CString* pcS2; ObjectsInit(); pRoot = ORoot(); cS1 = OMalloc(CString); cS1->Init("CS1"); cNS1 = ONMalloc(CTestNamedString, "NS1")->Init(cS1, ONull, "NS1"); cS2 = OMalloc(CString)->Init("CS2"); cNS2 = ONMalloc(CTestNamedString, "NS2")->Init(cS2, cNS1, "NS2"); pRoot->Add(cNS2); AssertPointer(cNS2->mpAnother.Object(), cNS1.Object()); AssertLongLongInt(6, gcObjects.NumMemoryIndexes()); pcNS2 = &cNS2; cNS2 = NULL; pRoot = NULL; cS1 = NULL; pcS2 = &cS2; cS2 = NULL; AssertLongLongInt(6, gcObjects.NumMemoryIndexes()); cNS1->Kill(); AssertNull(pcNS2->mpAnother.Object()); AssertLongLongInt(4, gcObjects.NumMemoryIndexes()); AssertPointer(pcNS2->mszString.Object(), pcS2); ObjectsKill(); }
void TestObjectsObjectKillInArrayInGraph(void) { Ptr<CTestNamedString> cNS1; Ptr<CArrayObject> cA1; Ptr<CArrayObject> cA2; Ptr<CRoot> pRoot; Ptr<CString> cS1; ObjectsInit(); pRoot = ORoot(); cS1 = OMalloc(CString)->Init("CS1"); cNS1 = ONMalloc(CTestNamedString, "NS1")->Init(cS1, ONull, "NS1"); cA1 = OMalloc(CArrayObject)->Init(); cA2 = OMalloc(CArrayObject)->Init(); cA1->Add(cNS1); cA2->Add(cNS1); pRoot->Add(cA1); pRoot->Add(cA2); AssertInt(1, cA1->NumPointerTos()); AssertInt(1, cA2->NumPointerTos()); AssertLongLongInt(6, gcObjects.NumMemoryIndexes()); pRoot = NULL; cS1 = NULL; AssertLongLongInt(6, gcObjects.NumMemoryIndexes()); cNS1->Kill(); AssertLongLongInt(4, gcObjects.NumMemoryIndexes()); AssertInt(0, cA1->NumPointerTos()); AssertInt(0, cA2->NumPointerTos()); ObjectsKill(); }
void TestEmbeddedStackPointersKill(void) { ObjectsInit(); CEmbeddedComplex cComplex; STestObjectKilledNotifier sKillNotifier; cComplex.Class(); cComplex.Init(); cComplex.mai[0] = 1234; cComplex.mai[1] = 7890; cComplex.mpTest = OMalloc(CTestObject)->Init(&sKillNotifier); AssertInt(0, cComplex.NumStackFroms()); AssertInt(1, cComplex.mpTest->NumStackFroms()); AssertLongLongInt(1, gcObjects.NumMemoryIndexes()); cComplex.Kill(); AssertTrue(sKillNotifier.bKilled); AssertLongLongInt(0, gcObjects.NumMemoryIndexes()); }
void TestIndexTreeMemoryAddLongLong(void) { CIndexTreeMemory cIndex; long long li; long long* pli; cIndex.Init(); li = 0x88LL; cIndex.Put("GraphRoot", &li, sizeof(long long)); pli = (long long*)cIndex.Get("GraphRoot"); AssertLongLongInt(li, *pli); cIndex.Kill(); }
void TestEmbeddedObjectPointTo(void) { BOOL bResult; CFileUtil cFileUtil; OIndex oiComplex; char* szClassName; cFileUtil.RemoveDir("Output/EmbeddedObject"); MemoryInit(); ObjectsInit("Output/EmbeddedObject/"); SetupEmbeddedObjectConstructors(); Ptr<CRoot> pRoot = ORoot(); Ptr<CEmbeddedComplex> pComplex = OMalloc(CEmbeddedComplex)->Init(); oiComplex = pComplex->GetOI(); Ptr<CEmbeddedContainer> pContainer = &pComplex->mcContainer; pRoot->Add(pContainer); bResult = gcObjects.Flush(TRUE, TRUE); AssertTrue(bResult); ObjectsKill(); MemoryKill(); AssertNull(&pContainer); MemoryInit(); ObjectsInit("Output/EmbeddedObject/"); SetupEmbeddedObjectConstructors(); pRoot = gcObjects.GetRoot(); AssertTrue(pRoot.IsNotNull()); pContainer = pRoot->Get(0); AssertTrue(pContainer.IsHollow()); AssertInt(0, pContainer.Object()->GetNumEmbedded()); AssertLongLongInt(-1, pContainer.GetIndex()); szClassName = pContainer->ClassName(); AssertString("CEmbeddedContainer", szClassName); pComplex = pContainer->GetEmbeddingContainer(); //Kinda feels like this test just stopped... ObjectsKill(); MemoryKill(); }
void TestObjectsFlushDurable(void) { CFileUtil cFileUtil; BOOL bResult; CIndexedConfig cConfig; cFileUtil.RemoveDir("Output"); cFileUtil.MakeDir("Output/Flush2"); cConfig.OptimiseForStreaming("Output/Flush2"); cConfig.SetObjectCacheSize(128 MB); //cConfig.SetWriteThrough(FALSE); ObjectsInit(&cConfig); SetupObjectsForDehollowfication(); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(0, gcObjects.NumDatabaseNames()); AssertLongLongInt(9, gcObjects.NumMemoryIndexes()); AssertLongLongInt(6, gcObjects.NumMemoryNames()); bResult = gcObjects.Flush(FALSE, FALSE); AssertTrue(bResult); AssertLongLongInt(9, gcObjects.NumDatabaseObjects()); AssertLongLongInt(6, gcObjects.NumDatabaseNames()); AssertLongLongInt(9, gcObjects.NumMemoryIndexes()); AssertLongLongInt(6, gcObjects.NumMemoryNames()); ObjectsKill(); AssertFile("Input/Dehollowfication/48_0.DAT", "Output/Flush2/48_0.DAT"); AssertFile("Input/Dehollowfication/56_0.DAT", "Output/Flush2/56_0.DAT"); AssertFile("Input/Dehollowfication/68_0.DAT", "Output/Flush2/68_0.DAT"); AssertFile("Input/Dehollowfication/89_0.DAT", "Output/Flush2/89_0.DAT"); AssertFile("Input/Dehollowfication/93_0.DAT", "Output/Flush2/93_0.DAT"); AssertFile("Input/Dehollowfication/101_0.DAT", "Output/Flush2/101_0.DAT"); AssertFile("Input/Dehollowfication/102_0.DAT", "Output/Flush2/102_0.DAT"); AssertFile("Input/Dehollowfication/Files.DAT", "Output/Flush2/Files.DAT"); AssertFile("Input/Dehollowfication/Indicies.DAT", "Output/Flush2/Indicies.DAT"); AssertFile("Input/Dehollowfication/32_0.NAM", "Output/Flush2/32_0.NAM"); AssertFile("Input/Dehollowfication/Files.NAM", "Output/Flush2/Files.NAM"); }
void TestChunkFileNameing(void) { CChunkFile cChunkFile; int iChunkNum; char acTwentyOne[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}; char acTwentyTwo[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19}; char acTwentyThree[] = {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29}; char acActual[10]; cChunkFile.Init(MemoryFile()); AssertTrue(cChunkFile.WriteOpen()); AssertTrue(cChunkFile.WriteChunkBegin()); AssertLongLongInt(1, cChunkFile.Write(acTwentyOne, 10, 1)); AssertTrue(cChunkFile.WriteChunkBegin()); AssertLongLongInt(1, cChunkFile.Write(acTwentyTwo, 10, 1)); AssertTrue(cChunkFile.WriteChunkEnd("Floopy")); AssertTrue(cChunkFile.WriteChunkBegin()); AssertLongLongInt(1, cChunkFile.Write(acTwentyThree, 10, 1)); AssertTrue(cChunkFile.WriteChunkEnd("Floopy")); AssertTrue(cChunkFile.WriteChunkEnd("Rise")); AssertTrue(cChunkFile.WriteClose()); AssertTrue(cChunkFile.ReadOpen()); iChunkNum = cChunkFile.FindFirstChunkWithName("Rise"); AssertInt(0, iChunkNum); AssertTrue(cChunkFile.ReadChunkBegin(iChunkNum)); AssertLongLongInt(1, cChunkFile.Read(acActual, 10, 1)); AssertMemory(acTwentyOne, acActual, 10); iChunkNum = cChunkFile.FindFirstChunkWithName("Floopy"); AssertInt(0, iChunkNum); AssertTrue(cChunkFile.ReadChunkBegin(iChunkNum)); AssertLongLongInt(1, cChunkFile.Read(acActual, 10, 1)); AssertMemory(acTwentyTwo, acActual, 10); AssertTrue(cChunkFile.ReadChunkEnd()); iChunkNum = cChunkFile.FindNextChunkWithName(); AssertInt(1, iChunkNum); AssertTrue(cChunkFile.ReadChunkBegin(iChunkNum)); AssertLongLongInt(1, cChunkFile.Read(acActual, 10, 1)); AssertMemory(acTwentyThree, acActual, 10); AssertTrue(cChunkFile.ReadChunkEnd()); AssertTrue(cChunkFile.ReadChunkEnd()); AssertTrue(cChunkFile.ReadClose()); cChunkFile.Kill(); }
void TestMapBlockGet(void) { CMapBlock cMapBlock; long long int llia[64]; int i; long long int lli; long long int* plli; int iSize; lli = 0x886c857864030e05; for (i = 0; i < 64; i++) { llia[i] = lli; lli = ((lli + 0x336b265cfdd8a7a6) / 2) * 3; } cMapBlock.Init(16, (CompareFunc)&strcmp, TRUE); AddToMapBlock(&cMapBlock, "cocker", llia[0]); AddToMapBlock(&cMapBlock, "c**k", llia[1]); AddToMapBlock(&cMapBlock, "cockerel", llia[2]); AssertInt(3, cMapBlock.NumElements()); AssertTrue(cMapBlock.Get("cocker", (void**)&plli, &iSize)); AssertLongLongInt(llia[0], *plli); AssertInt(sizeof(long long int), iSize); AssertTrue(cMapBlock.Get("c**k", (void**)&plli, &iSize)); AssertLongLongInt(llia[1], *plli); AssertInt(sizeof(long long int), iSize); AssertTrue(cMapBlock.Get("cockerel", (void**)&plli, &iSize)); AssertLongLongInt(llia[2], *plli); AddToMapBlock(&cMapBlock, "vizard", llia[3]); AddToMapBlock(&cMapBlock, "visard", llia[4]); AddToMapBlock(&cMapBlock, "wizard", llia[5]); AssertTrue(cMapBlock.Get("vizard", (void**)&plli, &iSize)); AssertLongLongInt(llia[3], *plli); AssertTrue(cMapBlock.Get("visard", (void**)&plli, &iSize)); AssertLongLongInt(llia[4], *plli); AssertTrue(cMapBlock.Get("wizard", (void**)&plli, &iSize)); AssertLongLongInt(llia[5], *plli); AddToMapBlock(&cMapBlock, "repletion", llia[6]); AddToMapBlock(&cMapBlock, "ponderous", llia[7]); AddToMapBlock(&cMapBlock, "quondam", llia[8]); AddToMapBlock(&cMapBlock, "inimical", llia[9]); AddToMapBlock(&cMapBlock, "ignominy", llia[10]); AssertTrue(cMapBlock.Get("inimical", (void**)&plli, &iSize)); AssertLongLongInt(llia[9], *plli); AssertInt(sizeof(long long int), iSize); AssertTrue(cMapBlock.Get("cocker", (void**)&plli, &iSize)); AssertLongLongInt(llia[0], *plli); AssertInt(sizeof(long long int), iSize); AddToMapBlock(&cMapBlock, "voluble", llia[11]); AddToMapBlock(&cMapBlock, "intransigent", llia[12]); AddToMapBlock(&cMapBlock, "potentate", llia[13]); AddToMapBlock(&cMapBlock, "sophist", llia[14]); AddToMapBlock(&cMapBlock, "solicitous", llia[15]); AssertInt(16, cMapBlock.NumElements()); AssertTrue(cMapBlock.Get("solicitous", (void**)&plli, &iSize)); AssertLongLongInt(llia[15], *plli); AssertInt(sizeof(long long int), iSize); AssertTrue(cMapBlock.Get("c**k", (void**)&plli, &iSize)); AssertLongLongInt(llia[1], *plli); AssertInt(sizeof(long long int), iSize); AddToMapBlock(&cMapBlock, "resplendent", llia[16]); AssertInt(17, cMapBlock.NumElements()); AssertMapBlock(&cMapBlock, "cocker", llia[0]); AssertMapBlock(&cMapBlock, "c**k", llia[1]); AssertMapBlock(&cMapBlock, "cockerel", llia[2]); AssertMapBlock(&cMapBlock, "vizard", llia[3]); AssertMapBlock(&cMapBlock, "visard", llia[4]); AssertMapBlock(&cMapBlock, "wizard", llia[5]); AssertMapBlock(&cMapBlock, "voluble", llia[11]); AssertMapBlock(&cMapBlock, "intransigent", llia[12]); AssertMapBlock(&cMapBlock, "potentate", llia[13]); AssertMapBlock(&cMapBlock, "sophist", llia[14]); AssertMapBlock(&cMapBlock, "solicitous", llia[15]); AssertMapBlock(&cMapBlock, "repletion", llia[6]); AssertMapBlock(&cMapBlock, "ponderous", llia[7]); AssertMapBlock(&cMapBlock, "quondam", llia[8]); AssertMapBlock(&cMapBlock, "inimical", llia[9]); AssertMapBlock(&cMapBlock, "ignominy", llia[10]); AssertMapBlock(&cMapBlock, "resplendent", llia[16]); cMapBlock.Kill(); }
void TestKillCanFindRoot(void) { ObjectsInit(); Ptr<CRoot> pRoot; Ptr<CGameWorld> pWorld; CGameWorld* pcWorld; pRoot = ORoot(); pWorld = OMalloc(CGameWorld); pWorld->Init(); pRoot->Add(pWorld); Ptr<CHarrier> pHarrier = ONMalloc(CHarrier, "Harrier"); pHarrier->Init(pWorld); Ptr<CJeep> pJeep = ONMalloc(CJeep, "Jeep"); pJeep->Init(pWorld); pWorld->AddPlayer(pHarrier); pWorld->AddPlayer(pJeep); SStateOnKill sHarrierBefore; SStateOnKill sHarrierAfter; SStateOnKill sJeepBefore; SStateOnKill sJeepAfter; pHarrier->SetKillHook(&sHarrierBefore, &sHarrierAfter); pJeep->SetKillHook(&sJeepBefore, &sJeepAfter); SStateOnKill sGooseBefore; SStateOnKill sGooseAfter; SStateOnKill sMaverickBefore; SStateOnKill sMaverickAfter; Ptr<CRedJet> pRedJetGoose = ONMalloc(CRedJet, "Goose"); Ptr<CRedJet> pRedJetMaverick = ONMalloc(CRedJet, "Maverick"); pRedJetGoose->Init(pWorld); pRedJetMaverick->Init(pWorld); pRedJetGoose->SetKillHook(&sGooseBefore, &sGooseAfter); pRedJetMaverick->SetKillHook(&sMaverickBefore, &sMaverickAfter); AssertTrue(pJeep->CanFindRoot()); AssertTrue(pRedJetMaverick->CanFindRoot()); AssertTrue(pHarrier->CanFindRoot()); AssertTrue(pHarrier->GetMissiles()->CanFindRoot()); AssertTrue(pRedJetGoose->CanFindRoot()); AssertTrue(pWorld->CanFindRoot()); AssertTrue(pWorld->GetTickables()->CanFindRoot()); AssertTrue(pRoot->CanFindRoot()); AssertTrue(pRoot->TestGetSet()->CanFindRoot()); AssertLongLongInt(9, gcObjects.NumMemoryIndexes()); // // 4 ArrayObject[6](4) // 4 ^ // 4 | pRedJetGoose[8,Goose](4) // 4 | ^/ // | // pRedJetMaverick[9,Maverick](4) // 3 pHarrier[5,Harrier](3) pJeep[7,Jeep](3) // ^/ // 3 |^ ^ /^ ^ // // // 3 || \ // | // // // 3 || // | // // // 3 || //\ | // // // 3 || // \ | /. // // 3 || // ArrayObject[4](3)/ // || // ^ . / // 2 || // / / / // 2 v| v/ / v v // 2 pWorld[3](2)--------------- // ^ // 1 | // 1 SetObject[2](1) // ^ // 0 | // 0 pRoot[1,GraphRoot](0) // pRoot->Remove(pWorld); AssertFalse(pJeep->CanFindRoot()); AssertFalse(pRedJetMaverick->CanFindRoot()); AssertFalse(pHarrier->CanFindRoot()); AssertFalse(pHarrier->GetMissiles()->CanFindRoot()); //The destruction of the pointer created by pHarrier->GetMissiles() set a lot of the root distances to -2. AssertFalse(pRedJetGoose->CanFindRoot()); AssertFalse(pWorld->CanFindRoot()); AssertFalse(pWorld->GetTickables()->CanFindRoot()); AssertTrue(pRoot->CanFindRoot()); AssertTrue(pRoot->TestGetSet()->CanFindRoot()); AssertInt(-1, pJeep->GetDistToRoot()); AssertInt(-1, pRedJetMaverick->GetDistToRoot()); AssertInt(-1, pHarrier->GetDistToRoot()); AssertInt(-1, pHarrier->GetMissiles()->GetDistToRoot()); AssertInt(-1, pRedJetGoose->GetDistToRoot()); AssertInt(-1, pWorld->GetDistToRoot()); AssertInt(-1, pWorld->GetTickables()->GetDistToRoot()); AssertLongLongInt(9, gcObjects.NumMemoryIndexes()); AssertLongLongInt(5, gcObjects.NumMemoryNames()); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(0, gcObjects.NumDatabaseNames()); pJeep = NULL; pRedJetMaverick = NULL; pHarrier = NULL; pRedJetGoose = NULL; pcWorld = &pWorld; pWorld = NULL; AssertLongLongInt(2, gcObjects.NumMemoryIndexes()); AssertLongLongInt(1, gcObjects.NumMemoryNames()); AssertInt('X', sHarrierBefore.sPoint.x); AssertInt('Y', sHarrierBefore.sPoint.y); AssertInt('Z', sHarrierBefore.sPoint.z); AssertString("012345678901234", sHarrierBefore.cPicture.mszPretenedImAPicture); AssertString("Alas I am Dead!", sHarrierAfter.cPicture.mszPretenedImAPicture); AssertString("012345678901234", sJeepBefore.cPicture.mszPretenedImAPicture); AssertString("Alas I am Dead!", sJeepAfter.cPicture.mszPretenedImAPicture); ObjectsKill(); }
void TestIndexTreeMemoryRemoveResize(void) { CIndexTreeMemory cIndex; long long li; CMemoryAllocator cMemoryAlloc; CCountingAllocator cTrackingAlloc; int iExpectedRootSize; cMemoryAlloc.Init(); cTrackingAlloc.Init(&cMemoryAlloc); cIndex.Init(&cTrackingAlloc); AssertInt(1, cIndex.CountAllocatedNodes()); AssertInt(0, cIndex.RecurseSize()); AssertInt(16, cIndex.SizeofNode()); AssertInt(4, cIndex.SizeofNodePtr()); iExpectedRootSize = cIndex.CalculateRootNodeSize(); AssertInt(1040, iExpectedRootSize); AssertInt(1040, cTrackingAlloc.AllocatedUserSize()); li = 0x77LL; cIndex.Put("M", &li, sizeof(long long)); AssertInt(2, cIndex.CountAllocatedNodes()); AssertInt(1, cIndex.RecurseSize()); AssertInt(1064, iExpectedRootSize + sizeof(CIndexTreeNodeMemory) + sizeof(long long)); AssertInt(1064, cTrackingAlloc.AllocatedUserSize()); li = 0x88LL; cIndex.Put("MA", &li, sizeof(long long)); AssertInt(1092, cTrackingAlloc.AllocatedUserSize()); li = 0x99LL; cIndex.Put("MC", &li, sizeof(long long)); AssertInt(4, cIndex.CountAllocatedNodes()); AssertInt(3, cIndex.RecurseSize()); AssertInt(1124, cTrackingAlloc.AllocatedUserSize()); li = 0xaaLL; cIndex.Put("MB", &li, sizeof(long long)); AssertInt(5, cIndex.CountAllocatedNodes()); AssertInt(4, cIndex.RecurseSize()); AssertInt(1148, cTrackingAlloc.AllocatedUserSize()); li = 0xbbLL; cIndex.Put("MBP", &li, sizeof(long long)); AssertInt(6, cIndex.CountAllocatedNodes()); AssertInt(5, cIndex.RecurseSize()); AssertInt(5, cIndex.NumElements()); AssertInt(1176, cTrackingAlloc.AllocatedUserSize()); AssertLongLongInt(0xaaLL, *((long long*)cIndex.Get("MB"))); cIndex.Remove("MB"); AssertInt(6, cIndex.CountAllocatedNodes()); AssertInt(4, cIndex.RecurseSize()); AssertInt(4, cIndex.NumElements()); AssertInt(1176, cTrackingAlloc.AllocatedUserSize()); AssertNull(cIndex.Get("MB")); AssertLongLongInt(0xbbLL, *((long long*)cIndex.Get("MBP"))); cIndex.Remove("MBP"); AssertInt(4, cIndex.CountAllocatedNodes()); AssertInt(3, cIndex.RecurseSize()); AssertInt(3, cIndex.NumElements()); AssertInt(1124, cTrackingAlloc.AllocatedUserSize()); AssertNull(cIndex.Get("MBP")); AssertLongLongInt(0x99LL, *((long long*)cIndex.Get("MC"))); AssertLongLongInt(0x88LL, *((long long*)cIndex.Get("MA"))); cIndex.Remove("MA"); AssertInt(3, cIndex.CountAllocatedNodes()); AssertInt(2, cIndex.RecurseSize()); AssertInt(2, cIndex.NumElements()); AssertInt(1092, cTrackingAlloc.AllocatedUserSize()); AssertNull(cIndex.Get("MA")); AssertLongLongInt(0x99LL, *((long long*)cIndex.Get("MC"))); cIndex.Remove("MC"); AssertInt(2, cIndex.CountAllocatedNodes()); AssertInt(1, cIndex.RecurseSize()); AssertInt(1, cIndex.NumElements()); AssertInt(1064, cTrackingAlloc.AllocatedUserSize()); AssertNull(cIndex.Get("MC")); AssertLongLongInt(0x77LL, *((long long*)cIndex.Get("M"))); cIndex.Remove("M"); AssertInt(1, cIndex.CountAllocatedNodes()); AssertInt(0, cIndex.RecurseSize()); AssertInt(0, cIndex.NumElements()); AssertInt(1040, cTrackingAlloc.AllocatedUserSize()); AssertNull(cIndex.Get("M")); cIndex.Kill(); cTrackingAlloc.Kill(); cMemoryAlloc.Kill(); }
void TestDehollowficationFromDatabase(void) { CIndexedConfig cConfig; CFileUtil cFileUtil; cConfig.Manual("Output\\Dehollowfication\\Database", FALSE, TRUE, FALSE, 1 MB); cFileUtil.RemoveDir("Output\\Dehollowfication\\Database"); MemoryInit(); ObjectsInit(&cConfig); SetupDehollowficationScene(); gcObjects.Flush(FALSE, FALSE); ObjectsKill(); MemoryKill(); MemoryInit(); ObjectsInit(&cConfig); SetupDehollowficationConstructors(); AssertLongLongInt(0, gcUnknowns.NumElements()); AssertInt(0, gcObjects.GetStackPointers()->UsedPointers()); AssertLongLongInt(0, gcObjects.NumMemoryIndexes()); AssertLongLongInt(0, gcObjects.NumMemoryNames()); AssertLongLongInt(11, gcObjects.NumDatabaseObjects()); AssertLongLongInt(0, gcObjects.NumDatabaseObjectsCached()); AssertLongLongInt(6, gcObjects.NumDatabaseNames()); Ptr<CRoot> pRoot = ORoot(); AssertTrue(pRoot->IsSetHollow()); AssertLongLongInt(2, gcUnknowns.NumElements()); AssertLongLongInt(2, gcObjects.NumMemoryIndexes()); AssertLongLongInt(1, gcObjects.NumMemoryNames()); AssertLongLongInt(1, gcObjects.NumDatabaseObjectsCached()); AssertLongLongInt(6, gcObjects.NumDatabaseNames()); AssertInt(1, gcObjects.GetStackPointers()->UsedPointers()); Ptr<CTestDoubleNamedString> pTest = pRoot->Get<CTestDoubleNamedString>("Double Start"); //This will cause pRoot.Set to be dehollowed. AssertInt(2, gcObjects.GetStackPointers()->UsedPointers()); AssertFalse(pRoot->IsSetHollow()); AssertTrue(pTest.IsNotNull()); AssertTrue(pTest.IsHollow()); AssertLongLongInt(10, pTest.GetIndex()); AssertLongLongInt(4, gcUnknowns.NumElements()); AssertLongLongInt(4, gcObjects.NumMemoryIndexes()); AssertString("12345", pTest->mpSplit1->mszEmbedded.Text()); //This will cause pTest and pTest.Split1 to be dehollowed. AssertLongLongInt(9, gcUnknowns.NumElements()); AssertLongLongInt(9, gcObjects.NumMemoryIndexes()); AssertFalse(pTest.IsHollow()); AssertLongLongInt(10, pTest.GetIndex()); AssertInt(2, gcObjects.GetStackPointers()->UsedPointers()); AssertTrue(pTest->mpSplit1->mpAnother.IsHollow()); AssertTrue(pTest->mpSplit2.IsHollow()); AssertTrue(pTest->mpSplit1->mszString.IsHollow()); AssertString("Diamond End", pTest->mpSplit1->mpAnother.GetName()); AssertString("6789", pTest->mpSplit1->mszString->Text()); AssertFalse(pTest->mpSplit1->mszString.IsHollow()); AssertInt(2, gcObjects.GetStackPointers()->UsedPointers()); Ptr<CTestNamedString> pDiamond = pTest->mpSplit1->mpAnother; AssertLongLongInt(9, gcUnknowns.NumElements()); AssertLongLongInt(9, gcObjects.NumMemoryIndexes()); AssertInt(3, gcObjects.GetStackPointers()->UsedPointers()); AssertTrue(pTest->mpSplit1->mpAnother.IsHollow()); AssertTrue(pDiamond.IsHollow()); pDiamond->ClassName(); //This will cause pDiamond to be de-hollowed AssertFalse(pDiamond.IsHollow()); AssertFalse(pTest->mpSplit1->mpAnother.IsHollow()); AssertLongLongInt(10, gcUnknowns.NumElements()); AssertLongLongInt(10, gcObjects.NumMemoryIndexes()); AssertLongLongInt(6, gcObjects.NumMemoryNames()); AssertLongLongInt(3, gcObjects.NumDatabaseObjectsCached()); AssertLongLongInt(6, gcObjects.NumDatabaseNames()); AssertTrue(pTest->mpSplit2.IsHollow()); pTest->mpSplit2->ClassSize(); AssertFalse(pTest->mpSplit2.IsHollow()); AssertFalse(pTest->mpSplit2->mpAnother.IsHollow()); AssertPointer(pDiamond.Object(), pTest->mpSplit2->mpAnother.Object()); AssertLongLongInt(11, gcObjects.NumMemoryIndexes()); AssertLongLongInt(6, gcObjects.NumMemoryNames()); AssertLongLongInt(2, gcObjects.NumDatabaseObjectsCached()); AssertLongLongInt(6, gcObjects.NumDatabaseNames()); Ptr<CTestNamedString> pRandom = pRoot->Get<CTestNamedString>("NamedString 3"); AssertTrue(pRandom.IsNotNull()); AssertTrue(pRandom.IsHollow()); AssertTrue(pRandom->mszString.IsHollow()); AssertFalse(pRandom.IsHollow()); AssertTrue(pTest->mpSplit2->mszString.IsHollow()); AssertString("World", pRandom->mszString->Text()); AssertFalse(pRandom->mszString.IsHollow()); AssertFalse(pTest->mpSplit2->mszString.IsHollow()); AssertPointer(pRandom->mszString.Object(), pTest->mpSplit2->mszString.Object()); AssertLongLongInt(11, gcObjects.NumDatabaseObjects()); ObjectsKill(); AssertTrue(pRoot.IsNull()); AssertTrue(pTest.IsNull()); AssertTrue(pDiamond.IsNull()); AssertTrue(pRandom.IsNull()); pDiamond.UnsafeClearObject(); MemoryKill(); }
void TestEmbeddedObjectKill(void) { char szClusterMissileState[64]; char szMissile1State[64]; ObjectsInit(); Ptr<CRoot> pRoot = ORoot(); Ptr<CGameWorld> pWorld = OMalloc(CGameWorld)->Init(); pRoot->Add(pWorld); Ptr<CClusterMissile> pClusterMissile = ONMalloc(CClusterMissile, "Anna")->Init(pWorld); pWorld = NULL; Ptr<CPointerContainer> pPointerPointer = OMalloc(CPointerContainer); pRoot->Add(pPointerPointer); pPointerPointer->Init(&pClusterMissile->mcMissile1); Ptr<CPointerContainer> pPointerPointer2 = OMalloc(CPointerContainer); pRoot->Add(pPointerPointer2); pPointerPointer2->Init(&pClusterMissile); //The number of allocated object shouldn't change until all the froms are removed //both from the embedded object and the 'normal' object. AssertLongLongInt(7, gcObjects.GetMemory()->NumIndexed()); AssertLongLongInt(7, gcUnknowns.NumElements()); pClusterMissile->SetKillString(szClusterMissileState); pClusterMissile->mcMissile1.SetKillString(szMissile1State); AssertInt(2, pClusterMissile->NumHeapFroms()); AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms()); AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms()); strcpy(szClusterMissileState, "Alive"); strcpy(szMissile1State, "Alive"); pPointerPointer->Clear(); AssertInt(1, pClusterMissile->NumHeapFroms()); AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms()); AssertInt(0, pClusterMissile->mcMissile1.NumHeapFroms()); AssertString("Alive", szClusterMissileState); AssertString("Alive", szMissile1State); pPointerPointer->mp = &pClusterMissile->mcMissile1; AssertInt(2, pClusterMissile->NumHeapFroms()); AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms()); AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms()); pPointerPointer2->Clear(); AssertInt(1, pClusterMissile->NumHeapFroms()); AssertInt(0, pClusterMissile->CEmbeddedObject::NumHeapFroms()); AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms()); AssertString("Alive", szClusterMissileState); AssertString("Alive", szMissile1State); pClusterMissile = NULL; //Make sure nothing has been de-allocated. AssertLongLongInt(7, gcObjects.GetMemory()->NumIndexed()); AssertLongLongInt(7, gcUnknowns.NumElements()); pPointerPointer->Clear(); AssertString("Killed", szClusterMissileState); AssertString("Killed", szMissile1State); AssertLongLongInt(6, gcObjects.GetMemory()->NumIndexed()); AssertLongLongInt(6, gcUnknowns.NumElements()); gcObjects.Flush(TRUE, FALSE); AssertLongLongInt(0, gcObjects.GetMemory()->NumIndexed()); AssertLongLongInt(0, gcUnknowns.NumElements()); ObjectsKill(); }
void TestEmbeddedObjectContainerDehollowfication(void) { BOOL bResult; CFileUtil cFileUtil; char* szClassName; OIndex oiComplex; cFileUtil.RemoveDir("Output/EmbeddedObject"); MemoryInit(); ObjectsInit("Output/EmbeddedObject/"); SetupEmbeddedObjectConstructors(); Ptr<CRoot> pRoot = ORoot(); Ptr<CEmbeddedComplex> pComplex = OMalloc(CEmbeddedComplex)->Init(); oiComplex = pComplex->GetOI(); pRoot->Add(pComplex); bResult = gcObjects.Flush(TRUE, TRUE); AssertTrue(bResult); ObjectsKill(); MemoryKill(); AssertInt(176, sizeof(CEmbeddedTest)); AssertInt(544, sizeof(CEmbeddedContainer)); AssertInt(1032, sizeof(CEmbeddedComplex)); MemoryInit(); ObjectsInit("Output/EmbeddedObject/"); SetupEmbeddedObjectConstructors(); pRoot = gcObjects.GetRoot(); AssertTrue(pRoot.IsNotNull()); pComplex = pRoot->Get(0); AssertTrue(pComplex.IsHollow()); szClassName = pComplex->ClassName(); AssertString("CEmbeddedComplex", szClassName); AssertLongLongInt(oiComplex, pComplex.GetIndex()); AssertInt(1, pComplex->mai[0]); AssertInt(2, pComplex->mai[1]); AssertLongLongInt(INVALID_O_INDEX, pComplex->mcSimple.GetOI()); AssertInt(85, pComplex->mcSimple.miAmANumber); AssertFloat(58.0f, pComplex->mcSimple.mfSoAmI, 0); AssertLongLongInt(INVALID_O_INDEX, pComplex->mcContainer.GetOI()); AssertInt(73, pComplex->mcContainer.mi); AssertFloat(666.0f, pComplex->mcContainer.mf, 0); AssertString("And", pComplex->mcContainer.msz); AssertLongLongInt(INVALID_O_INDEX, pComplex->mcContainer.mcOne.GetOI()); AssertInt(85, pComplex->mcContainer.mcOne.miAmANumber); AssertFloat(58.0f, pComplex->mcContainer.mcOne.mfSoAmI, 0); AssertLongLongInt(INVALID_O_INDEX, pComplex->mcContainer.mcTwo.GetOI()); AssertInt(85, pComplex->mcContainer.mcTwo.miAmANumber); AssertFloat(58.0f, pComplex->mcContainer.mcTwo.mfSoAmI, 0); AssertLongLongInt(3, gcObjects.NumMemoryIndexes()); ObjectsKill(); MemoryKill(); }
void TestLogFileWrite(void) { CLogFile* pcLogFile; CMemoryFile* pcMemoryFile; CFileBasic cFile; BOOL bResult; int iLength; char sz[200]; pcMemoryFile = MemoryFile(); pcLogFile = LogFile(pcMemoryFile); cFile.Init(pcLogFile); bResult = cFile.Open(EFM_ReadWrite_Create); AssertTrue(bResult); bResult = cFile.WriteString("The suspense is killing me!"); AssertTrue(bResult); AssertNull((char*)pcMemoryFile->GetBufferPointer()); AssertInt(1, pcLogFile->GetNumWrites()); AssertLongLongInt(32, pcLogFile->GetWriteSize(0)); bResult = cFile.Seek(8); AssertTrue(bResult); bResult = cFile.WriteData("camisole", 8); AssertTrue(bResult); AssertInt(1, pcLogFile->GetNumWrites()); AssertLongLongInt(32, pcLogFile->GetWriteSize(0)); AssertNull((char*)pcMemoryFile->GetBufferPointer()); cFile.Seek(0); bResult = cFile.ReadStringLength(&iLength); AssertTrue(bResult); AssertInt(28, iLength); AssertFalse(cFile.IsEndOfFile()); bResult = cFile.ReadStringChars(sz, iLength); AssertString("The camisole is killing me!", sz); AssertTrue(cFile.IsEndOfFile()); bResult = pcLogFile->Commit(); AssertTrue(bResult); AssertString("The camisole is killing me!", (char*)RemapSinglePointer(pcMemoryFile->GetBufferPointer(), sizeof(int))); bResult = cFile.Close(); //This should go before Commit AssertTrue(bResult); pcLogFile->Begin(); bResult = cFile.Open(EFM_ReadWrite_Create); AssertTrue(bResult); bResult = cFile.Seek(4); AssertTrue(bResult); bResult = cFile.WriteData("Dog", 3); bResult = cFile.Seek(20); AssertTrue(bResult); bResult = cFile.WriteData("plurgle", 7); AssertInt(2, pcLogFile->GetNumWrites()); AssertLongLongInt(3, pcLogFile->GetWriteSize(0)); AssertLongLongInt(7, pcLogFile->GetWriteSize(1)); AssertString("The camisole is killing me!", (char*)RemapSinglePointer(pcMemoryFile->GetBufferPointer(), sizeof(int))); cFile.Seek(0); bResult = cFile.ReadStringLength(&iLength); AssertTrue(bResult); AssertInt(28, iLength); AssertFalse(cFile.IsEndOfFile()); bResult = cFile.ReadStringChars(sz, iLength); AssertTrue(bResult); AssertString("Dog camisole is plurgle me!", sz); AssertTrue(cFile.IsEndOfFile()); bResult = pcLogFile->Commit(); AssertTrue(bResult); AssertString("Dog camisole is plurgle me!", (char*)RemapSinglePointer(pcMemoryFile->GetBufferPointer(), sizeof(int))); bResult = cFile.Close(); AssertTrue(bResult); pcLogFile->Begin(); bResult = cFile.Open(EFM_ReadWrite_Create); AssertTrue(bResult); cFile.Seek(4); cFile.WriteData("X", 1); cFile.Seek(6); bResult = cFile.WriteData("Z", 1); cFile.Seek(28); cFile.WriteData("A", 1); cFile.Seek(30); bResult = cFile.WriteData("C", 1); AssertInt(4, pcLogFile->GetNumWrites()); cFile.Seek(5); cFile.WriteData("Y", 1); AssertInt(3, pcLogFile->GetNumWrites()); cFile.Seek(29); cFile.WriteData("B", 1); AssertInt(2, pcLogFile->GetNumWrites()); cFile.Seek(0); bResult = cFile.ReadStringLength(&iLength); AssertTrue(bResult); bResult = cFile.ReadStringChars(sz, iLength); AssertString("XYZ camisole is plurgle ABC", sz); AssertTrue(cFile.IsEndOfFile()); bResult = pcLogFile->Commit(); AssertTrue(bResult); AssertString("XYZ camisole is plurgle ABC", (char*)RemapSinglePointer(pcMemoryFile->GetBufferPointer(), sizeof(int))); bResult = cFile.Close(); AssertTrue(bResult); cFile.Kill(); }
void TestObjectReaderChunkedDeserialised(void) { CObjectReaderChunkFileDisk cReader; CObjectGraphDeserialiser cGraphDeserialiser; CPointer cBase; Ptr<CTestWithArray> cA1; Ptr<CTestWithArray> cA2; Ptr<CTestNamedString> cNS1; Ptr<CTestNamedString> cNS2; Ptr<CTestNamedString> cNS3; Ptr<CTestNamedString> cNS4; Ptr<CString> sz1; Ptr<CString> sz2; Ptr<CString> sz3; CPointer cTemp; Ptr<CTestInteger> cI1; Ptr<CTestInteger> cI2; Ptr<CTestInteger> cI3; CObjectAllocator cAllocator; CDependentReadObjects cDependentReadObjects; OIndex oiI1; OIndex oiI2; OIndex oiI3; int iNumMemoryIndexes; gcObjects.AddConstructor<CTestWithArray>(); gcObjects.AddConstructor<CTestInteger>(); gcObjects.AddConstructor<CTestNamedString>(); gcObjects.AddConstructor<CString>(); gcObjects.AddConstructor<CArrayObject>(); iNumMemoryIndexes = WriteObjectReaderChunkedFile(); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(14, iNumMemoryIndexes); ObjectsKill(); ObjectsInit(); gcObjects.AddConstructor<CTestWithArray>(); gcObjects.AddConstructor<CTestInteger>(); gcObjects.AddConstructor<CTestNamedString>(); gcObjects.AddConstructor<CString>(); gcObjects.AddConstructor<CArrayObject>(); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(0, gcObjects.NumMemoryIndexes()); cAllocator.Init(&gcObjects); cDependentReadObjects.Init(); cReader.Init("Output\\ObjectReaderChunked\\Test\\", "Reader"); cGraphDeserialiser.Init(&cReader, FALSE, &cAllocator, &cDependentReadObjects, gcObjects.GetMemory()); cBase = cGraphDeserialiser.Read("Array 1"); AssertTrue(cBase.IsNotNull()); AssertString("CTestWithArray", cBase.ClassName()); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(14, gcObjects.NumMemoryIndexes()); cA1 = gcObjects.Get("Array 1"); AssertTrue(cA1.IsNotNull()); AssertString("CTestWithArray", cA1->ClassName()); AssertString("Something with One", cA1->mszString.Text()); AssertInt(1, cA1->mx); AssertPointer(cBase.Object(), cA1.Object()); cA2 = gcObjects.Get("Array X"); AssertTrue(cA2.IsNotNull()); AssertString("CTestWithArray", cA2.ClassName()); AssertString("An with 2", cA2->mszString.Text()); AssertInt(2, cA2->mx); cNS1 = gcObjects.Get("NamedString 1"); AssertTrue(cNS1.IsNotNull()); AssertString("CTestNamedString", cNS1->ClassName()); AssertString("In Named 1", cNS1->mszEmbedded.Text()); cNS2 = gcObjects.Get("NamedString 2"); AssertTrue(cNS2.IsNotNull()); AssertString("CTestNamedString", cNS2->ClassName()); AssertString("Another in 2", cNS2->mszEmbedded.Text()); cNS3 = gcObjects.Get("NamedString 3"); AssertTrue(cNS3.IsNotNull()); AssertString("CTestNamedString", cNS3->ClassName()); AssertString("Three", cNS3->mszEmbedded.Text()); cNS4 = gcObjects.Get("NamedString 4"); AssertTrue(cNS4.IsNotNull()); AssertTrue(cBase.IsNotNull()); AssertString("CTestWithArray", cBase->ClassName()); AssertPointer(&cA1, &cBase); AssertNotNull(&cA1->mcArray); AssertInt(6, cA1->mcArray->NumElements()) sz2 = cA1->mcArray->Get(0); AssertString("Ye!", sz2->Text()); cTemp = cA1->mcArray->Get(1); AssertPointer(&cNS1, &cTemp); oiI1 = cGraphDeserialiser.GetNewIndexFromOld(5LL); oiI2 = cGraphDeserialiser.GetNewIndexFromOld(6LL); oiI3 = cGraphDeserialiser.GetNewIndexFromOld(7LL); cI1 = gcObjects.Get(oiI1); AssertString("CTestInteger", cI1->ClassName()); cI2 = gcObjects.Get(oiI2); AssertString("CTestInteger", cI2->ClassName()); cI3 = gcObjects.Get(oiI3); AssertString("CTestInteger", cI3->ClassName()); AssertInt(3, cI1->mx); AssertInt(2, cI1->my); AssertInt(1, cI1->mz); AssertPointer(&cNS2, &cNS1->mpAnother); AssertPointer(&cI1, &cA1->mcArray->Get(2)); AssertPointer(&cNS3, &cA1->mcArray->Get(3)); AssertPointer(&cNS1, &cNS3->mpAnother); AssertPointer(&cI2, &cA1->mcArray->Get(4)); AssertPointer(&cA2, &cA1->mcArray->Get(5)); AssertNotNull(&cA2->mcArray); AssertInt(4, cA2->mcArray->NumElements()); AssertPointer(&cI3, &cA2->mcArray->Get(0)); AssertPointer(&cNS2, &cA2->mcArray->Get(1)); AssertPointer(&cNS3, &cNS2->mpAnother); AssertPointer(&cI1, &cA2->mcArray->Get(2)); AssertPointer(&cNS4, &cA2->mcArray->Get(3)); AssertPointer(NULL, &cNS4->mpAnother); AssertPointer(NULL, &cNS4->mszString); cGraphDeserialiser.Kill(); cDependentReadObjects.Kill(); cAllocator.Kill(); cReader.Kill(); }
void TestChunkFileFileRead(void) { CChunkFile cChunkFile; int iChunkNum; char szZ[] = {"Z"}; CChunkFileFile cChunkFileFile; char cz; cChunkFile.Init(MemoryFile()); AssertTrue(cChunkFile.WriteOpen()); AssertTrue(cChunkFile.WriteChunkBegin()); AssertLongLongInt(1, cChunkFile.Write(szZ, 1, 1)); AssertTrue(cChunkFile.WriteChunkEnd("Zynaps")); AssertTrue(cChunkFile.WriteClose()); AssertTrue(cChunkFile.ReadOpen()); iChunkNum = cChunkFile.FindFirstChunkWithName("Zynaps"); AssertInt(0, iChunkNum); AssertTrue(cChunkFile.ReadChunkBegin(iChunkNum)); cChunkFileFile.Init(&cChunkFile); AssertTrue(cChunkFileFile.Open(EFM_Read)); AssertLongLongInt(1, cChunkFileFile.Size()); AssertLongLongInt(0, cChunkFileFile.Tell()); AssertLongLongInt(1, cChunkFileFile.Read(&cz, 1, 1)); AssertChar('Z', cz); cz = 'Q'; AssertTrue(cChunkFileFile.Seek(0, EFSO_SET)); AssertLongLongInt(0, cChunkFileFile.Tell()); AssertLongLongInt(1, cChunkFileFile.Read(&cz, 1, 1)); AssertChar('Z', cz); cz = 'Q'; AssertLongLongInt(1, cChunkFileFile.Tell()); AssertFalse(cChunkFileFile.Eof()); AssertLongLongInt(0, cChunkFileFile.Read(&cz, 1, 1)); AssertTrue(cChunkFileFile.Eof()); AssertLongLongInt(1, cChunkFileFile.Tell()); AssertTrue(cChunkFileFile.Seek(0, EFSO_SET)); AssertFalse(cChunkFileFile.Eof()); AssertLongLongInt(1, cChunkFileFile.Read(&cz, 1, 2)); AssertChar('Z', cz); cz = 'Q'; AssertLongLongInt(1, cChunkFileFile.Tell()); AssertTrue(cChunkFileFile.Eof()); AssertTrue(cChunkFileFile.Close()); AssertTrue(cChunkFile.ReadChunkEnd()); AssertTrue(cChunkFile.ReadClose()); cChunkFile.Kill(); }