Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix test compile warnings #33

Merged
merged 3 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- `gcc` can now be set from env like the rest of the tools. ([#30](https://github.com/gkdr/axc/pull/30))) (thanks, [@henry-nicolas](https://github.com/henry-nicolas) and Helmut Grohne!)
- Fix the build for users without libsignal-protocol-c installed system-wide ([#31](https://github.com/gkdr/axc/pull/31)) (thanks, [@hartwork](https://github.com/hartwork)!)
- The example code is runnable again, and some memory leaks ([#14](https://github.com/gkdr/axc/pull/14)) (thanks, [@fbrausse](https://github.com/fbrausse)!)
- Compiler warnings for test files.

### Infrastructure
- Cover Linux build by GitHub Actions CI ([#31](https://github.com/gkdr/axc/pull/31)) (thanks, [@hartwork](https://github.com/hartwork)!)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CPPFLAGS += -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE -D_D
CFLAGS += $(PKGCFG_C) -std=c11 -g -Wall -Wextra -Wpedantic \
-Wstrict-overflow -fno-strict-aliasing -funsigned-char \
-fno-builtin-memset -fstack-protector-strong -Wformat -Werror=format-security
TESTFLAGS=$(PKGCFG_C) -g -O0 --coverage -fstack-protector-strong -Wformat -Werror=format-security
TESTFLAGS=$(PKGCFG_C) -g -O0 --coverage -Wall -Wextra -Wpedantic -Wstrict-overflow -fstack-protector-strong -Wformat -Werror=format-security
LDFLAGS += -pthread -ldl $(PKGCFG_L) -lm
LDFLAGS_T= -lcmocka $(LDFLAGS)
PICFLAGS=-fPIC $(CFLAGS)
Expand Down
30 changes: 21 additions & 9 deletions test/test_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ int global_teardown(void ** state) {
}

int client_setup(void **state) {
(void) state;

ctx_global_p = (void *) 0;

assert_int_equal(axc_context_create(&ctx_global_p), 0);
Expand All @@ -58,6 +60,8 @@ int client_setup(void **state) {
}

int client_teardown(void ** state) {
(void) state;

axc_crypto_teardown();
axc_cleanup(ctx_global_p);
ctx_global_p = (void *) 0;
Expand Down Expand Up @@ -110,7 +114,8 @@ int client_setup_sessions(void ** state) {
ctx_a_p),
0);

axc_buf * msg_buf_p = axc_buf_create("hello", strlen("hello") + 1);
const char * data = "hello";
axc_buf * msg_buf_p = axc_buf_create((uint8_t *) data, strlen(data) + 1);
assert_ptr_not_equal(msg_buf_p, (void *) 0);

axc_buf * ct_buf_p;
Expand Down Expand Up @@ -201,6 +206,8 @@ void test_recursive_mutex_unlock(void **state){
}

void test_install_should_generate_necessary_data(void **state) {
(void) state;

assert_int_equal(axc_install(ctx_global_p), 0);

sqlite3 * db_p = (void *) 0;
Expand Down Expand Up @@ -250,11 +257,12 @@ void test_install_should_not_do_anything_if_already_initialiased(void **state) {
(void) state;

assert_int_equal(axc_install(ctx_global_p), 0);
int reg_id_1 = 0;

uint32_t reg_id_1 = 0;
assert_int_equal(axc_db_identity_get_local_registration_id(ctx_global_p, &reg_id_1), 0);
assert_int_not_equal(reg_id_1, 0);

int reg_id_2 = 0;
uint32_t reg_id_2 = 0;
assert_int_equal(axc_install(ctx_global_p), 0);
assert_int_equal(axc_db_identity_get_local_registration_id(ctx_global_p, &reg_id_2), 0);
assert_int_not_equal(reg_id_2, 0);
Expand All @@ -266,13 +274,14 @@ void test_install_should_reset_if_needed(void **state) {
(void) state;

assert_int_equal(axc_install(ctx_global_p), 0);
int reg_id_1 = 0;

uint32_t reg_id_1 = 0;
assert_int_equal(axc_db_identity_get_local_registration_id(ctx_global_p, &reg_id_1), 0);
assert_int_not_equal(reg_id_1, 0);

assert_int_equal(axc_db_init_status_set(0, ctx_global_p), 0);

int reg_id_2 = 0;
uint32_t reg_id_2 = 0;
assert_int_equal(axc_install(ctx_global_p), 0);
assert_int_equal(axc_db_identity_get_local_registration_id(ctx_global_p, &reg_id_2), 0);
assert_int_not_equal(reg_id_2, 0);
Expand Down Expand Up @@ -370,7 +379,8 @@ void test_session_exists_any(void ** state) {
ctx_a_p),
0);

axc_buf * msg_buf_p = axc_buf_create("hello", strlen("hello") + 1);
const char * data = "hello";
axc_buf * msg_buf_p = axc_buf_create((uint8_t *) data, strlen(data) + 1);
assert_ptr_not_equal(msg_buf_p, (void *) 0);

axc_buf * ct_buf_p;
Expand All @@ -394,7 +404,7 @@ void test_session_from_bundle_and_handle_prekey_message(void **state) {
(void) state;

axc_address addr_bob = {.name = "bob", .name_len = 3, .device_id = 0};
assert_int_equal(axc_db_identity_get_local_registration_id(ctx_b_p, &(addr_bob.device_id)), 0);
assert_int_equal(axc_db_identity_get_local_registration_id(ctx_b_p, (uint32_t *)&(addr_bob.device_id)), 0);
assert_int_equal(axc_session_exists_initiated(&addr_bob, ctx_a_p), 0);

uint32_t pre_key_id_bob = 10;
Expand Down Expand Up @@ -514,7 +524,8 @@ void test_session_exists_prekeys(void ** state) {

assert_int_equal(axc_session_exists_initiated(&addr_bob, ctx_a_p), 1);

axc_buf * msg_buf_p = axc_buf_create("hello", strlen("hello") + 1);
const char * data = "hello";
axc_buf * msg_buf_p = axc_buf_create((uint8_t *) data, strlen(data) + 1);
assert_ptr_not_equal(msg_buf_p, (void *) 0);

axc_buf * ct_buf_p;
Expand All @@ -538,7 +549,8 @@ void test_session_exists_prekeys(void ** state) {
axc_buf_free(ct_buf_p);
axc_buf_free(pt_buf_p);

msg_buf_p = axc_buf_create("hello 234", strlen("hello 234") + 1);
const char * other_data = "hello 234";
msg_buf_p = axc_buf_create((uint8_t *) other_data, strlen(other_data) + 1);
assert_ptr_not_equal(msg_buf_p, (void *) 0);

assert_int_equal(axc_message_encrypt_and_serialize(msg_buf_p, &addr_bob, ctx_a_p, &ct_buf_p), 0);
Expand Down
13 changes: 6 additions & 7 deletions test/test_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
sqlite3 * db_p;
sqlite3_stmt * pstmt_p;

//axc_settings settings = {.db_filename = "test/test.sqlite"};
char * db_filename = "test/test.sqlite";
axc_context * ctx_global_p;

Expand Down Expand Up @@ -51,6 +50,8 @@ int db_setup_internal(void **state) {
}

int db_setup(void **state) {
(void) state;

db_setup_internal((void *) 0);

assert_int_equal(axc_db_create(ctx_global_p), 0);
Expand Down Expand Up @@ -418,7 +419,8 @@ void test_db_session_contains_should_return_correct_values(void ** state) {
ctx_a_p),
0);

axc_buf * msg_buf_p = axc_buf_create("hello", strlen("hello") + 1);
const char * data = "hello";
axc_buf * msg_buf_p = axc_buf_create((uint8_t *)data, strlen(data) + 1);
assert_ptr_not_equal(msg_buf_p, (void *) 0);

axc_buf * ct_buf_p;
Expand Down Expand Up @@ -579,13 +581,10 @@ void test_db_pre_key_get_list(void ** state) {
void test_db_pre_key_get_max_id(void ** state) {
(void) state;

uint32_t id = 10;
int ret_val = axc_db_pre_key_get_max_id(ctx_global_p, &id);

assert_int_equal(axc_init(ctx_global_p), 0);
assert_int_equal(axc_install(ctx_global_p), 0);


uint32_t id = 10;
assert_int_equal(axc_db_pre_key_get_max_id(ctx_global_p, &id), 0);
assert_int_equal(id, AXC_PRE_KEYS_AMOUNT - 1); // ids start with 0
}
Expand Down Expand Up @@ -700,7 +699,7 @@ void test_db_identity_get_local_registration_id(void **state) {

assert_int_equal(axc_db_identity_set_local_registration_id(id, ctx_global_p), 0);

int result = 0;
uint32_t result = 0;
assert_int_equal(axc_db_identity_get_local_registration_id(ctx_global_p, &result), 0);
assert_int_equal(id, result);
}
Expand Down