Ejemplo n.º 1
0
void t_mutable_string_copy(void) {
	mutable_string_t a;
	mutable_string_t b;

	CU_ASSERT_PTR_NOT_NULL(mutable_string_init(&a));
	CU_ASSERT_PTR_NOT_NULL(mutable_string_init(&b));

	CU_ASSERT_PTR_NOT_NULL(mutable_string_assign(&a, TEST_STR_1));
	CU_ASSERT_PTR_NOT_NULL(mutable_string_assign(&b, TEST_APPEND_WHOLE));

	CU_ASSERT_STRING_EQUAL(MUTSTR(&a), TEST_STR_1);
	CU_ASSERT_STRING_EQUAL(MUTSTR(&b), TEST_APPEND_WHOLE);

	CU_ASSERT_PTR_NOT_NULL(mutable_string_copy(&b, &a));

	CU_ASSERT_STRING_EQUAL(MUTSTR(&a), TEST_STR_1);
	CU_ASSERT_STRING_EQUAL(MUTSTR(&b), TEST_STR_1);

	mutable_string_free(&a);
	mutable_string_free(&b);
}
static void test_mutable_string_copy(void)
{
	MutableString* ms = mutable_string_new("Ryan");
	expect(ms != NULL);
	expect(ms->capacity == 5);
	expect(ms->length == 4);
	expect(ms->buffer != NULL);
	expect(str_equal("Ryan", ms->buffer));
	expect(ms->buffer[ms->length] == '\0');

	MutableString* copy;
	copy = mutable_string_copy(ms);

	expect(copy != NULL);
	expect(copy->capacity == 5);
	expect(copy->length == 4);
	expect(copy->buffer != NULL);
	expect(str_equal("Ryan", copy->buffer));
	expect(copy->buffer[copy->length] == '\0');

	mutable_string_free(ms);
	mutable_string_free(copy);

}