Ejemplo n.º 1
0
TEST(TestHarness_c, cpputest_malloc_out_of_memory)
{
	cpputest_malloc_set_out_of_memory();
	CHECK(0 == cpputest_malloc(100));

	cpputest_malloc_set_not_out_of_memory();
	void * mem = cpputest_malloc(100);
	CHECK(0 != mem);
	cpputest_free(mem);
}
Ejemplo n.º 2
0
TEST(TestHarness_c, count_mallocs)
{
	cpputest_malloc_count_reset();
	void * m1 = cpputest_malloc(10);
	void * m2 = cpputest_malloc(11);
	void * m3 = cpputest_malloc(12);
	cpputest_free(m1);
	cpputest_free(m2);
	cpputest_free(m3);
	LONGS_EQUAL(3, cpputest_malloc_get_count());
}
Ejemplo n.º 3
0
TEST(TestHarness_c, cpputest_malloc_out_of_memory_after_n_mallocs)
{
	cpputest_malloc_set_out_of_memory_countdown(3);
	void * m1 = cpputest_malloc(10);
	void * m2 = cpputest_malloc(11);
	void * m3 = cpputest_malloc(12);
	CHECK(m1);
	CHECK(m2);
	POINTERS_EQUAL(0, m3);
	cpputest_malloc_set_not_out_of_memory();
	cpputest_free(m1);
	cpputest_free(m2);
}
Ejemplo n.º 4
0
TEST(TestHarness_c, cpputest_malloc_out_of_memory_after_n_mallocs)
{
    cpputest_malloc_set_out_of_memory_countdown(3);
    void * m1 = cpputest_malloc(10);
    void * m2 = cpputest_malloc(11);
    void * m3 = cpputest_malloc(12);
    CHECK(m1 != NULLPTR);
    CHECK(m2 != NULLPTR);
    CHECK(m3 == NULLPTR);
    cpputest_malloc_set_not_out_of_memory();
    cpputest_free(m1);
    cpputest_free(m2);
}
Ejemplo n.º 5
0
TEST(TestHarness_c, cpputest_malloc_out_of_memory_after_0_mallocs)
{
	cpputest_malloc_set_out_of_memory_countdown(0);
	void * m1 = cpputest_malloc(10);
	CHECK(m1 == 0);
	cpputest_malloc_set_not_out_of_memory();
}
TEST(BasicBehavior, freeInvalidatesMemory)
{
	unsigned char* memory = (unsigned char*) cpputest_malloc(sizeof(unsigned char));
	*memory = 0xAD;
	cpputest_free(memory);
	CHECK(*memory != 0xAD);
}
Ejemplo n.º 7
0
TEST(TestHarness_c, cpputest_realloc_larger)
{
	const char* number_string = "123456789";

	char* mem1 = (char*) cpputest_malloc(10);

	PlatformSpecificStrCpy(mem1, number_string);
	CHECK(mem1 != 0);

	char* mem2 = (char*) cpputest_realloc(mem1, 1000);

	CHECK(mem2 != 0);
	STRCMP_EQUAL(number_string, mem2);

	cpputest_free(mem2);
}
Ejemplo n.º 8
0
TEST(TestHarness_c, cpputest_realloc_larger)
{
    const char* number_string = "123456789";

    char* mem1 = (char*) cpputest_malloc(10);

    SimpleString::StrNCpy(mem1, number_string, 10);

    CHECK(mem1 != NULLPTR);

    char* mem2 = (char*) cpputest_realloc(mem1, 1000);

    CHECK(mem2 != NULLPTR);
    STRCMP_EQUAL(number_string, mem2);

    cpputest_free(mem2);
}