static void test_Equals(TestBatchRunner *runner) { ByteBuf *wanted = BB_new_bytes("foo", 4); // Include terminating NULL. ByteBuf *got = BB_new_bytes("foo", 4); TEST_TRUE(runner, BB_Equals(wanted, (Obj*)got), "Equals"); TEST_INT_EQ(runner, BB_Hash_Sum(got), BB_Hash_Sum(wanted), "Hash_Sum"); TEST_TRUE(runner, BB_Equals_Bytes(got, "foo", 4), "Equals_Bytes"); TEST_FALSE(runner, BB_Equals_Bytes(got, "foo", 3), "Equals_Bytes spoiled by different size"); TEST_FALSE(runner, BB_Equals_Bytes(got, "bar", 4), "Equals_Bytes spoiled by different content"); BB_Set_Size(got, 3); TEST_FALSE(runner, BB_Equals(wanted, (Obj*)got), "Different size spoils Equals"); TEST_FALSE(runner, BB_Hash_Sum(got) == BB_Hash_Sum(wanted), "Different size spoils Hash_Sum (probably -- at least this one)"); BB_Mimic_Bytes(got, "bar", 4); TEST_INT_EQ(runner, BB_Get_Size(wanted), BB_Get_Size(got), "same length"); TEST_FALSE(runner, BB_Equals(wanted, (Obj*)got), "Different content spoils Equals"); DECREF(got); DECREF(wanted); }
static void test_Equals(TestBatchRunner *runner) { ByteBuf *bb = BB_new_bytes("foo", 4); // Include terminating NULL. { ByteBuf *other = BB_new_bytes("foo", 4); TEST_TRUE(runner, BB_Equals(bb, (Obj*)other), "Equals"); DECREF(other); } TEST_TRUE(runner, BB_Equals_Bytes(bb, "foo", 4), "Equals_Bytes"); TEST_FALSE(runner, BB_Equals_Bytes(bb, "foo", 3), "Equals_Bytes spoiled by different size"); TEST_FALSE(runner, BB_Equals_Bytes(bb, "bar", 4), "Equals_Bytes spoiled by different content"); { ByteBuf *other = BB_new_bytes("foo", 3); TEST_FALSE(runner, BB_Equals(bb, (Obj*)other), "Different size spoils Equals"); DECREF(other); } { ByteBuf *other = BB_new_bytes("bar", 4); TEST_UINT_EQ(runner, BB_Get_Size(bb), BB_Get_Size(other), "same length"); TEST_FALSE(runner, BB_Equals(bb, (Obj*)other), "Different content spoils Equals"); DECREF(other); } DECREF(bb); }
static void test_Cat(TestBatchRunner *runner) { ByteBuf *bb = BB_new_bytes("foo", 3); { Blob *blob = Blob_new("bar", 3); BB_Cat(bb, blob); TEST_TRUE(runner, BB_Equals_Bytes(bb, "foobar", 6), "Cat"); DECREF(blob); } BB_Cat_Bytes(bb, "baz", 3); TEST_TRUE(runner, BB_Equals_Bytes(bb, "foobarbaz", 9), "Cat_Bytes"); DECREF(bb); }
static void test_To_ByteBuf(TestBatchRunner *runner) { String *string = Str_newf("foo"); ByteBuf *bb = Str_To_ByteBuf(string); TEST_TRUE(runner, BB_Equals_Bytes(bb, "foo", 3), "To_ByteBuf"); DECREF(bb); DECREF(string); }
static void test_Slurp_File(TestBatch *batch) { Folder *folder = (Folder*)RAMFolder_new(NULL); FileHandle *fh = Folder_Open_FileHandle(folder, &foo, FH_CREATE | FH_WRITE_ONLY); ByteBuf *contents; FH_Write(fh, "stuff", 5); FH_Close(fh); DECREF(fh); contents = Folder_Slurp_File(folder, &foo); TEST_TRUE(batch, BB_Equals_Bytes(contents, "stuff", 5), "Slurp_File"); DECREF(contents); DECREF(folder); }