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 TestDehollowficationFromChunkFileSource(void) { CFileUtil cFileUtil; cFileUtil.RemoveDir("Output\\Dehollowfication\\ChunkFile"); MemoryInit(); ObjectsInit("Output\\Dehollowfication\\Temp"); WriteDehollowficationChunkedFile(); ObjectsKill(); MemoryKill(); cFileUtil.RemoveDir("Output\\Dehollowfication\\Temp"); CObjectSourceChunked* pcObjectSourceChunked; CDiskFile* pcDiskFile = DiskFile("Output\\Dehollowfication\\ChunkFile\\Double.DRG"); MemoryInit(); ObjectsInit("Output\\Dehollowfication\\Temp"); SetupDehollowficationConstructors(); pcObjectSourceChunked = (CObjectSourceChunked*)gcObjects.AddSource<CObjectConverterNative>(pcDiskFile, "Double"); //Note the .DRG is intentionally dropped. AssertNotNull(pcObjectSourceChunked); AssertInt(4, pcObjectSourceChunked->NumNames()); AssertString("Diamond End", pcObjectSourceChunked->GetName(0)); AssertString("Double Start", pcObjectSourceChunked->GetName(1)); AssertString("NamedString 1", pcObjectSourceChunked->GetName(2)); AssertString("NamedString 2", pcObjectSourceChunked->GetName(3)); Ptr<CTestDoubleNamedString> pStart; pStart = gcObjects.Get("Double Start"); AssertTrue(pStart.IsNotNull()); AssertString("CTestDoubleNamedString", pStart.ClassName()); AssertTrue(pStart->mpSplit1.IsHollow()); AssertTrue(pStart->mpSplit2.IsHollow()); AssertFalse(pStart->mszString.IsHollow()); pStart->mpSplit1->ClassName(); AssertFalse(pStart->mpSplit1.IsHollow()); AssertString("CTestNamedString", pStart->mpSplit1.ClassName()); ObjectsKill(); MemoryKill(); }
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 TestMemoryAllocatorFree(void) { MemoryInit(); CMemoryAllocator cAlloc; CConstructorTestClass* pcTest; gcConstructors.Add<CConstructorTestClass>("CConstructorTestClass"); cAlloc.Init(); AssertInt(0, cAlloc.GetMemory()->NumElements()); pcTest = (CConstructorTestClass*)gcConstructors.Construct("CConstructorTestClass", &cAlloc); AssertInt(1, cAlloc.GetMemory()->NumElements()); pcTest->k = 7; AssertInt(3, pcTest->Method1()); AssertInt(7, pcTest->k); cAlloc.Free(pcTest); AssertInt(0, cAlloc.GetMemory()->NumElements()); cAlloc.Kill(); MemoryKill(); }
void TestIndexTreeMemory(void) { BeginTests(); FastFunctionsInit(); MemoryInit(); TestIndexTreeMemoryKill(); TestIndexTreeMemoryAdd(); TestIndexTreeMemoryGet(); TestIndexTreeMemoryPutPtrDuplicate(); TestIndexTreeMemoryPutDifferenceSizeDuplicates(); TestIndexTreeMemoryValidateInternalConsistency(); TestIndexTreeMemoryCountAllocatedNodes(); TestIndexTreeMemoryRemoveResize(); TestIndexTreeMemoryRemoveByObject(); TestIndexTreeMemoryHasKey(); TestIndexTreeMemoryRemoveNullNode(); TestIndexTreeMemoryAddLongLong(); TestIndexTreeMemoryIterate(); TestIndexTreeMemoryReadWrite(); TestIndexTreeMemoryRemoveOnRoot(); TestIndexTreeMemoryResizeData(); MemoryKill(); FastFunctionsKill(); TestStatistics(); }
void TestEmbeddedGetEmbeddedIndex(void) { MemoryInit(); ObjectsInit(); CEmbeddedComplex cComplex; cComplex.Class(); cComplex.Init(); AssertInt(0, cComplex.TestGetNumEmbeddedFromFlags()); AssertInt(6, cComplex.GetNumEmbedded()); AssertInt(6, cComplex.TestGetNumEmbeddedFromFlags()); AssertInt(1, cComplex.mcSimple.GetNumEmbedded()); AssertInt(1, cComplex.ma.GetNumEmbedded()); AssertInt(3, cComplex.mcContainer.GetNumEmbedded()); AssertInt(1, cComplex.mcContainer.mcOne.GetNumEmbedded()); AssertInt(1, cComplex.mcContainer.mcOne.GetNumEmbedded()); AssertInt(0, cComplex.GetEmbeddedIndex(&cComplex)); AssertInt(1, cComplex.GetEmbeddedIndex(&cComplex.mcSimple)); AssertInt(2, cComplex.GetEmbeddedIndex(&cComplex.ma)); AssertInt(3, cComplex.GetEmbeddedIndex(&cComplex.mcContainer)); AssertInt(4, cComplex.GetEmbeddedIndex(&cComplex.mcContainer.mcOne)); AssertInt(5, cComplex.GetEmbeddedIndex(&cComplex.mcContainer.mcTwo)); AssertInt(-1, cComplex.GetEmbeddedIndex(NULL)); ObjectsKill(); MemoryKill(); }
void TestMapStringUnknownPut(void) { MemoryInit(); UnknownsInit(); CMapStringUnknown cMap; CTestUnknownJobbie* pcTest; cMap.Init(); AssertInt(0, cMap.NumElements()); pcTest = cMap.Put<CTestUnknownJobbie>("Hello"); pcTest->Init(7, "1st"); AssertInt(1, cMap.NumElements()); pcTest = cMap.Put<CTestUnknownJobbie>("World"); pcTest->Init(19, "A pony"); AssertInt(2, cMap.NumElements()); pcTest = cMap.Put<CTestUnknownJobbie>("Aardvark"); pcTest->Init(4, "Restore"); AssertInt(3, cMap.NumElements()); pcTest = cMap.Put<CTestUnknownJobbie>(NULL); AssertNull(pcTest); AssertInt(3, cMap.NumElements()); cMap.Kill(); UnknownsKill(); MemoryKill(); }
void TestMapStringUnknownNoOverwrite(void) { MemoryInit(); UnknownsInit(); CMapStringUnknown cMap; CTestUnknownJobbie* pcTest; cMap.Init(TRUE, FALSE); AssertInt(0, gcUnknowns.NumElements()); pcTest = cMap.Put<CTestUnknownJobbie>("One"); pcTest->Init(2, ""); AssertNotNull(pcTest); AssertInt(1, gcUnknowns.NumElements()); pcTest = cMap.Put<CTestUnknownJobbie>("One"); AssertNull(pcTest); AssertInt(1, gcUnknowns.NumElements()); cMap.Kill(); AssertInt(0, gcUnknowns.NumElements()); UnknownsKill(); MemoryKill(); }
void TestScratchPadAllocatorPop(void) { MemoryInit(); CScratchPadAllocator cAlloc; CConstructorTestClass* pcTest1; CConstructorTestClass* pcTest2; gcConstructors.Add<CConstructorTestClass>("CConstructorTestClass"); cAlloc.Init(); AssertInt(0, cAlloc.GetScratchPad()->GetUsedSize()); pcTest1 = (CConstructorTestClass*)gcConstructors.Construct("CConstructorTestClass", &cAlloc); AssertInt(28, cAlloc.GetScratchPad()->GetUsedSize()); pcTest1->k = 7; AssertInt(3, pcTest1->Method1()); AssertInt(7, pcTest1->k); pcTest2 = (CConstructorTestClass*)gcConstructors.Construct("CConstructorTestClass", &cAlloc); AssertInt(56, cAlloc.GetScratchPad()->GetUsedSize()); cAlloc.Free(pcTest1); AssertInt(56, cAlloc.GetScratchPad()->GetUsedSize()); cAlloc.Free(pcTest2); AssertInt(56, cAlloc.GetScratchPad()->GetUsedSize()); cAlloc.Kill(); MemoryKill(); }
void TestVirtualCall(void) { MemoryInit(); UnknownsInit(); CTestObjectIsListenerWithEvent* pcTest; CTestObjectIsListener* pcListener; CTestAnotherListener cAnother1; CTestAnotherListener cAnother2; CTestAnotherListener cAnother3; BOOL bResult; pcTest = UMalloc(CTestObjectIsListenerWithEvent); pcTest->Init(); pcListener = UMalloc(CTestObjectIsListener); pcListener->Init(); AssertInt(WH_SomeOneSetUpUsTheBomb, pcTest->meWhatHappen); AssertString("Nothing to see here", pcListener->mszAlsoBored.Text()); AssertInt(0, pcTest->miBored); bResult = pcTest->AddListener<CTestListener>(pcListener); AssertTrue(bResult); bResult = pcTest->AddListener(&cAnother1); AssertTrue(bResult); bResult = pcTest->AddListener(&cAnother2); AssertTrue(bResult); pcTest->MakeEventStyle1Happen(); AssertInt(WH_WeGetSignal, pcTest->meWhatHappen); AssertString("Sup my homies", pcListener->mszAlsoBored.Text()); AssertInt(1, pcTest->miBored); pcTest->MakeEventStyle2Happen(); AssertInt(WH_MoveZigForGreatJustice, pcTest->meWhatHappen); AssertString("Wikky wikky free styling", pcListener->mszAlsoBored.Text()); AssertInt(2, pcTest->miBored); pcTest->CallListeners(&CTestAnotherListener::Another, pcTest, NULL); AssertInt(1, cAnother1.iThisIsNotTheRightWayToUseListeners); AssertInt(1, cAnother2.iThisIsNotTheRightWayToUseListeners); AssertInt(0, cAnother3.iThisIsNotTheRightWayToUseListeners); bResult = pcTest->AddListener<CTestBadListener>(NULL); AssertFalse(bResult); pcListener->Kill(); pcTest->Kill(); UnknownsKill(); MemoryKill(); }
void TestChunkFile(void) { BeginTests(); FastFunctionsInit(); MemoryInit(); TestChunkFileSimple(); TestChunkFileMD5ing(); TestChunkFileNameing(); MemoryKill(); FastFunctionsKill(); TestStatistics(); }
void TestPackFilesPacker(void) { BeginTests(); FastFunctionsInit(); MemoryInit(); TestPackFilesPackerSimple(); TestPackFilesPackerCopyDir(); MemoryKill(); FastFunctionsKill(); TestStatistics(); }
void TestMapBlock(void) { BeginTests(); MemoryInit(); FastFunctionsInit(); TestMapBlockInternals(); TestMapBlockGet(); TestMapBlockAddDuplicate(); TestMapBlockRemove(); TestMapBlockReadWrite(); FastFunctionsKill(); MemoryKill(); TestStatistics(); }
void TestArrayTemplate(void) { BeginTests(); MemoryInit(); FastFunctionsInit(); TestMisc(); TestArrayAllocation(); TestArrayCopy(); TestArraySorting(); TestArrayRemove(); TestArrayFake(); FastFunctionsKill(); MemoryKill(); TestStatistics(); }
void TestEmbeddedObjectClass(void) { MemoryInit(); ObjectsInit(); CEmbeddedComplex cComplex; CPointer* pcPtr0; CPointer* pcPtr1; CPointer* pcPtr2; CPointer* pcPtr3; CPointer* pcPtr4; CPointer* pcPtr5; //Class not yet called. Always call Class. AssertInt(0, cComplex.GetNumFieldPointerTos()); AssertInt(1, cComplex.GetNumEmbedded()); cComplex.ClearFlagNumEmbedded(); cComplex.Class(); AssertInt(5, cComplex.GetNumFieldPointerTos()); AssertInt(6, cComplex.GetNumEmbedded()); pcPtr0 = cComplex.GetFieldPointerTo(0); pcPtr1 = cComplex.GetFieldPointerTo(1); pcPtr2 = cComplex.GetFieldPointerTo(2); pcPtr3 = cComplex.GetFieldPointerTo(3); pcPtr4 = cComplex.GetFieldPointerTo(4); pcPtr5 = cComplex.GetFieldPointerTo(5); AssertPointer(cComplex.mpTest.This(), pcPtr0); AssertPointer(cComplex.mcSimple.mpTest.This(), pcPtr1); AssertPointer(cComplex.mcContainer.mpTest.This(), pcPtr2); AssertPointer(cComplex.mcContainer.mcOne.mpTest.This(), pcPtr3); AssertPointer(cComplex.mcContainer.mcTwo.mpTest.This(), pcPtr4); AssertNull(pcPtr5); AssertInt(0, cComplex.GetFieldPointerToIndex(pcPtr0)); AssertInt(1, cComplex.GetFieldPointerToIndex(pcPtr1)); AssertInt(2, cComplex.GetFieldPointerToIndex(pcPtr2)); AssertInt(3, cComplex.GetFieldPointerToIndex(pcPtr3)); AssertInt(4, cComplex.GetFieldPointerToIndex(pcPtr4)); AssertInt(-1, cComplex.GetFieldPointerToIndex(NULL)); ObjectsKill(); MemoryKill(); }
void TestFileUtil(void) { BeginTests(); MemoryInit(); FastFunctionsInit(); TestFileUtilRemoveExtension(); TestFileUtilFindExtension(); TestFileUtilNaming(); TestFileUtilMisc(); TestFileUtilMakeNameFromDirectory(); TestFileUtilMakeDirectory(); TestFileUtilRemoveLastFromPath(); TestFileUtilTouchDirectory(); TestFileUtilPrependToPath(); FastFunctionsKill(); MemoryKill(); TestStatistics(); }
void TestFiles(void) { BeginTests(); FastFunctionsInit(); TypeConverterInit(); MemoryInit(); TestFilesSimple(); TestFileSystemIteration(); TestFilesIteration(); TestGetFileNames(); TestFilesWholeDirectory(); MemoryKill(); FastFunctionsKill(); TypeConverterKill(); TestStatistics(); }
void TestEmbeddedOjectIsAllocatedInObjects() { MemoryInit(); ObjectsInit(); Ptr<CClusterMissile> pClusterMissile = ONMalloc(CClusterMissile, "Gerbil")->Init(NULL); AssertTrue(pClusterMissile->IsAllocatedInObjects()); AssertTrue(pClusterMissile->mcMissile1.IsAllocatedInObjects()); AssertTrue(pClusterMissile->mcMissile2.IsAllocatedInObjects()); pClusterMissile = NULL; CClusterMissile cClusterMissile; cClusterMissile.Class(); cClusterMissile.Init(NULL); AssertFalse(cClusterMissile.IsAllocatedInObjects()); AssertFalse(cClusterMissile.mcMissile1.IsAllocatedInObjects()); AssertFalse(cClusterMissile.mcMissile2.IsAllocatedInObjects()); ObjectsKill(); MemoryKill(); }
void TestChannelsAccessor(void) { BeginTests(); MemoryInit(); TypesInit(); TypeConverterInit(); UnknownsInit(); TestChannelsAccessorContiguous(); TestChannelsAccessorByteAligned(); TestChannelsAccessorTypeConvert(); TestChannelsAccessorChannelBitty(); TestChannelsAccessorAccessBitty(); TestChannelsAccessorWorstCase(); UnknownsKill(); TypeConverterKill(); TypesKill(); MemoryKill(); TestStatistics(); }
void WriteObjectReaderSimpleFile(void) { MemoryInit(); ObjectsInit(); gcObjects.AddConstructor<CTestNamedString>(); CPointer cBase; CObjectWriterSimple cWriter; CObjectGraphSerialiser cGraphSerialiser; cBase = SetupObjectReaderSimpleFile(); cWriter.Init("Output\\ObjectReaderSimple\\Test\\", ""); cGraphSerialiser.Init(&cWriter); AssertTrue(cGraphSerialiser.Write(cBase.BaseObject())); cGraphSerialiser.Kill(); cWriter.Kill(); ObjectsKill(); MemoryKill(); }
void TestScratchPadAllocatorReadWrite(void) { MemoryInit(); CScratchPadAllocator cAlloc; CFileBasic cFile; CScratchPadAllocator cAllocIn; int i; SScratchPadParams sParams; cFile.Init(MemoryFile()); cFile.Open(EFM_ReadWrite_Create); cFile.WriteInt(789); cAlloc.Init(32 KB); AssertTrue(cAlloc.Write(&cFile)); cFile.WriteInt(124); cFile.Close(); cAlloc.Kill(); cFile.Open(EFM_Read); cFile.ReadInt(&i); AssertInt(789, i); AssertTrue(cAllocIn.Read(&cFile)); cFile.ReadInt(&i); AssertInt(124, i); AssertInt(0, cAllocIn.GetScratchPad()->GetMemorySize()); AssertInt(0, cAllocIn.GetScratchPad()->GetUsedSize()); cAllocIn.GetScratchPad()->GetParams(&sParams); AssertInt(32 KB, sParams.iChunkSize); MemoryKill(); }
void TestEmbeddedGetEmbeddedObject(void) { MemoryInit(); ObjectsInit(); CEmbeddedComplex cComplex; CEmbeddedObject* pcEmbedded; cComplex.Class(); cComplex.Init(); pcEmbedded = cComplex.GetEmbeddedObject(0); AssertPointer(&cComplex, pcEmbedded); pcEmbedded = cComplex.GetEmbeddedObject(1); AssertPointer(&cComplex.mcSimple, pcEmbedded); pcEmbedded = cComplex.GetEmbeddedObject(2); AssertPointer(&cComplex.ma, pcEmbedded); pcEmbedded = cComplex.GetEmbeddedObject(3); AssertPointer(&cComplex.mcContainer, pcEmbedded); pcEmbedded = cComplex.GetEmbeddedObject(4); AssertPointer(&cComplex.mcContainer.mcOne, pcEmbedded); pcEmbedded = cComplex.GetEmbeddedObject(5); AssertPointer(&cComplex.mcContainer.mcTwo, pcEmbedded); pcEmbedded = cComplex.GetEmbeddedObject(6); AssertNull(pcEmbedded); pcEmbedded = cComplex.mcSimple.GetEmbeddedObject(0); AssertPointer(&cComplex.mcSimple, pcEmbedded); pcEmbedded = cComplex.mcSimple.GetEmbeddedObject(1); AssertNull(pcEmbedded); pcEmbedded = cComplex.ma.GetEmbeddedObject(0); AssertPointer(&cComplex.ma, pcEmbedded); pcEmbedded = cComplex.ma.GetEmbeddedObject(1); AssertNull(pcEmbedded); ObjectsKill(); MemoryKill(); }
void TestSetRemoval(void) { MemoryInit(); UnknownsInit(); CSetUnknown cSet; CTestNamedUnknown* pcTest1; CTestNamedUnknown* pcTest2; CTestNamedUnknown* pcTest3; int iNum; CTestNamedUnknown* pcTest; SIteratorTemplate<CTestNamedUnknown> sIter; SSetIterator sSetIter; cSet.Init(); pcTest1 = cSet.Add<CTestNamedUnknown>(); pcTest1->Init("The One"); pcTest2 = cSet.Add<CTestNamedUnknown>(); pcTest2->Init("Two"); pcTest3 = UMalloc(CTestNamedUnknown); pcTest3->Init("There can be only three"); cSet.Add(pcTest3); iNum = cSet.NumElements(); AssertInt(3, iNum); cSet.StartIteration(&sSetIter); cSet.RemoveDuringIteration(&sSetIter); cSet.RemoveDuringIteration(&sSetIter); cSet.RemoveDuringIteration(&sSetIter); iNum = cSet.NumElements(); AssertInt(0, iNum); cSet.RemoveDuringIteration(&sSetIter); pcTest = gcUnknowns.StartIteration(&sIter); AssertNull(pcTest); cSet.Kill(); cSet.Init(); pcTest1 = cSet.Add<CTestNamedUnknown>(); pcTest1->Init("The One"); pcTest2 = cSet.Add<CTestNamedUnknown>(); pcTest2->Init("Two"); pcTest3 = UMalloc(CTestNamedUnknown); pcTest3->Init("There can be only three"); cSet.Add(pcTest3); iNum = cSet.NumElements(); AssertInt(3, iNum); pcTest = (CTestNamedUnknown*)cSet.StartIteration(&sSetIter); AssertString("The One", pcTest->GetName()); cSet.RemoveDuringIteration(&sSetIter); pcTest = (CTestNamedUnknown*)cSet.Iterate(&sSetIter); AssertString("Two", pcTest->GetName()); cSet.RemoveDuringIteration(&sSetIter); iNum = cSet.NumElements(); AssertInt(1, iNum); pcTest = (CTestNamedUnknown*)cSet.Iterate(&sSetIter); AssertString("There can be only three", pcTest->GetName()); cSet.RemoveDuringIteration(&sSetIter); iNum = cSet.NumElements(); AssertInt(0, iNum); cSet.RemoveDuringIteration(&sSetIter); cSet.Kill(); UnknownsKill(); MemoryKill(); }
void TestExternalChannelsSubBytePositions(void) { CChannelsAccessor* pcChannel0; CChannelsAccessor* pcChannel1; CChannelsAccessorCreator cCreator; CChannels cSourceChannels; unsigned char uc[11] = {0x29, 0x33, 0xBE, 0x84, 0xE1, 0x6C, 0xD6, 0xAE, 0x52, 0xE8, 0x01}; unsigned char* pucData; // MSb LSb // X 1 11101000 0 10100101 0 10111011 0 10110011 0 11001110 0 00110000 1 00101111 1 00011001 1 00101001 // ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ // 8 8 77777777 7 76666666 6 66555555 5 55544444 4 44443333 3 33333222 2 22222211 1 11111110 0 00000000 // 1 0 98765432 1 09876543 2 10987654 3 21098765 4 32109876 5 43210987 6 54321098 7 65432109 8 76543210 MemoryInit(); TypesInit(); TypeConverterInit(); UnknownsInit(); cSourceChannels.Init(); cSourceChannels.BeginChange(); cSourceChannels.AddChannel(0, PT_uchar); cSourceChannels.AddChannel(1, PT_bit); cSourceChannels.SetData((char*)uc); cSourceChannels.SetSize(9); cSourceChannels.EndChange(); cCreator.Init(&cSourceChannels); cCreator.AddAccess(0, PT_uchar); pcChannel0 = cCreator.CreateAndKill(); AssertString("CChannelsAccessorChannelBitty", pcChannel0->ClassName()); cCreator.Init(&cSourceChannels); cCreator.AddAccess(1, PT_uchar); pcChannel1 = cCreator.CreateAndKill(); AssertString("CChannelsAccessorChannelBitty", pcChannel1->ClassName()); pucData = (unsigned char*)pcChannel0->Get(0); AssertInt(0x29, *pucData); pucData = (unsigned char*)pcChannel1->Get(0); AssertInt(0xFF, *pucData); //LSb of the right hand 3 in 0x33 scaled up to a byte from a bit. pucData = (unsigned char*)pcChannel0->Get(1); AssertInt(0x19, *pucData); pucData = (unsigned char*)pcChannel1->Get(1); AssertInt(0xFF, *pucData); pucData = (unsigned char*)pcChannel0->Get(2); AssertInt(0x2F, *pucData); pucData = (unsigned char*)pcChannel1->Get(2); AssertInt(0xFF, *pucData); pucData = (unsigned char*)pcChannel0->Get(3); AssertInt(0x30, *pucData); pucData = (unsigned char*)pcChannel1->Get(3); AssertInt(0x00, *pucData); pucData = (unsigned char*)pcChannel0->Get(4); AssertInt(0xCE, *pucData); pucData = (unsigned char*)pcChannel1->Get(4); AssertInt(0x00, *pucData); pucData = (unsigned char*)pcChannel0->Get(5); AssertInt(0xB3, *pucData); pucData = (unsigned char*)pcChannel1->Get(5); AssertInt(0x00, *pucData); pucData = (unsigned char*)pcChannel0->Get(6); AssertInt(0xBB, *pucData); pucData = (unsigned char*)pcChannel1->Get(6); AssertInt(0x00, *pucData); pucData = (unsigned char*)pcChannel0->Get(7); AssertInt(0xA5, *pucData); pucData = (unsigned char*)pcChannel1->Get(7); AssertInt(0x00, *pucData); pucData = (unsigned char*)pcChannel0->Get(8); AssertInt(0xE8, *pucData); pucData = (unsigned char*)pcChannel1->Get(8); AssertInt(0xFF, *pucData); cSourceChannels.Kill(); UnknownsKill(); TypesKill(); TypeConverterKill(); MemoryKill(); }
void TestMapStringUnknownLoad(void) { MemoryInit(); UnknownsInit(); CMapStringUnknown cMap; CTestUnknownJobbie* pcTest; CChunkFile cFile; CFileUtil cFileUtil; BOOL bResult; gcUnknowns.AddConstructor<CTestUnknownJobbie>(); AssertInt(0, gcUnknowns.NumElements()); cFileUtil.RemoveDir("MapStringUnknown"); cFileUtil.MakeDir("MapStringUnknown"); cMap.Init(); pcTest = cMap.Put<CTestUnknownJobbie>("Hello"); pcTest->Init(7, "1st"); pcTest = cMap.Put<CTestUnknownJobbie>("World"); pcTest->Init(19, "A pony"); pcTest = cMap.Put<CTestUnknownJobbie>("Aardvark"); pcTest->Init(4, "Restore"); pcTest = cMap.Put<CTestUnknownJobbie>("Yurk"); pcTest->Init(8, "Yurk"); cFile.Init(DiskFile("MapStringUnknown/Map.dat")); bResult = cFile.WriteOpen(); AssertTrue(bResult); bResult = cMap.Save(&cFile); AssertTrue(bResult); bResult = cFile.WriteClose(); AssertTrue(bResult); cFile.Kill(); cMap.Kill(); AssertInt(0, gcUnknowns.NumElements()); cFile.Init(DiskFile("MapStringUnknown/Map.dat")); bResult = cFile.ReadOpen(); AssertTrue(bResult); bResult = cMap.Load(&cFile); AssertTrue(bResult); bResult = cFile.ReadClose(); AssertTrue(bResult); cFile.Kill(); AssertInt(4, cMap.NumElements()); AssertInt(4, gcUnknowns.NumElements()); pcTest = (CTestUnknownJobbie*)cMap.Get("Hello"); AssertInt(7, pcTest->miANumber); AssertString("1st", pcTest->mszText.Text()); pcTest = (CTestUnknownJobbie*)cMap.Get("World"); AssertInt(19, pcTest->miANumber); AssertString("A pony", pcTest->mszText.Text()); pcTest = (CTestUnknownJobbie*)cMap.Get("Aardvark"); AssertInt(4, pcTest->miANumber); AssertString("Restore", pcTest->mszText.Text()); pcTest = (CTestUnknownJobbie*)cMap.Get("Yurk"); AssertInt(8, pcTest->miANumber); AssertString("Yurk", pcTest->mszText.Text()); cMap.Kill(); AssertInt(0, gcUnknowns.NumElements()); cFileUtil.RemoveDir("MapStringUnknown"); UnknownsKill(); MemoryKill(); }
void TestMapStringUnknownGet(void) { MemoryInit(); UnknownsInit(); CMapStringUnknown cMap; CTestUnknownJobbie* pcTest; CTestUnknownJobbie* pcA1; CTestUnknownJobbie* pcA2; CTestUnknownJobbie* pcA3; cMap.Init(); pcTest = cMap.Put<CTestUnknownJobbie>("Hello"); pcTest->Init(7, "1st"); pcTest = cMap.Put<CTestUnknownJobbie>("World"); pcTest->Init(19, "A pony"); pcTest = cMap.Put<CTestUnknownJobbie>("Aardvark"); pcTest->Init(4, "Restore"); AssertInt(3, cMap.NumElements()); pcTest = (CTestUnknownJobbie*)cMap.Get("World"); AssertInt(19, pcTest->miANumber); AssertString("A pony", pcTest->mszText.Text()); pcA1 = UMalloc(CTestUnknownJobbie); pcA1->Init(999, "Grand"); cMap.Put("Thesaurus", pcA1); pcA2 = UMalloc(CTestUnknownJobbie); pcA2->Init(17, "Replaced!"); cMap.Put("World", pcA2); pcA3 = UMalloc(CTestUnknownJobbie); pcA3->Init(32, "Another"); cMap.Put("Jump", pcA3); AssertInt(5, cMap.NumElements()); AssertInt(5, gcUnknowns.NumElements()); pcTest = (CTestUnknownJobbie*)cMap.Get("World"); AssertPointer(pcA2, pcTest); AssertString("Replaced!", pcTest->mszText.Text()); pcTest = (CTestUnknownJobbie*)cMap.Get("world"); AssertPointer(NULL, pcTest); pcTest = (CTestUnknownJobbie*)cMap.Get(NULL); AssertPointer(NULL, pcTest); pcTest = (CTestUnknownJobbie*)cMap.Get(""); AssertPointer(NULL, pcTest); pcTest = cMap.Put<CTestUnknownJobbie>(""); pcTest->Init(0, "Empty"); pcTest = (CTestUnknownJobbie*)cMap.Get(""); AssertString("Empty", pcTest->mszText.Text()); cMap.Kill(); AssertInt(0, gcUnknowns.NumElements()); UnknownsKill(); MemoryKill(); }
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 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 TestMemoryAllocatorReadWrite(void) { MemoryInit(); CMemoryAllocator cAlloc; CFileBasic cFile; CMemoryAllocator cAllocIn; int i; SMemoryParams sParams; SMemoryFreeListParams* psBlockParams; cFile.Init(MemoryFile()); cFile.Open(EFM_ReadWrite_Create); cFile.WriteInt(789); cAlloc.Init(16, FALSE); cAlloc.GetMemory()->AddParamBlock(24 , 16 , 32*32); cAlloc.GetMemory()->AddParamBlock(32 , 24 , 28*32); cAlloc.GetMemory()->AddParamBlock(40 , 32 , 24*32); AssertTrue(cAlloc.Write(&cFile)); cFile.WriteInt(124); cFile.Close(); cAlloc.Kill(); cFile.Open(EFM_Read); cFile.ReadInt(&i); AssertInt(789, i); AssertTrue(cAllocIn.Read(&cFile)); cFile.ReadInt(&i); AssertInt(124, i); AssertInt(16, cAllocIn.GetMemory()->ByteSize()); cAllocIn.GetMemory()->GetParams(&sParams); AssertInt(16, sParams.iDefaultAlignment); AssertInt(56, sParams.uiFreeListSizeLimit); AssertInt(3, sParams.iFreeListParams); psBlockParams = cAllocIn.GetMemory()->GetFreeListParams(0); AssertNotNull(psBlockParams); AssertInt(32*32, psBlockParams->iChunkSize); AssertInt(17, psBlockParams->iMinElementSize); AssertInt(24, psBlockParams->iMaxElementSize); psBlockParams = cAllocIn.GetMemory()->GetFreeListParams(1); AssertNotNull(psBlockParams); AssertInt(28*32, psBlockParams->iChunkSize); AssertInt(25, psBlockParams->iMinElementSize); AssertInt(32, psBlockParams->iMaxElementSize); psBlockParams = cAllocIn.GetMemory()->GetFreeListParams(2); AssertNotNull(psBlockParams); AssertInt(24*32, psBlockParams->iChunkSize); AssertInt(33, psBlockParams->iMinElementSize); AssertInt(40, psBlockParams->iMaxElementSize); psBlockParams = cAllocIn.GetMemory()->GetFreeListParams(3); AssertNull(psBlockParams); MemoryKill(); }
void TestCleanNulls(void) { MemoryInit(); UnknownsInit(); CSetUnknown cSet; CTestNamedUnknown* apUnknowns[32]; CChars sz; int i; SSetIterator sSetIter; BOOL bResult; cSet.Init(4); for (int i = 0; i < 32; i++) { apUnknowns[i] = cSet.Add<CTestNamedUnknown>(); sz.Init(); sz.Append(i); apUnknowns[i]->Init(sz.Text()); sz.Kill(); } AssertInt(32, cSet.NumElements()); AssertInt(32, cSet.UnsafeNumElements()); cSet.Remove(apUnknowns[0]); cSet.Remove(apUnknowns[2]); cSet.Remove(apUnknowns[3]); cSet.Remove(apUnknowns[7]); cSet.Remove(apUnknowns[17]); cSet.Remove(apUnknowns[18]); cSet.Remove(apUnknowns[19]); cSet.Remove(apUnknowns[23]); cSet.Remove(apUnknowns[26]); cSet.Remove(apUnknowns[27]); cSet.Remove(apUnknowns[28]); AssertInt(21, cSet.NumElements()); AssertInt(32, cSet.UnsafeNumElements()); AssertPointer(NULL, cSet.UnsafeGet(0)); AssertPointer(apUnknowns[1], cSet.UnsafeGet(1)); AssertPointer(NULL, cSet.UnsafeGet(2)); AssertPointer(NULL, cSet.UnsafeGet(3)); AssertPointer(apUnknowns[4], cSet.UnsafeGet(4)); AssertPointer(apUnknowns[5], cSet.UnsafeGet(5)); AssertPointer(apUnknowns[6], cSet.UnsafeGet(6)); AssertPointer(NULL, cSet.UnsafeGet(7)); AssertPointer(apUnknowns[8], cSet.UnsafeGet(8)); AssertPointer(apUnknowns[9], cSet.UnsafeGet(9)); AssertPointer(apUnknowns[10], cSet.UnsafeGet(10)); AssertPointer(apUnknowns[11], cSet.UnsafeGet(11)); AssertPointer(apUnknowns[12], cSet.UnsafeGet(12)); AssertPointer(apUnknowns[13], cSet.UnsafeGet(13)); AssertPointer(apUnknowns[14], cSet.UnsafeGet(14)); AssertPointer(apUnknowns[15], cSet.UnsafeGet(15)); AssertPointer(apUnknowns[16], cSet.UnsafeGet(16)); AssertPointer(NULL, cSet.UnsafeGet(17)); AssertPointer(NULL, cSet.UnsafeGet(18)); AssertPointer(NULL, cSet.UnsafeGet(19)); AssertPointer(apUnknowns[20], cSet.UnsafeGet(20)); AssertPointer(apUnknowns[21], cSet.UnsafeGet(21)); AssertPointer(apUnknowns[22], cSet.UnsafeGet(22)); AssertPointer(NULL, cSet.UnsafeGet(23)); AssertPointer(apUnknowns[24], cSet.UnsafeGet(24)); AssertPointer(apUnknowns[25], cSet.UnsafeGet(25)); AssertPointer(NULL, cSet.UnsafeGet(26)); AssertPointer(NULL, cSet.UnsafeGet(27)); AssertPointer(NULL, cSet.UnsafeGet(28)); AssertPointer(apUnknowns[29], cSet.UnsafeGet(29)); AssertPointer(apUnknowns[30], cSet.UnsafeGet(30)); AssertPointer(apUnknowns[31], cSet.UnsafeGet(31)); //CleanNullsIfNecessary happens here. cSet.Remove(apUnknowns[29]); AssertInt(20, cSet.NumElements()); AssertInt(20, cSet.UnsafeNumElements()); AssertPointer(apUnknowns[1], cSet.UnsafeGet(0)); AssertPointer(apUnknowns[4], cSet.UnsafeGet(1)); AssertPointer(apUnknowns[5], cSet.UnsafeGet(2)); AssertPointer(apUnknowns[6], cSet.UnsafeGet(3)); AssertPointer(apUnknowns[8], cSet.UnsafeGet(4)); AssertPointer(apUnknowns[9], cSet.UnsafeGet(5)); AssertPointer(apUnknowns[10], cSet.UnsafeGet(6)); AssertPointer(apUnknowns[11], cSet.UnsafeGet(7)); AssertPointer(apUnknowns[12], cSet.UnsafeGet(8)); AssertPointer(apUnknowns[13], cSet.UnsafeGet(9)); AssertPointer(apUnknowns[14], cSet.UnsafeGet(10)); AssertPointer(apUnknowns[15], cSet.UnsafeGet(11)); AssertPointer(apUnknowns[16], cSet.UnsafeGet(12)); AssertPointer(apUnknowns[20], cSet.UnsafeGet(13)); AssertPointer(apUnknowns[21], cSet.UnsafeGet(14)); AssertPointer(apUnknowns[22], cSet.UnsafeGet(15)); AssertPointer(apUnknowns[24], cSet.UnsafeGet(16)); AssertPointer(apUnknowns[25], cSet.UnsafeGet(17)); AssertPointer(apUnknowns[30], cSet.UnsafeGet(18)); AssertPointer(apUnknowns[31], cSet.UnsafeGet(19)); cSet.StartIteration(&sSetIter); for (i = 0; i < 19; i++) { cSet.RemoveDuringIteration(&sSetIter); } AssertInt(1, cSet.NumElements()); bResult = cSet.Remove(apUnknowns[31]); AssertTrue(bResult); AssertInt(0, cSet.NumElements()); cSet.Kill(); UnknownsKill(); MemoryKill(); }