Skip to content

Commit

Permalink
Added a couple of tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeDP committed Jan 9, 2019
1 parent 4d74942 commit 7939ddf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module_ref should then return a new self_t* object, add it to a stack in module.
- [x] Use attribute format where needed
- [x] Use calloc where needed
- [x] Module register should avoid memleaks when it fails with NOMEM.
- [x] Added modules_ctx_loop test
- [x] Added module pubsub recv test

### Stack API
- [x] Add _clear function
Expand Down
3 changes: 3 additions & 0 deletions tests/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ int main(void) {
cmocka_unit_test(test_module_broadcast_wrong_size),
cmocka_unit_test(test_module_broadcast),

/* We have now 3 messages waiting for us (tell, publish, broadcast). Check. */
cmocka_unit_test(test_modules_ctx_loop),

/* Test module topic deregister */
cmocka_unit_test(test_deregister_topic_NULL_topic),
cmocka_unit_test(test_deregister_topic_NULL_self),
Expand Down
15 changes: 11 additions & 4 deletions tests/test_module.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "test_module.h"
#include <module/module.h>
#include <module/modules.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
Expand Down Expand Up @@ -352,7 +353,7 @@ void test_module_tell_wrong_size(void **state) {
void test_module_tell(void **state) {
(void) state; /* unused */

module_ret_code ret = module_tell(self, testSelf, "hi!", strlen("hi!"));
module_ret_code ret = module_tell(self, testSelf, "hi1!", strlen("hi!"));
assert_true(ret == MOD_OK);
}

Expand Down Expand Up @@ -394,7 +395,7 @@ void test_module_publish_wrong_size(void **state) {
void test_module_publish(void **state) {
(void) state; /* unused */

module_ret_code ret = module_publish(self, "topic", "hi!", strlen("hi!"));
module_ret_code ret = module_publish(self, "topic", "hi2!", strlen("hi!"));
assert_true(ret == MOD_OK);
}

Expand Down Expand Up @@ -422,7 +423,7 @@ void test_module_broadcast_wrong_size(void **state) {
void test_module_broadcast(void **state) {
(void) state; /* unused */

module_ret_code ret = module_broadcast(self, "hi!", strlen("hi!"));
module_ret_code ret = module_broadcast(self, "hi3!", strlen("hi!"));
assert_true(ret == MOD_OK);
}

Expand Down Expand Up @@ -479,7 +480,13 @@ static bool evaluate(void) {
}

static void recv(const msg_t *msg, const void *userdata) {

static int ctr = 0;
if (msg->is_pubsub && msg->pubsub_msg->type == USER) {
ctr++;
if (!strcmp((char *)msg->pubsub_msg->message, "hi3!")) {
modules_ctx_quit(CTX, ctr);
}
}
}

static void destroy(void) {
Expand Down
7 changes: 7 additions & 0 deletions tests/test_modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ void test_modules_ctx_loop_no_maxevents(void **state) {
module_ret_code ret = modules_ctx_loop_events(CTX, 0);
assert_false(ret == MOD_OK);
}

void test_modules_ctx_loop(void **state) {
(void) state; /* unused */

module_ret_code ret = modules_ctx_loop(CTX);
assert_true(ret == 3);
}
1 change: 1 addition & 0 deletions tests/test_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ void test_modules_ctx_quit_NULL_ctx(void **state);
void test_modules_ctx_quit_no_loop(void **state);
void test_modules_ctx_loop_NULL_ctx(void **state);
void test_modules_ctx_loop_no_maxevents(void **state);
void test_modules_ctx_loop(void **state);

0 comments on commit 7939ddf

Please sign in to comment.