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
640c1ade
Commit
640c1ade
authored
Jul 09, 2019
by
Richard Bayerle
Browse files
Test 'lurch-id-list' signal handler
parent
0a72a461
Changes
3
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
640c1ade
...
...
@@ -163,7 +163,10 @@ $(BDIR)/test_lurch_util: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(BDIR)/test_lurch
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)
$(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
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 @
640c1ade
...
...
@@ -43,4 +43,13 @@ 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
);
\ No newline at end of file
test/test_lurch_api.c
View file @
640c1ade
...
...
@@ -3,15 +3,124 @@
#include
<setjmp.h>
#include
<cmocka.h>
static
void
test_dummy
(
void
**
state
)
{
#include
<purple.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
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
;
assert_false
(
0
);
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
);
}
int
main
(
void
)
{
const
struct
CMUnitTest
tests
[]
=
{
cmocka_unit_test
(
test_dummy
)
cmocka_unit_test
(
test_lurch_api_id_list_handler
),
cmocka_unit_test
(
test_lurch_api_id_list_handler_error
)
};
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