Skip to content

Cellular: Removed boilerplate code #10703

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

Merged
merged 7 commits into from
Jun 19, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ set(unittest-includes ${unittest-includes}
# Source files
set(unittest-sources
../features/cellular/framework/AT/AT_CellularBase.cpp
../features/cellular/framework/AT/ATHandler_factory.cpp
)

# Test files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "CellularDevice_stub.h"
#include "equeue_stub.h"
#include "AT_CellularBase_stub.h"
#include "CellularUtil_stub.h"
#include "PinNames.h"

using namespace mbed;
using namespace events;
Expand Down Expand Up @@ -62,6 +64,9 @@ class TestAT_CellularContext : public testing::Test {
ATHandler_stub::read_string_table[kRead_string_table_size];
ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
CellularDevice_stub::connect_counter = 2;

CellularUtil_stub::char_table[0] = (char *)"\0";
CellularUtil_stub::table_idx = 0;
}

void TearDown()
Expand Down Expand Up @@ -131,6 +136,16 @@ class my_AT_CTX : public AT_CellularContext {
AT_CellularContext::cellular_callback(ev, ptr);
}

void activ_non_ip_context()
{
activate_non_ip_context();
}

void deactiv_non_ip_context()
{
deactivate_non_ip_context();
}

my_stack _st;
};

Expand All @@ -150,6 +165,19 @@ class my_AT_CTXIPV6 : public AT_CellularContext {
my_stack _st;
};

class def_AT_CTX : public AT_CellularContext {
public:
def_AT_CTX(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
AT_CellularContext(at, device, apn) {}
virtual ~def_AT_CTX() {}

uint32_t do_op()
{
return AT_CellularContext::get_timeout_for_operation(mbed::CellularContext::ContextOperation(_op));
}
int _op;
};

static int network_cb_count;
static void network_cb(nsapi_event_t ev, intptr_t intptr)
{
Expand All @@ -169,6 +197,9 @@ TEST_F(TestAT_CellularContext, Create)

ctx = new AT_CellularContext(at, &dev);
EXPECT_TRUE(ctx != NULL);

ctx->get_device();
EXPECT_EQ(NSAPI_STATUS_DISCONNECTED, ctx->get_connection_status());
delete ctx;
}

Expand Down Expand Up @@ -325,6 +356,20 @@ TEST_F(TestAT_CellularContext, get_pdpcontext_params)
ATHandler_stub::read_string_table[1] = (char *)"25.66.77.88";
ATHandler_stub::read_string_table[0] = (char *)"004.003.002.001";

CellularUtil_stub::table_idx = 12;
CellularUtil_stub::char_table[11] = (char *)"102:304:506:708:90A:B70:D0E:F10\0";
CellularUtil_stub::char_table[10] = (char *)"102:32C:3706:708:90A:B0C:D0E:F10\0";
CellularUtil_stub::char_table[9] = (char *)"1721:2C01:203:377B:E122:B01:000:7BEA\0";
CellularUtil_stub::char_table[8] = (char *)"1.2.3.4\0";
CellularUtil_stub::char_table[7] = (char *)"1.2.3.4\0";
CellularUtil_stub::char_table[6] = (char *)"1.2.3.4\0";
CellularUtil_stub::char_table[5] = (char *)"0.255.0.255\0";
CellularUtil_stub::char_table[4] = (char *)"1.2.3.4\0";
CellularUtil_stub::char_table[3] = (char *)"25.66.77.88\0";
CellularUtil_stub::char_table[2] = (char *)"1.2.3.4\0";
CellularUtil_stub::char_table[1] = (char *)"004.003.002.001\0";
CellularUtil_stub::char_table[0] = (char *)"1.2.3.4\0";

EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_pdpcontext_params(list));
CellularContext::pdpcontext_params_t *params = list.get_head();
EXPECT_TRUE(params != NULL);
Expand Down Expand Up @@ -457,6 +502,11 @@ TEST_F(TestAT_CellularContext, set_file_handle)
AT_CellularDevice dev(&fh1);
AT_CellularContext ctx(at, &dev);
ctx.set_file_handle(&fh1);

