#include "../tdkpin_strings.h" #include #include static uint8_t g_source[0x10000]; static uint8_t g_destination[0x10000]; static Win16FarPtr g_disposed_string; static uint16_t g_disposed_bytes; static Win16FarPtr g_allocated_string; static uint16_t g_allocated_bytes; void borland_free_mem(Win16FarPtr block, uint16_t bytes) { g_disposed_string = block; g_disposed_bytes = bytes; } Win16FarPtr borland_get_mem(uint16_t bytes) { g_allocated_bytes = bytes; return g_allocated_string; } static Win16FarPtr source_at(uint16_t offset) { return win16_make_far_pointer(0x1111, offset); } static Win16FarPtr destination_at(uint16_t offset) { return win16_make_far_pointer(0x2222, offset); } static void reset_memory(void) { memset(g_source, 0xcc, sizeof(g_source)); memset(g_destination, 0xdd, sizeof(g_destination)); win16_reset_segment_bindings(); win16_bind_segment(0x1111, g_source, sizeof(g_source), true); win16_bind_segment(0x2222, g_destination, sizeof(g_destination), true); } static void test_length_end_and_copy(void) { reset_memory(); memcpy(&g_source[10], "Abc", 4); assert(borland_far_strlen(source_at(10)) == 3); assert(borland_far_strend(source_at(10)) == source_at(13)); assert(borland_far_strcpy(destination_at(20), source_at(10)) == destination_at(20)); assert(memcmp(&g_destination[20], "Abc", 4) == 0); g_destination[30] = 0xaa; (void)borland_far_strncpy(destination_at(30), source_at(10), 2); assert(g_destination[30] == 'A' && g_destination[31] == 'b'); assert(g_destination[32] == 0); memset(&g_destination[40], 0xaa, 8); (void)borland_far_strncpy(destination_at(40), source_at(10), 4); assert(memcmp(&g_destination[40], "Abc\0\0", 5) == 0); reset_memory(); assert(borland_far_strlen(source_at(0)) == 0xfffe); assert(borland_far_strend(source_at(0)) == source_at(0xfffe)); } static void test_memmove_and_concat(void) { reset_memory(); win16_fill_bytes(destination_at(20), 5, 0x5a); assert(memcmp(&g_destination[20], "ZZZZZ", 5) == 0); memcpy(&g_source[40], "copy", 4); borland_far_copy(destination_at(40), source_at(40), 4); assert(memcmp(&g_destination[40], "copy", 4) == 0); memcpy(&g_source[100], "abcdef", 6); (void)borland_far_memmove(source_at(102), source_at(100), 4); assert(memcmp(&g_source[100], "ababcd", 6) == 0); memcpy(&g_source[300], "cross", 5); (void)borland_far_memmove(destination_at(500), source_at(300), 5); assert(memcmp(&g_destination[500], "cross", 5) == 0); memcpy(&g_destination[100], "one", 4); memcpy(&g_source[200], "two", 4); assert(borland_far_strcat(destination_at(100), source_at(200)) == destination_at(100)); assert(memcmp(&g_destination[100], "onetwo", 7) == 0); } static void test_short_strings(void) { reset_memory(); g_source[20] = 3; memcpy(&g_source[21], "xyz", 3); (void)borland_short_to_c_string(destination_at(20), source_at(20)); assert(memcmp(&g_destination[20], "xyz", 4) == 0); memcpy(&g_source[40], "hello", 6); borland_c_to_short_string(destination_at(40), source_at(40)); assert(g_destination[40] == 5); assert(memcmp(&g_destination[41], "hello", 5) == 0); memset(&g_source[100], 'q', 260); g_source[360] = 0; borland_c_to_short_string(destination_at(100), source_at(100)); assert(g_destination[100] == 4); assert(memcmp(&g_destination[101], &g_source[100], 260) == 0); } static void test_compare_and_search(void) { reset_memory(); memcpy(&g_source[100], "aBcD", 5); memcpy(&g_destination[100], "Abce", 5); assert(borland_far_strnicmp(source_at(100), destination_at(100), 3) == 0); assert(borland_far_strnicmp(source_at(100), destination_at(100), 4) == -1); assert(borland_far_strchr(source_at(100), 'B') == source_at(101)); assert(borland_far_strchr(source_at(100), 0) == source_at(104)); memcpy(&g_source[200], "abca", 5); assert(borland_far_strrchr(source_at(200), 'a') == source_at(203)); assert(borland_far_strrchr(source_at(200), 0) == source_at(204)); assert(borland_far_strrchr(source_at(200), 'z') == 0); } static void test_dispose(void) { reset_memory(); g_disposed_string = 0; g_disposed_bytes = 0; borland_far_strdispose(0); assert(g_disposed_string == 0 && g_disposed_bytes == 0); memcpy(&g_source[100], "abc", 4); borland_far_strdispose(source_at(100)); assert(g_disposed_string == source_at(100)); assert(g_disposed_bytes == 4); } static void test_duplicate(void) { reset_memory(); g_allocated_string = destination_at(1000); g_allocated_bytes = 0; assert(borland_far_strdup(0) == 0); g_source[50] = 0; assert(borland_far_strdup(source_at(50)) == 0); memcpy(&g_source[100], "copy", 5); assert(borland_far_strdup(source_at(100)) == g_allocated_string); assert(g_allocated_bytes == 5); assert(memcmp(&g_destination[1000], "copy", 5) == 0); g_allocated_string = 0; assert(borland_far_strdup(source_at(100)) == 0); } int main(void) { test_length_end_and_copy(); test_memmove_and_concat(); test_short_strings(); test_compare_and_search(); test_dispose(); test_duplicate(); return 0; }