#include <stdio.h> #include <errno.h> #include <kc.h> #include <kc_ut.h> #include <kc_assert.h> #include <kc_memory_entry.h> #include <kc_memory_entry_inner.h> // プロトタイプ宣言 static void test_memory_entry_new(void); static void test_memory_entry_new_alignment(void); static void test_memory_entry_new_realloc(void); static void test_memory_entry_set_null(void); /** * memory_entry 単体テストスイート */ void suite_memory_entry(void) { KcUt *ut = KcUt_get_instance(); ut->add(ut, UT_TESTCASE, "memory_entry new/delete", test_memory_entry_new); ut->add(ut, UT_TESTCASE, "memory_entry new (alignment)", test_memory_entry_new_alignment); ut->add(ut, UT_TESTCASE, "memory_entry new (realloc)", test_memory_entry_new_realloc); ut->add(ut, UT_TESTCASE, "memory_entry set (NULL Entry)", test_memory_entry_set_null); } /** * memory_entry 生成/破棄 * * @process KcMemoryEntry_new を用いて KcMemoryEntry を生成する。 * @result KcMemoryEntry が生成されること。各値が指定された値に設定されていること。 */ static void test_memory_entry_new(void) { KcMemoryEntry *entry = KcMemoryEntry_new( NULL, 0, 10, KC_MEMORY_ALLOCATED, "test_file", "test_func", 34); assert_not_null(entry); assert_equals(KC_MEMORY_ALLOCATED, entry->mark); assert_equals(10, entry->size); assert_equals("test_file", entry->file); assert_equals("test_func", entry->func); assert_equals(34, entry->line); KcMemoryEntry_delete(entry); // entry->mark には、KC_MEMORY_DELETED を格納してから破棄されているが、 // free 後のメモリ領域は、確認不可。 } /** * memory_entry 生成 (alignment指定) * * @process alignment を指定して KcMemoryEntry を生成する。 * @result KcMemoryEntry が生成されること。各値が指定された値に設定されていること。 */ static void test_memory_entry_new_alignment(void) { KcMemoryEntry *entry = KcMemoryEntry_new( NULL, sizeof(int), 10, KC_MEMORY_ALLOCATED, "test_file", "test_func", 34); assert_not_null(entry); assert_equals(KC_MEMORY_ALLOCATED, entry->mark); assert_equals(10, entry->size); assert_equals("test_file", entry->file); assert_equals("test_func", entry->func); assert_equals(34, entry->line); KcMemoryEntry_delete(entry); } /** * memory_entry 生成 (entry 指定) * * @process entry を指定して KcMemoryEntry を生成する。 * @result KcMemoryEntry が生成されること。各値が指定された値に更新されていること。 */ static void test_memory_entry_new_realloc(void) { KcMemoryEntry *entry = KcMemoryEntry_new( NULL, sizeof(int), 10, KC_MEMORY_ALLOCATED, "test_file", "test_func", 34); KcMemoryEntry *new_entry = KcMemoryEntry_new( entry, 0, 250, KC_MEMORY_ALLOCATED, "test_file2", "test_func2", 123); assert_not_null(new_entry); assert_equals(KC_MEMORY_ALLOCATED, new_entry->mark); assert_equals(250, new_entry->size); assert_equals("test_file2", new_entry->file); assert_equals("test_func2", new_entry->func); assert_equals(123, new_entry->line); KcMemoryEntry_delete(new_entry); } /** * memory_entry 設定 * * @process NULL を指定して、KcMemoryEntry_set を用いて各値を設定する。 * @result エントリが NULL のため、何も処理されないこと。 */ static void test_memory_entry_set_null(void) { KcMemoryEntry_set(NULL, 10, KC_MEMORY_ALLOCATED, "test_file", "test_func", 123); }