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 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(); }