void TestMapStringUnknownLoad(void) { MemoryInit(); UnknownsInit(); CMapStringUnknown cMap; CTestUnknownJobbie* pcTest; CChunkFile cFile; CFileUtil cFileUtil; BOOL bResult; gcUnknowns.AddConstructor<CTestUnknownJobbie>(); AssertInt(0, gcUnknowns.NumElements()); cFileUtil.RemoveDir("MapStringUnknown"); cFileUtil.MakeDir("MapStringUnknown"); cMap.Init(); pcTest = cMap.Put<CTestUnknownJobbie>("Hello"); pcTest->Init(7, "1st"); pcTest = cMap.Put<CTestUnknownJobbie>("World"); pcTest->Init(19, "A pony"); pcTest = cMap.Put<CTestUnknownJobbie>("Aardvark"); pcTest->Init(4, "Restore"); pcTest = cMap.Put<CTestUnknownJobbie>("Yurk"); pcTest->Init(8, "Yurk"); cFile.Init(DiskFile("MapStringUnknown/Map.dat")); bResult = cFile.WriteOpen(); AssertTrue(bResult); bResult = cMap.Save(&cFile); AssertTrue(bResult); bResult = cFile.WriteClose(); AssertTrue(bResult); cFile.Kill(); cMap.Kill(); AssertInt(0, gcUnknowns.NumElements()); cFile.Init(DiskFile("MapStringUnknown/Map.dat")); bResult = cFile.ReadOpen(); AssertTrue(bResult); bResult = cMap.Load(&cFile); AssertTrue(bResult); bResult = cFile.ReadClose(); AssertTrue(bResult); cFile.Kill(); AssertInt(4, cMap.NumElements()); AssertInt(4, gcUnknowns.NumElements()); pcTest = (CTestUnknownJobbie*)cMap.Get("Hello"); AssertInt(7, pcTest->miANumber); AssertString("1st", pcTest->mszText.Text()); pcTest = (CTestUnknownJobbie*)cMap.Get("World"); AssertInt(19, pcTest->miANumber); AssertString("A pony", pcTest->mszText.Text()); pcTest = (CTestUnknownJobbie*)cMap.Get("Aardvark"); AssertInt(4, pcTest->miANumber); AssertString("Restore", pcTest->mszText.Text()); pcTest = (CTestUnknownJobbie*)cMap.Get("Yurk"); AssertInt(8, pcTest->miANumber); AssertString("Yurk", pcTest->mszText.Text()); cMap.Kill(); AssertInt(0, gcUnknowns.NumElements()); cFileUtil.RemoveDir("MapStringUnknown"); UnknownsKill(); MemoryKill(); }
void TestChannelsAccessorChannelBitty(void) { CChannels* pcChannels; CChannelsAccessor* pcAccessor; CChannelsAccessorCreator cCreator; unsigned char* pucData; unsigned char aucData[3]; float* pfData; pcChannels = UMalloc(CChannels); pcChannels->Init(); pcChannels->BeginChange(); pcChannels->SetSize(1); pcChannels->AddChannel(CHANNEL_NAME_JACK, PT_bit); pcChannels->AddChannel(CHANNEL_NAME_BOB, PT_crumb); pcChannels->AddChannel(CHANNEL_NAME_ALICE, PT_bit); pcChannels->EndChange(); pcChannels->Clear(); AssertInt(1, pcChannels->GetByteSize()); AssertInt(1, pcChannels->GetSize()); cCreator.Init(pcChannels); cCreator.AddAccess(CHANNEL_NAME_JACK, PT_uchar); cCreator.AddAccess(CHANNEL_NAME_BOB, PT_uchar); cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_uchar); pcAccessor = cCreator.CreateAndKill(); AssertString("CChannelsAccessorChannelBitty", pcAccessor->ClassName()); aucData[0] = 0xff; aucData[1] = 0x55; aucData[2] = 0xff; pcAccessor->Set(0, aucData); AssertChar(0xb, *pcChannels->GetData()); //Or maybe 0xd. I'm not sure of the ordering pucData = (unsigned char*)pcAccessor->Get(0); AssertChar((char)0xff, pucData[0]); AssertChar((char)0x55, pucData[1]); AssertChar((char)0xff, pucData[2]); pcAccessor->Kill(); pcChannels->BeginChange(); pcChannels->SetSize(2); pcChannels->EndChange(); AssertInt(1, pcChannels->GetByteSize()); AssertInt(2, pcChannels->GetSize()); cCreator.Init(pcChannels); cCreator.AddAccess(CHANNEL_NAME_JACK, PT_uchar); cCreator.AddAccess(CHANNEL_NAME_BOB, PT_uchar); cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_uchar); pcAccessor = cCreator.CreateAndKill(); AssertString("CChannelsAccessorChannelBitty", pcAccessor->ClassName()); pucData = (unsigned char*)pcAccessor->Get(0); AssertChar((char)0xff, pucData[0]); AssertChar((char)0x55, pucData[1]); AssertChar((char)0xff, pucData[2]); aucData[0] = 0x00; aucData[1] = 0xaa; aucData[2] = 0xff; pcAccessor->Set(1, aucData); AssertChar(0xc, ((unsigned char)*pcChannels->GetData()) >> 4); //Or maybe 0xd. I'm not sure of the ordering pucData = (unsigned char*)pcAccessor->Get(1); AssertChar((char)0x00, pucData[0]); AssertChar((char)0xaa, pucData[1]); AssertChar((char)0xff, pucData[2]); pcAccessor->Kill(); cCreator.Init(pcChannels); cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_float); cCreator.AddAccess(CHANNEL_NAME_BOB, PT_float); pcAccessor = cCreator.CreateAndKill(); AssertString("CChannelsAccessorChannelBitty", pcAccessor->ClassName()); pfData = (float*)pcAccessor->Get(0); AssertFloat(1.0f, pfData[0], 2); AssertFloat(0.33f, pfData[1], 2); pfData = (float*)pcAccessor->Get(1); AssertFloat(1.0f, pfData[0], 2); AssertFloat(0.67f, pfData[1], 2); pcAccessor->Kill(); }
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 TestArrayIntAddFind(void) { CArrayInt cArray; cArray.Init(1); cArray.AddList(-1, 1, 2, 3, 4, -1); cArray.AddIfUnique(5); AssertInt(5, cArray.NumElements()); AssertInt(1, cArray[0]); AssertInt(2, cArray[1]); AssertInt(3, cArray[2]); AssertInt(4, cArray[3]); AssertInt(5, cArray[4]); cArray.AddIfUnique(5); AssertInt(5, cArray.NumElements()); AssertInt(1, cArray[0]); AssertInt(2, cArray[1]); AssertInt(3, cArray[2]); AssertInt(4, cArray[3]); AssertInt(5, cArray[4]); cArray.InsertIntoSorted(2, FALSE); AssertInt(6, cArray.NumElements()); AssertInt(1, cArray[0]); AssertInt(2, cArray[1]); AssertInt(2, cArray[2]); AssertInt(3, cArray[3]); AssertInt(4, cArray[4]); AssertInt(5, cArray[5]); cArray.Kill(); }
void TestObjectReaderChunkedDeserialised(void) { CObjectReaderChunkFileDisk cReader; CObjectGraphDeserialiser cGraphDeserialiser; CPointer cBase; Ptr<CTestWithArray> cA1; Ptr<CTestWithArray> cA2; Ptr<CTestNamedString> cNS1; Ptr<CTestNamedString> cNS2; Ptr<CTestNamedString> cNS3; Ptr<CTestNamedString> cNS4; Ptr<CString> sz1; Ptr<CString> sz2; Ptr<CString> sz3; CPointer cTemp; Ptr<CTestInteger> cI1; Ptr<CTestInteger> cI2; Ptr<CTestInteger> cI3; CObjectAllocator cAllocator; CDependentReadObjects cDependentReadObjects; OIndex oiI1; OIndex oiI2; OIndex oiI3; int iNumMemoryIndexes; gcObjects.AddConstructor<CTestWithArray>(); gcObjects.AddConstructor<CTestInteger>(); gcObjects.AddConstructor<CTestNamedString>(); gcObjects.AddConstructor<CString>(); gcObjects.AddConstructor<CArrayObject>(); iNumMemoryIndexes = WriteObjectReaderChunkedFile(); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(14, iNumMemoryIndexes); ObjectsKill(); ObjectsInit(); gcObjects.AddConstructor<CTestWithArray>(); gcObjects.AddConstructor<CTestInteger>(); gcObjects.AddConstructor<CTestNamedString>(); gcObjects.AddConstructor<CString>(); gcObjects.AddConstructor<CArrayObject>(); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(0, gcObjects.NumMemoryIndexes()); cAllocator.Init(&gcObjects); cDependentReadObjects.Init(); cReader.Init("Output\\ObjectReaderChunked\\Test\\", "Reader"); cGraphDeserialiser.Init(&cReader, FALSE, &cAllocator, &cDependentReadObjects, gcObjects.GetMemory()); cBase = cGraphDeserialiser.Read("Array 1"); AssertTrue(cBase.IsNotNull()); AssertString("CTestWithArray", cBase.ClassName()); AssertLongLongInt(0, gcObjects.NumDatabaseObjects()); AssertLongLongInt(14, gcObjects.NumMemoryIndexes()); cA1 = gcObjects.Get("Array 1"); AssertTrue(cA1.IsNotNull()); AssertString("CTestWithArray", cA1->ClassName()); AssertString("Something with One", cA1->mszString.Text()); AssertInt(1, cA1->mx); AssertPointer(cBase.Object(), cA1.Object()); cA2 = gcObjects.Get("Array X"); AssertTrue(cA2.IsNotNull()); AssertString("CTestWithArray", cA2.ClassName()); AssertString("An with 2", cA2->mszString.Text()); AssertInt(2, cA2->mx); cNS1 = gcObjects.Get("NamedString 1"); AssertTrue(cNS1.IsNotNull()); AssertString("CTestNamedString", cNS1->ClassName()); AssertString("In Named 1", cNS1->mszEmbedded.Text()); cNS2 = gcObjects.Get("NamedString 2"); AssertTrue(cNS2.IsNotNull()); AssertString("CTestNamedString", cNS2->ClassName()); AssertString("Another in 2", cNS2->mszEmbedded.Text()); cNS3 = gcObjects.Get("NamedString 3"); AssertTrue(cNS3.IsNotNull()); AssertString("CTestNamedString", cNS3->ClassName()); AssertString("Three", cNS3->mszEmbedded.Text()); cNS4 = gcObjects.Get("NamedString 4"); AssertTrue(cNS4.IsNotNull()); AssertTrue(cBase.IsNotNull()); AssertString("CTestWithArray", cBase->ClassName()); AssertPointer(&cA1, &cBase); AssertNotNull(&cA1->mcArray); AssertInt(6, cA1->mcArray->NumElements()) sz2 = cA1->mcArray->Get(0); AssertString("Ye!", sz2->Text()); cTemp = cA1->mcArray->Get(1); AssertPointer(&cNS1, &cTemp); oiI1 = cGraphDeserialiser.GetNewIndexFromOld(5LL); oiI2 = cGraphDeserialiser.GetNewIndexFromOld(6LL); oiI3 = cGraphDeserialiser.GetNewIndexFromOld(7LL); cI1 = gcObjects.Get(oiI1); AssertString("CTestInteger", cI1->ClassName()); cI2 = gcObjects.Get(oiI2); AssertString("CTestInteger", cI2->ClassName()); cI3 = gcObjects.Get(oiI3); AssertString("CTestInteger", cI3->ClassName()); AssertInt(3, cI1->mx); AssertInt(2, cI1->my); AssertInt(1, cI1->mz); AssertPointer(&cNS2, &cNS1->mpAnother); AssertPointer(&cI1, &cA1->mcArray->Get(2)); AssertPointer(&cNS3, &cA1->mcArray->Get(3)); AssertPointer(&cNS1, &cNS3->mpAnother); AssertPointer(&cI2, &cA1->mcArray->Get(4)); AssertPointer(&cA2, &cA1->mcArray->Get(5)); AssertNotNull(&cA2->mcArray); AssertInt(4, cA2->mcArray->NumElements()); AssertPointer(&cI3, &cA2->mcArray->Get(0)); AssertPointer(&cNS2, &cA2->mcArray->Get(1)); AssertPointer(&cNS3, &cNS2->mpAnother); AssertPointer(&cI1, &cA2->mcArray->Get(2)); AssertPointer(&cNS4, &cA2->mcArray->Get(3)); AssertPointer(NULL, &cNS4->mpAnother); AssertPointer(NULL, &cNS4->mszString); cGraphDeserialiser.Kill(); cDependentReadObjects.Kill(); cAllocator.Kill(); cReader.Kill(); }
void TestArrayEmbeddedRemoveAt(void) { CArrayEmbedded<int, 5> cArray; int* piEmbeddedData; int* pi; int i; cArray.Init(); piEmbeddedData = cArray.GetData(); cArray.GrowByNumElements(6); AssertFalse(piEmbeddedData == cArray.GetData()); AssertInt(6, cArray.NumElements()); *cArray.Get(0) = 7; *cArray.Get(1) = 6; *cArray.Get(2) = 5; *cArray.Get(3) = 4; *cArray.Get(4) = 22; *cArray.Get(5) = 20; 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)); cArray.GrowToNumElements(5); AssertPointer(piEmbeddedData, cArray.GetData()); AssertInt(5, cArray.NumElements()); 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)); pi = cArray.Add(); *pi = 20; AssertInt(6, cArray.NumElements()); AssertFalse(piEmbeddedData == cArray.GetData()); cArray.RemoveAt(2); AssertPointer(piEmbeddedData, cArray.GetData()); AssertInt(5, cArray.NumElements()); AssertInt(7, *cArray.Get(0)); AssertInt(6, *cArray.Get(1)); AssertInt(4, *cArray.Get(2)); AssertInt(22, *cArray.Get(3)); AssertInt(20, *cArray.Get(4)); cArray.RemoveAt(3); AssertPointer(piEmbeddedData, cArray.GetData()); AssertInt(4, cArray.NumElements()); AssertInt(7, *cArray.Get(0)); AssertInt(6, *cArray.Get(1)); AssertInt(4, *cArray.Get(2)); AssertInt(20, *cArray.Get(3)); i = 8; cArray.InsertAt(&i, 4); AssertInt(5, cArray.NumElements()); AssertInt(8, *cArray.Get(4)); i = 9; cArray.InsertAt(&i, 5); AssertFalse(piEmbeddedData == cArray.GetData()); AssertInt(6, cArray.NumElements()); AssertInt(8, *cArray.Get(4)); AssertInt(9, *cArray.Get(5)); cArray.RemoveAt(5); AssertPointer(piEmbeddedData, cArray.GetData()); AssertInt(5, cArray.NumElements()); AssertInt(7, *cArray.Get(0)); AssertInt(6, *cArray.Get(1)); AssertInt(4, *cArray.Get(2)); AssertInt(20, *cArray.Get(3)); AssertInt(8, *cArray.Get(4)); }
void TestArrayIntRemoveAt(void) { CArrayInt cArray; CArrayInt cKiller; //////////////////////////////////////////////// cArray.Init(1); // 0 1 2 3 4 5 6 7 8 9 Stop cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1); AssertInt(10, cArray.NumElements()); cKiller.Init(1); cKiller.AddList(-1, 8, 5, 0, 5, -1); cKiller.MakeUnique(); cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements()); AssertInt(7, cArray.NumElements()); AssertInt(3, cArray[0]); AssertInt(7, cArray[1]); AssertInt(8, cArray[2]); AssertInt(1, cArray[3]); AssertInt(0, cArray[4]); AssertInt(2, cArray[5]); AssertInt(2, cArray[6]); cKiller.Kill(); cArray.Kill(); //////////////////////////////////////////////// cArray.Init(1); // 0 1 2 3 4 5 6 7 8 9 Stop cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1); AssertInt(10, cArray.NumElements()); cKiller.Init(1); cKiller.AddList(-1, 8, 5, 2, -1); cKiller.MakeUnique(); cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements()); AssertInt(7, cArray.NumElements()); AssertInt(4, cArray[0]); AssertInt(3, cArray[1]); AssertInt(8, cArray[2]); AssertInt(1, cArray[3]); AssertInt(0, cArray[4]); AssertInt(2, cArray[5]); AssertInt(2, cArray[6]); cKiller.Kill(); cArray.Kill(); //////////////////////////////////////////////// cArray.Init(1); // 0 1 2 3 4 5 6 7 8 9 Stop cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1); AssertInt(10, cArray.NumElements()); cKiller.Init(1); cKiller.AddList(-1, 0, 1, 2, 7, 8, 9, -1); cKiller.MakeUnique(); cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements()); AssertInt(4, cArray.NumElements()); AssertInt(8, cArray[0]); AssertInt(1, cArray[1]); AssertInt(9, cArray[2]); AssertInt(0, cArray[3]); cKiller.Kill(); cArray.Kill(); //////////////////////////////////////////////// cArray.Init(1); // 0 1 2 3 4 5 6 7 8 9 Stop cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1); AssertInt(10, cArray.NumElements()); cKiller.Init(1); cKiller.AddList(-1, 3, 4, 5, 6, -1); cKiller.MakeUnique(); cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements()); AssertInt(6, cArray.NumElements()); AssertInt(4, cArray[0]); AssertInt(3, cArray[1]); AssertInt(7, cArray[2]); AssertInt(2, cArray[3]); AssertInt(4, cArray[4]); AssertInt(2, cArray[5]); cKiller.Kill(); cArray.Kill(); //////////////////////////////////////////////// cArray.Init(1); // 0 1 2 3 4 5 6 7 8 9 Stop cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1); cKiller.Init(1); cKiller.AddList(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1); cKiller.MakeUnique(); cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements()); AssertInt(0, cArray.NumElements()); cKiller.Kill(); cArray.Kill(); //////////////////////////////////////////////// cArray.Init(1); // 0 1 2 3 4 5 6 7 8 9 Stop cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1); cKiller.Init(1); cKiller.AddList(-1, -1); cKiller.MakeUnique(); cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements()); AssertInt(10, cArray.NumElements()); AssertInt(4, cArray[0]); AssertInt(3, cArray[1]); AssertInt(7, cArray[2]); AssertInt(8, cArray[3]); AssertInt(1, cArray[4]); AssertInt(9, cArray[5]); AssertInt(0, cArray[6]); AssertInt(2, cArray[7]); AssertInt(4, cArray[8]); AssertInt(2, cArray[9]); cKiller.Kill(); cArray.Kill(); //////////////////////////////////////////////// cArray.Init(1); // 0 1 2 3 4 5 6 7 8 9 Stop cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1); cKiller.Init(1); cKiller.AddList(-1, 0, 2, 4, 6, 8, -1); cKiller.MakeUnique(); cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements()); AssertInt(5, cArray.NumElements()); AssertInt(3, cArray[0]); AssertInt(8, cArray[1]); AssertInt(9, cArray[2]); AssertInt(2, cArray[3]); AssertInt(2, cArray[4]); cKiller.Kill(); cArray.Kill(); //////////////////////////////////////////////// cArray.Init(1); // 0 1 2 3 4 5 6 7 8 9 Stop cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1); cKiller.Init(1); cKiller.AddList(-1, 1, 3, 5, 7, 9, -1); cKiller.MakeUnique(); cArray.RemoveAt(cKiller.GetData(), cKiller.NumElements()); AssertInt(5, cArray.NumElements()); AssertInt(4, cArray[0]); AssertInt(7, cArray[1]); AssertInt(1, cArray[2]); AssertInt(0, cArray[3]); AssertInt(4, cArray[4]); cKiller.Kill(); cArray.Kill(); }
void TestMisc(void) { CTestArray cArray; STestArrayTemplateItem sStack; int iIndex; STestArrayTemplateItem* psHeap; STestArrayTemplateItem* psReturn; cArray.Init(5); iIndex = cArray.GetIndex(&sStack); AssertInt(-1, iIndex); psHeap = cArray.Add(); psHeap->i1 = 0; psHeap->i2 = 1; sStack.i2 = 7; sStack.i1 = 8; cArray.InsertAt(&sStack, 0); AssertInt(2, cArray.NumElements()); psReturn = cArray.Get(0); AssertInt(8, psReturn->i1); AssertInt(7, psReturn->i2); psReturn = cArray.Get(1); AssertInt(0, psReturn->i1); AssertInt(1, psReturn->i2); cArray.RemoveAt(0, TRUE); AssertInt(1, cArray.NumElements()); psReturn = cArray.Get(0); AssertInt(0, psReturn->i1); AssertInt(1, psReturn->i2); cArray.PushCopy(); AssertInt(2, cArray.NumElements()); psReturn = cArray.Get(0); AssertInt(0, psReturn->i1); AssertInt(1, psReturn->i2); psReturn = cArray.Get(1); AssertInt(0, psReturn->i1); AssertInt(1, psReturn->i2); cArray.RemoveAt(1); cArray.Pop(&sStack); AssertInt(0, sStack.i1); AssertInt(1, sStack.i2); cArray.Kill(); cArray.Init(1); psReturn = cArray.Add(); psReturn->i1 = 1; psReturn->i2 = 2; psReturn = cArray.Add(); psReturn->i1 = 3; psReturn->i2 = 4; psReturn = cArray.Add(); psReturn->i1 = 5; psReturn->i2 = 6; iIndex = cArray.FindWithIntKey(5); AssertInt(2, iIndex); iIndex = cArray.FindWithIntKey(6, sizeof(int)); AssertInt(2, iIndex); iIndex = cArray.FindWithKey(psReturn, 0, sizeof(int)); AssertInt(2, iIndex); iIndex = cArray.FindWithKey(psReturn, 4, sizeof(int)); AssertInt(2, iIndex); cArray.Swap(1, 2); psReturn = cArray.Get(1); AssertInt(5, psReturn->i1); AssertInt(6, psReturn->i2); psReturn = cArray.Get(2); AssertInt(3, psReturn->i1); AssertInt(4, psReturn->i2); }
void TestArrayRemove(void) { CTestArray cArray; STestArrayTemplateItem* psTest1; STestArrayTemplateItem* psTest2; cArray.Init(1); psTest1 = cArray.Add(); psTest1->i1 = 0; psTest1->i2 = 0; cArray.RemoveAt(0, TRUE); AssertInt(0, cArray.NumElements()); cArray.Kill(); cArray.Init(1); psTest1 = cArray.Add(); psTest2 = cArray.Add(); psTest1->i1 = 0; psTest1->i2 = 0; psTest2->i1 = 1; psTest2->i2 = 1; cArray.RemoveAt(0, TRUE); psTest1 = cArray.Get(0); AssertInt(1, psTest1->i1); AssertInt(1, cArray.NumElements()); cArray.Kill(); cArray.Init(1); psTest1 = cArray.Add(); psTest1->i1 = 0; psTest1->i2 = 0; psTest2 = cArray.Add(); psTest2->i1 = 1; psTest2->i2 = 1; psTest1 = cArray.Get(0); AssertInt(0, psTest1->i1); psTest2 = cArray.Get(1); AssertInt(1, psTest2->i1); cArray.RemoveAt(1, TRUE); psTest1 = cArray.Get(0); AssertInt(0, psTest1->i1); AssertInt(1, cArray.NumElements()); cArray.Kill(); cArray.Init(1); psTest1 = cArray.Add(); psTest1->i1 = 0; psTest1->i2 = 0; psTest2 = cArray.Add(); psTest2->i1 = 1; psTest2->i2 = 1; cArray.RemoveAt(0, FALSE); psTest1 = cArray.Get(0); AssertInt(1, psTest1->i1); AssertInt(1, cArray.NumElements()); cArray.Kill(); cArray.Init(1); psTest1 = cArray.Add(); psTest1->i1 = 0; psTest1->i2 = 0; psTest2 = cArray.Add(); psTest2->i1 = 1; psTest2->i2 = 1; cArray.RemoveAt(1, FALSE); psTest1 = cArray.Get(0); AssertInt(0, psTest1->i1); AssertInt(1, cArray.NumElements()); cArray.Kill(); }
void TestEmbeddedObjectContainerDehollowfication(void) { BOOL bResult; CFileUtil cFileUtil; char* szClassName; OIndex oiComplex; cFileUtil.RemoveDir("Output/EmbeddedObject"); MemoryInit(); ObjectsInit("Output/EmbeddedObject/"); SetupEmbeddedObjectConstructors(); Ptr<CRoot> pRoot = ORoot(); Ptr<CEmbeddedComplex> pComplex = OMalloc(CEmbeddedComplex)->Init(); oiComplex = pComplex->GetOI(); pRoot->Add(pComplex); bResult = gcObjects.Flush(TRUE, TRUE); AssertTrue(bResult); ObjectsKill(); MemoryKill(); AssertInt(176, sizeof(CEmbeddedTest)); AssertInt(544, sizeof(CEmbeddedContainer)); AssertInt(1032, sizeof(CEmbeddedComplex)); MemoryInit(); ObjectsInit("Output/EmbeddedObject/"); SetupEmbeddedObjectConstructors(); pRoot = gcObjects.GetRoot(); AssertTrue(pRoot.IsNotNull()); pComplex = pRoot->Get(0); AssertTrue(pComplex.IsHollow()); szClassName = pComplex->ClassName(); AssertString("CEmbeddedComplex", szClassName); AssertLongLongInt(oiComplex, pComplex.GetIndex()); AssertInt(1, pComplex->mai[0]); AssertInt(2, pComplex->mai[1]); AssertLongLongInt(INVALID_O_INDEX, pComplex->mcSimple.GetOI()); AssertInt(85, pComplex->mcSimple.miAmANumber); AssertFloat(58.0f, pComplex->mcSimple.mfSoAmI, 0); AssertLongLongInt(INVALID_O_INDEX, pComplex->mcContainer.GetOI()); AssertInt(73, pComplex->mcContainer.mi); AssertFloat(666.0f, pComplex->mcContainer.mf, 0); AssertString("And", pComplex->mcContainer.msz); AssertLongLongInt(INVALID_O_INDEX, pComplex->mcContainer.mcOne.GetOI()); AssertInt(85, pComplex->mcContainer.mcOne.miAmANumber); AssertFloat(58.0f, pComplex->mcContainer.mcOne.mfSoAmI, 0); AssertLongLongInt(INVALID_O_INDEX, pComplex->mcContainer.mcTwo.GetOI()); AssertInt(85, pComplex->mcContainer.mcTwo.miAmANumber); AssertFloat(58.0f, pComplex->mcContainer.mcTwo.mfSoAmI, 0); AssertLongLongInt(3, gcObjects.NumMemoryIndexes()); ObjectsKill(); MemoryKill(); }
void TestEmbeddedGetEmbeddedIndex(void) { MemoryInit(); ObjectsInit(); CEmbeddedComplex cComplex; cComplex.Class(); cComplex.Init(); AssertInt(0, cComplex.TestGetNumEmbeddedFromFlags()); AssertInt(6, cComplex.GetNumEmbedded()); AssertInt(6, cComplex.TestGetNumEmbeddedFromFlags()); AssertInt(1, cComplex.mcSimple.GetNumEmbedded()); AssertInt(1, cComplex.ma.GetNumEmbedded()); AssertInt(3, cComplex.mcContainer.GetNumEmbedded()); AssertInt(1, cComplex.mcContainer.mcOne.GetNumEmbedded()); AssertInt(1, cComplex.mcContainer.mcOne.GetNumEmbedded()); AssertInt(0, cComplex.GetEmbeddedIndex(&cComplex)); AssertInt(1, cComplex.GetEmbeddedIndex(&cComplex.mcSimple)); AssertInt(2, cComplex.GetEmbeddedIndex(&cComplex.ma)); AssertInt(3, cComplex.GetEmbeddedIndex(&cComplex.mcContainer)); AssertInt(4, cComplex.GetEmbeddedIndex(&cComplex.mcContainer.mcOne)); AssertInt(5, cComplex.GetEmbeddedIndex(&cComplex.mcContainer.mcTwo)); AssertInt(-1, cComplex.GetEmbeddedIndex(NULL)); ObjectsKill(); MemoryKill(); }
void TestEmbeddedObjectKill(void) { char szClusterMissileState[64]; char szMissile1State[64]; ObjectsInit(); Ptr<CRoot> pRoot = ORoot(); Ptr<CGameWorld> pWorld = OMalloc(CGameWorld)->Init(); pRoot->Add(pWorld); Ptr<CClusterMissile> pClusterMissile = ONMalloc(CClusterMissile, "Anna")->Init(pWorld); pWorld = NULL; Ptr<CPointerContainer> pPointerPointer = OMalloc(CPointerContainer); pRoot->Add(pPointerPointer); pPointerPointer->Init(&pClusterMissile->mcMissile1); Ptr<CPointerContainer> pPointerPointer2 = OMalloc(CPointerContainer); pRoot->Add(pPointerPointer2); pPointerPointer2->Init(&pClusterMissile); //The number of allocated object shouldn't change until all the froms are removed //both from the embedded object and the 'normal' object. AssertLongLongInt(7, gcObjects.GetMemory()->NumIndexed()); AssertLongLongInt(7, gcUnknowns.NumElements()); pClusterMissile->SetKillString(szClusterMissileState); pClusterMissile->mcMissile1.SetKillString(szMissile1State); AssertInt(2, pClusterMissile->NumHeapFroms()); AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms()); AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms()); strcpy(szClusterMissileState, "Alive"); strcpy(szMissile1State, "Alive"); pPointerPointer->Clear(); AssertInt(1, pClusterMissile->NumHeapFroms()); AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms()); AssertInt(0, pClusterMissile->mcMissile1.NumHeapFroms()); AssertString("Alive", szClusterMissileState); AssertString("Alive", szMissile1State); pPointerPointer->mp = &pClusterMissile->mcMissile1; AssertInt(2, pClusterMissile->NumHeapFroms()); AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms()); AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms()); pPointerPointer2->Clear(); AssertInt(1, pClusterMissile->NumHeapFroms()); AssertInt(0, pClusterMissile->CEmbeddedObject::NumHeapFroms()); AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms()); AssertString("Alive", szClusterMissileState); AssertString("Alive", szMissile1State); pClusterMissile = NULL; //Make sure nothing has been de-allocated. AssertLongLongInt(7, gcObjects.GetMemory()->NumIndexed()); AssertLongLongInt(7, gcUnknowns.NumElements()); pPointerPointer->Clear(); AssertString("Killed", szClusterMissileState); AssertString("Killed", szMissile1State); AssertLongLongInt(6, gcObjects.GetMemory()->NumIndexed()); AssertLongLongInt(6, gcUnknowns.NumElements()); gcObjects.Flush(TRUE, FALSE); AssertLongLongInt(0, gcObjects.GetMemory()->NumIndexed()); AssertLongLongInt(0, gcUnknowns.NumElements()); ObjectsKill(); }
void TestEmbeddedObjectRemoveDistToRoot(void) { ObjectsInit(); Ptr<CRoot> pRoot = ORoot(); Ptr<CGameWorld> pWorld = OMalloc(CGameWorld)->Init(); pRoot->Add(pWorld); Ptr<CClusterMissile> pMissile = ONMalloc(CClusterMissile, "Frank")->Init(pWorld); Ptr<CHarrier> pHarrier = OMalloc(CHarrier)->Init(pWorld); Ptr<CMissile> pHolder = OMalloc(CMissile)->Init(pWorld); pWorld->AddTickable(pHolder); AssertInt(4, pHolder->GetDistToRoot()); pHolder->SetTarget(pHarrier); AssertInt(5, pHarrier->GetDistToRoot()); Ptr<CClusterLauncher> pLauncher = OMalloc(CClusterLauncher)->Init(); pRoot->Add(pLauncher); AssertInt(2, pLauncher->GetDistToRoot()); pLauncher->mpMissile = pMissile; AssertInt(3, pMissile->GetDistToRoot()); AssertInt(3, pMissile->mcMissile1.GetDistToRoot()); AssertInt(3, pMissile->mcMissile2.GetDistToRoot()); AssertInt(5, pHarrier->GetDistToRoot()); AssertInt(1, pHarrier->NumHeapFroms()); pMissile->mcMissile1.SetTarget(pHarrier); AssertInt(4, pHarrier->GetDistToRoot()); AssertInt(2, pHarrier->NumHeapFroms()); pWorld->RemoveTickable(pHolder); pHolder = NULL; AssertInt(4, pHarrier->GetDistToRoot()); AssertInt(1, pHarrier->NumHeapFroms()); pRoot->Add(pHarrier); AssertInt(2, pHarrier->GetDistToRoot()); pRoot->Remove(pHarrier); AssertInt(4, pHarrier->GetDistToRoot()); ObjectsKill(); }
void TestMapStringUnknownGet(void) { MemoryInit(); UnknownsInit(); CMapStringUnknown cMap; CTestUnknownJobbie* pcTest; CTestUnknownJobbie* pcA1; CTestUnknownJobbie* pcA2; CTestUnknownJobbie* pcA3; cMap.Init(); pcTest = cMap.Put<CTestUnknownJobbie>("Hello"); pcTest->Init(7, "1st"); pcTest = cMap.Put<CTestUnknownJobbie>("World"); pcTest->Init(19, "A pony"); pcTest = cMap.Put<CTestUnknownJobbie>("Aardvark"); pcTest->Init(4, "Restore"); AssertInt(3, cMap.NumElements()); pcTest = (CTestUnknownJobbie*)cMap.Get("World"); AssertInt(19, pcTest->miANumber); AssertString("A pony", pcTest->mszText.Text()); pcA1 = UMalloc(CTestUnknownJobbie); pcA1->Init(999, "Grand"); cMap.Put("Thesaurus", pcA1); pcA2 = UMalloc(CTestUnknownJobbie); pcA2->Init(17, "Replaced!"); cMap.Put("World", pcA2); pcA3 = UMalloc(CTestUnknownJobbie); pcA3->Init(32, "Another"); cMap.Put("Jump", pcA3); AssertInt(5, cMap.NumElements()); AssertInt(5, gcUnknowns.NumElements()); pcTest = (CTestUnknownJobbie*)cMap.Get("World"); AssertPointer(pcA2, pcTest); AssertString("Replaced!", pcTest->mszText.Text()); pcTest = (CTestUnknownJobbie*)cMap.Get("world"); AssertPointer(NULL, pcTest); pcTest = (CTestUnknownJobbie*)cMap.Get(NULL); AssertPointer(NULL, pcTest); pcTest = (CTestUnknownJobbie*)cMap.Get(""); AssertPointer(NULL, pcTest); pcTest = cMap.Put<CTestUnknownJobbie>(""); pcTest->Init(0, "Empty"); pcTest = (CTestUnknownJobbie*)cMap.Get(""); AssertString("Empty", pcTest->mszText.Text()); cMap.Kill(); AssertInt(0, gcUnknowns.NumElements()); UnknownsKill(); MemoryKill(); }
void TestCleanNulls(void) { MemoryInit(); UnknownsInit(); CSetUnknown cSet; CTestNamedUnknown* apUnknowns[32]; CChars sz; int i; SSetIterator sSetIter; BOOL bResult; cSet.Init(4); for (int i = 0; i < 32; i++) { apUnknowns[i] = cSet.Add<CTestNamedUnknown>(); sz.Init(); sz.Append(i); apUnknowns[i]->Init(sz.Text()); sz.Kill(); } AssertInt(32, cSet.NumElements()); AssertInt(32, cSet.UnsafeNumElements()); cSet.Remove(apUnknowns[0]); cSet.Remove(apUnknowns[2]); cSet.Remove(apUnknowns[3]); cSet.Remove(apUnknowns[7]); cSet.Remove(apUnknowns[17]); cSet.Remove(apUnknowns[18]); cSet.Remove(apUnknowns[19]); cSet.Remove(apUnknowns[23]); cSet.Remove(apUnknowns[26]); cSet.Remove(apUnknowns[27]); cSet.Remove(apUnknowns[28]); AssertInt(21, cSet.NumElements()); AssertInt(32, cSet.UnsafeNumElements()); AssertPointer(NULL, cSet.UnsafeGet(0)); AssertPointer(apUnknowns[1], cSet.UnsafeGet(1)); AssertPointer(NULL, cSet.UnsafeGet(2)); AssertPointer(NULL, cSet.UnsafeGet(3)); AssertPointer(apUnknowns[4], cSet.UnsafeGet(4)); AssertPointer(apUnknowns[5], cSet.UnsafeGet(5)); AssertPointer(apUnknowns[6], cSet.UnsafeGet(6)); AssertPointer(NULL, cSet.UnsafeGet(7)); AssertPointer(apUnknowns[8], cSet.UnsafeGet(8)); AssertPointer(apUnknowns[9], cSet.UnsafeGet(9)); AssertPointer(apUnknowns[10], cSet.UnsafeGet(10)); AssertPointer(apUnknowns[11], cSet.UnsafeGet(11)); AssertPointer(apUnknowns[12], cSet.UnsafeGet(12)); AssertPointer(apUnknowns[13], cSet.UnsafeGet(13)); AssertPointer(apUnknowns[14], cSet.UnsafeGet(14)); AssertPointer(apUnknowns[15], cSet.UnsafeGet(15)); AssertPointer(apUnknowns[16], cSet.UnsafeGet(16)); AssertPointer(NULL, cSet.UnsafeGet(17)); AssertPointer(NULL, cSet.UnsafeGet(18)); AssertPointer(NULL, cSet.UnsafeGet(19)); AssertPointer(apUnknowns[20], cSet.UnsafeGet(20)); AssertPointer(apUnknowns[21], cSet.UnsafeGet(21)); AssertPointer(apUnknowns[22], cSet.UnsafeGet(22)); AssertPointer(NULL, cSet.UnsafeGet(23)); AssertPointer(apUnknowns[24], cSet.UnsafeGet(24)); AssertPointer(apUnknowns[25], cSet.UnsafeGet(25)); AssertPointer(NULL, cSet.UnsafeGet(26)); AssertPointer(NULL, cSet.UnsafeGet(27)); AssertPointer(NULL, cSet.UnsafeGet(28)); AssertPointer(apUnknowns[29], cSet.UnsafeGet(29)); AssertPointer(apUnknowns[30], cSet.UnsafeGet(30)); AssertPointer(apUnknowns[31], cSet.UnsafeGet(31)); //CleanNullsIfNecessary happens here. cSet.Remove(apUnknowns[29]); AssertInt(20, cSet.NumElements()); AssertInt(20, cSet.UnsafeNumElements()); AssertPointer(apUnknowns[1], cSet.UnsafeGet(0)); AssertPointer(apUnknowns[4], cSet.UnsafeGet(1)); AssertPointer(apUnknowns[5], cSet.UnsafeGet(2)); AssertPointer(apUnknowns[6], cSet.UnsafeGet(3)); AssertPointer(apUnknowns[8], cSet.UnsafeGet(4)); AssertPointer(apUnknowns[9], cSet.UnsafeGet(5)); AssertPointer(apUnknowns[10], cSet.UnsafeGet(6)); AssertPointer(apUnknowns[11], cSet.UnsafeGet(7)); AssertPointer(apUnknowns[12], cSet.UnsafeGet(8)); AssertPointer(apUnknowns[13], cSet.UnsafeGet(9)); AssertPointer(apUnknowns[14], cSet.UnsafeGet(10)); AssertPointer(apUnknowns[15], cSet.UnsafeGet(11)); AssertPointer(apUnknowns[16], cSet.UnsafeGet(12)); AssertPointer(apUnknowns[20], cSet.UnsafeGet(13)); AssertPointer(apUnknowns[21], cSet.UnsafeGet(14)); AssertPointer(apUnknowns[22], cSet.UnsafeGet(15)); AssertPointer(apUnknowns[24], cSet.UnsafeGet(16)); AssertPointer(apUnknowns[25], cSet.UnsafeGet(17)); AssertPointer(apUnknowns[30], cSet.UnsafeGet(18)); AssertPointer(apUnknowns[31], cSet.UnsafeGet(19)); cSet.StartIteration(&sSetIter); for (i = 0; i < 19; i++) { cSet.RemoveDuringIteration(&sSetIter); } AssertInt(1, cSet.NumElements()); bResult = cSet.Remove(apUnknowns[31]); AssertTrue(bResult); AssertInt(0, cSet.NumElements()); cSet.Kill(); UnknownsKill(); MemoryKill(); }
void TestImageCelCropBorders(void) { CImageCel cCel; CImage cImage; ReadImage(&cImage, "Input\\cel1.png"); cCel.Init(&cImage); cCel.CropTransparentBorders(); AssertInt(24, cCel.GetSubImage()->GetFullWidth()); AssertInt(24, cCel.GetSubImage()->GetImageWidth()); AssertInt(24, cCel.GetSubImage()->GetFullHeight()); AssertInt(24, cCel.GetSubImage()->GetImageHeight()); cCel.Kill(); cImage.Kill(); ReadImage(&cImage, "Input\\cel2.png"); cCel.Init(&cImage); cCel.CropTransparentBorders(); AssertInt(24, cCel.GetSubImage()->GetFullWidth()); AssertInt(21, cCel.GetSubImage()->GetImageWidth()); AssertInt(24, cCel.GetSubImage()->GetFullHeight()); AssertInt(18, cCel.GetSubImage()->GetImageHeight()); AssertInt(1, cCel.GetSubImage()->mcImageRect.miLeft); AssertInt(3, cCel.GetSubImage()->mcImageRect.miTop); ReadImage(&cImage, "Input\\cel3.png"); cCel.Init(&cImage); cCel.CropTransparentBorders(); AssertInt(24, cCel.GetSubImage()->GetFullWidth()); AssertInt(0, cCel.GetSubImage()->GetImageWidth()); AssertInt(24, cCel.GetSubImage()->GetFullHeight()); AssertInt(0, cCel.GetSubImage()->GetImageHeight()); AssertBool(TRUE, cCel.GetSubImage()->IsImageEmpty()); cCel.Kill(); cImage.Kill(); }
void TestSetRemoval(void) { MemoryInit(); UnknownsInit(); CSetUnknown cSet; CTestNamedUnknown* pcTest1; CTestNamedUnknown* pcTest2; CTestNamedUnknown* pcTest3; int iNum; CTestNamedUnknown* pcTest; SIteratorTemplate<CTestNamedUnknown> sIter; SSetIterator sSetIter; cSet.Init(); pcTest1 = cSet.Add<CTestNamedUnknown>(); pcTest1->Init("The One"); pcTest2 = cSet.Add<CTestNamedUnknown>(); pcTest2->Init("Two"); pcTest3 = UMalloc(CTestNamedUnknown); pcTest3->Init("There can be only three"); cSet.Add(pcTest3); iNum = cSet.NumElements(); AssertInt(3, iNum); cSet.StartIteration(&sSetIter); cSet.RemoveDuringIteration(&sSetIter); cSet.RemoveDuringIteration(&sSetIter); cSet.RemoveDuringIteration(&sSetIter); iNum = cSet.NumElements(); AssertInt(0, iNum); cSet.RemoveDuringIteration(&sSetIter); pcTest = gcUnknowns.StartIteration(&sIter); AssertNull(pcTest); cSet.Kill(); cSet.Init(); pcTest1 = cSet.Add<CTestNamedUnknown>(); pcTest1->Init("The One"); pcTest2 = cSet.Add<CTestNamedUnknown>(); pcTest2->Init("Two"); pcTest3 = UMalloc(CTestNamedUnknown); pcTest3->Init("There can be only three"); cSet.Add(pcTest3); iNum = cSet.NumElements(); AssertInt(3, iNum); pcTest = (CTestNamedUnknown*)cSet.StartIteration(&sSetIter); AssertString("The One", pcTest->GetName()); cSet.RemoveDuringIteration(&sSetIter); pcTest = (CTestNamedUnknown*)cSet.Iterate(&sSetIter); AssertString("Two", pcTest->GetName()); cSet.RemoveDuringIteration(&sSetIter); iNum = cSet.NumElements(); AssertInt(1, iNum); pcTest = (CTestNamedUnknown*)cSet.Iterate(&sSetIter); AssertString("There can be only three", pcTest->GetName()); cSet.RemoveDuringIteration(&sSetIter); iNum = cSet.NumElements(); AssertInt(0, iNum); cSet.RemoveDuringIteration(&sSetIter); cSet.Kill(); UnknownsKill(); MemoryKill(); }
void TestImageCelMaskCropBorders(void) { CImage cImage; CImageDivider cDivider; CImageCelMask* pcRect1; CImageCelMask* pcRect2; CImage cMask; ReadImage(&cImage, "Input\\cel4.png"); cDivider.Init(&cImage); cDivider.GenerateFromBorder(&cMask); AssertInt(2, cDivider.GetDestImageCels()->NumElements()); pcRect1 = (CImageCelMask*)cDivider.GetDestImageCels()->UnsafeGet(0); pcRect2 = (CImageCelMask*)cDivider.GetDestImageCels()->UnsafeGet(1); AssertInt(1, pcRect1->GetMask()); AssertInt(2, pcRect2->GetMask()); AssertInt(36, pcRect1->GetSubImage()->GetFullWidth()); AssertInt(28, pcRect1->GetSubImage()->GetImageWidth()); AssertInt(22, pcRect1->GetSubImage()->GetFullHeight()); AssertInt(18, pcRect1->GetSubImage()->GetImageHeight()); AssertInt(31, pcRect2->GetSubImage()->GetFullWidth()); AssertInt(25, pcRect2->GetSubImage()->GetImageWidth()); AssertInt(22, pcRect2->GetSubImage()->GetFullHeight()); AssertInt(11, pcRect2->GetSubImage()->GetImageHeight()); cMask.Kill(); cImage.Kill(); cDivider.Kill(); }
void TestArrayEmbeddedAdd(void) { CArrayEmbedded<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.GrowByNumElements(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()); }
void TestRectanglePow2PackerStuff(void) { CRectanglePow2Packer cPacker; CRectangle cRect1; CRectangle cRect2; CRectangle cRect3; char sz1[] = "1"; char sz2[] = "2"; char sz3[] = "3"; CArrayPackedRectangle macRects; CPackedRectangle* pcPackedRect; SInt2 sImageSize; cRect1.Init(0, 0, 7, 5); cRect2.Init(0, 0, 3, 5); cRect3.Init(0, 0, 4, 5); cPacker.Init(0, 0); cPacker.AddRectangle(&cRect1, sz1); cPacker.AddRectangle(&cRect2, sz2); cPacker.AddRectangle(&cRect3, sz3); cPacker.Pack(); macRects.Init(); cPacker.GetPackedRectangles(&macRects); AssertInt(3, macRects.NumElements()); pcPackedRect = macRects.Get(0); AssertInt(0, pcPackedRect->miLeft); AssertInt(0, pcPackedRect->miTop); AssertInt(7, pcPackedRect->miRight); AssertInt(5, pcPackedRect->miBottom); pcPackedRect = macRects.Get(1); AssertInt(7, pcPackedRect->miLeft); AssertInt(0, pcPackedRect->miTop); AssertInt(11, pcPackedRect->miRight); AssertInt(5, pcPackedRect->miBottom); pcPackedRect = macRects.Get(2); AssertInt(11, pcPackedRect->miLeft); AssertInt(0, pcPackedRect->miTop); AssertInt(14, pcPackedRect->miRight); AssertInt(5, pcPackedRect->miBottom); sImageSize = cPacker.GetPackedImageSize(); AssertInt(16, sImageSize.x); AssertInt(8, sImageSize.y); macRects.Kill(); cPacker.Kill(); ///// cPacker.Init(2, 1); cPacker.AddRectangle(&cRect1, sz1); cPacker.AddRectangle(&cRect2, sz2); cPacker.AddRectangle(&cRect3, sz3); cPacker.Pack(); macRects.Init(); cPacker.GetPackedRectangles(&macRects); AssertInt(3, macRects.NumElements()); pcPackedRect = macRects.Get(0); AssertInt(2, pcPackedRect->miLeft); AssertInt(2, pcPackedRect->miTop); AssertInt(9, pcPackedRect->miRight); AssertInt(7, pcPackedRect->miBottom); pcPackedRect = macRects.Get(1); AssertInt(10, pcPackedRect->miLeft); AssertInt(2, pcPackedRect->miTop); AssertInt(14, pcPackedRect->miRight); AssertInt(7, pcPackedRect->miBottom); pcPackedRect = macRects.Get(2); AssertInt(2, pcPackedRect->miLeft); AssertInt(8, pcPackedRect->miTop); AssertInt(5, pcPackedRect->miRight); AssertInt(13, pcPackedRect->miBottom); sImageSize = cPacker.GetPackedImageSize(); AssertInt(16, sImageSize.x); AssertInt(16, sImageSize.y); macRects.Kill(); cPacker.Kill(); }
void TestArrayIntSorting(void) { CArrayInt cArray; cArray.Init(1); cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1); cArray.QuickSort(); AssertInt(10, cArray.NumElements()); AssertInt(0, cArray[0]); AssertInt(1, cArray[1]); AssertInt(2, cArray[2]); AssertInt(2, cArray[3]); AssertInt(3, cArray[4]); AssertInt(4, cArray[5]); AssertInt(4, cArray[6]); AssertInt(7, cArray[7]); AssertInt(8, cArray[8]); AssertInt(9, cArray[9]); cArray.InsertIntoSorted(7, FALSE); cArray.InsertIntoSorted(1, TRUE); AssertInt(11, cArray.NumElements()); AssertInt(0, cArray[0]); AssertInt(1, cArray[1]); AssertInt(2, cArray[2]); AssertInt(2, cArray[3]); AssertInt(3, cArray[4]); AssertInt(4, cArray[5]); AssertInt(4, cArray[6]); AssertInt(7, cArray[7]); AssertInt(7, cArray[8]); AssertInt(8, cArray[9]); AssertInt(9, cArray[10]); cArray.Kill(); }
void TestImageDividerGenerateFromBorder(void) { CImageDivider cImageDivider; CImage cImage; CImage cMask; CImageCelMask* pcRectangle; ReadImage(&cImage, "Input\\splitter.png"); cImageDivider.Init(&cImage); cImageDivider.GenerateFromBorder(&cMask); AssertInt(20, cImageDivider.GetDestImageCels()->NumElements()); pcRectangle = (CImageCelMask*)cImageDivider.GetDestImageCels()->Get(0); AssertInt(1, pcRectangle->GetSubImage()->mcImageRect.miLeft); AssertInt(1, pcRectangle->GetSubImage()->mcImageRect.miTop); AssertInt(13, pcRectangle->GetSubImage()->mcImageRect.GetWidth()); AssertInt(13, pcRectangle->GetSubImage()->mcImageRect.GetHeight()); pcRectangle = (CImageCelMask*)cImageDivider.GetDestImageCels()->Get(1); AssertInt(15, pcRectangle->GetSubImage()->mcImageRect.miLeft); AssertInt(1, pcRectangle->GetSubImage()->mcImageRect.miTop); AssertInt(13, pcRectangle->GetSubImage()->mcImageRect.GetWidth()); AssertInt(13, pcRectangle->GetSubImage()->mcImageRect.GetHeight()); pcRectangle = (CImageCelMask*)cImageDivider.GetDestImageCels()->Get(17); AssertInt(21, pcRectangle->GetSubImage()->mcImageRect.miLeft); AssertInt(39, pcRectangle->GetSubImage()->mcImageRect.miTop); AssertInt(3, pcRectangle->GetSubImage()->mcImageRect.GetWidth()); AssertInt(3, pcRectangle->GetSubImage()->mcImageRect.GetHeight()); WriteImage(&cMask, "Output\\splitter.raw"); AssertFileMemory("input\\splitter.raw", cMask.mcChannels.GetData(), cMask.GetByteSize()); cImageDivider.Kill(); cMask.Kill(); cImage.Kill(); }
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(); }
void TestImageDividerGenerateFromNumbers(void) { CImageDivider cImageDivider; CImage cImage; CImageCel* pcImageCel; CImageDividerNumbers cNumbers; ReadImage(&cImage, "Input\\grid.png"); //int iCelWidth, int iCelHeight, int iColumnCount, int iRowCount, int iLeftOffset, int iTopOffset, int iWidthSpacing, int iHeightSpacing cNumbers.InitGeneral(-1, -1, 4, 3, 0, 0, 0, 0); cImageDivider.Init(&cImage, NULL); cImageDivider.GenerateFromNumbers(&cNumbers); AssertInt(12, cImageDivider.GetDestImageCels()->NumElements()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(0); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(11); AssertInt(48, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(32, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); cImageDivider.Kill(); cNumbers.InitGeneral(16, 16, -1, -1, 0, 0, 0, 0); cImageDivider.Init(&cImage, NULL); cImageDivider.GenerateFromNumbers(&cNumbers); AssertInt(12, cImageDivider.GetDestImageCels()->NumElements()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(0); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(11); AssertInt(48, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(32, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); cImageDivider.Kill(); cNumbers.InitGeneral(16, 16, -1, -1, 0, 0, 16, 0); cImageDivider.Init(&cImage, NULL); cImageDivider.GenerateFromNumbers(&cNumbers); AssertInt(6, cImageDivider.GetDestImageCels()->NumElements()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(0); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(5); AssertInt(32, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(32, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); cImageDivider.Kill(); cNumbers.InitGeneral(16, 16, -1, -1, 0, 0, 0, 16); cImageDivider.Init(&cImage, NULL); cImageDivider.GenerateFromNumbers(&cNumbers); AssertInt(8, cImageDivider.GetDestImageCels()->NumElements()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(0); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(7); AssertInt(48, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(32, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); cImageDivider.Kill(); cNumbers.InitGeneral(16, 16, -1, -1, 16, 0, 0, 0); cImageDivider.Init(&cImage, NULL); cImageDivider.GenerateFromNumbers(&cNumbers); AssertInt(9, cImageDivider.GetDestImageCels()->NumElements()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(0); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(8); AssertInt(48, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(32, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); cImageDivider.Kill(); cNumbers.InitGeneral(16, 16, -1, -1, 16, 0, 16, 0); cImageDivider.Init(&cImage, NULL); cImageDivider.GenerateFromNumbers(&cNumbers); AssertInt(6, cImageDivider.GetDestImageCels()->NumElements()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(0); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(5); AssertInt(48, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(32, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); cImageDivider.Kill(); cNumbers.InitGeneral(-1, -1, 3, 3, 16, 0, 0, 0); cImageDivider.Init(&cImage, NULL); cImageDivider.GenerateFromNumbers(&cNumbers); AssertInt(9, cImageDivider.GetDestImageCels()->NumElements()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(0); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(8); AssertInt(48, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(32, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); cImageDivider.Kill(); cNumbers.InitGeneral(-1, -1, 2, 3, 16, 0, 16, 0); cImageDivider.Init(&cImage, NULL); cImageDivider.GenerateFromNumbers(&cNumbers); AssertInt(6, cImageDivider.GetDestImageCels()->NumElements()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(0); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(0, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); pcImageCel = (CImageCel*)cImageDivider.GetDestImageCels()->Get(5); AssertInt(48, pcImageCel->GetSubImage()->mcImageRect.miLeft); AssertInt(32, pcImageCel->GetSubImage()->mcImageRect.miTop); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetWidth()); AssertInt(16, pcImageCel->GetSubImage()->mcImageRect.GetHeight()); cImageDivider.Kill(); cImage.Kill(); }
void TestChannelsAccessorContiguous(void) { CChannels* pcChannels; CChannelsAccessor* pcAccessor; CChannelsAccessorCreator cCreator; void* pvData; int iData; short sData; pcChannels = UMalloc(CChannels); pcChannels->Init(); pcChannels->BeginChange(); pcChannels->SetSize(2); pcChannels->AddChannel(CHANNEL_NAME_BOB, PT_int); pcChannels->EndChange(); cCreator.Init(pcChannels); cCreator.AddAccess(CHANNEL_NAME_BOB, PT_Undefined); pcAccessor = cCreator.CreateAndKill(); AssertString("CChannelsAccessorContiguous", pcAccessor->ClassName()); pvData = pcAccessor->Get(0); AssertPointer(pcChannels->GetData(), pvData); iData = 784; pcAccessor->Set(1, &iData); pvData = pcAccessor->Get(1); AssertInt(784, *(int*)pvData); pcAccessor->Kill(); pcChannels->BeginChange(); pcChannels->AddChannel(CHANNEL_NAME_ALICE, PT_short); pcChannels->EndChange(); cCreator.Init(pcChannels); cCreator.AddAccess(CHANNEL_NAME_BOB, PT_Undefined); pcAccessor = cCreator.CreateAndKill(); AssertString("CChannelsAccessorContiguous", pcAccessor->ClassName()); pvData = pcAccessor->Get(1); AssertInt(784, *(int*)pvData); pcAccessor->Kill(); cCreator.Init(pcChannels); cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_Undefined); pcAccessor = cCreator.CreateAndKill(); AssertString("CChannelsAccessorContiguous", pcAccessor->ClassName()); pvData = pcAccessor->Get(0); AssertPointer(RemapSinglePointer(pcChannels->GetData(), 4), pvData); sData = 602; pcAccessor->Set(1, &sData); pvData = pcAccessor->Get(1); AssertShort(602, *(short*)pvData); pcAccessor->Kill(); cCreator.Init(pcChannels); cCreator.AddAccess(CHANNEL_NAME_BOB, CHANNEL_NAME_ALICE, PT_Undefined); pcAccessor = cCreator.CreateAndKill(); AssertString("CChannelsAccessorContiguous", pcAccessor->ClassName()); AssertInt(6, pcAccessor->GetByteSize()); pvData = pcAccessor->Get(1); AssertInt(784, *(int*)pvData); pvData = RemapSinglePointer(pvData, 4); AssertInt(602, *(short*)pvData); pcAccessor->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 TestChannelsAccessorWorstCase(void) { CChannels* pcChannels; CChannelsAccessor* pcAccessor; CChannelsAccessorCreator cCreator; unsigned char* pucData; unsigned char aucData[5]; pcChannels = UMalloc(CChannels); pcChannels->Init(); pcChannels->BeginChange(); pcChannels->SetSize(2); pcChannels->AddChannel(CHANNEL_NAME_JACK, PT_bit); pcChannels->AddChannel(CHANNEL_NAME_BOB, PT_uint); pcChannels->AddChannel(CHANNEL_NAME_ALICE, PT_uchar); pcChannels->EndChange(); pcChannels->Clear(); AssertInt(2, pcChannels->GetSize()); AssertInt(11, pcChannels->GetByteSize()); AssertInt(41, pcChannels->GetBitStride()); AssertInt(-1, pcChannels->GetByteStride()); AssertInt(FALSE, pcChannels->IsOnlyBasicTypes()); memset(aucData, 0, 5); cCreator.Init(pcChannels); cCreator.AddAccess(CHANNEL_NAME_JACK, PT_uint); cCreator.AddAccess(CHANNEL_NAME_BOB, PT_bit); cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_nybble); pcAccessor = cCreator.CreateAndKill(); AssertString("CChannelsAccessorWorstCase", pcAccessor->ClassName()); AssertInt(-1, pcAccessor->GetByteSize()); AssertInt(37, pcAccessor->GetBitSize()); AssertInt(5, pcAccessor->GetBufferSize()); aucData[0] = 0xff; aucData[1] = 0xff; aucData[2] = 0xff; aucData[3] = 0xff; aucData[4] = 0xff; pcAccessor->Set(0, aucData); AssertChar((unsigned char)0xff, pcChannels->GetData()[0]); AssertChar((unsigned char)0xff, pcChannels->GetData()[1]); AssertChar((unsigned char)0xff, pcChannels->GetData()[2]); AssertChar((unsigned char)0xff, pcChannels->GetData()[3]); AssertChar((unsigned char)0xff, pcChannels->GetData()[4]); AssertChar((unsigned char)0x01, pcChannels->GetData()[5]); //01 because the next 'pixel' is all zeros. The 1 is the high bit of the char in ALICE. pucData = (unsigned char*)pcAccessor->Get(0); AssertChar((unsigned char)0xff, pucData[0]); AssertChar((unsigned char)0xff, pucData[1]); AssertChar((unsigned char)0xff, pucData[2]); AssertChar((unsigned char)0xff, pucData[3]); AssertChar((unsigned char)0x1f, pucData[4]); aucData[0] = 0xff; aucData[1] = 0xff; aucData[2] = 0xff; aucData[3] = 0xff; aucData[4] = 0xfe; pcAccessor->Set(1, aucData); AssertChar((unsigned char)0x03, pcChannels->GetData()[5]); //01 from 'pixel' 0 and 02 from the bit in JACK in 'pixel' 1. AssertChar((unsigned char)0x00, pcChannels->GetData()[6]); AssertChar((unsigned char)0x00, pcChannels->GetData()[7]); AssertChar((unsigned char)0x00, pcChannels->GetData()[8]); AssertChar((unsigned char)0xfc, pcChannels->GetData()[9]); //fc it the six low bits of the char AssertChar((unsigned char)0x03, pcChannels->GetData()[10] & 0x03); //03 is the two high bits. pucData = (unsigned char*)pcAccessor->Get(1); AssertChar((unsigned char)0xff, pucData[0]); AssertChar((unsigned char)0xff, pucData[1]); AssertChar((unsigned char)0xff, pucData[2]); AssertChar((unsigned char)0xff, pucData[3]); AssertChar((unsigned char)0x1e, pucData[4]); }
void TestEmbeddedStackPointersEmbeddedDistPassThruPointer(void) { ObjectsInit(); CEmbeddedTest* pcTest; CEmbeddedComplex cComplex; Ptr<CEmbeddedTest> pTest; cComplex.Class(); cComplex.Init(); cComplex.mai[0] = 1234; cComplex.mai[1] = 7890; AssertInt(0, cComplex.GetDistToStack()); AssertInt(0, cComplex.NumStackFroms()); Ptr<CEmbeddedComplex> pComplex; pComplex = &cComplex; AssertInt(1, cComplex.NumStackFroms()); AssertInt(1234, pComplex->mai[0]); AssertInt(7890, pComplex->mai[1]); AssertInt(0, cComplex.GetDistToStack()); pTest = OMalloc(CEmbeddedTest); pcTest = (CEmbeddedTest*)pTest.Object(); pTest->Init(); cComplex.mpTest = pTest; AssertInt(UNKNOWN_DIST_TO_STACK, pcTest->GetDistToStack()); AssertInt(2, pComplex->mpTest->NumStackFroms()); AssertInt(1, cComplex.NumStackFroms()); pTest = NULL; AssertInt(UNKNOWN_DIST_TO_STACK, pcTest->GetDistToStack()); AssertLongLongInt(1, gcObjects.NumMemoryIndexes()); AssertInt(1, pComplex->mpTest->NumStackFroms()); AssertInt(1, cComplex.NumStackFroms()); cComplex.Kill(); AssertLongLongInt(0, gcObjects.NumMemoryIndexes()); ObjectsKill(); }
void TestLogFileWrite(void) { CLogFile* pcLogFile; CMemoryFile* pcMemoryFile; CFileBasic cFile; BOOL bResult; int iLength; char sz[200]; pcMemoryFile = MemoryFile(); pcLogFile = LogFile(pcMemoryFile); cFile.Init(pcLogFile); bResult = cFile.Open(EFM_ReadWrite_Create); AssertTrue(bResult); bResult = cFile.WriteString("The suspense is killing me!"); AssertTrue(bResult); AssertNull((char*)pcMemoryFile->GetBufferPointer()); AssertInt(1, pcLogFile->GetNumWrites()); AssertLongLongInt(32, pcLogFile->GetWriteSize(0)); bResult = cFile.Seek(8); AssertTrue(bResult); bResult = cFile.WriteData("camisole", 8); AssertTrue(bResult); AssertInt(1, pcLogFile->GetNumWrites()); AssertLongLongInt(32, pcLogFile->GetWriteSize(0)); AssertNull((char*)pcMemoryFile->GetBufferPointer()); cFile.Seek(0); bResult = cFile.ReadStringLength(&iLength); AssertTrue(bResult); AssertInt(28, iLength); AssertFalse(cFile.IsEndOfFile()); bResult = cFile.ReadStringChars(sz, iLength); AssertString("The camisole is killing me!", sz); AssertTrue(cFile.IsEndOfFile()); bResult = pcLogFile->Commit(); AssertTrue(bResult); AssertString("The camisole is killing me!", (char*)RemapSinglePointer(pcMemoryFile->GetBufferPointer(), sizeof(int))); bResult = cFile.Close(); //This should go before Commit AssertTrue(bResult); pcLogFile->Begin(); bResult = cFile.Open(EFM_ReadWrite_Create); AssertTrue(bResult); bResult = cFile.Seek(4); AssertTrue(bResult); bResult = cFile.WriteData("Dog", 3); bResult = cFile.Seek(20); AssertTrue(bResult); bResult = cFile.WriteData("plurgle", 7); AssertInt(2, pcLogFile->GetNumWrites()); AssertLongLongInt(3, pcLogFile->GetWriteSize(0)); AssertLongLongInt(7, pcLogFile->GetWriteSize(1)); AssertString("The camisole is killing me!", (char*)RemapSinglePointer(pcMemoryFile->GetBufferPointer(), sizeof(int))); cFile.Seek(0); bResult = cFile.ReadStringLength(&iLength); AssertTrue(bResult); AssertInt(28, iLength); AssertFalse(cFile.IsEndOfFile()); bResult = cFile.ReadStringChars(sz, iLength); AssertTrue(bResult); AssertString("Dog camisole is plurgle me!", sz); AssertTrue(cFile.IsEndOfFile()); bResult = pcLogFile->Commit(); AssertTrue(bResult); AssertString("Dog camisole is plurgle me!", (char*)RemapSinglePointer(pcMemoryFile->GetBufferPointer(), sizeof(int))); bResult = cFile.Close(); AssertTrue(bResult); pcLogFile->Begin(); bResult = cFile.Open(EFM_ReadWrite_Create); AssertTrue(bResult); cFile.Seek(4); cFile.WriteData("X", 1); cFile.Seek(6); bResult = cFile.WriteData("Z", 1); cFile.Seek(28); cFile.WriteData("A", 1); cFile.Seek(30); bResult = cFile.WriteData("C", 1); AssertInt(4, pcLogFile->GetNumWrites()); cFile.Seek(5); cFile.WriteData("Y", 1); AssertInt(3, pcLogFile->GetNumWrites()); cFile.Seek(29); cFile.WriteData("B", 1); AssertInt(2, pcLogFile->GetNumWrites()); cFile.Seek(0); bResult = cFile.ReadStringLength(&iLength); AssertTrue(bResult); bResult = cFile.ReadStringChars(sz, iLength); AssertString("XYZ camisole is plurgle ABC", sz); AssertTrue(cFile.IsEndOfFile()); bResult = pcLogFile->Commit(); AssertTrue(bResult); AssertString("XYZ camisole is plurgle ABC", (char*)RemapSinglePointer(pcMemoryFile->GetBufferPointer(), sizeof(int))); bResult = cFile.Close(); AssertTrue(bResult); cFile.Kill(); }
void TestImageReaderPNG(void) { CImage cImage; ReadImage(&cImage, "Input\\basn0g01.png"); WriteImage(&cImage, "Output\\basn0g01.raw"); AssertFileMemory("input\\basn0g01.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); ReadImage(&cImage, "Input\\basn0g02.png"); WriteImage(&cImage, "Output\\basn0g02.raw"); AssertFileMemory("input\\basn0g02.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); ReadImage(&cImage, "Input\\basn0g04.png"); WriteImage(&cImage, "Output\\basn0g04.raw"); AssertFileMemory("input\\basn0g04.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); ReadImage(&cImage, "Input\\basn0g08.png"); WriteImage(&cImage, "Output\\basn0g08.raw"); AssertFileMemory("input\\basn0g08.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); ReadImage(&cImage, "Input\\basn0g16.png"); WriteImage(&cImage, "Output\\basn0g16.raw"); AssertFileMemory("input\\basn0g16.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); ReadImage(&cImage, "Input\\basn2c08.png"); WriteImage(&cImage, "Output\\basn2c08.raw"); AssertFileMemory("input\\basn2c08.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); ReadImage(&cImage, "Input\\basn2c16.png"); WriteImage(&cImage, "Output\\basn2c16.raw"); AssertFileMemory("input\\basn2c16.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); ReadImage(&cImage, "Input\\basn4a08.png"); AssertInt(32, cImage.GetWidth()); AssertInt(32, cImage.GetHeight()); AssertInt(2048, cImage.GetByteSize()); WriteImage(&cImage, "Output\\basn4a08.raw"); AssertFileMemory("input\\basn4a08.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); ReadImage(&cImage, "Input\\basn4a16.png"); WriteImage(&cImage, "Output\\basn4a16.raw"); AssertFileMemory("input\\basn4a16.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); ReadImage(&cImage, "Input\\basn6a08.png"); WriteImage(&cImage, "Output\\basn6a08.raw"); AssertFileMemory("input\\basn6a08.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); ReadImage(&cImage, "Input\\basn6a16.png"); WriteImage(&cImage, "Output\\basn6a16.raw"); AssertFileMemory("input\\basn6a16.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); }