about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-02-17 21:52:42 +0000
committerJames Booth <boothj5@gmail.com>2014-02-17 21:52:42 +0000
commit82ad0cd306968ae6821127829e9d52f01932e82e (patch)
tree2f51ef1906072a784d57685d3d836307960260d8
parent6e58d95469d289058b4d5bf6325ade01caf40ca3 (diff)
downloadprofani-tty-82ad0cd306968ae6821127829e9d52f01932e82e.tar.gz
Added /otr myfp test
-rw-r--r--src/ui/ui.h2
-rw-r--r--tests/otr/mock_otr.c14
-rw-r--r--tests/otr/mock_otr.h3
-rw-r--r--tests/test_cmd_otr.c22
-rw-r--r--tests/test_cmd_otr.h1
-rw-r--r--tests/testsuite.c1
-rw-r--r--tests/ui/mock_ui.c26
-rw-r--r--tests/ui/mock_ui.h3
8 files changed, 66 insertions, 6 deletions
diff --git a/src/ui/ui.h b/src/ui/ui.h
index af254ae6..77d081ab 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -83,7 +83,7 @@ gboolean (*ui_current_win_is_otr)(void);
 void (*ui_current_set_otr)(gboolean value);
 char* (*ui_current_recipient)(void);
 void (*ui_current_print_line)(const char * const msg, ...);
-void (*ui_current_print_formatted_line)(const char show_chat, int attrs, const char * const msg, ...);
+void (*ui_current_print_formatted_line)(const char show_char, int attrs, const char * const msg, ...);
 void (*ui_current_error_line)(const char * const msg);
 void (*ui_current_page_off)(void);
 void (*ui_current_refresh)(void);
diff --git a/tests/otr/mock_otr.c b/tests/otr/mock_otr.c
index b8b43d9b..2fb2eab0 100644
--- a/tests/otr/mock_otr.c
+++ b/tests/otr/mock_otr.c
@@ -21,10 +21,10 @@ _mock_otr_libotr_version(void)
     return (char *)mock();
 }
 
-void
-mock_otr_libotr_version(void)
+static char *
+_mock_otr_get_my_fingerprint(void)
 {
-    otr_libotr_version = _mock_otr_libotr_version;
+    return (char *)mock();
 }
 
 void
@@ -37,5 +37,13 @@ otr_keygen_expect(ProfAccount *account)
 void
 otr_libotr_version_returns(char *version)
 {
+    otr_libotr_version = _mock_otr_libotr_version;
     will_return(_mock_otr_libotr_version, version);
 }
+
+void
+otr_get_my_fingerprint_returns(char *fingerprint)
+{
+    otr_get_my_fingerprint = _mock_otr_get_my_fingerprint;
+    will_return(_mock_otr_get_my_fingerprint, fingerprint);
+}
diff --git a/tests/otr/mock_otr.h b/tests/otr/mock_otr.h
index d9a6c492..e3908a64 100644
--- a/tests/otr/mock_otr.h
+++ b/tests/otr/mock_otr.h
@@ -5,7 +5,8 @@
 
 void otr_keygen_expect(ProfAccount *account);
 
-void mock_otr_libotr_version(void);
 void otr_libotr_version_returns(char *version);
 
+void otr_get_my_fingerprint_returns(char *fingerprint);
+
 #endif
diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c
index f4469ae5..9a731d12 100644
--- a/tests/test_cmd_otr.c
+++ b/tests/test_cmd_otr.c
@@ -254,7 +254,6 @@ void cmd_otr_libver_shows_libotr_version(void **state)
     char *version = "9.9.9";
     GString *message = g_string_new("Using libotr version ");
     g_string_append(message, version);
-    mock_otr_libotr_version();
     otr_libotr_version_returns(version);
 
     expect_cons_show(message->str);
@@ -367,6 +366,27 @@ void cmd_otr_myfp_shows_message_when_disconnecting(void **state)
     test_with_command_and_connection_status("myfp", JABBER_DISCONNECTING);
 }
 
