Commit 143c5ff5 authored by Andrea Schaefer's avatar Andrea Schaefer
Browse files

Merge branch 'dev' of https://github.com/gkdr/lurch into gkdr-changes

parents 9075d9b4 527bb6cc
Pipeline #28556 passed with stages
in 2 minutes and 1 second
......@@ -11,10 +11,10 @@ build_script:
- sh: make
test_script:
- sh: CMOCKA_MESSAGE_OUTPUT=XML CMOCKA_XML_FILE=build/cmocka_results.xml make test
- sh: CMOCKA_MESSAGE_OUTPUT=XML CMOCKA_XML_FILE=build/cmocka_results_%g.xml make test --ignore-errors
after_test:
- sh: curl -v -F "file=@$APPVEYOR_BUILD_FOLDER/build/cmocka_results.xml" "https://ci.appveyor.com/api/testresults/junit/$APPVEYOR_JOB_ID"
- sh: find build/ -type f -name *.xml -exec curl -v -F "file=@$APPVEYOR_BUILD_FOLDER/{}" "https://ci.appveyor.com/api/testresults/junit/$APPVEYOR_JOB_ID" \;
- sh: bash <(curl -s https://codecov.io/bash) -g test/ -B $APPVEYOR_REPO_BRANCH -b $APPVEYOR_BUILD_VERSION
artifacts:
......
......@@ -58,13 +58,7 @@ PLUGIN_CPPFLAGS=-DPURPLE_PLUGINS
# -D_BSD_SOURCE can be removed once nobody uses glibc <= 2.18 any more
CPPFLAGS += -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE
LDFLAGS += -ldl -lm $(PKGCFG_L) $(LJABBER) -Wl,-rpath,$(PURPLE_PLUGIN_DIR)
LDFLAGS_T=$(LDFLAGS) -lpurple -lcmocka \
-Wl,--wrap=purple_user_dir \
-Wl,--wrap=purple_prefs_get_bool \
-Wl,--wrap=purple_prefs_get_int \
-Wl,--wrap=purple_debug_error \
-Wl,--wrap=purple_debug_info \
-Wl,--wrap=purple_debug_misc \
LDFLAGS_T=$(LDFLAGS) -lpurple -lcmocka
### directories
#
......@@ -95,6 +89,7 @@ OBJECTS := $(patsubst $(SDIR)/%.c, $(BDIR)/%.o, $(SOURCES))
OBJECTS_W_COVERAGE := $(patsubst $(SDIR)/%.c, $(BDIR)/%_w_coverage.o, $(SOURCES))
TEST_SOURCES := $(wildcard $(TDIR)/test_*.c)
TEST_OBJECTS := $(patsubst $(TDIR)/test_%.c, $(BDIR)/test_%.o, $(TEST_SOURCES))
TEST_TARGETS := $(patsubst $(TDIR)/test_%.c, $(BDIR)/test_%, $(TEST_SOURCES))
VENDOR_LIBS=$(LOMEMO_PATH) $(AXC_PATH) $(AX_PATH)
......@@ -157,9 +152,29 @@ tarball: | clean-all $(BDIR)
mv $(TARBALL_FILE_NAME) $(TARBALL_DIR_NAME)/
mv $(TARBALL_DIR_NAME) $(BDIR)/
test: $(TEST_OBJECTS) $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS)
$(CC) $(CFLAGS) $(CPPFLAGS) -O0 --coverage $^ $(PURPLE_DIR)/libjabber.so.0 -o $(BDIR)/$@ $(LDFLAGS_T)
-$(BDIR)/$@ 2>&1 | grep -Ev ".*CRITICAL.*" | tr -s '\n' # filter annoying and irrelevant glib output
$(BDIR)/test_lurch_util: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(BDIR)/test_lurch_util.o
$(CC) $(CFLAGS) $(CPPFLAGS) -O0 --coverage $^ $(PURPLE_DIR)/libjabber.so.0 -o $@ $(LDFLAGS_T) \
-Wl,--wrap=purple_user_dir \
-Wl,--wrap=purple_prefs_get_bool \
-Wl,--wrap=purple_prefs_get_int \
-Wl,--wrap=purple_debug_error \
-Wl,--wrap=purple_debug_info \
-Wl,--wrap=purple_debug_misc \
-Wl,--wrap=purple_base16_encode_chunked
bash -c "set -o pipefail; $@ 2>&1 | grep -Ev ".*CRITICAL.*" | tr -s '\n'" # filter annoying and irrelevant glib output
$(BDIR)/test_lurch_api: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(BDIR)/test_lurch_api.o
$(CC) $(CFLAGS) $(CPPFLAGS) -O0 --coverage $^ $(PURPLE_DIR)/libjabber.so.0 -o $@ $(LDFLAGS_T) \
-Wl,--wrap=purple_account_get_username \
-Wl,--wrap=omemo_storage_user_devicelist_retrieve \
-Wl,--wrap=axc_get_device_id \
-Wl,--wrap=jabber_pep_publish \
-Wl,--wrap=purple_account_get_connection \
-Wl,--wrap=omemo_storage_chatlist_delete \
-Wl,--wrap=omemo_storage_chatlist_save
bash -c "set -o pipefail; $@ 2>&1 | grep -Ev ".*CRITICAL.*" | tr -s '\n'" # filter annoying and irrelevant glib output
test: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(TEST_TARGETS)
coverage: test
gcovr -r . --html --html-details -o build/coverage.html
......
......@@ -2142,7 +2142,6 @@ static PurpleCmdRet lurch_cmd_func(PurpleConversation * conv_p,
uint32_t id = 0;
uint32_t remove_id = 0;
axc_buf * key_buf_p = (void *) 0;
gchar * fp = (void *) 0;
char * fp_printable = (void *) 0;
omemo_devicelist * own_dl_p = (void *) 0;
omemo_devicelist * other_dl_p = (void *) 0;
......@@ -2302,8 +2301,7 @@ static PurpleCmdRet lurch_cmd_func(PurpleConversation * conv_p,
goto cleanup;
}
fp = purple_base16_encode_chunked(axc_buf_get_data(key_buf_p), axc_buf_get_len(key_buf_p));
fp_printable = lurch_util_fp_get_printable(fp);
fp_printable = lurch_util_fp_get_printable(key_buf_p);
msg = g_strdup_printf("This device's fingerprint is:\n%s\n"
"You should make sure that your conversation partner gets displayed the same for this device.", fp_printable);
} else if (!g_strcmp0(args[2], "conv")) {
......@@ -2314,8 +2312,7 @@ static PurpleCmdRet lurch_cmd_func(PurpleConversation * conv_p,
goto cleanup;
}
fp = purple_base16_encode_chunked(axc_buf_get_data(key_buf_p), axc_buf_get_len(key_buf_p));
fp_printable = lurch_util_fp_get_printable(fp);
fp_printable = lurch_util_fp_get_printable(key_buf_p);
temp_msg_1 = g_strdup_printf("The devices participating in this conversation and their fingerprints are as follows:\n"
"This device's (%s:%i) fingerprint:\n%s\n", uname, id, fp_printable);
......@@ -2337,9 +2334,7 @@ static PurpleCmdRet lurch_cmd_func(PurpleConversation * conv_p,
continue;
}
g_free(fp);
fp = purple_base16_encode_chunked(axc_buf_get_data(key_buf_p), axc_buf_get_len(key_buf_p));
fp_printable = lurch_util_fp_get_printable(fp);
fp_printable = lurch_util_fp_get_printable(key_buf_p);
axc_buf_free(key_buf_p);
key_buf_p = (void *) 0;
......@@ -2371,9 +2366,7 @@ static PurpleCmdRet lurch_cmd_func(PurpleConversation * conv_p,
continue;
}
g_free(fp);
fp = purple_base16_encode_chunked(axc_buf_get_data(key_buf_p), axc_buf_get_len(key_buf_p));
fp_printable = lurch_util_fp_get_printable(fp);
fp_printable = lurch_util_fp_get_printable(key_buf_p);
axc_buf_free(key_buf_p);
key_buf_p = (void *) 0;
......@@ -2475,7 +2468,6 @@ cleanup:
axc_context_destroy_all(axc_ctx_p);
g_free(msg);
axc_buf_free(key_buf_p);
g_free(fp);
g_free(fp_printable);
omemo_devicelist_destroy(own_dl_p);
omemo_devicelist_destroy(other_dl_p);
......
......@@ -190,7 +190,6 @@ void lurch_api_fp_get_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, con
char * uname = (void *) 0;
axc_context * axc_ctx_p = (void *) 0;
axc_buf * key_buf_p = (void *) 0;
gchar * fp = (void *) 0;
char * fp_printable = (void *) 0;
uname = lurch_util_uname_strip(purple_account_get_username(acc_p));
......@@ -207,20 +206,18 @@ void lurch_api_fp_get_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, con
goto cleanup;
}
fp = purple_base16_encode_chunked(axc_buf_get_data(key_buf_p), axc_buf_get_len(key_buf_p));
fp_printable = lurch_util_fp_get_printable(fp);
fp_printable = lurch_util_fp_get_printable(key_buf_p);
cleanup:
cb(ret_val, fp_printable, user_data_p);
g_free(fp_printable);
g_free(fp);
axc_buf_free(key_buf_p);
axc_context_destroy_all(axc_ctx_p);
}
/**
* Given a list of IDs, retrieves the public keys from the libsignal sessions and creates hash table with ID to fingerprint pairs.
* Given a list of IDs, retrieves the public keys from the libsignal sessions and creates a hash table with ID to fingerprint pairs.
* If there is an entry in the devicelist, but no session yet, the fingerprint cannot be retrieved this way and the value will be NULL.
* g_hash_table_destroy() the table when done with it.
*/
......@@ -230,7 +227,6 @@ static int32_t lurch_api_fp_create_table(const char * jid, axc_context * axc_ct
const GList * curr_p = (void *) 0;
uint32_t curr_device_id = 0;
axc_buf * key_buf_p = (void *) 0;
gchar * fp = (void *) 0;
id_fp_table = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, g_free);
......@@ -247,13 +243,10 @@ static int32_t lurch_api_fp_create_table(const char * jid, axc_context * axc_ct
continue;
}
fp = purple_base16_encode_chunked(axc_buf_get_data(key_buf_p), axc_buf_get_len(key_buf_p));
(void) g_hash_table_insert(id_fp_table, curr_p->data, lurch_util_fp_get_printable(fp));
(void) g_hash_table_insert(id_fp_table, curr_p->data, lurch_util_fp_get_printable(key_buf_p));
axc_buf_free(key_buf_p);
key_buf_p = (void *) 0;
g_free(fp);
fp = (void *) 0;
ret_val = 0;
}
......@@ -276,7 +269,6 @@ void lurch_api_fp_list_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, GH
axc_context * axc_ctx_p = (void *) 0;
GHashTable * id_fp_table = (void *) 0;
axc_buf * key_buf_p = (void *) 0;
gchar * fp = (void *) 0;
ret_val = lurch_api_id_list_get_own(acc_p, &own_id_list);
if (ret_val) {
......@@ -306,10 +298,7 @@ void lurch_api_fp_list_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, GH
goto cleanup;
}
fp = purple_base16_encode_chunked(axc_buf_get_data(key_buf_p), axc_buf_get_len(key_buf_p));
(void) g_hash_table_insert(id_fp_table, own_id_list->data, lurch_util_fp_get_printable(fp));
g_free(fp);
fp = (void *) 0;
(void) g_hash_table_insert(id_fp_table, own_id_list->data, lurch_util_fp_get_printable(key_buf_p));
cleanup:
cb(ret_val, id_fp_table, user_data_p);
......@@ -319,7 +308,6 @@ cleanup:
axc_context_destroy_all(axc_ctx_p);
g_hash_table_destroy(id_fp_table);
axc_buf_free(key_buf_p);
g_free(fp);
}
// returns NULL as hash table if devicelist is empty
......
......@@ -43,4 +43,34 @@ typedef enum {
* - Emit the signal using the plugin system handle as the instance and pass the necessary data.
* If you do it wrong, there will be no compiler errors and the pointers are gibberish, so take care.
* You can easily get the plugin system handle anywhere by calling purple_plugins_get_handle().
*/
\ No newline at end of file
*/
/**
* SIGNAL: lurch-id-list
*
* Gets the specified account's OMEMO devicelist and passes it to the callback as a GList containing uint32_t *.
* To access the actual ID, cast the data member to a uint32_t * and dereference it.
* This device's ID will be the first item in the list.
*/
void lurch_api_id_list_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, GList * id_list, void * user_data_p), void * user_data_p);
/**
* SIGNAL: lurch-id-remove
*
* Removes the specified OMEMO device ID from the specified account's devicelist.
*/
void lurch_api_id_remove_handler(PurpleAccount * acc_p, uint32_t device_id, void (*cb)(int32_t err, void * user_data_p), void * user_data_p);
/**
* SIGNAL: lurch-enable-im
*
* Enables OMEMO for the specified contact.
*/
void lurch_api_enable_im_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, void * user_data_p), void * user_data_p);
/**
* SIGNAL: lurch-disable-im
*
* Disables OMEMO for the specified contact.
*/
void lurch_api_disable_im_handler(PurpleAccount * acc_p, const char * contact_bare_jid, void (*cb)(int32_t err, void * user_data_p), void * user_data_p);
\ No newline at end of file
......@@ -127,27 +127,40 @@ char * lurch_util_uname_get_db_fn(const char * uname, const char * which) {
return g_strconcat(purple_user_dir(), "/", uname, "_", which, LURCH_DB_SUFFIX, NULL);
}
char * lurch_util_fp_get_printable(const char * fp) {
char * lurch_util_fp_get_printable(axc_buf * key_buf_p) {
gchar * fp = (void *) 0;
char ** split = (void *) 0;
const size_t split_len = 32;
const size_t fp_parts_len = 32;
char * printable = (void *) 0;
const size_t printable_len = 72;
if (!key_buf_p) {
purple_debug_warning("lurch", "%s: Key buffer is null, aborting\n", __func__);
goto cleanup;
}
fp = purple_base16_encode_chunked(axc_buf_get_data(key_buf_p), axc_buf_get_len(key_buf_p));
if (!fp || strlen(fp) != 98) {
return (void *) 0;
purple_debug_warning("lurch", "%s: Unexpected fingerprint length, aborting\n", __func__);
goto cleanup;
}
split = g_strsplit(fp, ":", 0);
// first part is dismissed for display
split = g_strsplit(fp, ":", fp_parts_len + 1);
printable = g_malloc0(printable_len);
for (int i = 1; i <= split_len; i++) {
for (int i = 1; i <= fp_parts_len; i++) {
g_strlcat(printable, split[i], printable_len);
if (i % 4 == 0 && i != split_len) {
if (i % 4 == 0 && i != fp_parts_len) {
g_strlcat(printable, " ", printable_len);
}
}
cleanup:
g_free(fp);
g_strfreev(split);
return printable;
}
\ No newline at end of file
}
......@@ -44,7 +44,7 @@ char * lurch_util_uname_get_db_fn(const char * uname, const char * which);
* Creates a fingerprint which resembles the one displayed by Conversations etc.
* Also useful for avoiding the smileys produced by ':d'...
*
* @param fp The fingerprint string as returned by purple_base16_encode_chunked
* @param key_buf_p The buffer containing the public key data.
* @return A newly allocated string which contains the fingerprint in printable format, or NULL. g_free() when done.
*/
char * lurch_util_fp_get_printable(const char * fp);
\ No newline at end of file
char * lurch_util_fp_get_printable(axc_buf * key_buf_p);
\ No newline at end of file
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <purple.h>
#include "jabber.h"
#include "axc.h"
#include "libomemo.h"
#include "../src/lurch_api.h"
char * __wrap_purple_account_get_username(PurpleAccount * acc_p) {
char * username;
username = mock_ptr_type(char *);
return username;
}
int __wrap_omemo_storage_user_devicelist_retrieve(const char * user, const char * db_fn, omemo_devicelist ** dl_pp) {
omemo_devicelist * dl_p;
dl_p = mock_ptr_type(omemo_devicelist *);
*dl_pp = dl_p;
int ret_val;
ret_val = mock_type(int);
return ret_val;
}
int __wrap_axc_get_device_id(axc_context * ctx_p, uint32_t * id_p) {
uint32_t id;
id = mock_type(uint32_t);
*id_p = id;
return EXIT_SUCCESS;
}
void __wrap_jabber_pep_publish(JabberStream * js_p, xmlnode * publish_node_p) {
xmlnode * item_node_p = xmlnode_get_child(publish_node_p, "item");
xmlnode * list_node_p = xmlnode_get_child(item_node_p, "list");
xmlnode * device_node_p = xmlnode_get_child(list_node_p, "device");
const char * device_id = xmlnode_get_attrib(device_node_p, "id");
check_expected(device_id);
check_expected_ptr(device_node_p->next);
}
PurpleConnection * __wrap_purple_account_get_connection(PurpleAccount * acc_p) {
function_called();
}
int __wrap_omemo_storage_chatlist_delete(const char * chat, const char * db_fn) {
check_expected(chat);
int ret_val;
ret_val = mock_type(int);
return ret_val;
}
int __wrap_omemo_storage_chatlist_save(const char * chat, const char * db_fn) {
check_expected(chat);
int ret_val;
ret_val = mock_type(int);
return ret_val;
}
void lurch_api_id_list_handler_cb_mock(int32_t err, GList * id_list, void * user_data_p) {
check_expected(err);
int32_t first_id = omemo_devicelist_list_data(id_list);
check_expected(first_id);
int32_t second_id = omemo_devicelist_list_data(id_list->next);
check_expected(second_id);
GList * third_item = id_list->next->next;
check_expected(third_item);
check_expected(user_data_p);
}
void lurch_api_id_list_handler_cb_err_mock(int32_t err, GList * id_list, void * user_data_p) {
check_expected(err);
check_expected(user_data_p);
}
/**
* Calls the supplied callback with the devicelist and the supplied user data, making sure the own ID comes first.
*/
static void test_lurch_api_id_list_handler(void ** state) {
(void) state;
const char * test_jid = "me-testing@test.org/resource";
will_return(__wrap_purple_account_get_username, test_jid);
char * devicelist = "<items node='urn:xmpp:omemo:0:devicelist'>"
"<item>"
"<list xmlns='urn:xmpp:omemo:0'>"
"<device id='4223' />"
"<device id='1337' />"
"</list>"
"</item>"
"</items>";
omemo_devicelist * dl_p;
omemo_devicelist_import(devicelist, test_jid, &dl_p);
will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p);
will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS);
uint32_t test_own_id = 1337;
will_return(__wrap_axc_get_device_id, test_own_id);
expect_value(lurch_api_id_list_handler_cb_mock, err, 0);
expect_value(lurch_api_id_list_handler_cb_mock, first_id, test_own_id);
expect_value(lurch_api_id_list_handler_cb_mock, second_id, 4223);
expect_value(lurch_api_id_list_handler_cb_mock, third_item, NULL);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_id_list_handler_cb_mock, user_data_p, test_user_data);
lurch_api_id_list_handler(NULL, lurch_api_id_list_handler_cb_mock, test_user_data);
}
/**
* When an error occurs, the supplied callback is called with the error code and the supplied user data.
*/
static void test_lurch_api_id_list_handler_error(void ** state) {
(void) state;
const char * test_jid = "me-testing@test.org/resource";
will_return(__wrap_purple_account_get_username, test_jid);
int test_errcode = -12345;
will_return(__wrap_omemo_storage_user_devicelist_retrieve, NULL);
will_return(__wrap_omemo_storage_user_devicelist_retrieve, test_errcode);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_id_list_handler_cb_err_mock, err, test_errcode);
expect_value(lurch_api_id_list_handler_cb_err_mock, user_data_p, test_user_data);
lurch_api_id_list_handler(NULL, lurch_api_id_list_handler_cb_err_mock, test_user_data);
}
static void lurch_api_id_remove_handler_cb_mock(int32_t err, void * user_data_p) {
check_expected(err);
check_expected(user_data_p);
}
/**
* Success case for removing a device ID from the own device list.
*/
static void test_lurch_api_id_remove_handler(void ** state) {
(void) state;
const char * test_jid = "me-testing@test.org/resource";
will_return(__wrap_purple_account_get_username, test_jid);
char * devicelist = "<items node='urn:xmpp:omemo:0:devicelist'>"
"<item>"
"<list xmlns='urn:xmpp:omemo:0'>"
"<device id='4223' />"
"<device id='1337' />"
"</list>"
"</item>"
"</items>";
omemo_devicelist * dl_p;
omemo_devicelist_import(devicelist, test_jid, &dl_p);
will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p);
will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS);
expect_function_call(__wrap_purple_account_get_connection);
expect_string(__wrap_jabber_pep_publish, device_id, "4223");
expect_value(__wrap_jabber_pep_publish, device_node_p->next, NULL);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_id_remove_handler_cb_mock, err, EXIT_SUCCESS);
expect_value(lurch_api_id_remove_handler_cb_mock, user_data_p, test_user_data);
lurch_api_id_remove_handler((void *) "ignored", 1337, lurch_api_id_remove_handler_cb_mock, test_user_data);
}
/**
* Fails when the device ID to remove is not in the own devicelist, and call the callback with the correct error code.
*/
static void test_lurch_api_id_remove_handler_id_not_in_list(void ** state) {
(void) state;
const char * test_jid = "me-testing@test.org/resource";
will_return(__wrap_purple_account_get_username, test_jid);
char * devicelist = "<items node='urn:xmpp:omemo:0:devicelist'>"
"<item>"
"<list xmlns='urn:xmpp:omemo:0'>"
"<device id='4223' />"
"<device id='1337' />"
"</list>"
"</item>"
"</items>";
omemo_devicelist * dl_p;
omemo_devicelist_import(devicelist, test_jid, &dl_p);
will_return(__wrap_omemo_storage_user_devicelist_retrieve, dl_p);
will_return(__wrap_omemo_storage_user_devicelist_retrieve, EXIT_SUCCESS);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_id_remove_handler_cb_mock, err, LURCH_ERR_DEVICE_NOT_IN_LIST);
expect_value(lurch_api_id_remove_handler_cb_mock, user_data_p, test_user_data);
lurch_api_id_remove_handler((void *) "ignored", 7331, lurch_api_id_remove_handler_cb_mock, test_user_data);
}
static void lurch_api_enable_im_handler_cb_mock(int32_t err, void * user_data_p) {
check_expected(err);
check_expected(user_data_p);
}
/**
* Deletes contact from 'the list' in the OMEMO DB when the signal is received, enabling OMEMO for this contact.
*/
static void test_lurch_api_enable_im_handler(void ** state) {
(void) state;
const char * contact_bare_jid = "contact_bare_jid";
const char * test_jid = "me-testing@test.org/resource";
will_return(__wrap_purple_account_get_username, test_jid);
expect_string(__wrap_omemo_storage_chatlist_delete, chat, contact_bare_jid);
will_return(__wrap_omemo_storage_chatlist_delete, EXIT_SUCCESS);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_enable_im_handler_cb_mock, err, EXIT_SUCCESS);
expect_value(lurch_api_enable_im_handler_cb_mock, user_data_p, test_user_data);
lurch_api_enable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_im_handler_cb_mock, test_user_data);
}
/**
* Calls the callback with the return code in case of an error.
*/
static void test_lurch_api_enable_im_handler_err(void ** state) {
(void) state;
const char * contact_bare_jid = "contact_bare_jid";
const char * test_jid = "me-testing@test.org/resource";
will_return(__wrap_purple_account_get_username, test_jid);
expect_string(__wrap_omemo_storage_chatlist_delete, chat, contact_bare_jid);
will_return(__wrap_omemo_storage_chatlist_delete, EXIT_FAILURE);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_enable_im_handler_cb_mock, err, EXIT_FAILURE);
expect_value(lurch_api_enable_im_handler_cb_mock, user_data_p, test_user_data);
lurch_api_enable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_enable_im_handler_cb_mock, test_user_data);
}
static void lurch_api_disable_im_handler_cb_mock(int32_t err, void * user_data_p) {
check_expected(err);
check_expected(user_data_p);
}
/**
* Saves contact to 'the list' in the OMEMO DB when the signal is received, disabling OMEMO for this contact.
*/
static void test_lurch_api_disable_im_handler(void ** state) {
(void) state;
const char * contact_bare_jid = "contact_bare_jid";
const char * test_jid = "me-testing@test.org/resource";
will_return(__wrap_purple_account_get_username, test_jid);
expect_string(__wrap_omemo_storage_chatlist_save, chat, contact_bare_jid);
will_return(__wrap_omemo_storage_chatlist_save, EXIT_SUCCESS);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_disable_im_handler_cb_mock, err, EXIT_SUCCESS);
expect_value(lurch_api_disable_im_handler_cb_mock, user_data_p, test_user_data);
lurch_api_disable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_disable_im_handler_cb_mock, test_user_data);
}
/**
* Calls the callback with the return code in case of an error.
*/
static void test_lurch_api_disable_im_handler_err(void ** state) {
(void) state;
const char * contact_bare_jid = "contact_bare_jid";
const char * test_jid = "me-testing@test.org/resource";
will_return(__wrap_purple_account_get_username, test_jid);
expect_string(__wrap_omemo_storage_chatlist_save, chat, contact_bare_jid);
will_return(__wrap_omemo_storage_chatlist_save, 12345);
char * test_user_data = "TEST USER DATA";
expect_value(lurch_api_disable_im_handler_cb_mock, err, 12345);
expect_value(lurch_api_disable_im_handler_cb_mock, user_data_p, test_user_data);
lurch_api_disable_im_handler((void *) "ignored", contact_bare_jid, lurch_api_disable_im_handler_cb_mock, test_user_data);
}
int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_lurch_api_id_list_handler),
cmocka_unit_test(test_lurch_api_id_list_handler_error),
cmocka_unit_test(test_lurch_api_id_remove_handler),
cmocka_unit_test(test_lurch_api_id_remove_handler_id_not_in_list),
cmocka_unit_test(test_lurch_api_enable_im_handler),
cmocka_unit_test(test_lurch_api_enable_im_handler_err),
cmocka_unit_test(test_lurch_api_disable_im_handler),
cmocka_unit_test(test_lurch_api_disable_im_handler_err)
};