Skip to content

Commit

Permalink
Fixed LLC data unit test and add new functions to test
Browse files Browse the repository at this point in the history
  • Loading branch information
Juha Heiskanen authored and juhhei01 committed Mar 8, 2018
1 parent 94e516f commit 90fbb45
Show file tree
Hide file tree
Showing 7 changed files with 445 additions and 1 deletion.
273 changes: 273 additions & 0 deletions test/nanostack/unittest/6LoWPAN/ws_ie_lib/test_ws_ie_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "6LoWPAN/ws/ws_ie_lib.h"
#include "6LoWPAN/ws/ws_common_defines.h"
#include "common_functions_stub.h"
#include "mac_ie_lib_stub.h"

bool test_ws_ie_lib_header()
{
Expand Down Expand Up @@ -117,3 +118,275 @@ bool test_ws_ie_lib_payload()

return true;
}

bool test_ws_wp_nested_hopping_schedule_length()
{
uint16_t length;
ws_hopping_schedule_t shedule;

memset (&shedule, 0, sizeof(ws_hopping_schedule_t));
length = ws_wp_nested_hopping_schedule_length(&shedule, true);
if (length != 4 + 2 +2)
{
return false;
}

shedule.channel_plan = 1;
shedule.channel_function = 1;
length = ws_wp_nested_hopping_schedule_length(&shedule, true);
if (length != 4 + 6)
{
return false;
}
shedule.channel_plan = 2;
shedule.channel_function = 3;

length = ws_wp_nested_hopping_schedule_length(&shedule, true);
if (length != 6)
{
return false;
}

length = ws_wp_nested_hopping_schedule_length(&shedule, false);
if (length != 12)
{
return false;
}
return true;
}

bool test_ws_wp_nested_hopping_schedule_write()
{
uint8_t temp_buf[20];
uint8_t *ptr;
ws_hopping_schedule_t shedule;
memset (&shedule, 0, sizeof(ws_hopping_schedule_t));

ptr = ws_wp_nested_hopping_schedule_write(temp_buf, &shedule, true);
if (ptr != temp_buf + 8 + 2) {
return false;
}

shedule.channel_plan = 1;
shedule.channel_function = 1;
ptr = ws_wp_nested_hopping_schedule_write(temp_buf, &shedule, true);
if (ptr != temp_buf + 10 + 2) {
return false;
}

shedule.channel_plan = 2;
shedule.channel_function = 3;
ptr = ws_wp_nested_hopping_schedule_write(temp_buf, &shedule, false);
if (ptr != temp_buf + 10 + 2 + 2) {
return false;
}

return true;
}

bool test_ws_wh_utt_read()
{
uint8_t temp_buf[20];
ws_utt_ie_t utt_ie;
mac_ie_lib_stub_def.value_uint8 = 0;
if (ws_wh_utt_read(temp_buf, 8, &utt_ie) ) {
return false;
}

mac_ie_lib_stub_def.value_uint8 = 4;
return ws_wh_utt_read(temp_buf, 8, &utt_ie);
}

bool test_ws_wh_bt_read()
{
uint8_t temp_buf[20];
ws_bt_ie_t bt_ie;
mac_ie_lib_stub_def.value_uint8 = 0;
if (ws_wh_bt_read(temp_buf, 8, &bt_ie) ) {
return false;
}

mac_ie_lib_stub_def.value_uint8 = 5;
return ws_wh_bt_read(temp_buf, 8, &bt_ie);
}

bool test_ws_wp_nested_us_read()
{

ws_us_ie_t ws_us_ie;
uint8_t temp_buf[20];
mac_ie_lib_stub_def.value_uint16 = 3;
temp_buf[3] = 0;
if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie) ){
return false;
}

mac_ie_lib_stub_def.value_uint16 = 4;
if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie) ){
return false;
}

mac_ie_lib_stub_def.value_uint16 = 7;
if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie) ){
return false;
}

mac_ie_lib_stub_def.value_uint16 = 8;
if (!ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) {
return false;
}
temp_buf[3] = 1;

if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) {
return false;
}
mac_ie_lib_stub_def.value_uint16 = 12;
if (!ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) {
return false;
}
temp_buf[3] = 2;
if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) {
return false;
}

temp_buf[3] = 1 << 3;
mac_ie_lib_stub_def.value_uint16 = 6;
if (!ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) {
return false;
}

temp_buf[3] = 3 << 3;
mac_ie_lib_stub_def.value_uint16 = 7;
temp_buf[6] = 2;
if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) {
return false;
}
mac_ie_lib_stub_def.value_uint16 = 9;
if (!ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) {
return false;
}

temp_buf[3] = 4 << 3;
if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) {
return false;
}

return true;

}


bool test_ws_wp_nested_bs_read()
{

ws_bs_ie_t ws_bs_ie;
uint8_t temp_buf[20];
mac_ie_lib_stub_def.value_uint16 = 9;
temp_buf[9] = 0;
if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie) ){
return false;
}

