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
13cf6d16
Commit
13cf6d16
authored
Sep 14, 2019
by
Richard Bayerle
Browse files
Test 'lurch-fp-other' signal handler
parent
d82c8b49
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lurch_api.h
View file @
13cf6d16
...
...
@@ -90,4 +90,11 @@ void lurch_api_fp_get_handler(PurpleAccount * acc_p, void (*cb)(int32_t err, con
* If the whole devicelist is empty, i.e. the account is not an OMEMO user, the whole table will be NULL.
* Watch out as this is not a valid GHashTable.
*/
void
lurch_api_fp_list_handler
(
PurpleAccount
*
acc_p
,
void
(
*
cb
)(
int32_t
err
,
GHashTable
*
id_fp_table
,
void
*
user_data_p
),
void
*
user_data_p
);
\ No newline at end of file
void
lurch_api_fp_list_handler
(
PurpleAccount
*
acc_p
,
void
(
*
cb
)(
int32_t
err
,
GHashTable
*
id_fp_table
,
void
*
user_data_p
),
void
*
user_data_p
);
/**
* SIGNAL: lurch-fp-other
*
* Same as above, but for the specified contact.
*/
void
lurch_api_fp_other_handler
(
PurpleAccount
*
acc_p
,
const
char
*
contact_bare_jid
,
void
(
*
cb
)(
int32_t
err
,
GHashTable
*
id_fp_table
,
void
*
user_data_p
),
void
*
user_data_p
);
\ No newline at end of file
test/test_lurch_api.c
View file @
13cf6d16
...
...
@@ -401,7 +401,7 @@ static void test_lurch_api_fp_get_handler_err(void ** state) {
/**
* Mock callback that checks whether the given table is the same as the expected table passed through the user data.
*/
static
void
lurch_api_fp_
list_handl
er
_cb_mock
(
int32_t
err
,
GHashTable
*
id_fp_table
,
void
*
user_data_p
)
{
static
void
list_handl
ing
_cb_mock
(
int32_t
err
,
GHashTable
*
id_fp_table
,
void
*
user_data_p
)
{
check_expected
(
err
);
if
(
err
)
{
...
...
@@ -409,6 +409,12 @@ static void lurch_api_fp_list_handler_cb_mock(int32_t err, GHashTable * id_fp_ta
}
GHashTable
*
expected_table
=
(
GHashTable
*
)
user_data_p
;
if
(
!
expected_table
)
{
assert_null
(
id_fp_table
);
return
;
}
GHashTableIter
iter
;
gpointer
key
,
value
;
char
*
generated_fp
=
(
void
*
)
0
;
...
...
@@ -486,9 +492,9 @@ static void test_lurch_api_fp_list_handler(void ** state) {
g_hash_table_insert
(
expected_table
,
&
id_4223
,
mock_fp_4223
);
g_hash_table_insert
(
expected_table
,
&
id_1338
,
NULL
);
expect_value
(
lurch_api_fp_
list_handl
er
_cb_mock
,
err
,
EXIT_SUCCESS
);
expect_value
(
list_handl
ing
_cb_mock
,
err
,
EXIT_SUCCESS
);
lurch_api_fp_list_handler
(
NULL
,
lurch_api_fp_
list_handl
er
_cb_mock
,
expected_table
);
lurch_api_fp_list_handler
(
NULL
,
list_handl
ing
_cb_mock
,
expected_table
);
}
/**
...
...
@@ -497,7 +503,6 @@ static void test_lurch_api_fp_list_handler(void ** state) {
static
void
test_lurch_api_fp_list_handler_err
(
void
**
state
)
{
(
void
)
state
;
const
char
*
bare_jid
=
"me-testing@test.org"
;
const
char
*
test_jid
=
"me-testing@test.org/resource"
;
will_return_always
(
__wrap_purple_account_get_username
,
test_jid
);
...
...
@@ -517,8 +522,132 @@ static void test_lurch_api_fp_list_handler_err(void ** state) {
will_return
(
__wrap_axc_get_device_id
,
id_which_does_not_matter
);
will_return
(
__wrap_axc_get_device_id
,
EXIT_FAILURE
);
expect_value
(
lurch_api_fp_list_handler_cb_mock
,
err
,
EXIT_FAILURE
);
lurch_api_fp_list_handler
(
NULL
,
lurch_api_fp_list_handler_cb_mock
,
NULL
);
expect_value
(
list_handling_cb_mock
,
err
,
EXIT_FAILURE
);
lurch_api_fp_list_handler
(
NULL
,
list_handling_cb_mock
,
NULL
);
}
/**
* Generates the same table, but for a contact.
*/
static
void
test_lurch_api_fp_other_handler
(
void
**
state
)
{
(
void
)
state
;
const
char
*
own_jid
=
"me-testing@test.org/resource"
;
const
char
*
other_jid
=
"other-guy-testing@test.org/resource"
;
const
char
*
other_bare_jid
=
"other-guy-testing@test.org"
;
will_return
(
__wrap_purple_account_get_username
,
own_jid
);
char
*
devicelist
=
"<items node='urn:xmpp:omemo:0:devicelist'>"
"<item>"
"<list xmlns='urn:xmpp:omemo:0'>"
"<device id='4223' />"
"</list>"
"</item>"
"</items>"
;
omemo_devicelist
*
dl_p
;
omemo_devicelist_import
(
devicelist
,
other_jid
,
&
dl_p
);
will_return
(
__wrap_omemo_storage_user_devicelist_retrieve
,
dl_p
);
will_return
(
__wrap_omemo_storage_user_devicelist_retrieve
,
EXIT_SUCCESS
);
int
id_4223
=
4223
;
expect_string
(
__wrap_axc_key_load_public_addr
,
name
,
other_bare_jid
);
expect_value
(
__wrap_axc_key_load_public_addr
,
device_id
,
id_4223
);
char
*
mock_key_4223
=
"FAKE KEY 4223"
;
axc_buf
*
mock_key_buf_4223
=
axc_buf_create
((
unsigned
char
*
)
mock_key_4223
,
strlen
(
mock_key_4223
));
will_return
(
__wrap_axc_key_load_public_addr
,
mock_key_buf_4223
);
will_return
(
__wrap_axc_key_load_public_addr
,
1
);
expect_function_call
(
__wrap_lurch_util_fp_get_printable
);
expect_value
(
__wrap_lurch_util_fp_get_printable
,
key_buf_p
,
mock_key_buf_4223
);
char
*
mock_fp_4223
=
g_strdup
(
"FAKE FP 4223"
);
will_return
(
__wrap_lurch_util_fp_get_printable
,
mock_fp_4223
);
GHashTable
*
expected_table
=
g_hash_table_new
(
g_int_hash
,
g_int_equal
);
g_hash_table_insert
(
expected_table
,
&
id_4223
,
mock_fp_4223
);
expect_value
(
list_handling_cb_mock
,
err
,
EXIT_SUCCESS
);
lurch_api_fp_other_handler
(
NULL
,
other_bare_jid
,
list_handling_cb_mock
,
expected_table
);
}
/**
* Correctly handles a key retrieval error when building the table.
*/
static
void
test_lurch_api_fp_other_handler_keyerr
(
void
**
state
)
{
(
void
)
state
;
const
char
*
own_jid
=
"me-testing@test.org/resource"
;
const
char
*
other_jid
=
"other-guy-testing@test.org/resource"
;
const
char
*
other_bare_jid
=
"other-guy-testing@test.org"
;
will_return
(
__wrap_purple_account_get_username
,
own_jid
);
char
*
devicelist
=
"<items node='urn:xmpp:omemo:0:devicelist'>"
"<item>"
"<list xmlns='urn:xmpp:omemo:0'>"
"<device id='4223' />"
"</list>"
"</item>"
"</items>"
;
omemo_devicelist
*
dl_p
;
omemo_devicelist_import
(
devicelist
,
other_jid
,
&
dl_p
);
will_return
(
__wrap_omemo_storage_user_devicelist_retrieve
,
dl_p
);
will_return
(
__wrap_omemo_storage_user_devicelist_retrieve
,
EXIT_SUCCESS
);
int
id_4223
=
4223
;
expect_string
(
__wrap_axc_key_load_public_addr
,
name
,
other_bare_jid
);
expect_value
(
__wrap_axc_key_load_public_addr
,
device_id
,
id_4223
);
char
*
mock_key_4223
=
"FAKE KEY 4223"
;
axc_buf
*
mock_key_buf_4223
=
axc_buf_create
((
unsigned
char
*
)
mock_key_4223
,
strlen
(
mock_key_4223
));
will_return
(
__wrap_axc_key_load_public_addr
,
mock_key_buf_4223
);
will_return
(
__wrap_axc_key_load_public_addr
,
-
11
);
expect_value
(
list_handling_cb_mock
,
err
,
-
11
);
lurch_api_fp_other_handler
(
NULL
,
other_bare_jid
,
list_handling_cb_mock
,
NULL
);
}
/**
* Hands over NULL as the table if the contact's devicelist is empty.
*/
static
void
test_lurch_api_fp_other_handler_empty
(
void
**
state
)
{
(
void
)
state
;
const
char
*
own_jid
=
"me-testing@test.org/resource"
;
const
char
*
other_jid
=
"other-guy-testing@test.org/resource"
;
const
char
*
other_bare_jid
=
"other-guy-testing@test.org"
;
will_return
(
__wrap_purple_account_get_username
,
own_jid
);
char
*
devicelist
=
"<items node='urn:xmpp:omemo:0:devicelist'>"
"<item>"
"<list xmlns='urn:xmpp:omemo:0'>"
"</list>"
"</item>"
"</items>"
;
omemo_devicelist
*
dl_p
;
omemo_devicelist_import
(
devicelist
,
other_jid
,
&
dl_p
);
will_return
(
__wrap_omemo_storage_user_devicelist_retrieve
,
dl_p
);
will_return
(
__wrap_omemo_storage_user_devicelist_retrieve
,
EXIT_SUCCESS
);
expect_value
(
list_handling_cb_mock
,
err
,
EXIT_SUCCESS
);
lurch_api_fp_other_handler
(
NULL
,
other_bare_jid
,
list_handling_cb_mock
,
NULL
);
}
/**
* Calls the callback with the return code in case of an error.
*/
static
void
test_lurch_api_fp_other_handler_err
(
void
**
state
)
{
(
void
)
state
;
const
char
*
own_jid
=
"me-testing@test.org/resource"
;
const
char
*
other_bare_jid
=
"other-guy-testing@test.org"
;
will_return
(
__wrap_purple_account_get_username
,
own_jid
);
int
test_errcode
=
-
1234
;
will_return
(
__wrap_omemo_storage_user_devicelist_retrieve
,
NULL
);
will_return
(
__wrap_omemo_storage_user_devicelist_retrieve
,
test_errcode
);
expect_value
(
list_handling_cb_mock
,
err
,
test_errcode
);
lurch_api_fp_other_handler
(
NULL
,
other_bare_jid
,
list_handling_cb_mock
,
NULL
);
}
int
main
(
void
)
{
...
...
@@ -534,7 +663,11 @@ int main(void) {
cmocka_unit_test
(
test_lurch_api_fp_get_handler
),
cmocka_unit_test
(
test_lurch_api_fp_get_handler_err
),
cmocka_unit_test
(
test_lurch_api_fp_list_handler
),
cmocka_unit_test
(
test_lurch_api_fp_list_handler_err
)
cmocka_unit_test
(
test_lurch_api_fp_list_handler_err
),
cmocka_unit_test
(
test_lurch_api_fp_other_handler
),
cmocka_unit_test
(
test_lurch_api_fp_other_handler_keyerr
),
cmocka_unit_test
(
test_lurch_api_fp_other_handler_empty
),
cmocka_unit_test
(
test_lurch_api_fp_other_handler_err
)
};
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