+void cmd_otr_myfp_shows_my_fingerprint(void **state)
+{
+    char *fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE";
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    gchar *args[] = { "myfp", NULL };
+    mock_connection_status(JABBER_CONNECTED);
+    otr_get_my_fingerprint_returns(strdup(fingerprint));
+    mock_ui_current_print_formatted_line();
+
+    GString *message = g_string_new("Your OTR fingerprint: ");
+    g_string_append(message, fingerprint);
+
+    ui_current_print_formatted_line_expect('!', 0, message->str);
+
+    gboolean result = cmd_otr(args, *help);
+    assert_true(result);
+
+    g_string_free(message, TRUE);
+    free(help);
+}
+
 #else
 void cmd_otr_shows_message_when_otr_unsupported(void **state)
 {
diff --git a/tests/test_cmd_otr.h b/tests/test_cmd_otr.h
index e645867d..4fda3559 100644
--- a/tests/test_cmd_otr.h
+++ b/tests/test_cmd_otr.h
@@ -27,6 +27,7 @@ void cmd_otr_myfp_shows_message_when_undefined(void **state);
 void cmd_otr_myfp_shows_message_when_started(void **state);
 void cmd_otr_myfp_shows_message_when_connecting(void **state);
 void cmd_otr_myfp_shows_message_when_disconnecting(void **state);
+void cmd_otr_myfp_shows_my_fingerprint(void **state);
 #else
 void cmd_otr_shows_message_when_otr_unsupported(void **state);
 #endif
diff --git a/tests/testsuite.c b/tests/testsuite.c
index e1b95b2e..b49ff7b2 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -468,6 +468,7 @@ int main(int argc, char* argv[]) {
         unit_test(cmd_otr_myfp_shows_message_when_started),
         unit_test(cmd_otr_myfp_shows_message_when_connecting),
         unit_test(cmd_otr_myfp_shows_message_when_disconnecting),
+        unit_test(cmd_otr_myfp_shows_my_fingerprint),
 #else
         unit_test(cmd_otr_shows_message_when_otr_unsupported),
 #endif
diff --git a/tests/ui/mock_ui.c b/tests/ui/mock_ui.c
index 7175d2b9..af9d1a6b 100644
--- a/tests/ui/mock_ui.c
+++ b/tests/ui/mock_ui.c
@@ -159,6 +159,18 @@ void _stub_ui_current_refresh(void)
 {
 }
 
+static
+void _mock_ui_current_print_formatted_line(const char show_char, int attrs, const char * const msg, ...)
+{
+    check_expected(show_char);
+    check_expected(attrs);
+    va_list args;
+    va_start(args, msg);
+    vsnprintf(output, sizeof(output), msg, args);
+    check_expected(output);
+    va_end(args);
+}
+
 // bind mocks and stubs
 
 void
@@ -252,6 +264,12 @@ stub_ui_current_refresh(void)
     ui_current_refresh = _stub_ui_current_refresh;
 }
 
+void
+mock_ui_current_print_formatted_line(void)
+{
+    ui_current_print_formatted_line = _mock_ui_current_print_formatted_line;
+}
+
 // expectations
 
 void
@@ -368,3 +386,11 @@ ui_current_recipient_returns(char *jid)
 {
     will_return(_mock_ui_current_recipeint, jid);
 }
+
+void
+ui_current_print_formatted_line_expect(char show_char, int attrs, char *message)
+{
+    expect_value(_mock_ui_current_print_formatted_line, show_char, show_char);
+    expect_value(_mock_ui_current_print_formatted_line, attrs, attrs);
+    expect_string(_mock_ui_current_print_formatted_line, output, message);
+}
diff --git a/tests/ui/mock_ui.h b/tests/ui/mock_ui.h
index 3d264970..9cdd6b34 100644
--- a/tests/ui/mock_ui.h
+++ b/tests/ui/mock_ui.h
@@ -51,4 +51,7 @@ void ui_current_recipient_returns(char *jid);
 
 void stub_ui_current_refresh(void);
 
+void mock_ui_current_print_formatted_line(void);
+void ui_current_print_formatted_line_expect(char show_char, int attrs, char *message);
+
 #endif