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 CImageCelsSource::AddDiskFileSource(char* szFileName, char* szImageName, CImageCelSource* pcCelSource) { CImageSourceDiskFile* pcDiskFile; int iLen; CChars szNewName; CFileUtil cFileUtil; if (!szFileName) { return; } iLen = (int)strlen(szFileName); if (iLen == 0) { return; } pcDiskFile = UMalloc(CImageSourceDiskFile); if (szImageName) { pcDiskFile->Init(szFileName, szImageName); } else { szNewName.Init(szFileName); cFileUtil.RemovePath(&szNewName); pcDiskFile->Init(szFileName, szNewName.Text()); szNewName.Kill(); } AddSource(pcDiskFile, pcCelSource); }
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(); }
CObjectSource* CObjectConverterNative::CreateSource(CAbstractFile* pcFile, char* szFileName) { CObjectSourceChunked* pcSourceChunked; CObjectSourceSimple* pcSourceSimple; BOOL bResult; CFileBasic cFile; int c; if ((!pcFile) || (!szFileName)) { return NULL; } cFile.Init(pcFile); bResult = cFile.Open(EFM_Read); if (!bResult) { return NULL; } bResult = cFile.ReadInt(&c); if (!bResult) { return NULL; } if (c == CHUNKED_OBJECT_FILE) { pcSourceChunked = UMalloc(CObjectSourceChunked); bResult = pcSourceChunked->Init(this, pcFile, szFileName); if (!bResult) { return NULL; } return pcSourceChunked; } else if (c == BASIC_OBJECT_FILE) { pcSourceSimple = UMalloc(CObjectSourceSimple); pcSourceSimple->Init(this, pcFile, szFileName); return pcSourceSimple; } else { return NULL; } }
void CImageCelsSource::AddMemorySource(CImage* pcImage, CImageCelSource* pcCelSource) { CImageSourceMemory* pcMemory; pcMemory = UMalloc(CImageSourceMemory); pcMemory->Init(pcImage); AddSource(pcMemory, pcCelSource); }
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(); }
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(); }
void CImageCelsSource::AddDiskFileSources(char* szPathName, char* szFileNameContains, char* szImageName, CImageCelSource* pcCelSource) { CFileUtil cFileUtil; CArrayString cFileNames; int i; CChars* pszName; CImageSourceDiskFile* pcDiskFile; CChars szNiceName; int iIndex; int iLen; if (!szFileNameContains) { return; } iLen = (int)strlen(szFileNameContains); if (iLen == 0) { return; } cFileNames.Init(32); cFileUtil.FindFilesWithNameContaining(szPathName, szFileNameContains, &cFileNames, FALSE); for (i = 0; i < cFileNames.NumElements(); i++) { pszName = cFileNames.Get(i); pcDiskFile = UMalloc(CImageSourceDiskFile); if (szImageName) { szNiceName.Init(*pszName); cFileUtil.RemovePath(&szNiceName); cFileUtil.RemoveExtension(&szNiceName); iIndex = szNiceName.Find(0, szFileNameContains); iIndex += iLen; szNiceName.RemoveFromStart(iIndex); szNiceName.Insert(0, szImageName); pcDiskFile->Init(pszName->Text(), szNiceName.Text()); szNiceName.Kill(); } else { pcDiskFile->Init(pszName->Text()); } AddSource(pcDiskFile, pcCelSource); } cFileNames.Kill(); }
void TestChannelsAccessorAccessBitty(void) { CChannels* pcChannels; CChannelsAccessor* pcAccessor; CChannelsAccessorCreator cCreator; unsigned char* pucData; unsigned char aucData[2]; pcChannels = UMalloc(CChannels); pcChannels->Init(); pcChannels->BeginChange(); pcChannels->SetSize(1); pcChannels->AddChannel(CHANNEL_NAME_JACK, PT_ushort); pcChannels->AddChannel(CHANNEL_NAME_BOB, PT_ushort); pcChannels->AddChannel(CHANNEL_NAME_ALICE, PT_ushort); pcChannels->EndChange(); pcChannels->Clear(); cCreator.Init(pcChannels); cCreator.AddAccess(CHANNEL_NAME_JACK, PT_sixbits); cCreator.AddAccess(CHANNEL_NAME_BOB, PT_sixbits); cCreator.AddAccess(CHANNEL_NAME_ALICE, PT_nybble); pcAccessor = cCreator.CreateAndKill(); AssertString("CChannelsAccessorAccessBitty", pcAccessor->ClassName()); //XX10110010100011 aucData[0] = 0xa3; aucData[1] = 0x2c; pcAccessor->Set(0, aucData); AssertShortHex((unsigned short)0x8e38, *(unsigned short*)RemapSinglePointer(pcChannels->GetData(), 0 + 0)); AssertShortHex((unsigned short)0xcb2b, *(unsigned short*)RemapSinglePointer(pcChannels->GetData(), 0 + 2)); AssertShortHex((unsigned short)0x2222, *(unsigned short*)RemapSinglePointer(pcChannels->GetData(), 0 + 4)); pucData = (unsigned char*)pcAccessor->Get(0); AssertShortHex((unsigned short)0x2ca3, *(unsigned short*)pucData); pcAccessor->Kill(); }
BOOL CObjectSourcesXML::ImportImage(CTileType* pcType, CMarkupTag* pcTag) { CMarkupTag* pcName; CMarkupTag* pcCelIndex; CMarkupTag* pcBrushID; CMarkupTag* pcSourceName; CMarkupTag* pcProperties; CChars szName; int iCelIndex; int iBrushID; CChars szSourceName; CTileImageCel* pcTile; Ptr<CImageCelGroup> pcGroup; CImageCel* pcCel; pcName = CMarkupTextParser::GetTag(pcTag, "Name"); if (!pcName) { return FALSE; } pcCelIndex = CMarkupTextParser::GetTag(pcTag, "CelIndex"); if (!pcCelIndex) { return FALSE; } pcBrushID = CMarkupTextParser::GetTag(pcTag, "BrushID"); if (!pcBrushID) { return FALSE; } pcSourceName = CMarkupTextParser::GetTag(pcTag, "SourceName"); if (!pcSourceName) { return FALSE; } pcProperties = CMarkupTextParser::GetTag(pcTag, "Properties"); szName.Init(); pcName->GetText(&szName); if (!CMarkupTextParser::ReadInteger(pcCelIndex, &iCelIndex)) { szName.Kill(); return FALSE; } if (!CMarkupTextParser::ReadInteger(pcBrushID, &iBrushID)) { szName.Kill(); return FALSE; } szSourceName.Init(); pcSourceName->GetText(&szSourceName); if (szSourceName.Empty()) { CMarkupTextParser::LogErrorTagWasEmpty(pcSourceName); szName.Kill(); szSourceName.Kill(); return FALSE; } pcGroup = mpcWorld->GetGroup(szSourceName.Text()); if (!pcGroup) { szName.Kill(); szSourceName.Kill(); gcLogger.Error("Couldn't find Cel Group."); return FALSE; } pcCel = pcGroup->GetCel(iCelIndex); if (!pcCel) { szName.Kill(); szSourceName.Kill(); gcLogger.Error("Couldn't find Cel."); return FALSE; } pcTile = UMalloc(CTileImageCel); pcTile->Init(pcCel, pcType, szName.Text()); pcType->AddTile(pcTile); return TRUE; }
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 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 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 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 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 TestSetTypeAddAll(void) { UnknownsInit(); CSetType<CTestNamedUnknown> cSet; int i; CTestNamedUnknown* pcTest; CSetType<CTestNamedUnknown> cDest; CChars sz; CTestNamedUnknown* pcTest25; cSet.Init(); pcTest25 = NULL; for (i = 0; i < 50; i++) { pcTest = UMalloc(CTestNamedUnknown); sz.Init(":"); sz.Append(i); pcTest->Init(sz.Text()); sz.Kill(); cSet.Add(pcTest); if (i == 25) { pcTest25 = pcTest; } } cSet.Remove(pcTest25); cDest.Init(); cDest.AddAll(&cSet); cSet.KillElements(FALSE); cSet.Kill(); AssertInt(49, cDest.NumElements()); for (i = 0; i < 25; i++) { pcTest = (CTestNamedUnknown*)cDest.UnsafeGet(i); sz.Init(":"); sz.Append(i); AssertString(sz.Text(), pcTest->mszName.Text()); sz.Kill(); } pcTest = (CTestNamedUnknown*)cDest.UnsafeGet(i); AssertNull(pcTest); for (i = 26; i < 50; i++) { pcTest = (CTestNamedUnknown*)cDest.UnsafeGet(i); sz.Init(":"); sz.Append(i); AssertString(sz.Text(), pcTest->mszName.Text()); sz.Kill(); } cDest.Kill(); UnknownsKill(); }