Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Librem5
lurch
Commits
02fb4308
Commit
02fb4308
authored
Jul 15, 2019
by
Richard Bayerle
Browse files
Test 'lurch-id-remove' signal handler
parent
640c1ade
Changes
3
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
02fb4308
...
...
@@ -166,7 +166,9 @@ $(BDIR)/test_lurch_api: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(BDIR)/test_lurch_
$(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
=
axc_get_device_id
\
-Wl
,--wrap
=
jabber_pep_publish
\
-Wl
,--wrap
=
purple_account_get_connection
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)
...
...
src/lurch_api.h
View file @
02fb4308
...
...
@@ -52,4 +52,11 @@ typedef enum {
* 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
);
\ No newline at end of file
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
);
\ No newline at end of file
test/test_lurch_api.c
View file @
02fb4308
...
...
@@ -4,6 +4,7 @@
#include
<cmocka.h>
#include
<purple.h>
#include
"jabber.h"
#include
"axc.h"
#include
"libomemo.h"
...
...
@@ -39,6 +40,21 @@ int __wrap_axc_get_device_id(axc_context * ctx_p, uint32_t * id_p) {
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
();
}
void
lurch_api_id_list_handler_cb_mock
(
int32_t
err
,
GList
*
id_list
,
void
*
user_data_p
)
{
check_expected
(
err
);
...
...
@@ -117,10 +133,81 @@ static void test_lurch_api_id_list_handler_error(void ** state) {
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
);
}
/**
* Fail when the device ID to remove is not in the own devicelist.
*/
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
);
}
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_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
)
};
return
cmocka_run_group_tests_name
(
"lurch_api"
,
tests
,
NULL
,
NULL
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment