void TestObjectsFlushRemovesStackPointers(void)
{
	CFileUtil						cFileUtil;
	Ptr<CTestDoubleNamedString>		pDouble;
	Ptr<CRoot>						pRoot;

	cFileUtil.RemoveDir("Output");
	cFileUtil.MakeDir("Output/ClearPointers");

	ObjectsInit("Output/ClearPointers");
	SetupObjectsConstructors();

	pRoot = ORoot();

	gcObjects.Flush(TRUE, TRUE);
	AssertLongLongInt(2, gcObjects.NumDatabaseObjects());

	AssertNull(&pRoot);

	pDouble = ONMalloc(CTestDoubleNamedString, "Double")->Init();
	AssertString("CTestDoubleNamedString", pDouble.ClassName());

	pRoot = ORoot();
	AssertString("CRoot", pRoot.ClassName());

	ObjectsKill();
}
void TestObjectsFlushClearGetByName(void)
{
	CFileUtil						cFileUtil;
	CPointer						pObject;
	Ptr<CTestDoubleNamedString>		pDouble;
	Ptr<CRoot>						pRoot;

	cFileUtil.RemoveDir("Output");
	cFileUtil.MakeDir("Output/Dehollowfication");

	ObjectsInit("Output/Dehollowfication");
	SetupObjectsConstructors();

	pRoot = ORoot();
	pDouble = ONMalloc(CTestDoubleNamedString, "Double")->Init();
	pRoot->Add(pDouble);
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	pObject = gcObjects.Get(3);
	AssertNotNull(pObject.Object());
	AssertString("CTestDoubleNamedString", pObject.ClassName());

	gcObjects.Flush(TRUE, TRUE);
	AssertLongLongInt(3, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(2, gcObjects.NumDatabaseNames());

	pObject = gcObjects.Get("Double");
	AssertNotNull(pObject.Object());
	AssertString("CTestDoubleNamedString", pObject.ClassName());

	ObjectsKill();
}
Esempio n. 3
0
void TestArrayMinimalTemplateChar(void)
{
	CArrayCharMinimal	cac;

	cac.Init("aabbc");
	AssertString("aabbc", cac.GetArray());

	cac.BatchInsertElements(0, 3, 2, 2);

	cac.GetArray()[0] = cac.GetArray()[1] = cac.GetArray()[2]='_';
	cac.GetArray()[5] = cac.GetArray()[6] = cac.GetArray()[7]='_';
	AssertString("___aa___bbc", cac.GetArray());

	cac.InsertNumElementsAt(2, 1);

	cac.GetArray()[1]=cac.GetArray()[2]='X';
	AssertString("_XX__aa___bbc", cac.GetArray());

	cac.Kill();

	cac.Init("ABCDEFGHIJK");
	cac.BatchRemoveElements(2, 2, 3, 3);
	AssertString("ABEHK", cac.GetArray());

	cac.Kill();
}
Esempio n. 4
0
void TestFileSystemNearest(void)
{
	CFileSystem				cSystem;
	CFileUtil				cFileUtil;
	CChars					szWorkingDirectory;
	CFileNodeSystemFile*	pcNode;
	CChars					szRemaining;

	szWorkingDirectory.Init("Finder");
	cFileUtil.FullPath(&szWorkingDirectory);

	cSystem.Init("Finder");

	szRemaining.Init();
	pcNode = cSystem.GetFileNode("Lord/1.rar/Happy/Quan", &szRemaining);
	AssertNotNull(pcNode);
	AssertString("Happy/Quan", szRemaining.Text());
	szRemaining.Kill();

	szRemaining.Init();
	pcNode = cSystem.GetFileNode("File.txt/Sad/Quan", &szRemaining);
	AssertNotNull(pcNode);
	AssertString("Sad/Quan", szRemaining.Text());
	szRemaining.Kill();

	cSystem.Kill();
}
Esempio n. 5
0
void TestMapBlockAddDuplicate(void)
{
	CMapBlock	cMapBlock;
	int			ia = 'a';
	int			ib = 'a';
	BOOL		bResult;
	int			iWorldLen;
	int			iHelloLen;

	iWorldLen = strlen("World");
	iHelloLen = strlen("Hello");

	cMapBlock.Init(1024, &CompareInt, TRUE);
	bResult = cMapBlock.Put(&ia, sizeof(int), "Hello", iHelloLen + 1);
	AssertTrue(bResult);
	AssertInt(1, cMapBlock.NumElements());
	AssertString("Hello", (char*)cMapBlock.Get(&ia));

	bResult = cMapBlock.Put(&ib, sizeof(int), "World", iWorldLen + 1);
	AssertTrue(bResult);
	AssertInt(1, cMapBlock.NumElements());
	AssertString("World", (char*)cMapBlock.Get(&ia));

	cMapBlock.Kill();
}
Esempio n. 6
0
void TestFileSystemInit(void)
{
	CFileSystem		cSystem;
	char*			szFullName;
	CFileUtil		cFileUtil;
	CChars			szWorkingDirectory;
	CChars			szTemp;
	CTextFile		cTextFile;

	szWorkingDirectory.Init("Finder");
	cFileUtil.FullPath(&szWorkingDirectory);

	cSystem.Init("Finder");

	szFullName = cSystem.GetFileName("Lord/1.rar");
	szTemp.Init(szFullName);
	szTemp.RemoveFromStart(szWorkingDirectory.Length()+1);
	szTemp.Replace(FILE_SEPARATOR[0], '/');

	AssertString("Lord/1.rar", szTemp.Text());
	szTemp.Kill();

	szFullName = cSystem.GetFileName("File.txt");
	cTextFile.Init();
	cTextFile.Read(szFullName);

	AssertString("Hello World.", cTextFile.Text());

	cTextFile.Kill();

	cSystem.Kill();
}
Esempio n. 7
0
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 TestChannelsAccessorByteAligned(void)
{
	CChannels*					pcChannels;
	CChannelsAccessor*			pcAccessor;
	CChannelsAccessorCreator	cCreator;
	short*						psData;
	short						sData[3];
	int							iData;

	pcChannels = UMalloc(CChannels);
	pcChannels->Init();
	pcChannels->BeginChange();
	pcChannels->SetSize(2);
	pcChannels->AddChannel(CHANNEL_NAME_JACK, PT_short);
	pcChannels->AddChannel(CHANNEL_NAME_BOB, PT_int);
	pcChannels->AddChannel(CHANNEL_NAME_ALICE, PT_short);
	pcChannels->EndChange();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_JACK, PT_Undefined);
	cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_Undefined);
	pcAccessor = cCreator.CreateAndKill();
	AssertString("CChannelsAccessorByteAligned", pcAccessor->ClassName());
	sData[0] = 784;
	sData[1] = 602;
	pcAccessor->Set(1, &sData);
	AssertShort(784, *(short*)RemapSinglePointer(pcChannels->GetData(), 8 + 0));
	AssertShort(602, *(short*)RemapSinglePointer(pcChannels->GetData(), 8 + 6));
	psData = (short*)pcAccessor->Get(1);
	AssertShort(784, psData[0]);
	AssertShort(602, psData[1]);
	pcAccessor->Kill();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_BOB, PT_Undefined);
	pcAccessor = cCreator.CreateAndKill();
	iData = 999999;
	pcAccessor->Set(1, &iData);
	pcAccessor->Kill();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_Undefined);
	cCreator.AddAccess(CHANNEL_NAME_BOB, PT_Undefined);
	pcAccessor = cCreator.CreateAndKill();
	AssertString("CChannelsAccessorByteAligned", pcAccessor->ClassName());
	psData = (short*)pcAccessor->Get(1);
	AssertShort(602, psData[0]);
	AssertInt(999999, *(int*)&psData[1]);
	sData[0] = 22172;
	sData[1] = 18432;
	sData[2] = 30812;
	pcAccessor->Set(0, sData);
	AssertInt(2019313664, *(int*)RemapSinglePointer(pcChannels->GetData(), 2));
	AssertShort(22172, *(short*)RemapSinglePointer(pcChannels->GetData(), 6));
	pcAccessor->Kill();
}
Esempio n. 9
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());
}
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 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 TestObjectReaderSimpleDeserialised(void)
{
	WriteObjectReaderSimpleFile();

	CObjectReaderSimpleDisk		cReader;
	CObjectGraphDeserialiser	cGraphDeserialiser;
	CPointer					cBase;

	Ptr<CTestNamedString>		cNS1;
	Ptr<CTestNamedString>		cNS2;
	CPointer					cTemp;

	CObjectAllocator			cAllocator;
	CDependentReadObjects		cDependentReadObjects;

	MemoryInit();
	ObjectsInit();

	gcObjects.AddConstructor<CTestNamedString>();

	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumMemoryIndexes());

	cAllocator.Init(&gcObjects);
	cDependentReadObjects.Init();
	cReader.Init("Output\\ObjectReaderSimple\\Test\\");
	cGraphDeserialiser.Init(&cReader, FALSE, &cAllocator, &cDependentReadObjects, gcObjects.GetMemory());
	cBase = cGraphDeserialiser.Read("Waggy");

	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(2, gcObjects.NumMemoryIndexes());

	cNS1 = gcObjects.Get("Waggy");
	AssertTrue(cNS1.IsNotNull());
	AssertString("NS1", cNS1->mszEmbedded.Text());

	cNS2 = gcObjects.Get("Dog");
	AssertTrue(cNS2.IsNotNull());
	AssertString("NS2", cNS2->mszEmbedded.Text());

	AssertTrue(cBase.IsNotNull());
	AssertString("CTestNamedString", cBase->ClassName());
	AssertPointer(&cNS1, &cBase);

	AssertPointer(&cNS2, &cNS1->mpAnother);
	AssertPointer(NULL, &cNS2->mpAnother);

	cGraphDeserialiser.Kill();
	cDependentReadObjects.Kill();
	cAllocator.Kill();
	cReader.Kill();

	ObjectsKill();
}
void TestStrIStr(void)
{
    char    szFooBar[] = "FooBar";
    char*   sz;

    sz = StrIStr(szFooBar, "bar");
    AssertString("Bar", sz);

	sz = StrIStr(szFooBar, "FOO");
	AssertString("FooBar", sz);
}
Esempio n. 14
0
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();
}
Esempio n. 15
0
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 TestChannelsAccessorTypeConvert(void)
{
	CChannels*					pcChannels;
	CChannelsAccessor*			pcAccessor;
	CChannelsAccessorCreator	cCreator;
	float*						pfData;
	float						afData[3];

	pcChannels = UMalloc(CChannels);
	pcChannels->Init();
	pcChannels->BeginChange();
	pcChannels->SetSize(2);
	pcChannels->AddChannel(CHANNEL_NAME_JACK, PT_ushort);
	pcChannels->AddChannel(CHANNEL_NAME_BOB, PT_uint);
	pcChannels->AddChannel(CHANNEL_NAME_ALICE, PT_ushort);
	pcChannels->EndChange();
	pcChannels->Clear();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_JACK, PT_float);
	cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_float);
	pcAccessor = cCreator.CreateAndKill();
	AssertString("CChannelsAccessorTypeConvert", pcAccessor->ClassName());
	afData[0] = 1.0f;
	afData[1] = 0.34f;
	pcAccessor->Set(1, afData);
	AssertShortHex((short)0xffff, *(unsigned short*)RemapSinglePointer(pcChannels->GetData(), 8 + 0));
	AssertShortHex(0x5709, *(unsigned short*)RemapSinglePointer(pcChannels->GetData(), 8 + 6));
	pfData = (float*)pcAccessor->Get(1);
	AssertFloat(1.0f, pfData[0], 2);
	AssertFloat(0.34f, pfData[1], 2);
	pcAccessor->Kill();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_BOB, PT_float);
	pcAccessor = cCreator.CreateAndKill();
	AssertString("CChannelsAccessorTypeConvert", pcAccessor->ClassName());
	afData[0] = 0.8f;
	pcAccessor->Set(1, afData);
	AssertIntHex(0xcccccd00, *(int*)RemapSinglePointer(pcChannels->GetData(), 8 + 2));
	pcAccessor->Kill();

	cCreator.Init(pcChannels);
	cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_float);
	cCreator.AddAccess(CHANNEL_NAME_BOB, PT_float);
	pcAccessor = cCreator.CreateAndKill();
	AssertString("CChannelsAccessorTypeConvert", pcAccessor->ClassName());
	pfData = (float*)pcAccessor->Get(1);
	AssertFloat(0.34f, pfData[0], 2);
	AssertFloat(0.80f, pfData[1], 2);
	pcAccessor->Kill();
}
Esempio n. 17
0
void TestRemoveExtension(void)
{
	CChars		szFileName;
	CFileUtil	cFileUtil;

	szFileName.Init("/mnt/world/hello.txt");
	cFileUtil.RemoveExtension(&szFileName);
	AssertString("/mnt/world/hello", szFileName.Text());

	cFileUtil.RemoveExtension(&szFileName);
	AssertString("/mnt/world/hello", szFileName.Text());
	szFileName.Kill();
}
Esempio n. 18
0
void TestReadExternalReference(void)
{
	CXMLFile	cXMLFile;
	CChars		szDoc;
	int			iLine;
	char		szExpected[] = "<InputDevices>\n\
  This is text &lt; and doom stuff\n\
  <RootInSecond>\n\
    Hello\n\
  </RootInSecond>\n\
  Sweet &gt; other stuff\n\
  <ThirdsRoot>\n\
    World\n\
  </ThirdsRoot>\n\
</InputDevices>\n";
	CMarkupTag*	pcTag;
	CMarkupTag*	pcSecondTag;
	CMarkupTag*	pcThirdTag;
	CChars		szText;

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

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

	pcTag = cXMLFile.mcMarkup.mpcDoc->GetRootTag();
	pcSecondTag = pcTag->GetTag("RootInSecond");
	AssertNotNull(pcSecondTag);
	szText.Init();
	pcSecondTag->GetText(&szText);
	szText.StripWhiteSpace(TRUE);
	AssertString("Hello", szText.Text());
	szText.Kill();

	pcTag = cXMLFile.mcMarkup.mpcDoc->GetRootTag();
	pcThirdTag = pcTag->GetTag("ThirdsRoot");
	AssertNotNull(pcThirdTag);
	szText.Init();
	pcThirdTag->GetText(&szText);
	szText.StripWhiteSpace(TRUE);
	AssertString("World", szText.Text());
	szText.Kill();

	cXMLFile.Kill();
}
Esempio n. 19
0
void TestIndexTreeBlockMemoryReadWrite(void)
{
	CFileBasic				cFile;
	CIndexTreeBlockMemory	cIndex;
	CIndexTreeBlockMemory	cIndexIn;

	cIndex.Init();
	cIndex.Put("AAA", "DENISA", 7);
	cIndex.Put("AA", "FATJETA", 8);
	cIndex.Put("AAB", "ARIANA", 7);
	cIndex.Put("AAC", "GEORGE", 7);
	cIndex.Put("AB", "IRMA", 5);
	cIndex.Put("ABA", "JULIANA", 8);
	cIndex.Put("ABB", "LULE", 5);
	cIndex.Put("C", "VENERA", 7);
	cIndex.Put("DDDD", "PRANVERA", 9);
	cIndex.Put("DD", "PRIMERA", 8);
	AssertInt(14, cIndex.CountAllocatedNodes());
	AssertInt(10, cIndex.RecurseSize());
	AssertInt(10, cIndex.NumElements());
	AssertInt(4, cIndex.GetLargestKeySize());

	cFile.Init(MemoryFile());
	cFile.Open(EFM_Write_Create);
	AssertTrue(cIndex.Write(&cFile));
	cIndex.Kill();
	cFile.Close();

	cFile.Open(EFM_Read);
	AssertTrue(cIndexIn.Read(&cFile));
	cFile.Close();

	AssertInt(14, cIndexIn.CountAllocatedNodes());
	AssertInt(10, cIndexIn.RecurseSize());
	AssertInt(10, cIndexIn.NumElements());
	AssertInt(4, cIndexIn.GetLargestKeySize());
	AssertString("DENISA", (char*)cIndexIn.Get("AAA"));
	AssertString("FATJETA", (char*)cIndexIn.Get("AA"));
	AssertString("ARIANA", (char*)cIndexIn.Get("AAB"));
	AssertString("GEORGE", (char*)cIndexIn.Get("AAC"));
	AssertString("IRMA", (char*)cIndexIn.Get("AB"));
	AssertString("JULIANA", (char*)cIndexIn.Get("ABA"));
	AssertString("LULE", (char*)cIndexIn.Get("ABB"));
	AssertString("VENERA", (char*)cIndexIn.Get("C"));
	AssertString("PRANVERA", (char*)cIndexIn.Get("DDDD"));
	AssertString("PRIMERA", (char*)cIndexIn.Get("DD"));

	cIndexIn.Kill();
}
void TestStrRev(void)
{
    char    szAndrew[] = "Andrew";
    char    szCat[] = "cat";
    char    szMinus[] = "1-";

    StrRev(szCat);
    AssertString("tac", szCat);

    StrRev(szAndrew);
    AssertString("werdnA", szAndrew);

    StrRev(szMinus);
    AssertString("-1", szMinus);
}
Esempio n. 21
0
void TestReverseBytes(void)
{
	char szAuto[9] = "Autobody";
	char szAutoDash[10] = "Auto-Body";
	char szOne[2] = "1";

	ReverseBytes(szAuto, 8);
	AssertString("ydobotuA", szAuto);
	ReverseBytes(szAutoDash, 9);
	AssertString("ydoB-otuA", szAutoDash);
	ReverseBytes(szOne, 1);
	AssertString("1", szOne);
	ReverseBytes(szOne, 0);
	AssertString("1", szOne);
}
Esempio n. 22
0
void TestUsageNullPointers(void)
{
	ObjectsInit();

	Ptr<CGameWorld>			pWorld;
	CPointer				pNull = ONull;
	Ptr<CPlayerVehicle>		pVehicle = ONull;
	Ptr<CHarrier>			pHarrier;

	pWorld = pNull;
	pWorld->AddTickable(pNull);
	pWorld->AddTickable(pVehicle);
	pWorld->AddTickable(ONull);

	pVehicle = pNull;
	pWorld->AddPlayer(pVehicle);
	pWorld->AddPlayer(pNull);
	pWorld->AddPlayer(ONull);

	pVehicle = pHarrier;

	AssertString("This code must compile", "This code must compile");

	pWorld = pHarrier;  //This probably shouldn't compile but it does because pHarrier (Ptr<CHarrier>) extends CPointer.

	ObjectsKill();
}
Esempio n. 23
0
void TestSetTypeInstantiation(void)
{
	UnknownsInit();

	CSetType<CTestUnknown>	cSet;
	CTestUnknown*			pcTest1;
	CTestUnknown*			pcTest2;
	CTestUnknown*			pcTest;
	int						iSize;
	char*					szName;
	SSetIterator			sIter;
	int						iCount;

	cSet.Init();

	pcTest1 = cSet.Add();
	pcTest1->Init();
	pcTest2 = UMalloc(CTestUnknown);
	pcTest2->Init();
	cSet.Add(pcTest2);

	iCount = 0;
	pcTest = cSet.StartIteration(&sIter);
	while (pcTest)
	{
		iCount++;
		pcTest = cSet.Iterate(&sIter);
	}
	AssertInt(2, iCount);
	AssertInt(2, cSet.NumElements());

	//This test is not correct.  The order is not guaranteed.
	//However it necessary to make the template compile.
	AssertTrue(cSet.Contains(pcTest1));
	AssertTrue(cSet.Contains(pcTest2));

	pcTest = cSet.StartIteration(&sIter);
	AssertPointer(pcTest1, pcTest);
	pcTest = cSet.Iterate(&sIter);
	AssertPointer(pcTest2, pcTest);

	pcTest = cSet.StartIteration(&sIter);
	cSet.RemoveDuringIteration(&sIter);
	pcTest = cSet.Iterate(&sIter);
	AssertPointer(pcTest2, pcTest);

	AssertInt(1, cSet.NumElements());

	cSet.Remove(pcTest2);
	AssertInt(0, cSet.NumElements());

	iSize = cSet.ClassSize();
	AssertInt(40, iSize);

	szName = cSet.ClassName();
	AssertString("CSetType", szName);

	cSet.Kill();
	UnknownsKill();
}
Esempio n. 24
0
void TestMapBlockRemove(void)
{
	CMapBlock	cMapBlock;
	int			ia = 'a';
	int			ib = 'b';
	int			ic = 'c';
	BOOL		bResult;
	char*		szData;

	cMapBlock.Init(1024, &CompareInt, TRUE);
	bResult = cMapBlock.Put(&ia, sizeof(int), "Hello", strlen("Hello") + 1);
	bResult = cMapBlock.Put(&ib, sizeof(int), "World", strlen("World") + 1);
	bResult = cMapBlock.Put(&ic, sizeof(int), "Rogue", strlen("Rogue") + 1);
	AssertInt(3, cMapBlock.NumElements());

	cMapBlock.Remove(&ib);
	AssertInt(2, cMapBlock.NumElements());
	bResult = cMapBlock.Get(&ia, (void**)&szData, NULL);
	AssertTrue(bResult);
	AssertString(szData, "Hello");
	bResult = cMapBlock.Get(&ic, (void**)&szData, NULL);
	AssertTrue(bResult);
	AssertString(szData, "Rogue");
	bResult = cMapBlock.Get(&ib, (void**)&szData, NULL);
	AssertFalse(bResult);

	cMapBlock.Remove(&ia);
	AssertInt(1, cMapBlock.NumElements());
	bResult = cMapBlock.Get(&ia, (void**)&szData, NULL);
	AssertFalse(bResult);
	bResult = cMapBlock.Get(&ic, (void**)&szData, NULL);
	AssertTrue(bResult);
	AssertString(szData, "Rogue");
	bResult = cMapBlock.Get(&ib, (void**)&szData, NULL);
	AssertFalse(bResult);

	cMapBlock.Remove(&ic);
	AssertInt(0, cMapBlock.NumElements());
	bResult = cMapBlock.Get(&ia, (void**)&szData, NULL);
	AssertFalse(bResult);
	bResult = cMapBlock.Get(&ic, (void**)&szData, NULL);
	AssertFalse(bResult);
	bResult = cMapBlock.Get(&ib, (void**)&szData, NULL);
	AssertFalse(bResult);

	cMapBlock.Kill();
}
Esempio n. 25
0
void TestUsageDefaultPointer(void)
{
	Ptr<CBaseObject>	pBase;
	Ptr<>				pDefault;
	CPointer			pObject;

	AssertString("This code must compile", "This code must compile");
}
void TestToLower(void)
{
	char	szTest[] = "In The Age of C:\\ to Fractions %^&222";
	char	szExpected[] = "in the age of c:\\ to fractions %^&222";

	ToLower(szTest);
	AssertString(szExpected, szTest);
}
void TestToUpper(void)
{
	char	szTest[] = "In The Age of C:\\ to Fractions %^&222";
	char	szExpected[] = "IN THE AGE OF C:\\ TO FRACTIONS %^&222";

	ToUpper(szTest);
	AssertString(szExpected, szTest);
}
Esempio n. 28
0
void TestFileUtilNaming(void)
{
	CFileUtil	cFileUtil;
	CChars		sz;
	CChars		szExpected;

	sz.Init();
	cFileUtil.FullPath(&sz);
	sz.LowerCase();
	szExpected.Init("C:\\GameEngine\\Test\\TestBaseLib\\TestBaseLib");
	szExpected.LowerCase();
	AssertString(szExpected.Text(), sz.Text());
	szExpected.Kill();
	sz.Kill();

	sz.Init("c:\\Documents and Settings\\Joe\\..\\..\\");
	cFileUtil.CollapsePath(&sz);
	AssertStringCase("C:\\", sz.Text(), FALSE);
	sz.Kill();

	sz.Init("\\Documents\\and\\Settings\\..\\..\\Joe");
	cFileUtil.CollapsePath(&sz);
	AssertString("\\Documents\\Joe", sz.Text());
	sz.Kill();

	sz.Init("\\Documents\\and\\Settings\\..\\..\\Joe\\");
	cFileUtil.CollapsePath(&sz);
	AssertString("\\Documents\\Joe", sz.Text());
	sz.Kill();

	sz.Init(".\\.\\.\\.");
	cFileUtil.CollapsePath(&sz);
	AssertString("", sz.Text());
	sz.Kill();

	sz.Init(".\\.\\.\\");
	cFileUtil.CollapsePath(&sz);
	AssertString("", sz.Text());
	sz.Kill();

	sz.Init("c:\\..");
	cFileUtil.CollapsePath(&sz);
	AssertString("c:", sz.Text());
	sz.Kill();

	sz.Init("c:\\..\\..");
	cFileUtil.CollapsePath(&sz);
	AssertString("c:", sz.Text());
	sz.Kill();

	sz.Init("\\..\\..");
	cFileUtil.CollapsePath(&sz);
	AssertString("", sz.Text());
	sz.Kill();
}
void TestIToA(void)
{
    char    sz[256];

    IToA(7, sz, 10);
    AssertString("7", sz);

    IToA(456, sz, 10);
    AssertString("456", sz);

    IToA(12, sz, 10);
    AssertString("12", sz);

    IToA(-1, sz, 10);
    AssertString("-1", sz);

    IToA(-32456, sz, 10);
    AssertString("-32456", sz);
}
Esempio n. 30
0
void TestMakeNameFromDirectory(void)
{
	CFileUtil	cFileUtil;
	CChars		szName;
	CChars		szDirectory;
	CChars		szFileName;

	szDirectory.Init("c:"_FS_"Some"_FS_"Directory"_FS_"Or"_FS_"Other"_FS_);
	szFileName.Init("c:"_FS_"Some"_FS_"Directory"_FS_"Or"_FS_"Other"_FS_"More"_FS_"Dir"_FS_"FileName.txt");
	cFileUtil.MakeNameFromDirectory(&szName, &szFileName, &szDirectory);

	AssertString("More/Dir/FileName.txt", szName.Text());
	szName.Kill();

	cFileUtil.MakeNameFromDirectory(&szName, &szDirectory, &szDirectory);

	AssertString("", szName.Text());
	szName.Kill();

	szDirectory.Kill();
	szFileName.Kill();
}