Ejemplo n.º 1
0
void TestMemoryStackOutOfMemory(void)
{
	CMemoryStack	cStack;
	void*			pvData;

	cStack.Init(3);
	pvData = cStack.Add(2);
	AssertNotNull(pvData);

	pvData = cStack.Add(2);
	AssertNull(pvData);

	pvData = cStack.Add(1);
	AssertNotNull(pvData);

	pvData = cStack.Add(1);
	AssertNull(pvData);

	cStack.Clear();

	pvData = cStack.Add(3);
	AssertNotNull(pvData);

	pvData = cStack.Add(1);
	AssertNull(pvData);

	cStack.Kill();
}
void TestLinkListAlignedRemove(void)
{
	CLinkListAligned	cLinkListAligned;
	void*				pv1;
	void*				pv2;
	void*				pv3;
	void*				pv;

	cLinkListAligned.Init();
	pv1 = cLinkListAligned.InsertAfterTail(1, 4, 0);
	pv2 = cLinkListAligned.InsertAfterTail(2, 4, 0);
	pv3 = cLinkListAligned.InsertAfterTail(3, 4, 0);
	cLinkListAligned.Remove(pv2);

	pv = cLinkListAligned.GetHead();
	AssertPointer(pv1, pv);
	pv = cLinkListAligned.GetNext(pv);
	AssertPointer(pv3, pv);
	pv = cLinkListAligned.GetNext(pv);
	AssertNull(pv);

	cLinkListAligned.Remove(pv1);
	cLinkListAligned.Remove(pv3);

	pv = cLinkListAligned.GetHead();
	AssertNull(pv);
}
Ejemplo n.º 3
0
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();
}
Ejemplo n.º 4
0
static void test_server_CyaSSL_new(void)
{
#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
    CYASSL_CTX *ctx;
    CYASSL_CTX *ctx_nocert;
    CYASSL *ssl;

    AssertNotNull(ctx_nocert = CyaSSL_CTX_new(CyaSSLv23_server_method()));
    AssertNotNull(ctx        = CyaSSL_CTX_new(CyaSSLv23_server_method()));

    AssertTrue(CyaSSL_CTX_use_certificate_file(ctx, svrCert, SSL_FILETYPE_PEM));
    AssertTrue(CyaSSL_CTX_use_PrivateKey_file(ctx, svrKey, SSL_FILETYPE_PEM));

    /* invalid context */
    AssertNull(ssl = CyaSSL_new(NULL));
    AssertNull(ssl = CyaSSL_new(ctx_nocert));

    /* success */
    AssertNotNull(ssl = CyaSSL_new(ctx));

    CyaSSL_free(ssl);
    CyaSSL_CTX_free(ctx);
    CyaSSL_CTX_free(ctx_nocert);
#endif
}
Ejemplo n.º 5
0
void test_assert_ptr()
{
	int a, b;
	int *ap = &a;
	int *bp = &b;
	int *cp = &a;
	int *n = NULL;

	AssertPtr(ap);
	AssertNull(n);

	test_failure( AssertPtr(n) );
	test_failure( AssertNull(ap) );

	AssertPtrEq(ap,cp);
	AssertPtrNe(ap,bp);
	AssertPtrGt(ap,bp);
	AssertPtrGe(ap,bp);
	AssertPtrGe(ap,cp);
	AssertPtrLt(bp,ap);
	AssertPtrLe(bp,ap);
	AssertPtrLe(cp,ap);

	test_failure( AssertPtrEq(ap,bp) );
	test_failure( AssertPtrNe(ap,cp) );
	test_failure( AssertPtrGt(ap,cp) );
	test_failure( AssertPtrGt(bp,cp) );
	test_failure( AssertPtrGe(bp,ap) );
	test_failure( AssertPtrLt(cp,ap) );
	test_failure( AssertPtrLt(cp,bp) );
	test_failure( AssertPtrLe(ap,bp) );
}
Ejemplo n.º 6
0
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());
}
Ejemplo n.º 7
0
void TestTreeTemplateInsert(void)
{
	CTestTree				cTree;
	STestTreeTemplateItem*	pcNode0;
	STestTreeTemplateItem*	pcNode00;
	STestTreeTemplateItem*	pcNode01;
	STestTreeTemplateItem*	pcNode02;
	STestTreeTemplateItem*	pcNode000;
	STestTreeTemplateItem*	pcTest;

	cTree.Init();
	pcNode0 = cTree.InsertRoot();
	pcNode0->Init(672, 7645);

	pcNode00 = cTree.InsertOnRightOfChildren(pcNode0);
	pcNode00->Init(720, 6);

	pcNode000 = cTree.InsertOnRightOfChildren(pcNode00);
	pcNode000->Init(325, 28274);

	pcNode01 = cTree.InsertOnRightOfChildren(pcNode0);
	pcNode01->Init(8, 12);

	pcNode02 = cTree.InsertOnRightOfChildren(pcNode0);
	pcNode02->Init(99, 7);

	AssertInt(5, cTree.NumElements());
	pcTest = cTree.GetRoot();
	AssertPointer(pcNode0, pcTest);
	AssertTrue(pcTest->IsOkay(672, 7645));
	pcTest = cTree.GetUp(pcNode0);
	AssertPointer(pcNode00, pcTest);
	AssertTrue(pcTest->IsOkay(720, 6));
	pcTest = cTree.GetUp(pcNode00);
	AssertPointer(pcNode000, pcTest);
	pcTest = cTree.GetRight(pcNode00);
	AssertPointer(pcNode01, pcTest);
	pcTest = cTree.GetRight(pcNode01);
	AssertPointer(pcNode02, pcTest);
	pcTest = cTree.GetRight(pcNode02);
	AssertNull(pcTest);
	AssertNull(cTree.GetUp(pcNode01));
	AssertNull(cTree.GetUp(pcNode02));
	AssertPointer(pcNode0, cTree.GetDown(pcNode00));
	AssertPointer(pcNode0, cTree.GetDown(pcNode01));
	AssertPointer(pcNode0, cTree.GetDown(pcNode02));

	cTree.Kill();
}
Ejemplo n.º 8
0
static void test_client_CyaSSL_new(void)
{
#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
    CYASSL_CTX *ctx;
    CYASSL_CTX *ctx_nocert;
    CYASSL *ssl;

    AssertNotNull(ctx_nocert = CyaSSL_CTX_new(CyaSSLv23_client_method()));
    AssertNotNull(ctx        = CyaSSL_CTX_new(CyaSSLv23_client_method()));

    AssertTrue(CyaSSL_CTX_load_verify_locations(ctx, caCert, 0));
    
    /* invalid context */
    AssertNull(ssl = CyaSSL_new(NULL));

    /* success */
    AssertNotNull(ssl = CyaSSL_new(ctx_nocert));
    CyaSSL_free(ssl);
    
    /* success */
    AssertNotNull(ssl = CyaSSL_new(ctx));
    CyaSSL_free(ssl);
    
    CyaSSL_CTX_free(ctx);
    CyaSSL_CTX_free(ctx_nocert);
#endif
}
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();
}
Ejemplo n.º 11
0
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();
}
Ejemplo n.º 12
0
static void verify_SNI_no_matching(WOLFSSL* ssl)
{
    byte type = WOLFSSL_SNI_HOST_NAME;
    char* request = (char*) &type; /* to be overwriten */

    AssertIntEQ(WOLFSSL_SNI_NO_MATCH, wolfSSL_SNI_Status(ssl, type));
    AssertNotNull(request);
    AssertIntEQ(0, wolfSSL_SNI_GetRequest(ssl, type, (void**) &request));
    AssertNull(request);
}
Ejemplo n.º 13
0
void TestMapBlockInternals(void)
{
	CMapBlock			cMapBlock;
	int					i;
	int					j;
	int					iKey;
	int*				piData;
	CArrayBlockSorted*	paBlock;
	SMNode**			psNode1;
	SMNode**			psNode2;
	int*				piKey;

	cMapBlock.Init(1024, &CompareInt, TRUE);
	i = 7; j = 43;
	cMapBlock.Put(&i, sizeof(int), &j, sizeof(int));

	i = 9; j = 21;
	cMapBlock.Put(&i, sizeof(int), &j, sizeof(int));
	AssertInt(2, cMapBlock.NumElements());

	paBlock = cMapBlock.GetArray();
	paBlock->InsertHoldingIntoSorted();
	psNode1 = (SMNode**)paBlock->GetInSorted(0);
	psNode2 = (SMNode**)paBlock->GetInSorted(1);
	AssertInt(sizeof(int), (*psNode1)->iDataSize);
	AssertInt(sizeof(int), (*psNode1)->iKeySize);
	AssertPointer(&cMapBlock, (*psNode1)->pcMapBlock);
	AssertInt(sizeof(int), (*psNode2)->iDataSize);
	AssertInt(sizeof(int), (*psNode2)->iKeySize);
	AssertPointer(&cMapBlock, (*psNode2)->pcMapBlock);
	piKey = (int*)RemapSinglePointer(*psNode1, sizeof(SMNode));
	AssertInt(7, *piKey);
	piData = (int*)RemapSinglePointer(piKey, (int)sizeof(int));
	AssertInt(43, *piData);
	piKey = (int*)RemapSinglePointer(*psNode2, sizeof(SMNode));
	AssertInt(9, *piKey);
	piData = (int*)RemapSinglePointer(piKey, (int)sizeof(int));
	AssertInt(21, *piData);

	iKey = 7; piData = NULL;
	cMapBlock.Get(&iKey, (void**)&piData, NULL);
	AssertNotNull(piData);
	AssertInt(43, *piData);

	iKey = 9; piData = NULL;
	cMapBlock.Get(&iKey, (void**)&piData, NULL);
	AssertNotNull(piData);
	AssertInt(21, *piData);

	iKey = 3; piData = NULL;
	cMapBlock.Get(&iKey, (void**)&piData, NULL);
	AssertNull(piData);

	cMapBlock.Kill();
}
Ejemplo n.º 14
0
static void test_CyaSSL_CTX_new(CYASSL_METHOD *method)
{
    CYASSL_CTX *ctx;
    
    AssertNull(ctx = CyaSSL_CTX_new(NULL));
    
    AssertNotNull(method);
    AssertNotNull(ctx = CyaSSL_CTX_new(method));

    CyaSSL_CTX_free(ctx);
}
Ejemplo n.º 15
0
static void test_wolfSSL_CTX_new(WOLFSSL_METHOD *method)
{
    WOLFSSL_CTX *ctx;

    AssertNull(ctx = wolfSSL_CTX_new(NULL));

    AssertNotNull(method);
    AssertNotNull(ctx = wolfSSL_CTX_new(method));

    wolfSSL_CTX_free(ctx);
}
Ejemplo n.º 16
0
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();
}
Ejemplo n.º 17
0
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 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();
}
Ejemplo n.º 19
0
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();
}
Ejemplo n.º 20
0
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();
}
Ejemplo n.º 21
0
void TestMemoryStackAdd(void)
{
	CMemoryStack	cStack;
	char			szNumbers[] = {"0123456789"};
	char			szLetters[] = {"ABCDEFGHIJ"};
	char			szStuff[] = {"%^&"};
	char*			sz1;
	char*			sz2;
	char*			sz3;
	char*			sz4;

	cStack.Init(100);

	sz1 = (char*)cStack.Add(10);
	memcpy(sz1, szNumbers, 10);
	sz2 = (char*)cStack.Add(11);
	memcpy(sz2, szLetters, 11);
	
	AssertString("0123456789ABCDEFGHIJ", (char*)cStack.mpvMemory);
	
	cStack.Remove();  //Removing doesn't do anything unless every item is removed.
	AssertString("0123456789ABCDEFGHIJ", (char*)cStack.mpvMemory);
	((char*)cStack.mpvMemory)[20] = '.';

	sz3 = (char*)cStack.Add(4);
	memcpy(sz3, szStuff, 4);	
	AssertString("0123456789ABCDEFGHIJ.%^&", (char*)cStack.mpvMemory);

	cStack.Remove(2);
	sz4 = (char*)cStack.Add(4);
	memcpy(sz4, szStuff, 4);	
	AssertString("%^&", (char*)cStack.mpvMemory);
	
	cStack.Kill();

	AssertNull(cStack.mpvMemory);
}
Ejemplo n.º 22
0
void TestFileSystemIterator(void)
{
	CFileSystem			cSystem;
	CFileSystemIterator	cIter;

	cSystem.Init("Finder");

	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\Lord\\1.rar", cSystem.StartIteration(&cIter)->File()->GetFullName(), FALSE);
	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\Rising\\2.rar", cSystem.Iterate(&cIter)->File()->GetFullName(), FALSE);
	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\Storm\\3.rar", cSystem.Iterate(&cIter)->File()->GetFullName(), FALSE);
	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\Ants.rar", cSystem.Iterate(&cIter)->File()->GetFullName(), FALSE);
	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\Ants.txt", cSystem.Iterate(&cIter)->File()->GetFullName(), FALSE);
	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\Echo.rar", cSystem.Iterate(&cIter)->File()->GetFullName(), FALSE);
	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\File.txt", cSystem.Iterate(&cIter)->File()->GetFullName(), FALSE);
	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\Glenmark.wav", cSystem.Iterate(&cIter)->File()->GetFullName(), FALSE);
	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\Last.txt", cSystem.Iterate(&cIter)->File()->GetFullName(), FALSE);
	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\March.rar", cSystem.Iterate(&cIter)->File()->GetFullName(), FALSE);
	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\Marching.txt", cSystem.Iterate(&cIter)->File()->GetFullName(), FALSE);
	AssertStringCase("C:\\gameengine\\Test\\TestBaseLib\\TestBaseLib\\Finder\\Ninja.txt", cSystem.Iterate(&cIter)->File()->GetFullName(), FALSE);
	AssertNull(cSystem.Iterate(&cIter));
	cSystem.StopIteration(&cIter);

	cSystem.Kill();
}
Ejemplo n.º 23
0
void TestRepeatedExternalTags(void)
{
	CXMLFile		cXMLFile;
	CChars			szDoc;
	int				iLine;
	char			szExpected[] = "<Root>\n\
  <ExtTag>\n\
    <SubTag>Look at me!  I&apos;m going to be an elite pilot.</SubTag>\n\
    <SubTag>Also *very* messed up.</SubTag>\n\
  </ExtTag>\n\
  <ExtTag>\n\
    <SubTag>Look at me!  I&apos;m going to be an elite pilot.</SubTag>\n\
    <SubTag>Also *very* messed up.</SubTag>\n\
  </ExtTag>\n\
  <ExtTag>\n\
    <SubTag>Look at me!  I&apos;m going to be an elite pilot.</SubTag>\n\
    <SubTag>Also *very* messed up.</SubTag>\n\
  </ExtTag>\n\
  <ExtTag>\n\
    <SubTag>Look at me!  I&apos;m going to be an elite pilot.</SubTag>\n\
    <SubTag>Also *very* messed up.</SubTag>\n\
  </ExtTag>\n\
</Root>\n";
	CMarkupTag*		pcRoot;
	int				iCount;
	CMarkupTag*		pcExtTag;
	CMarkupTag*		pcSubTag1;
	CMarkupTag*		pcSubTag2;
	CMarkupTag*		pcSubTag3;
	CChars			szText;
	STagIterator	sIter;

	cXMLFile.Init();
	cXMLFile.Read("File.xml", ".");

	szDoc.Init(16);
	iLine = cXMLFile.mcMarkup.mpcDoc->ToString(&szDoc);
	AssertInt(18, iLine);
	AssertString(szExpected, szDoc.Text());
	szDoc.Kill();

	pcRoot = cXMLFile.mcMarkup.mpcDoc->GetRootTag();

	iCount = 0;
	pcExtTag = pcRoot->GetTag("ExtTag", &sIter);
	while (pcExtTag)
	{
		iCount++;

		if (iCount > 4)
		{
			//This is to take care of the case where GetNextTag always get's the first tag.
			break;
		}

		pcSubTag1 = pcExtTag->GetTag("SubTag", 0);
		pcSubTag2 = pcExtTag->GetTag("SubTag", 1);
		pcSubTag3 = pcExtTag->GetTag("SubTag", 2);

		szText.Init();
		pcSubTag1->GetText(&szText);
		AssertString("Look at me!  I'm going to be an elite pilot.", szText.Text());
		szText.Kill();		
		
		szText.Init();
		pcSubTag2->GetText(&szText);
		AssertString("Also *very* messed up.", szText.Text());
		szText.Kill();

		AssertNull(pcSubTag3);

		pcExtTag = pcRoot->GetNextTag(&sIter);
	}

	AssertInt(4, iCount);
	cXMLFile.Kill();
}
Ejemplo n.º 24
0
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 TestIndexTreeMemoryResizeData(void)
{
	CIndexTreeMemory		cIndex;
	char*					szResult;
	CIndexTreeNodeMemory*	pcNode;
	CIndexTreeNodeMemory*	pcOldNode;
	CIndexTreeNodeMemory*	pcRoot;
	char					szAAObject[] = "Hello";
	char					szACObject[] = "Goodbye";
	char					szAObject[] = "Centrist Policies";
	int						iNodeMemoryOffset1;
	int						iNodeMemoryOffset2;
	CChars					sz;

	cIndex.Init();
	szResult = (char*)cIndex.Put("AA", szAAObject, (unsigned char)strlen(szAAObject) + 1);
	AssertString(szAAObject, szResult);

	szResult = (char*)cIndex.Put("AC", szACObject, (unsigned char)strlen(szACObject) + 1);
	AssertString(szACObject, szResult);

	pcNode = cIndex.GetNode("A", 1);
	pcOldNode = pcNode;
	AssertInt(3, pcNode->NumIndexes());
	AssertInt(2, pcNode->NumValidIndexes());
	AssertInt(0, pcNode->ObjectSize());
	iNodeMemoryOffset1 = (size_t)pcNode->GetNodesMemory() - (size_t)pcNode;
	AssertInt(cIndex.SizeofNode(), iNodeMemoryOffset1);

	szResult = (char*)cIndex.Put("A", szAObject, (unsigned char)strlen(szAObject) + 1);
	AssertString(szAObject, szResult);

	pcNode = cIndex.GetNode("A", 1);
	AssertInt(3, pcNode->NumIndexes());
	AssertInt(2, pcNode->NumValidIndexes());
	AssertInt(18, pcNode->ObjectSize());
	iNodeMemoryOffset2 = (size_t)pcNode->GetNodesMemory() - (size_t)pcNode;
	AssertInt(cIndex.SizeofNode() + pcNode->ObjectSize(), iNodeMemoryOffset2);
	AssertTrue(iNodeMemoryOffset2 > iNodeMemoryOffset1);

	AssertString(szAAObject, (char*)cIndex.Get("AA"));
	AssertString(szACObject, (char*)cIndex.Get("AC"));
	AssertString(szAObject, (char*)cIndex.Get("A"));

	pcRoot = cIndex.GetRoot();
	sz.Init(); pcRoot->Print(&sz, FALSE); 
	AssertString("0:255 .................................................................x..............................................................................................................................................................................................", sz.Text());
	sz.Kill();
	pcNode = pcRoot->Get('A');
	sz.Init(); pcNode->Print(&sz, FALSE);
	AssertString("65:67 (18) x.x", sz.Text()); 
	sz.Kill();
	sz.Init(); pcNode->Get('A')->Print(&sz, FALSE);
	AssertString("0:0 (6)", sz.Text()); 
	sz.Kill();
	AssertNull(pcNode->Get('B'));
	sz.Init(); pcNode->Get('C')->Print(&sz, FALSE);
	AssertString("0:0 (8)", sz.Text()); 
	sz.Kill();

	cIndex.Kill();
}
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 TestIndexTreeMemoryPutDifferenceSizeDuplicates(void)
{
	CIndexTreeMemory		cIndex;
	char					szOne[] = "1";
	char					szTwo[] = "22";
	char					szOtherTwo[] = "OT";
	char					szThree[] = "333";
	char					szKerfuffle[] = "kerfuffle";
	char*					pvResult;
	CCountingAllocator		cAllocator;
	int						iKeyLength;
	CIndexTreeNodeMemory*	pcNode;
	CIndexTreeNodeMemory*	pcChildNode;

	cAllocator.Init(&gcSystemAllocator);
	AssertInt(0, cAllocator.AllocatedUserSize());

	cIndex.Init(&cAllocator);
	AssertInt(0, cIndex.NumElements());
	AssertInt(cIndex.ByteSize(), cAllocator.AllocatedUserSize());

	iKeyLength = strlen("Spoedling");
	AssertNull(cIndex.GetNode("Spoedling", iKeyLength));

	pvResult = (char*)cIndex.Put("SpoedlingZ", szKerfuffle, 10);
	AssertString("kerfuffle", pvResult);
	AssertInt(1, cIndex.NumElements());

	AssertInt(cIndex.ByteSize(), cAllocator.AllocatedUserSize());
	pcNode = cIndex.GetNode("Spoedling", iKeyLength);
	AssertNotNull(pcNode);
	pcChildNode = pcNode->Get('Z');
	AssertNotNull(pcChildNode);
	AssertPointer(pcNode, pcChildNode->GetParent());

	pvResult = (char*)cIndex.Put("Spoedling", szTwo, 3);
	AssertString("22", pvResult);
	AssertInt(2, cIndex.NumElements());
	AssertInt(cIndex.ByteSize(), cAllocator.AllocatedUserSize());
	AssertString("kerfuffle", (char*)cIndex.Get("SpoedlingZ"));
	AssertString("22", (char*)cIndex.Get("Spoedling"));

	pcNode = cIndex.GetNode("Spoedling", iKeyLength);
	AssertNotNull(pcNode);
	pcChildNode = pcNode->Get('Z');
	AssertNotNull(pcChildNode);
	AssertPointer(pcNode, pcChildNode->GetParent());

	pvResult = (char*)cIndex.Put("Spoedling", szOtherTwo, 3);
	AssertString("OT", pvResult);
	AssertInt(2, cIndex.NumElements());
	AssertInt(cIndex.ByteSize(), cAllocator.AllocatedUserSize());
	AssertString("kerfuffle", (char*)cIndex.Get("SpoedlingZ"));
	AssertString("OT", (char*)cIndex.Get("Spoedling"));

	pcNode = cIndex.GetNode("Spoedling", iKeyLength);
	AssertNotNull(pcNode);
	pcChildNode = pcNode->Get('Z');
	AssertNotNull(pcChildNode);
	AssertPointer(pcNode, pcChildNode->GetParent());

	pvResult = (char*)cIndex.Put("Spoedling", szThree, 4);
	AssertString("333", pvResult);
	AssertInt(2, cIndex.NumElements());
	AssertInt(cIndex.ByteSize(), cAllocator.AllocatedUserSize());
	AssertString("kerfuffle", (char*)cIndex.Get("SpoedlingZ"));
	AssertString("333", (char*)cIndex.Get("Spoedling"));

	pcNode = cIndex.GetNode("Spoedling", iKeyLength);
	AssertNotNull(pcNode);
	pcChildNode = pcNode->Get('Z');
	AssertNotNull(pcChildNode);
	AssertPointer(pcNode, pcChildNode->GetParent());

	pvResult = (char*)cIndex.Put("Spoedling", szOne, 2);
	AssertString("1", pvResult);
	AssertInt(2, cIndex.NumElements());
	AssertInt(cIndex.ByteSize(), cAllocator.AllocatedUserSize());
	AssertString("kerfuffle", (char*)cIndex.Get("SpoedlingZ"));
	AssertString("1", (char*)cIndex.Get("Spoedling"));

	pcNode = cIndex.GetNode("Spoedling", iKeyLength);
	AssertNotNull(pcNode);
	pcChildNode = pcNode->Get('Z');
	AssertNotNull(pcChildNode);
	AssertPointer(pcNode, pcChildNode->GetParent());

	cIndex.Kill();
	AssertInt(0, cAllocator.AllocatedUserSize());
}
void TestIndexTreeMemoryGet(void)
{
	CIndexTreeMemory	cIndex;
	CTestIndexTreeObject	andrew;
	CTestIndexTreeObject**	pcResult;
	CArrayVoidPtr			avp;
	CTestIndexTreeObject	batman;
	CTestIndexTreeObject	batmam;
	CTestIndexTreeObject	andre;
	CIndexTreeNodeMemory*	pcNodeBatman;
	CIndexTreeNodeMemory*	pcNodeBatmam;
	char*					szBatmam;

	cIndex.Init();

	andrew.Init("Andrew");
	cIndex.PutPtr(andrew.GetName(), &andrew);
	pcResult = (CTestIndexTreeObject**)cIndex.Get("Andrew");
	AssertPointer(*pcResult, &andrew);
	avp.Init();
	cIndex.FindAll(&avp);
	AssertInt(1, avp.NumElements());
	avp.Kill();

	batman.Init("Batman");
	cIndex.PutPtr(batman.GetName(), &batman);
	pcNodeBatman = cIndex.GetNode("Batman", 6);
	AssertInt(0, pcNodeBatman->NumIndexes());
	pcResult = (CTestIndexTreeObject**)cIndex.Get("Batman");
	AssertPointer(*pcResult, &batman);
	avp.Init();
	cIndex.FindAll(&avp);
	AssertInt(2, avp.NumElements());
	avp.Kill();

	szBatmam = "Batmam";
	batmam.Init(szBatmam);
	cIndex.PutPtr(szBatmam, &batmam);
	pcNodeBatman = cIndex.GetNode("Batman", 6);
	pcNodeBatmam = cIndex.GetNode(szBatmam, 6);
	pcResult = (CTestIndexTreeObject**)cIndex.Get(szBatmam);
	AssertPointer(&batmam, *pcResult);
	avp.Init();
	cIndex.FindAll(&avp);
	AssertInt(3, avp.NumElements());
	avp.Kill();

	andre.Init("Andre");
	cIndex.PutPtr(andre.GetName(), &andre);
	pcResult = (CTestIndexTreeObject**)cIndex.Get("Andre");
	AssertPointer(&andre, *pcResult);
	avp.Init();
	cIndex.FindAll(&avp);
	AssertInt(4, avp.NumElements());
	avp.Kill();

	AssertNull(cIndex.Get(NULL));
	AssertNull(cIndex.Get(""));
	AssertNull(cIndex.Get("Batma"));
	AssertNull(cIndex.Get("Batmano"));
	AssertNull(cIndex.Get("Batmao"));

	cIndex.Kill();
}
Ejemplo n.º 29
0
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();
}
Ejemplo n.º 30
0
void TestFilesIteration(void)
{
	CFiles			cFiles;
	CFileIterator	cIter;

	cFiles.Init("Game", "PAK");
	AssertInt(6, cFiles.GetNumPackFiles());
	AssertString("C:\\gameengine\\Test\\TestCoreLib\\TestCoreLib\\Game\\Sounds\\Cheese.PAK", cFiles.GetPackFiles(0)->GetFileName());
	AssertString("C:\\gameengine\\Test\\TestCoreLib\\TestCoreLib\\Game\\Sounds\\Santa.PAK", cFiles.GetPackFiles(1)->GetFileName());
	AssertString("C:\\gameengine\\Test\\TestCoreLib\\TestCoreLib\\Game\\Textures.PAK", cFiles.GetPackFiles(2)->GetFileName());
	AssertString("C:\\gameengine\\Test\\TestCoreLib\\TestCoreLib\\Game\\Models.PAK", cFiles.GetPackFiles(3)->GetFileName());
	AssertString("C:\\gameengine\\Test\\TestCoreLib\\TestCoreLib\\Game\\Sounds.PAK", cFiles.GetPackFiles(4)->GetFileName());
	AssertString("C:\\gameengine\\Test\\TestCoreLib\\TestCoreLib\\Game\\Videos.PAK", cFiles.GetPackFiles(5)->GetFileName());

	AssertStringCase("Sounds/Cheese/Moose.txt", cFiles.StartIteration(&cIter)->GetFullName(), FALSE);
	AssertInt(1, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Sounds/Cheese/Scream.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(1, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Sounds/Santa/Slay/Spelling.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(1, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Sounds/Santa/Seattle.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(1, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Models/Super/Barbie.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(0, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Models/Super/Ken.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(0, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Models/Cars.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(0, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Sounds/Cheese/Moose.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(0, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Sounds/Cheese/Scream.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(0, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Sounds/Santa/Seattle.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(0, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Sounds/Ambient.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(0, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Sounds/General.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(0, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Videos/Intro.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(0, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_PackFiles, cIter.GetCurrent()->GetType());

	AssertStringCase("Models/Super/Barbie.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(FILE_SYSTEM_RANK, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_FileSystem, cIter.GetCurrent()->GetType());

	AssertStringCase("Models/Super/Ken.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(FILE_SYSTEM_RANK, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_FileSystem, cIter.GetCurrent()->GetType());

	AssertStringCase("Models/Cars.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(FILE_SYSTEM_RANK, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_FileSystem, cIter.GetCurrent()->GetType());

	AssertStringCase("Sounds/Santa/Seattle.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(FILE_SYSTEM_RANK, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_FileSystem, cIter.GetCurrent()->GetType());

	AssertStringCase("Sounds/Ambient.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(FILE_SYSTEM_RANK, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_FileSystem, cIter.GetCurrent()->GetType());

	AssertStringCase("Videos/Intro.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(FILE_SYSTEM_RANK, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_FileSystem, cIter.GetCurrent()->GetType());

	AssertStringCase("Videos/Outro.txt", cFiles.Iterate(&cIter)->GetFullName(), FALSE); 
	AssertInt(FILE_SYSTEM_RANK, cIter.GetCurrent()->GetFileRank());
	AssertInt(FIRT_FileSystem, cIter.GetCurrent()->GetType());

	AssertNull(cFiles.Iterate(&cIter));
	AssertNull(cIter.GetCurrent());
	cFiles.StopIteration(&cIter);

	cFiles.Kill();
}