Skip to content

Commit

Permalink
unittests: add test for correct returned netif array
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Mar 16, 2015
1 parent 49e5938 commit 2909c87
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/unittests/tests-netif/Makefile.include
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
USEMODULE += ng_netif

CFLAGS += -DNG_NETIF_NUMOF=3
27 changes: 27 additions & 0 deletions tests/unittests/tests-netif/tests-netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,32 @@ static void test_ng_netif_get__empty(void)
TEST_ASSERT_EQUAL_INT(0, size);
}

/* takes one out of the middle of the netif list and checks if all interfaces
* are gotten regardless */
static void test_ng_netif_get__success_3_minus_one(void)
{
size_t size = TEST_UINT8;
kernel_pid_t *ifs;
int count = 0;

for (int i = 0; i < 3; i++) {
TEST_ASSERT_EQUAL_INT(0, ng_netif_add(TEST_UINT8 + i));
}

ng_netif_remove(TEST_UINT8 + 1);

ifs = ng_netif_get(&size);
TEST_ASSERT_EQUAL_INT(2, size);

for (size_t i = 0; i < size; i++) {
if ((ifs[i] == TEST_UINT8) || ifs[i] == (TEST_UINT8 + 2)) {
count++;
}
}

TEST_ASSERT_EQUAL_INT(size, count);
}

static void test_ng_netif_get__full(void)
{
size_t size = TEST_UINT8;
Expand All @@ -141,6 +167,7 @@ Test *tests_netif_tests(void)
new_TestFixture(test_ng_netif_remove__not_an_if),
new_TestFixture(test_ng_netif_remove__success),
new_TestFixture(test_ng_netif_get__empty),
new_TestFixture(test_ng_netif_get__success_3_minus_one),
new_TestFixture(test_ng_netif_get__full),
};

Expand Down

0 comments on commit 2909c87

Please sign in to comment.