Пример #1
0
static void test_empty_string(string_t *str)
{
	TEST_EXPECT(string_size(str) == 0);
	TEST_EXPECT(string_data(str) != 0);
	TEST_EXPECT(string_c_str(str) != 0);
	TEST_EXPECT(*string_c_str(str) == '\0');
}
Пример #2
0
int bcopy_01()
{
	BFILE* in;
	BFILE* out;
	int i = 0;

	in = bfopen("test.txt", "rb");
	TEST_EXPECT(in != NULL);
	out = bfopen("copy.txt", "wb");
	TEST_EXPECT(out != NULL);

	while (!bfeof(in))
	{
		bfputc(bfgetc(in), out);
		i++;
	}

	bfclose(in);
	bfclose(out);

	if (i == LENGTH_OF_TEST_FILE)
	{
		TEST_SUCCESS;
	}
	else
	{
		TEST_FAILURE("didn't copy all expected data (total bytes copied incorrect).");
	}
}
Пример #3
0
int bopen_01()
{
    BFILE* f;

    f = bfopen("nonexistant.blah", "rb");
    TEST_EXPECT(f == NULL);
    f = bfopen("test.txt", "rb");
    TEST_EXPECT(f != NULL);
    bfclose(f);

    TEST_SUCCESS;
}
Пример #4
0
static void check_join_equal(
	char const *left,
	char const *right,
	char const *joined)
{
	char *result = path_join(left, right);
	TEST_EXPECT(result);
	if (result)
	{
		TEST_EXPECT(!strcmp(result, joined));
	}
	free(result);
}
Пример #5
0
void test_string(void)
{
	string_t str;
	TEST_EXPECT(string_create(&str));
	test_empty_string(&str);

	string_clear(&str);
	test_empty_string(&str);

	string_destroy(&str);

	TEST_EXPECT(string_create(&str));
	test_empty_string(&str);
	string_destroy(&str);

	test_append_c_str();
}
Пример #6
0
static void test_append_c_str()
{
	string_t s;
	TEST_EXPECT(string_create(&s));
	TEST_EXPECT(string_append_c_str(&s, ""));
	TEST_EXPECT(!strcmp(string_c_str(&s), ""));
	TEST_EXPECT(string_size(&s) == 0);

	TEST_EXPECT(string_append_c_str(&s, "abc"));
	TEST_EXPECT(!strcmp(string_c_str(&s), "abc"));
	TEST_EXPECT(string_size(&s) == 3);

	TEST_EXPECT(string_append_c_str(&s, "123"));
	TEST_EXPECT(!strcmp(string_c_str(&s), "abc123"));
	TEST_EXPECT(string_size(&s) == 6);

	string_destroy(&s);
}
Пример #7
0
static void test_append_range()
{
	static char const * const str_0 = "abc";
	static char const * const str_1 = "12345";

	bool success;

	WS_GEN_VECTOR(v, char);
	WS_GEN_VECTOR_CREATE(v);

	TEST_EXPECT(WS_GEN_VECTOR_EMPTY(v));
	TEST_EXPECT(WS_GEN_VECTOR_SIZE(v) == 0);
	TEST_EXPECT(!memcmp(WS_GEN_VECTOR_DATA(v), "", 0));

	WS_GEN_VECTOR_APPEND_RANGE(v, str_0, str_0 + strlen(str_0), success);
	TEST_EXPECT(success);

	TEST_EXPECT(!WS_GEN_VECTOR_EMPTY(v));
	TEST_EXPECT(WS_GEN_VECTOR_SIZE(v) == 3);
	TEST_EXPECT(!memcmp(WS_GEN_VECTOR_DATA(v), str_0, 3));

	WS_GEN_VECTOR_APPEND_RANGE(v, str_1, str_1 + strlen(str_1), success);
	TEST_EXPECT(success);

	TEST_EXPECT(!WS_GEN_VECTOR_EMPTY(v));
	TEST_EXPECT(WS_GEN_VECTOR_SIZE(v) == 8);
	TEST_EXPECT(!memcmp(WS_GEN_VECTOR_DATA(v), "abc12345", 8));

	WS_GEN_VECTOR_DESTROY(v);
}
Пример #8
0
void test_generic_vector()
{
	bool success;

	WS_GEN_VECTOR(v, int);
	WS_GEN_VECTOR_CREATE(v);

	TEST_EXPECT(WS_GEN_VECTOR_SIZE(v) == 0);
	WS_GEN_VECTOR_PUSH_BACK(v, 2, success);
	TEST_EXPECT(success);

	TEST_EXPECT(WS_GEN_VECTOR_SIZE(v) == 1);
	TEST_EXPECT(WS_GEN_VECTOR_CAPACITY(v) >= 1);

	WS_GEN_VECTOR_PUSH_BACK(v, 3, success);
	TEST_EXPECT(success);

	TEST_EXPECT(WS_GEN_VECTOR_SIZE(v) == 2);
	TEST_EXPECT(WS_GEN_VECTOR_CAPACITY(v) >= 2);

	WS_GEN_VECTOR_PUSH_BACK(v, 5, success);
	TEST_EXPECT(success);

	TEST_EXPECT(WS_GEN_VECTOR_SIZE(v) == 3);
	TEST_EXPECT(WS_GEN_VECTOR_CAPACITY(v) >= 3);

	WS_GEN_VECTOR_PUSH_BACK(v, 7, success);
	TEST_EXPECT(success);

	TEST_EXPECT(WS_GEN_VECTOR_SIZE(v) == 4);
	TEST_EXPECT(WS_GEN_VECTOR_CAPACITY(v) >= 4);

	TEST_EXPECT(WS_GEN_VECTOR_DATA(v)[0] == 2);
	TEST_EXPECT(WS_GEN_VECTOR_DATA(v)[1] == 3);
	TEST_EXPECT(WS_GEN_VECTOR_DATA(v)[2] == 5);
	TEST_EXPECT(WS_GEN_VECTOR_DATA(v)[3] == 7);

	WS_GEN_VECTOR_DESTROY(v);

	test_append_range();
}