Beispiel #1
0
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);
}
Beispiel #3
0
static void
test_Clone(TestBatchRunner *runner) {
    ByteBuf *bb = BB_new_bytes("foo", 3);
    ByteBuf *twin = BB_Clone(bb);
    TEST_TRUE(runner, BB_Equals(bb, (Obj*)twin), "Clone");
    DECREF(bb);
    DECREF(twin);
}
Beispiel #4
0
static void
test_Cat(TestBatchRunner *runner) {
    ByteBuf *wanted  = BB_new_bytes("foobar", 6);
    ByteBuf *got     = BB_new_bytes("foo", 3);
    ByteBuf *scratch = BB_new_bytes("bar", 3);

    BB_Cat(got, scratch);
    TEST_TRUE(runner, BB_Equals(wanted, (Obj*)got), "Cat");

    BB_Mimic_Bytes(wanted, "foobarbaz", 9);
    BB_Cat_Bytes(got, "baz", 3);
    TEST_TRUE(runner, BB_Equals(wanted, (Obj*)got), "Cat_Bytes");

    DECREF(scratch);
    DECREF(got);
    DECREF(wanted);
}
Beispiel #5
0
static void
test_Mimic(TestBatchRunner *runner) {
    ByteBuf *a = BB_new_bytes("foo", 3);
    ByteBuf *b = BB_new(0);

    BB_Mimic(b, (Obj*)a);
    TEST_TRUE(runner, BB_Equals(a, (Obj*)b), "Mimic");

    BB_Mimic_Bytes(a, "bar", 4);
    TEST_TRUE(runner, strcmp(BB_Get_Buf(a), "bar") == 0,
              "Mimic_Bytes content");
    TEST_INT_EQ(runner, BB_Get_Size(a), 4, "Mimic_Bytes size");

    BB_Mimic(b, (Obj*)a);
    TEST_TRUE(runner, BB_Equals(a, (Obj*)b), "Mimic");

    DECREF(a);
    DECREF(b);
}