From ba50414ac2acc3bdba3792e750c3a777e8a1e4b9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 16 Jul 2015 23:53:26 +0100 Subject: [PATCH] Debugging expect test --- tests/functionaltests/functionaltests.c | 7 +++++-- tests/functionaltests/proftest.c | 27 ++++++++++++++++++++----- tests/functionaltests/test_presence.c | 11 +++++++++- tests/functionaltests/test_presence.h | 1 + 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c index 2a979003..24818e3b 100644 --- a/tests/functionaltests/functionaltests.c +++ b/tests/functionaltests/functionaltests.c @@ -57,10 +57,12 @@ int main(int argc, char* argv[]) { init_prof_test, close_prof_test), */ + unit_test(expect_test), +/* + unit_test_setup_teardown(presence_online, init_prof_test, close_prof_test), -/* unit_test_setup_teardown(presence_online_with_message, init_prof_test, close_prof_test), @@ -117,7 +119,7 @@ int main(int argc, char* argv[]) { unit_test_setup_teardown(new_session_when_message_received_from_different_fulljid, init_prof_test, close_prof_test), -*/ + unit_test_setup_teardown(send_enable_carbons, init_prof_test, close_prof_test), @@ -127,6 +129,7 @@ int main(int argc, char* argv[]) { unit_test_setup_teardown(send_disable_carbons, init_prof_test, close_prof_test), +*/ }; return run_tests(all_tests); diff --git a/tests/functionaltests/proftest.c b/tests/functionaltests/proftest.c index 1ae17e1e..064f5192 100644 --- a/tests/functionaltests/proftest.c +++ b/tests/functionaltests/proftest.c @@ -1,5 +1,6 @@ #include #include +#include "glib/gstdio.h" #include #include @@ -130,6 +131,10 @@ prof_start(void) Tcl_Init(interp); Expect_Init(interp); + FILE *logp = fopen("./expout.log", "a"); + g_chmod("./expout.log", S_IRUSR | S_IWUSR); + exp_debugfile = logp; + // helper script sets terminal columns, avoids assertions failing // based on the test runner terminal size fd = exp_spawnl("sh", @@ -137,6 +142,7 @@ prof_start(void) "-c", "./tests/functionaltests/start_profanity.sh", NULL); + FILE *fp = fdopen(fd, "r+"); assert_true(fp != NULL); @@ -179,7 +185,10 @@ init_prof_test(void **state) assert_true(prof_output_exact("Word wrap disabled")); prof_input("/roster hide"); assert_true(prof_output_exact("Roster disabled")); - prof_input("/time off"); + prof_input("/time statusbar off"); + assert_true(prof_output_exact("Status bar time display disabled")); + prof_input("/time main off"); + assert_true(prof_output_exact("Time display disabled")); } void @@ -203,10 +212,18 @@ close_prof_test(void **state) void prof_input(char *input) { - GString *inp_str = g_string_new(input); - g_string_append(inp_str, "\r"); - write(fd, inp_str->str, inp_str->len); - g_string_free(inp_str, TRUE); + int i = 0; + for (i = 0; i < strlen(input); i++) { + write(fd, &input[i], 1); + } + prof_output_exact(input); + char *newline = "\r"; + write(fd, newline, 1); + +// GString *inp_str = g_string_new(input); +// g_string_append(inp_str, "\r"); +// write(fd, inp_str->str, inp_str->len); +// g_string_free(inp_str, TRUE); } int diff --git a/tests/functionaltests/test_presence.c b/tests/functionaltests/test_presence.c index cb2eacd3..89a7e177 100644 --- a/tests/functionaltests/test_presence.c +++ b/tests/functionaltests/test_presence.c @@ -11,6 +11,13 @@ #include "proftest.h" +void +expect_test(void **state) +{ + init_prof_test(state); + prof_input("0123456789"); +} + void presence_online(void **state) { @@ -23,8 +30,10 @@ presence_online(void **state) "" "" )); +// +// assert_true(prof_output_exact("Status set to online (priority 0)")); - assert_true(prof_output_exact("Status set to online (priority 0)")); + assert_true(1); } void diff --git a/tests/functionaltests/test_presence.h b/tests/functionaltests/test_presence.h index 0603732a..491c718a 100644 --- a/tests/functionaltests/test_presence.h +++ b/tests/functionaltests/test_presence.h @@ -1,3 +1,4 @@ +void expect_test(void **state); void presence_away(void **state); void presence_away_with_message(void **state); void presence_online(void **state);