static void test_write_cchr(ScmObj port, int type) { const char *expected = "?"; scm_char_t c = { .ascii = '?' }; SCM_REFSTK_INIT_REG(&port); TEST_ASSERT_EQUAL_INT(0, scm_write_cchr(c, SCM_ENC_SRC, port)); scm_close_port(port); if (type == FILEPORT) chk_file_contents(expected); else if (type == STRINGPORT) chk_string_port_contents(port, expected); } static void test_write_cchr__specify_closed_port__return_ERROR(ScmObj port, int type) { scm_char_t c = { .ascii = '?' }; SCM_REFSTK_INIT_REG(&port); scm_close_port(port); TEST_ASSERT_EQUAL_INT(-1, scm_write_cchr(c, SCM_ENC_SRC, port)); } static void test_write_char(ScmObj port, int type) { const char *expected = "?"; ScmObj c = SCM_OBJ_INIT; SCM_REFSTK_INIT_REG(&port, &c); c = scm_make_char(&(scm_char_t){ .ascii = '?' }, SCM_ENC_SRC); TEST_ASSERT_EQUAL_INT(0, scm_write_char(c, port)); scm_close_port(port); if (type == FILEPORT) chk_file_contents(expected); else if (type == STRINGPORT) chk_string_port_contents(port, expected); }
char * gdbscm_exception_message_to_string (SCM exception) { SCM port = scm_open_output_string (); SCM key, args; char *result; gdb_assert (gdbscm_is_exception (exception)); key = gdbscm_exception_key (exception); args = gdbscm_exception_args (exception); if (scm_is_eq (key, with_stack_error_symbol) /* Don't crash on a badly generated gdb:with-stack exception. */ && scm_is_pair (args) && scm_is_pair (scm_cdr (args))) { key = scm_car (args); args = scm_cddr (args); } gdbscm_print_exception_message (port, SCM_BOOL_F, key, args); result = gdbscm_scm_to_c_string (scm_get_output_string (port)); scm_close_port (port); return result; }
static void test_newline__specify_closed_port__return_ERROR(ScmObj port, int type) { SCM_REFSTK_INIT_REG(&port); scm_close_port(port); TEST_ASSERT_EQUAL_INT(-1, scm_newline(port)); }
static void test_read__specify_closed_port__return_ERROR(ScmObj port) { SCM_REFSTK_INIT_REG(&port); scm_close_port(port); TEST_ASSERT_SCM_NULL(scm_read(port)); }
static int port_close (void *cookie) { SCM port = PTR2SCM (cookie); scm_close_port (port); return PORT_OK; }
static void test_read_cchr__specify_closed_port__return_ERROR(ScmObj port) { scm_char_t actual; SCM_REFSTK_INIT_REG(&port); scm_close_port(port); TEST_ASSERT_EQUAL_INT(-1, scm_read_cchr(&actual, port)); }
// // These write/read scheme objects to scheme strings: // static SCM string_to_object (SCM str) { SCM port = scm_open_input_string (str); SCM obj = scm_read (port); scm_close_port (port); return obj; }
static void test_display__specify_closed_port__return_ERROR(ScmObj port, int type) { ScmObj o = SCM_OBJ_INIT; SCM_REFSTK_INIT_REG(&port, &o); o = scm_make_string_from_cstr("hello", SCM_ENC_SRC); scm_close_port(port); TEST_ASSERT_EQUAL_INT(-1, scm_display(o, port)); }
static void test_newline(ScmObj port, int type) { const char *expected = "\n"; SCM_REFSTK_INIT_REG(&port); TEST_ASSERT_EQUAL_INT(0, scm_newline(port)); scm_close_port(port); if (type == FILEPORT) chk_file_contents(expected); else if (type == STRINGPORT) chk_string_port_contents(port, expected); }
static void test_display__write_NULL(ScmObj port, int type) { const char *expected = "#<INTERNAL-NULL-VALUE 0>"; SCM_REFSTK_INIT_REG(&port); TEST_ASSERT_EQUAL_INT(0, scm_display(SCM_OBJ_NULL, port)); scm_close_port(port); if (type == FILEPORT) chk_file_contents(expected); else if (type == STRINGPORT) chk_string_port_contents(port, expected); }
static void test_write_shared(ScmObj port, int type) { const char *expected = "\"hello\""; ScmObj o = SCM_OBJ_INIT; SCM_REFSTK_INIT_REG(&port, &o); o = scm_make_string_from_cstr("hello", SCM_ENC_SRC); TEST_ASSERT_EQUAL_INT(0, scm_write_shared(o, port)); scm_close_port(port); if (type == FILEPORT) chk_file_contents(expected); else if (type == STRINGPORT) chk_string_port_contents(port, expected); }
static void test_display__write_shared_structure(ScmObj port, int type) { const char *expected = "#0=(#t . #0#)"; ScmObj o = SCM_OBJ_INIT; SCM_REFSTK_INIT_REG(&port, &o); o = scm_cons(SCM_TRUE_OBJ, SCM_FALSE_OBJ); scm_set_cdr(o, o); TEST_ASSERT_EQUAL_INT(0, scm_display(o, port)); scm_close_port(port); if (type == FILEPORT) chk_file_contents(expected); else if (type == STRINGPORT) chk_string_port_contents(port, expected); }