static void test_CyaSSL_CTX_load_verify_locations(void) { #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) CYASSL_CTX *ctx; AssertNotNull(ctx = CyaSSL_CTX_new(CyaSSLv23_client_method())); /* invalid context */ AssertFalse(CyaSSL_CTX_load_verify_locations(NULL, caCert, 0)); /* invalid ca file */ AssertFalse(CyaSSL_CTX_load_verify_locations(ctx, NULL, 0)); AssertFalse(CyaSSL_CTX_load_verify_locations(ctx, bogusFile, 0)); #ifndef CYASSL_TIRTOS /* invalid path */ /* not working... investigate! */ /* AssertFalse(CyaSSL_CTX_load_verify_locations(ctx, caCert, bogusFile)); */ #endif /* success */ AssertTrue(CyaSSL_CTX_load_verify_locations(ctx, caCert, 0)); CyaSSL_CTX_free(ctx); #endif }
static void test_CyaSSL_CTX_use_PrivateKey_file(void) { #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) CYASSL_CTX *ctx; AssertNotNull(ctx = CyaSSL_CTX_new(CyaSSLv23_server_method())); /* invalid context */ AssertFalse(CyaSSL_CTX_use_PrivateKey_file(NULL, svrKey, SSL_FILETYPE_PEM)); /* invalid key file */ AssertFalse(CyaSSL_CTX_use_PrivateKey_file(ctx, bogusFile, SSL_FILETYPE_PEM)); /* invalid key type */ AssertFalse(CyaSSL_CTX_use_PrivateKey_file(ctx, svrKey, 9999)); /* success */ #ifdef NO_RSA /* rsa needed */ AssertFalse(CyaSSL_CTX_use_PrivateKey_file(ctx, svrKey, SSL_FILETYPE_PEM)); #else /* success */ AssertTrue(CyaSSL_CTX_use_PrivateKey_file(ctx, svrKey, SSL_FILETYPE_PEM)); #endif CyaSSL_CTX_free(ctx); #endif }
void TestChunkFileSimple(void) { CChunkFile cChunkFile; CFileUtil cFileUtil; int iChunkNum; cFileUtil.MakeDir("Output"); cFileUtil.Delete("Output/ChunkFile.bin"); cChunkFile.Init(DiskFile("Output/ChunkFile.bin")); AssertFalse(cChunkFile.IsOpen()); AssertTrue(cChunkFile.WriteOpen()); AssertTrue(cChunkFile.IsOpen()); AssertTrue(cChunkFile.WriteChunkBegin()); AssertTrue(cChunkFile.WriteChunkEnd("ThisChunk")); AssertTrue(cChunkFile.WriteClose()); AssertFalse(cChunkFile.IsOpen()); cChunkFile.Kill(); cChunkFile.Init(DiskFile("Output/ChunkFile.bin")); AssertFalse(cChunkFile.IsOpen()); AssertTrue(cChunkFile.ReadOpen()); AssertTrue(cChunkFile.IsOpen()); iChunkNum = cChunkFile.FindFirstChunkWithName("ThisChunk"); AssertInt(0, iChunkNum); AssertTrue(cChunkFile.ReadChunkBegin(iChunkNum)); AssertTrue(cChunkFile.ReadClose()); AssertFalse(cChunkFile.IsOpen()); cChunkFile.Kill(); }
void TestIndexTreeBlockMemoryRemoveByObject(void) { CIndexTreeBlockMemory cIndex; CTestIndexTreeObject object1; CTestIndexTreeObject object2; CTestIndexTreeObject object3; CTestIndexTreeObject** ppcRemoved; cIndex.Init(); AssertInt(1, cIndex.CountAllocatedNodes()); object1.Init("denarii"); cIndex.PutPtr(object1.GetName(), &object1); AssertInt(8, cIndex.CountAllocatedNodes()); object2.Init("dendrodra"); cIndex.PutPtr(object2.GetName(), &object2); object3.Init("dendrons"); cIndex.PutPtr(object3.GetName(), &object3); AssertInt(3, cIndex.NumElements()); ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object2.GetName()); AssertPointer(&object2, *ppcRemoved); AssertTrue(cIndex.Remove(object2.GetName())); ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object2.GetName()); AssertNull(ppcRemoved); AssertInt(2, cIndex.NumElements()); AssertFalse(cIndex.Remove(object2.GetName())); AssertInt(2, cIndex.NumElements()); AssertInt(13, cIndex.CountAllocatedNodes()); cIndex.Remove(object3.GetName()); AssertInt(1, cIndex.NumElements()); AssertInt(8, cIndex.CountAllocatedNodes()); cIndex.PutPtr(object3.GetName(), &object3); AssertInt(13, cIndex.CountAllocatedNodes()); AssertInt(2, cIndex.NumElements()); ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object3.GetName()); AssertPointer(&object3, *ppcRemoved); AssertTrue(cIndex.Remove(object3.GetName())); ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object3.GetName()); AssertNull(ppcRemoved); AssertInt(1, cIndex.NumElements()); ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object1.GetName()); AssertPointer(&object1, *ppcRemoved); AssertTrue(cIndex.Remove(object1.GetName())); ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object1.GetName()); AssertNull(ppcRemoved); AssertInt(0, cIndex.NumElements()); AssertFalse(cIndex.Remove(NULL)); AssertFalse(cIndex.Remove("")); cIndex.Kill(); }
void TestFileUtilTouchDirectory(void) { CFileUtil cFileUtil; CChars szDirectory; CChars szFileName; cFileUtil.RemoveDir("file_util"); szDirectory.Init("file_util" _FS_ "directory" _FS_ "make" _FS_ "test"); cFileUtil.FullPath(&szDirectory); szFileName.Init(szDirectory); cFileUtil.AppendToPath(&szFileName, "Warthog.PIG"); AssertTrue(cFileUtil.TouchDir(szFileName.Text())); AssertTrue(cFileUtil.Touch(szFileName.Text())); szDirectory.Kill(); szFileName.Kill(); cFileUtil.RemoveDir("file_util"); AssertFalse(cFileUtil.TouchDir("C:\\Warthog.PIG")); AssertFalse(cFileUtil.TouchDir("\\Warthog.PIG")); szDirectory.Init(); cFileUtil.CurrentDirectory(&szDirectory); szDirectory.Append("War-pig.hog"); AssertFalse(cFileUtil.TouchDir(szDirectory.Text())); szDirectory.Kill(); }
static void test_wolfSSL_CTX_use_certificate_file(void) { #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) WOLFSSL_CTX *ctx; AssertNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())); /* invalid context */ AssertFalse(wolfSSL_CTX_use_certificate_file(NULL, svrCert, SSL_FILETYPE_PEM)); /* invalid cert file */ AssertFalse(wolfSSL_CTX_use_certificate_file(ctx, bogusFile, SSL_FILETYPE_PEM)); /* invalid cert type */ AssertFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCert, 9999)); #ifdef NO_RSA /* rsa needed */ AssertFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCert,SSL_FILETYPE_PEM)); #else /* success */ AssertTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCert, SSL_FILETYPE_PEM)); #endif wolfSSL_CTX_free(ctx); #endif }
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 TestIndexTreeMemoryAdd(void) { CIndexTreeMemory cIndex; CTestIndexTreeObject a; CTestIndexTreeObject aa; CTestIndexTreeObject temp; CArrayVoidPtr avp; BOOL bResult; CIndexTreeNodeMemory* pcNode; CTestIndexTreeObject** ppvTest; CTestIndexTreeObject*** ppvTestA; CTestIndexTreeObject*** ppvTestAA; cIndex.Init(); a.Init("A"); bResult = cIndex.PutPtr(a.GetName(), &a); AssertTrue(bResult); pcNode = cIndex.GetNode("A", 1); ppvTest = (CTestIndexTreeObject**)pcNode->GetObjectPtr(); AssertPointer(&a, *ppvTest); aa.Init("AA"); bResult = cIndex.PutPtr(aa.GetName(), &aa); AssertTrue(bResult); pcNode = cIndex.GetNode("A", 1); ppvTest = (CTestIndexTreeObject**)pcNode->GetObjectPtr(); AssertPointer(&a, *ppvTest); pcNode = cIndex.GetNode("AA", 2); ppvTest = (CTestIndexTreeObject**)pcNode->GetObjectPtr(); AssertPointer(&aa, *ppvTest); avp.Init(); cIndex.FindAll(&avp); AssertInt(2, avp.NumElements()); ppvTestA = (CTestIndexTreeObject***)avp.Get(0); ppvTestAA = (CTestIndexTreeObject***)avp.Get(1); AssertPointer(&a, **ppvTestA); AssertPointer(&aa, **ppvTestAA); AssertString("A", (**ppvTestA)->mszName); AssertString("AA", (**ppvTestAA)->mszName); avp.Kill(); cIndex.Kill(); cIndex.Init(); bResult = cIndex.PutPtr(NULL, &temp); AssertFalse(bResult); bResult = cIndex.PutPtr("", &temp); AssertFalse(bResult); cIndex.Kill(); }
void TestEmbeddedStackPointersComplex(void) { ObjectsInit(); CEmbeddedComplex cComplexOnStack1; CEmbeddedComplex cComplexOnStack2; Ptr<CTestObject> pTestObject1; STestObjectKilledNotifier sKillNotifier1; Ptr<CTestObject> pTestObject2; STestObjectKilledNotifier sKillNotifier2; cComplexOnStack1.Class(); cComplexOnStack2.Class(); cComplexOnStack1.Init(); cComplexOnStack2.Init(); pTestObject1 = OMalloc(CTestObject); pTestObject1->Init(&sKillNotifier1); pTestObject2 = OMalloc(CTestObject); pTestObject2->Init(&sKillNotifier2); AssertInt(0, cComplexOnStack1.GetDistToStack()); AssertInt(0, cComplexOnStack1.NumStackFroms()); AssertInt(0, cComplexOnStack2.GetDistToStack()); AssertInt(0, cComplexOnStack2.NumStackFroms()); cComplexOnStack1.mpTest = &cComplexOnStack2; cComplexOnStack1.mcSimple.mpTest = &cComplexOnStack2; cComplexOnStack1.mcContainer.mcOne.mpTest = pTestObject1; cComplexOnStack2.mcContainer.mcOne.mpTest = pTestObject1; AssertInt(0, cComplexOnStack1.GetDistToStack()); AssertInt(0, cComplexOnStack1.NumStackFroms()); AssertInt(3, cComplexOnStack1.NumPointerTos()); AssertInt(0, cComplexOnStack2.GetDistToStack()); AssertInt(2, cComplexOnStack2.NumStackFroms()); AssertInt(1, cComplexOnStack2.NumPointerTos()); AssertFalse(sKillNotifier1.bKilled); AssertFalse(sKillNotifier2.bKilled); TestEmbeddedStackPointersComplex(&cComplexOnStack1, &cComplexOnStack2); AssertFalse(sKillNotifier1.bKilled); AssertFalse(sKillNotifier2.bKilled); AssertInt(0, cComplexOnStack1.GetDistToStack()); AssertInt(0, cComplexOnStack1.NumStackFroms()); AssertInt(0, cComplexOnStack2.GetDistToStack()); AssertInt(2, cComplexOnStack2.NumStackFroms()); ObjectsKill(); }
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(); }
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 TestArrayAllocation(void) { CTestArray asTestArray; STestArrayTemplateItem* psItem; int i; asTestArray.Init(10); AssertInt(sizeof(STestArrayTemplateItem), asTestArray.ElementSize()); AssertInt(0, asTestArray.NumElements()); AssertInt(0, asTestArray.AllocatedElements()); AssertInt(10, asTestArray.ChunkSize()); AssertPointer(NULL, asTestArray.GetData()); psItem = asTestArray.Add(); AssertInt(1, asTestArray.NumElements()); AssertInt(10, asTestArray.AllocatedElements()); AssertInt(10, asTestArray.ChunkSize()); AssertFalse(asTestArray.GetData() == NULL); psItem->i1 = 1; psItem->i2 = 2; //Add upto and including the eleventh element. This will cause the array to be reallocated. for (i = 0; i < 10; i++) { asTestArray.Add(); } //Make sure the elements haven't been corrupted on reallocation. psItem = asTestArray.Get(0); AssertInt(1, psItem->i1); AssertInt(2, psItem->i2); asTestArray.Kill(); }
void TestIndexTreeBlockMemoryPutDuplicate(void) { CIndexTreeBlockMemory cIndex; CTestIndexTreeObject andrew; CTestIndexTreeObject andrewToo; CTestIndexTreeObject** pcResult; CArrayVoidPtr avp; BOOL bResult; cIndex.Init(); andrew.Init("Andrew"); bResult = cIndex.PutPtr(andrew.mszName, &andrew); AssertTrue(bResult); andrewToo.Init("Andrew"); bResult = cIndex.PutPtr(andrewToo.GetName(), &andrewToo); AssertFalse(bResult); pcResult = (CTestIndexTreeObject**)cIndex.Get("Andrew"); AssertPointer(&andrew, *pcResult); avp.Init(); cIndex.FindAll(&avp); AssertInt(1, avp.NumElements()); avp.Kill(); cIndex.Kill(); }
void TestIndexTreeBlockMemoryHasKey(void) { CIndexTreeBlockMemory cIndex; CTestIndexTreeObject cObject; cIndex.Init(); cObject.Init("Not Important"); cIndex.PutPtr("fabaceous", &cObject); cIndex.PutPtr("fabled", &cObject); cIndex.PutPtr("fabricative", &cObject); cIndex.PutPtr("fabulous", &cObject); cIndex.PutPtr("face-centered", &cObject); cIndex.PutPtr("face-centred", &cObject); cIndex.PutPtr("face-saving", &cObject); cIndex.PutPtr("faceable", &cObject); cIndex.PutPtr("faceless", &cObject); cIndex.PutPtr("facete", &cObject); cIndex.PutPtr("facetious", &cObject); cIndex.PutPtr("facile", &cObject); AssertFalse(cIndex.HasKey(NULL)); AssertFalse(cIndex.HasKey("")); AssertFalse(cIndex.HasKey(" ")); AssertFalse(cIndex.HasKey("fab")); AssertFalse(cIndex.HasKey("facilee")); AssertInt(13, cIndex.GetLargestKeySize()); AssertTrue(cIndex.HasKey("fabricative")); AssertTrue(cIndex.HasKey("fabled")); AssertTrue(cIndex.HasKey("fabulous")); AssertTrue(cIndex.HasKey("face-centered")); AssertTrue(cIndex.HasKey("fabaceous")); AssertTrue(cIndex.HasKey("face-centred")); AssertTrue(cIndex.HasKey("face-saving")); AssertTrue(cIndex.HasKey("faceable")); AssertTrue(cIndex.HasKey("faceless")); AssertTrue(cIndex.HasKey("facete")); AssertTrue(cIndex.HasKey("facetious")); AssertTrue(cIndex.HasKey("facile")); cIndex.Kill(); }
void TestIndexesSomething(void) { CIndexes cIndexes; char szOne[] = "One"; char szTwo[] = "Two"; char szThree[] = "Three"; char szFour[] = "Four"; char* szTemp; BOOL bResult; cIndexes.Init(512); AssertInt(0, cIndexes.TestNumLevels()); cIndexes.Add(17LL, szOne); szTemp = (char*)cIndexes.Get(17LL); AssertString(szOne, szTemp); AssertInt(7, cIndexes.TestNumLevels()); szTemp = (char*)cIndexes.Get(268472648234LL); AssertNull(szTemp); cIndexes.Add(268472648234LL, szTwo); szTemp = (char*)cIndexes.Get(268472648234LL); AssertString(szTwo, szTemp); AssertInt(11, cIndexes.TestNumLevels()); szTemp = (char*)cIndexes.Get(268472648233LL); AssertNull(szTemp); cIndexes.Add(268472648233LL, szThree); szTemp = (char*)cIndexes.Get(268472648233LL); AssertString(szThree, szTemp); AssertInt(11, cIndexes.TestNumLevels()); szTemp = (char*)cIndexes.Get(268472648234LL); AssertString(szTwo, szTemp); bResult = cIndexes.Add(17LL, szFour); AssertFalse(bResult); szTemp = (char*)cIndexes.Get(17LL); AssertString(szOne, szTemp); AssertInt(11, cIndexes.TestNumLevels()); bResult = cIndexes.Remove(17LL); AssertBool(TRUE, bResult) szTemp = (char*)cIndexes.Get(17LL); AssertNull(szTemp); AssertInt(7, cIndexes.TestNumLevels()); bResult = cIndexes.Remove(268472648233LL); AssertBool(TRUE, bResult); AssertInt(7, cIndexes.TestNumLevels()); bResult = cIndexes.Remove(268472648234LL); AssertBool(TRUE, bResult); AssertInt(0, cIndexes.TestNumLevels()); }
void TestArrayCopy(void) { CTestArray asTestArray; CTestArray asDestArray; STestArrayTemplateItem* psItem; void* pvDest1; void* pvDest2; BOOL bResult; asTestArray.Init(5); psItem = asTestArray.Add(); psItem->i1 = psItem->i2 = 8; psItem = asTestArray.Add(); psItem->i1 = psItem->i2 = 5; psItem = asTestArray.Add(); psItem->i1 = psItem->i2 = 7; psItem = asTestArray.Add(); psItem->i1 = psItem->i2 = 2; psItem = asTestArray.Add(); psItem->i1 = psItem->i2 = 1; asDestArray.Init(1); bResult = asDestArray.Copy(&asTestArray); AssertTrue(bResult); pvDest1 = asDestArray.GetData(); bResult = asDestArray.Copy(&asTestArray); AssertFalse(bResult); pvDest2 = asDestArray.GetData(); AssertTrue(pvDest1 == pvDest2); psItem = asTestArray.Add(); psItem->i1 = psItem->i2 = 3; bResult = asDestArray.Copy(&asTestArray); AssertTrue(bResult); AssertInt(10, asDestArray.AllocatedElements()); AssertInt(6, asDestArray.NumElements()); psItem = asDestArray.Get(0); AssertInt(8, psItem->i1); psItem = asDestArray.Get(1); AssertInt(5, psItem->i1); psItem = asDestArray.Get(2); AssertInt(7, psItem->i1); psItem = asDestArray.Get(3); AssertInt(2, psItem->i1); psItem = asDestArray.Get(4); AssertInt(1, psItem->i1); psItem = asDestArray.Get(5); AssertInt(3, psItem->i1); asTestArray.Kill(); asDestArray.Kill(); }
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 TestLogFileCommandsComplex(void) { CLogFile* pcLogFile; CMemoryFile* pcMemoryFile; CFileBasic cFile; BOOL bResult; int iWritten; char szABC[] = {"ABCDEFGHIJK"}; char sz123[] = {"123"}; char sz4[] = {"4"}; char szExclamation[] = {"!?"}; char szQWE[] = {"_QWE_"}; char szResult[12]; pcMemoryFile = MemoryFile(); pcMemoryFile->Open(EFM_ReadWrite_Create); pcMemoryFile->Write(szABC, 1, 12); pcMemoryFile->Close(); pcLogFile = LogFile(pcMemoryFile); cFile.Init(pcLogFile); pcLogFile->Begin(); cFile.Open(EFM_ReadWrite_Create); AssertInt(12, (int)cFile.GetFileLength()); iWritten = (int)cFile.Write(sz123, 1, 3); AssertInt(3, iWritten); iWritten = (int)cFile.Write(sz4, 1, 1); AssertInt(1, iWritten); cFile.Close(); cFile.Open(EFM_ReadWrite_Create); cFile.Write(szExclamation, 1, 2); cFile.Seek(3, EFSO_CURRENT); cFile.Write(szQWE, 5, 1); cFile.Close(); cFile.Open(EFM_Read); AssertInt(12, (int)cFile.GetFileLength()); memset(szResult, 0, 12); cFile.Read(szResult, 12, 1); AssertString("!?34E_QWE_K", szResult); cFile.Close(); bResult = pcLogFile->Commit(); AssertTrue(bResult); AssertFalse(pcMemoryFile->IsOpen()); AssertInt(12, pcMemoryFile->GetBufferSize()); AssertString("!?34E_QWE_K", (char*)pcMemoryFile->GetBufferPointer()); pcLogFile->Kill(); }
void AssertCache(CMemoryCache* pcCache, int iLen1, char c1, int iLen2, char c2, int iLen3, char c3) { SMemoryCacheDescriptor* psFirst; SMemoryCacheDescriptor* psLast; AssertInt(3, pcCache->NumCached()); psFirst = pcCache->GetFirst(); psLast = pcCache->GetLast(); AssertNotNull(psFirst); AssertFalse(psFirst == psLast); AssertFalse(psFirst->psNext == psLast); AssertPointer(psFirst->psNext->psNext, psLast); AssertPointer(psLast->psNext, psFirst); AssertCacheElement(pcCache, psFirst, iLen1, c1); AssertCacheElement(pcCache, psFirst->psNext, iLen2, c2); AssertCacheElement(pcCache, psFirst->psNext->psNext, iLen3, c3); }
void TestIndexTreeNodeFileRootMemory(void) { CIndexTreeNodeFile* pcNode; CIndexTreeBlockFile cIndex; CIndexTreeNodeFile cChildNode; CIndexTreeChildNode* pcResult; cIndex.FakeInit(); pcNode = (CIndexTreeNodeFile*)malloc(sizeof(CIndexTreeNodeFile) + sizeof(CIndexTreeChildNode)); //Node. No object. One child. pcNode->Init(&cIndex, NULL); AssertTrue(pcNode->IsEmpty()); AssertFalse(pcNode->HasNodes()); AssertFalse(pcNode->HasObject()); AssertTrue(pcNode->ValidateNodesEmpty()); pcNode->Contain(33); AssertFalse(pcNode->IsEmpty()); AssertTrue(pcNode->HasNodes()); AssertFalse(pcNode->HasObject()); gcLogger.SetBreakOnError(FALSE); AssertFalse(pcNode->ValidateNodesEmpty()); gcLogger.SetBreakOnError(TRUE); AssertInt(33, pcNode->GetFirstIndex()); AssertInt(33, pcNode->GetLastIndex()); pcNode->Set(33, &cChildNode); AssertFalse(pcNode->IsEmpty()); AssertTrue(pcNode->HasNodes()); AssertFalse(pcNode->HasObject()); AssertInt(1, pcNode->NumInitialisedIndexes()); AssertTrue(pcNode->ValidateNodesEmpty()); pcResult = pcNode->Get(33); AssertTrue(pcResult->IsMemory()); AssertPointer(&cChildNode, pcResult->u.mpcMemory); AssertFalse(pcNode->ContainsIndex(32)); AssertTrue(pcNode->ContainsIndex(33)); AssertFalse(pcNode->ContainsIndex(34)); free(pcNode); }
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 TestObjectStackInit(void) { ObjectsInit(); CTestObject cObject; STestObjectKilledNotifier sKillNotifier; AssertFalse(cObject.IsAllocatedInObjects()); AssertTrue(cObject.GetFlags() & OBJECT_FLAGS_CALLED_CONSTRUCTOR); AssertFalse(cObject.GetFlags() & OBJECT_FLAGS_CALLED_ALLOCATE); AssertFalse(cObject.GetFlags() & OBJECT_FLAGS_CALLED_INIT); AssertInt(0, cObject.GetDistToStack()); AssertInt(UNATTACHED_DIST_TO_ROOT, cObject.GetDistToRoot()); cObject.Class(); cObject.Init(&sKillNotifier); AssertTrue(cObject.GetFlags() & OBJECT_FLAGS_CALLED_INIT); ObjectsKill(); }
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 TestIndexTreeNodeFileUnion(void) { CIndexTreeChildNode cChild; memset(&cChild, 0, sizeof(CIndexTreeChildNode)); cChild.u.mcFile.Init(); AssertInt(0, cChild.u.msType.iType); cChild.u.mpcMemory = (CIndexTreeNodeFile*)0x80808080; AssertInt(0, cChild.u.msType.iType); AssertFalse(cChild.IsValid()); memset(&cChild, 1, sizeof(CIndexTreeChildNode)); AssertTrue(cChild.IsValid()); AssertTrue(cChild.IsMemory()); AssertFalse(cChild.IsFile()); memset(&cChild, 2, sizeof(CIndexTreeChildNode)); AssertTrue(cChild.IsValid()); AssertFalse(cChild.IsMemory()); AssertTrue(cChild.IsFile()); }
void TestLogFileCommandsSimple(void) { CLogFile* pcLogFile; CMemoryFile* pcMemoryFile; CFileBasic cFile; BOOL bResult; int iInt; int iWritten; int iResult; int iRead; pcMemoryFile = MemoryFile(); pcLogFile = LogFile(pcMemoryFile); cFile.Init(pcLogFile); pcLogFile->Begin(); bResult = cFile.Open(EFM_ReadWrite_Create); AssertTrue(bResult); AssertTrue(cFile.IsOpen()); iInt = 872349342; iWritten = (int)cFile.Write(&iInt, sizeof(int), 1); AssertInt(1, iWritten); AssertInt(0, pcMemoryFile->GetBufferSize()); bResult = cFile.Close(); AssertTrue(bResult); AssertInt(3, pcLogFile->GetNumCommands()); bResult = cFile.Open(EFM_ReadWrite_Create); AssertTrue(bResult); AssertTrue(cFile.IsOpen()); AssertInt(sizeof(int), (int)cFile.GetFileLength()); iRead = (int)cFile.Read(&iResult, sizeof(int), 1); AssertInt(1, iRead); AssertInt(iInt, iResult); bResult = cFile.Close(); AssertTrue(bResult); AssertInt(5, pcLogFile->GetNumCommands()); bResult = pcLogFile->Commit(); AssertTrue(bResult); AssertFalse(pcMemoryFile->IsOpen()); AssertInt(sizeof(int), pcMemoryFile->GetBufferSize()); AssertInt(iInt, *((int*)pcMemoryFile->GetBufferPointer())); pcLogFile->Kill(); }
void TestArrayTemplateEmbeddedAdd(void) { CArrayTemplateEmbedded<int, 5> cArray; int* pi; int* piEmbeddedData; cArray.Init(); AssertInt(0, cArray.NumElements()); piEmbeddedData = cArray.GetData(); pi = cArray.Add(); *pi = 7; AssertInt(1, cArray.NumElements()); AssertPointer(piEmbeddedData, cArray.GetData()); pi = cArray.Get(0); AssertInt(7,* pi); cArray.AddNum(3); AssertInt(4, cArray.NumElements()); AssertPointer(piEmbeddedData, cArray.GetData()); *cArray.Get(1) = 6; *cArray.Get(2) = 5; *cArray.Get(3) = 4; pi = cArray.Add(); *pi = 22; AssertInt(5, cArray.NumElements()); AssertPointer(piEmbeddedData, cArray.GetData()); AssertInt(7, *cArray.Get(0)); AssertInt(22, *cArray.Get(4)); pi = cArray.Add(); *pi = 20; AssertInt(6, cArray.NumElements()); AssertFalse(piEmbeddedData == cArray.GetData()); AssertInt(7, *cArray.Get(0)); AssertInt(6, *cArray.Get(1)); AssertInt(5, *cArray.Get(2)); AssertInt(4, *cArray.Get(3)); AssertInt(22, *cArray.Get(4)); AssertInt(20, *cArray.Get(5)); AssertTrue(cArray.TestInternalConsistency()); cArray.Kill(); }
void TestLinkListAlignedGrow(void) { CLinkListAligned cLinkListAligned; int* pi; void* pvOld; void* pvNew; cLinkListAligned.Init(); pi = (int*)cLinkListAligned.InsertAfterTail(20, 4, 0); pi[0] = 0; pi[1] = 1; pi[2] = 2; pi[3] = 3; pi[4] = 4; pi = (int*)cLinkListAligned.Grow(pi, 24); AssertInt(0, pi[0]); AssertInt(1, pi[1]); AssertInt(2, pi[2]); AssertInt(3, pi[3]); AssertInt(4, pi[4]); pi[5] = 5; pi = (int*)cLinkListAligned.Grow(pi, 8); AssertInt(0, pi[0]); AssertInt(1, pi[1]); pi = (int*)cLinkListAligned.Grow(pi, 0); AssertNull(pi); cLinkListAligned.Kill(); cLinkListAligned.Init(); pvOld = cLinkListAligned.InsertAfterTail(1, 4, 0); pvNew = cLinkListAligned.Grow(pvOld, 2); AssertPointer(pvOld, pvNew); pvNew = cLinkListAligned.Grow(pvOld, 3); AssertPointer(pvOld, pvNew); pvNew = cLinkListAligned.Grow(pvOld, 3); AssertPointer(pvOld, pvNew); pvNew = cLinkListAligned.Grow(pvOld, 4); AssertPointer(pvOld, pvNew); pvNew = cLinkListAligned.Grow(pvOld, 8); AssertFalse(pvOld == pvNew); cLinkListAligned.Kill(); }
void AssertCache(CMemoryCache* pcCache, int iFirstLength, char cFirstChar, int iSecondLength, char cSecondChar) { SMemoryCacheDescriptor* psFirst; SMemoryCacheDescriptor* psLast; AssertInt(2, pcCache->NumCached()); psFirst = pcCache->GetFirst(); psLast = pcCache->GetLast(); AssertNotNull(psFirst); AssertFalse(psFirst == psLast); AssertPointer(psLast, psFirst->psNext); AssertPointer(psFirst, psLast->psNext); AssertCacheElement(pcCache, psFirst, iFirstLength, cFirstChar); AssertCacheElement(pcCache, psLast, iSecondLength, cSecondChar); }
void TestFileUtilMakeDirectory(void) { CFileUtil cFileUtil; CChars szDirectory; CChars szFileName; CArrayString aszFiles; CChars szParentDirectory; CChars szCurrentDirectory; BOOL bResult; cFileUtil.RemoveDir("file_util"); szParentDirectory.Init("file_util" _FS_ "directory" _FS_ "make" _FS_ "test"); szDirectory.Init(szParentDirectory); szDirectory.Append(_FS_); szDirectory.Append("GABBA"); szFileName.Init(szDirectory); szFileName.Append(_FS_); szFileName.Append("FileName.txt"); bResult = cFileUtil.Touch(szFileName.Text()); AssertFalse(bResult); cFileUtil.MakeDir(szDirectory.Text()); szCurrentDirectory.Init(); cFileUtil.CurrentDirectory(&szCurrentDirectory); szCurrentDirectory.Append(_FS_); szCurrentDirectory.Append(szDirectory); aszFiles.Init(1); cFileUtil.FindAllDirectories(szParentDirectory.Text(), &aszFiles, FALSE); AssertInt(1, aszFiles.NumElements()); AssertString(szCurrentDirectory.Text(), aszFiles.GetText(0)); bResult = cFileUtil.Touch(szFileName.Text()); AssertTrue(bResult); szParentDirectory.Kill(); szDirectory.Kill(); szFileName.Kill(); cFileUtil.RemoveDir("file_util"); }