mac_ie_lib_stub_def.value_uint16 = 10;
if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie) ){
return false;
}

mac_ie_lib_stub_def.value_uint16 = 13;
if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie) ){
return false;
}

mac_ie_lib_stub_def.value_uint16 = 14;
if (!ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) {
return false;
}

temp_buf[9] = 1;
if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) {
return false;
}

mac_ie_lib_stub_def.value_uint16 = 18;
if (!ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) {
return false;
}

temp_buf[9] = 2;
if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) {
return false;
}

temp_buf[9] = 4 << 3;
if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) {
return false;
}

temp_buf[9] = 1 << 3;
mac_ie_lib_stub_def.value_uint16 = 12;
if (!ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) {
return false;
}

temp_buf[9] = 3 << 3;
temp_buf[12] = 2;
mac_ie_lib_stub_def.value_uint16 = 13;
if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) {
return false;
}

mac_ie_lib_stub_def.value_uint16 = 15;
if (!ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) {
return false;
}

return true;

}

bool test_ws_wp_nested_pan_read()
{
ws_pan_information_t ws_pan_ie;
uint8_t temp_buf[20];
mac_ie_lib_stub_def.value_uint16 = 4;
if (ws_wp_nested_pan_read(temp_buf, 20, &ws_pan_ie)) {
return false;
}
mac_ie_lib_stub_def.value_uint16 = 5;

return ws_wp_nested_pan_read(temp_buf, 20, &ws_pan_ie);
}

bool test_ws_wp_nested_pan_version_read()
{
uint16_t ws_pan_version;
uint8_t temp_buf[20];
mac_ie_lib_stub_def.value_uint16 = 4;
if (ws_wp_nested_pan_version_read(temp_buf, 20, &ws_pan_version)) {
return false;
}

mac_ie_lib_stub_def.value_uint16 = 2;
if (!ws_wp_nested_pan_version_read(temp_buf, 20, &ws_pan_version)) {
return false;
}

return true;
}

bool test_ws_wp_nested_gtkhash_read()
{
uint8_t temp_buf[40];
mac_ie_lib_stub_def.value_uint16 = 4;
if (ws_wp_nested_gtkhash_read(temp_buf, 40)) {
return false;
}

mac_ie_lib_stub_def.value_uint16 = 32;
if (!ws_wp_nested_gtkhash_read(temp_buf, 20)) {
return false;
}

return true;
}

18 changes: 18 additions & 0 deletions test/nanostack/unittest/6LoWPAN/ws_ie_lib/test_ws_ie_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ bool test_ws_ie_lib_header();

bool test_ws_ie_lib_payload();

bool test_ws_wp_nested_hopping_schedule_length();

bool test_ws_wp_nested_hopping_schedule_write();

bool test_ws_wh_utt_read();

bool test_ws_wh_bt_read();

bool test_ws_wp_nested_us_read();

bool test_ws_wp_nested_bs_read();

bool test_ws_wp_nested_pan_read();

bool test_ws_wp_nested_pan_version_read();

bool test_ws_wp_nested_gtkhash_read();

#ifdef __cplusplus
}
#endif
Expand Down
47 changes: 47 additions & 0 deletions test/nanostack/unittest/6LoWPAN/ws_ie_lib/ws_ie_libtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,53 @@ TEST(ws_ie_lib, test_ws_ie_lib_payload)
CHECK(test_ws_ie_lib_payload());
}

TEST(ws_ie_lib, test_ws_wp_nested_hopping_schedule_length)
{
CHECK(test_ws_wp_nested_hopping_schedule_length());
}

TEST(ws_ie_lib, test_ws_wp_nested_hopping_schedule_write)
{
CHECK(test_ws_wp_nested_hopping_schedule_write());
}

TEST(ws_ie_lib, test_ws_wh_utt_read)
{
CHECK(test_ws_wh_utt_read());
}

TEST(ws_ie_lib, test_ws_wh_bt_read)
{
CHECK(test_ws_wh_bt_read());
}

TEST(ws_ie_lib, test_ws_wp_nested_us_read)
{
CHECK(test_ws_wp_nested_us_read());
}

TEST(ws_ie_lib, test_ws_wp_nested_bs_read)
{
CHECK(test_ws_wp_nested_bs_read());
}

TEST(ws_ie_lib, test_ws_wp_nested_pan_read)
{
CHECK(test_ws_wp_nested_pan_read());
}

TEST(ws_ie_lib, test_ws_wp_nested_pan_version_read)
{
CHECK(test_ws_wp_nested_pan_version_read());
}

TEST(ws_ie_lib, test_ws_wp_nested_gtkhash_read)
{
CHECK(test_ws_wp_nested_gtkhash_read());
}






Expand Down
Loading

0 comments on commit 90fbb45

Please sign in to comment.