static void TestWrite(void) { cByteBuffer buf(50); buf.WriteVarInt32(5); buf.WriteVarInt32(300); buf.WriteVarInt32(0); AString All; buf.ReadAll(All); assert_test(All.size() == 4); assert_test(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0); }
static void TestRead(void) { cByteBuffer buf(50); buf.Write("\x05\xac\x02\x00", 4); UInt32 v1; assert_test(buf.ReadVarInt(v1) && (v1 == 5)); UInt32 v2; assert_test(buf.ReadVarInt(v2) && (v2 == 300)); UInt32 v3; assert_test(buf.ReadVarInt(v3) && (v3 == 0)); }
static void DoTest(void) { cBlockArea ba; ba.Create(21, 256, 21); ba.RelLine(0, 0, 0, 9, 8, 7, cBlockArea::baTypes | cBlockArea::baMetas, E_BLOCK_WOODEN_STAIRS, 1); AString Schematic; if (!cSchematicFileSerializer::SaveToSchematicString(ba, Schematic)) { assert_test(!"Schematic failed to save!"); } cBlockArea ba2; if (!cSchematicFileSerializer::LoadFromSchematicString(ba2, Schematic)) { assert_test(!"Schematic failed to load!"); } }
/** Test that IsNil correctly identifies nil UUIDs. */ static void UUIDNil() { const auto NilString = "00000000-0000-0000-0000-000000000000"; const auto NonNilString = "e760d270-d8b3-4288-b895-d9f78a31e083"; { cUUID UUID; assert_test(UUID.FromString(NilString)); assert_test(UUID.IsNil()); } { cUUID UUID; assert_test(UUID.FromString(NonNilString)); assert_test(!UUID.IsNil()); } }
/** Test that FromString -> ToLongString preserves the original value for long UUIDs. */ static void UUIDFromStringToLongString() { const char TestStrings[][37]{ "01234567-89ab-cdef-0123-456789ABCDEF", "d188b264-8cc3-11e7-bb31-be2e44b06b34", "e760d270-d8b3-4288-b895-d9f78a31e083", "7052f2f2-5942-46ab-b8e3-fed602158870", "7f14d4b6-0cd8-4ba7-885c-8301b67ce891", "57be7039-2505-48b5-90af-272291fabcfa" }; for (auto TestString : TestStrings) { cUUID UUID; assert_test(UUID.FromString(TestString)); auto ResultString = UUID.ToLongString(); // Result should be equivalent to original assert_test(NoCaseCompare(ResultString, TestString) == 0); // And should be all lower case assert_test(ResultString == StrToLower(ResultString)); } }
/** Test that FromString -> ToShortString preserves the original value for short UUIDs. */ static void UUIDFromStringToShortString() { const char TestStrings[][33]{ "0123456789abcdef0123456789ABCDEF", "d188b2648cc311e7bb31be2e44b06b34", "e760d270d8b34288b895d9f78a31e083", "7052f2f2594246abb8e3fed602158870", "7f14d4b60cd84ba7885c8301b67ce891", "57be7039250548b590af272291fabcfa" }; for (auto TestString : TestStrings) { cUUID UUID; assert_test(UUID.FromString(TestString)); auto ResultString = UUID.ToShortString(); // Result should be equivalent to original assert_test(NoCaseCompare(ResultString, TestString) == 0); // And should be all lower case assert_test(ResultString == StrToLower(ResultString)); } }
static void TestWrap(void) { cByteBuffer buf(3); for (int i = 0; i < 1000; i++) { size_t FreeSpace = buf.GetFreeSpace(); assert_test(buf.GetReadableSpace() == 0); assert_test(FreeSpace > 0); assert_test(buf.Write("a", 1)); assert_test(buf.CanReadBytes(1)); assert_test(buf.GetReadableSpace() == 1); UInt8 v = 0; assert_test(buf.ReadBEUInt8(v)); assert_test(v == 'a'); assert_test(buf.GetReadableSpace() == 0); buf.CommitRead(); assert_test(buf.GetFreeSpace() == FreeSpace); // We're back to normal } }
/** Test that FromRaw -> ToRaw preserves the original value. */ static void UUIDFromRawToRaw() { std::array<Byte, 16> TestData[16]{}; // Fill test data with all values 0 - 255 for (int i = 0; i != 16; ++i) { std::iota(begin(TestData[i]), end(TestData[i]), i * 16); } for (const auto & TestRaw : TestData) { cUUID UUID; UUID.FromRaw(TestRaw); auto ResultRaw = UUID.ToRaw(); assert_test(ResultRaw == TestRaw); } }
int main(){ char *c; int out; lv_string_t *str1=lv_string_new(16); assert_test((str1->capacity==16), "new str1 capacity not 16, is %d", str1->capacity) ; lv_string_write_str(str1, "hurroh"); assert_test((str1->write_pos==6), "str1 writepos not 6 after 'hurroh', is %d", str1->write_pos); lv_string_write_str(str1, "hurroh"); assert_test((str1->write_pos==12), "str1 writepos not 12 after 'hurrohhurroh', is %d", str1->write_pos); c=lv_string_read(str1, 2, &out); assert_test((*c=='h'), "read did not start at 0, wanted 'h', got '%c'", *c); c=lv_string_read(str1, 2, &out); assert_test((*c=='r'), "read did not start at 2, wanted 'r', got '%c'", *c); assert_test((str1->read_pos==4), "str1 readpos not 4, is %d", str1->read_pos); assert_test((out==2), "read out not 2, is %d", out); lv_string_t *str2=lv_string_dup_from_ptr("sailor", 6); assert_test((str2->capacity==6), "new str2 capacity not 6, is %d", str2->capacity) ; lv_string_concat(str1, str2); assert_test((str1->capacity==36), "str1 capacity not 32 after concat & realloc, is %d", str1->capacity); assert_test((str1->write_pos==18), "str1 write_pos not 18 after concat, is %d", str1->write_pos); char *cmp="hurrohhurrohsailor"; assert_test((memcmp(str1->ptr, cmp, 18)==0), "unexpected memory contents after concat & realloc"); lv_string_nullterm(str1); assert_test((memcmp(str1->ptr, cmp, 19)==0), "nullterm failed"); assert_test((str1->write_pos==18), "write_pos not the same after nullterm should be 18, is %d",str1->read_pos); lv_string_reset(str1); assert_test((str1->read_pos==0 && str1->write_pos==0), "Unexpected indexes after reset, read_pos=%d, write_pos=%d", str1->read_pos, str2->write_pos); lv_string_write_int_as_str(str1, 667); lv_string_nullterm(str1); assert_test((memcmp(str1->ptr, "667", 3)==0), "Write int of '667' failed, is '%s'", str1->ptr); lv_string_destroy(str1); lv_string_destroy(str2); return 0; }
int main(int argc, char ** argv) { LOGD("Test started"); // Set up a cChunkData with known contents - all blocks 0x01, all metas 0x02: class cMockAllocationPool : public cAllocationPool<cChunkData::sChunkSection> { virtual cChunkData::sChunkSection * Allocate() { return new cChunkData::sChunkSection(); } virtual void Free(cChunkData::sChunkSection * a_Ptr) { delete a_Ptr; } } Pool; cChunkData Data(Pool); cChunkDef::BlockTypes BlockTypes; cChunkDef::BlockNibbles BlockMetas; memset(BlockTypes, 0x01, sizeof(BlockTypes)); memset(BlockMetas, 0x02, sizeof(BlockMetas)); Data.SetBlockTypes(BlockTypes); Data.SetMetas(BlockMetas); // Try to read varying amounts of blocktypes from the cChunkData. // Verify that the exact amount of memory is copied, by copying to a larger buffer and checking its boundaries BLOCKTYPE TestBuffer[5 * cChunkDef::NumBlocks]; size_t WritePosIdx = 2 * cChunkDef::NumBlocks; BLOCKTYPE * WritePosition = &TestBuffer[WritePosIdx]; memset(TestBuffer, 0x03, sizeof(TestBuffer)); size_t LastReportedStep = 1; for (size_t idx = 0; idx < 5000; idx += 73) { if (idx / 500 != LastReportedStep) { printf("Testing index %u...\n", (unsigned)idx); LastReportedStep = idx / 500; } for (size_t len = 3; len < 700; len += 13) { Data.CopyBlockTypes(WritePosition, idx, len); // Verify the data copied: for (size_t i = 0; i < len; i++) { assert_test(WritePosition[i] == 0x01); } // Verify the space before the copied data hasn't been changed: for (size_t i = 0; i < WritePosIdx; i++) { assert_test(TestBuffer[i] == 0x03); } // Verify the space after the copied data hasn't been changed: for (size_t i = WritePosIdx + idx + len; i < ARRAYCOUNT(TestBuffer); i++) { assert_test(TestBuffer[i] == 0x03); } // Re-initialize the buffer for the next test: for (size_t i = 0; i < len; i++) { WritePosition[i] = 0x03; } } // for len } // for idx return 0; }