UARTSerial ss(NC, NC);

ctx.set_file_handle(&ss, PTC0, true);
ctx.enable_hup(true);
}

TEST_F(TestAT_CellularContext, connect_disconnect_sync)
Expand All @@ -481,10 +531,44 @@ TEST_F(TestAT_CellularContext, connect_disconnect_sync)
data.error = NSAPI_ERROR_OK;
ctx1.cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data);

ATHandler_stub::resp_info_true_counter = 1;
ATHandler_stub::read_string_table[0] = (char *)"APN";
ATHandler_stub::read_string_table[1] = (char *)"IP";
ATHandler_stub::read_string_index = 2;
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);

ASSERT_EQ(network_cb_count, 5);

ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
ATHandler_stub::resp_info_true_counter = 1;
ATHandler_stub::read_string_table[1] = (char *)"Non-IP";
ATHandler_stub::read_string_index = 2;
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);

ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
ATHandler_stub::resp_info_true_counter = 1;
ATHandler_stub::read_string_table[1] = (char *)"IPV6";
ATHandler_stub::read_string_index = 2;
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);

AT_CellularBase_stub::supported_bool = true;
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
ATHandler_stub::resp_info_true_counter = 1;
ATHandler_stub::read_string_table[1] = (char *)"IPV4V6";
ATHandler_stub::read_string_index = 2;
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
AT_CellularBase_stub::supported_bool = false;

ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
ATHandler_stub::resp_info_true_counter = 1;
ATHandler_stub::read_string_table[0] = (char *)"APN2";
ATHandler_stub::read_string_table[1] = (char *)"IPV4V6";
ATHandler_stub::read_string_index = 2;
ATHandler_stub::int_value = 10;
ctx1.set_credentials("APN");
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
ATHandler_stub::int_value = -1;

ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_IS_CONNECTED);

EXPECT_TRUE(ctx1.is_connected() == true);
Expand Down Expand Up @@ -519,6 +603,26 @@ TEST_F(TestAT_CellularContext, connect_disconnect_sync)
// More connect test after we are re-writted getting of PDP context...
}

TEST_F(TestAT_CellularContext, de_and_activate_non_ip_context)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularDevice dev(&fh1);
my_AT_CTX ctx(at, &dev);
ctx.attach(&network_cb);
Semaphore_stub::acquire_return_value = true;

// call callback so that network is opened which is needed in disconnect
cell_callback_data_t data;
data.error = NSAPI_ERROR_OK;
ctx.cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data);

ctx.activ_non_ip_context();

ctx.deactiv_non_ip_context();
}

TEST_F(TestAT_CellularContext, set_device_ready_sync)
{
EventQueue que;
Expand Down Expand Up @@ -618,3 +722,22 @@ TEST_F(TestAT_CellularContext, connect_disconnect_async)

// More connect test after we are re-writted getting of PDP context...
}

TEST_F(TestAT_CellularContext, get_timeout_for_operation)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");

AT_CellularDevice dev(&fh1);
def_AT_CTX ctx1(at, &dev);
ctx1._op = 1;
EXPECT_EQ(300 * 1000, ctx1.do_op());

ctx1._op = 0;
EXPECT_EQ(300 * 1000, ctx1.do_op());

ctx1._op = -1;
EXPECT_EQ(1800 * 1000, ctx1.do_op());

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ set(unittest-includes ${unittest-includes}
# Source files
set(unittest-sources
../features/cellular/framework/AT/AT_CellularContext.cpp
../features/cellular/framework/AT/ATHandler_factory.cpp
../features/cellular/framework/common/CellularUtil.cpp
)

# Test files
Expand All @@ -42,4 +40,5 @@ set(unittest-test-sources
stubs/UARTSerial_stub.cpp
stubs/SerialBase_stub.cpp
stubs/CellularContext_stub.cpp
stubs/CellularUtil_stub.cpp
)
Loading