From 5ebdb439af53956d4d494fb49ad07909e021f825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Wed, 18 Apr 2018 14:41:59 +0300 Subject: [PATCH 1/2] Cellular: fixed cellular unit tests and one bug which was found while fixing. --- .../at_cellularnetworktest.cpp | 9 +++++ .../test_at_cellularnetwork.cpp | 36 ++++++++++++++++--- .../test_at_cellularnetwork.h | 4 +++ .../stubs/AT_CellularNetwork_stub.cpp | 8 +++++ .../framework/AT/AT_CellularNetwork.cpp | 3 +- 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/features/cellular/UNITTESTS/at/at_cellularnetwork/at_cellularnetworktest.cpp b/features/cellular/UNITTESTS/at/at_cellularnetwork/at_cellularnetworktest.cpp index 48e3518296..67f37eebef 100644 --- a/features/cellular/UNITTESTS/at/at_cellularnetwork/at_cellularnetworktest.cpp +++ b/features/cellular/UNITTESTS/at/at_cellularnetwork/at_cellularnetworktest.cpp @@ -82,6 +82,11 @@ TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_attach) unit->test_AT_CellularNetwork_get_attach(); } +TEST(AT_CellularNetwork, test_AT_CellularNetwork_detach) +{ + unit->test_AT_CellularNetwork_detach(); +} + TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_rate_control) { unit->test_AT_CellularNetwork_get_rate_control(); @@ -157,3 +162,7 @@ TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_operator_params) unit->test_AT_CellularNetwork_get_operator_params(); } +TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_operator_names) +{ + unit->test_AT_CellularNetwork_get_operator_names(); +} diff --git a/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.cpp b/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.cpp index e14edd57ac..cdd6a060a0 100644 --- a/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.cpp +++ b/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.cpp @@ -81,7 +81,7 @@ void Test_AT_CellularNetwork::test_AT_CellularNetwork_connect() AT_CellularNetwork cn(at); cn.set_stack_type(IPV4V6_STACK); - CHECK(NSAPI_ERROR_NO_CONNECTION == cn.connect("APN", "a", "b")); + CHECK(NSAPI_ERROR_UNSUPPORTED == cn.connect("APN", "a", "b")); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST; CHECK(NSAPI_ERROR_NO_CONNECTION == cn.connect("APN")); @@ -152,6 +152,17 @@ void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_attach() CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.get_attach(stat)); } +void Test_AT_CellularNetwork::test_AT_CellularNetwork_detach() +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST; + CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.detach()); +} + void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_rate_control() { EventQueue que; @@ -174,10 +185,12 @@ void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_apn_backoff_timer() AT_CellularNetwork cn(at); int time; ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST; + CHECK(NSAPI_ERROR_PARAMETER == cn.get_apn_backoff_timer(time)); + + cn.set_credentials("internet", NULL, NULL); CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.get_apn_backoff_timer(time)); } - void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_ip_address() { EventQueue que; @@ -306,8 +319,8 @@ void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_cell_id() AT_CellularNetwork cn(at); int id; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST; - CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.get_cell_id(id)); + CHECK(NSAPI_ERROR_OK == cn.get_cell_id(id)); + CHECK(id == -1); } void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_3gpp_error() @@ -334,3 +347,18 @@ void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_operator_params() CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.get_operator_params(format, ops)); } +void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_operator_names() +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + CellularNetwork::operator_names_list name_list; + + CHECK(NSAPI_ERROR_OK == cn.get_operator_names(name_list)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST; + CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.get_operator_names(name_list)); +} + diff --git a/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.h b/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.h index f36fdf034a..e7775ff8be 100644 --- a/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.h +++ b/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.h @@ -42,6 +42,8 @@ public: void test_AT_CellularNetwork_get_attach(); + void test_AT_CellularNetwork_detach(); + void test_AT_CellularNetwork_get_rate_control(); void test_AT_CellularNetwork_get_apn_backoff_timer(); @@ -71,6 +73,8 @@ public: void test_AT_CellularNetwork_get_3gpp_error(); void test_AT_CellularNetwork_get_operator_params(); + + void test_AT_CellularNetwork_get_operator_names(); }; #endif // TEST_AT_CELLULARNETWORK_H diff --git a/features/cellular/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp b/features/cellular/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp index 86fb1471d3..602717d029 100644 --- a/features/cellular/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp +++ b/features/cellular/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp @@ -151,6 +151,10 @@ nsapi_error_t AT_CellularNetwork::get_attach(AttachStatus &status) return NSAPI_ERROR_OK; } +nsapi_error_t AT_CellularNetwork::detach() +{ + return NSAPI_ERROR_OK; +} nsapi_error_t AT_CellularNetwork::get_apn_backoff_timer(int &backoffTime) { @@ -253,3 +257,7 @@ int AT_CellularNetwork::get_3gpp_error() return 0; } +nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_names) +{ + return NSAPI_ERROR_OK; +} diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index 9987e65154..3555bde276 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -744,7 +744,8 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type, nsapi_error_t AT_CellularNetwork::get_cell_id(int &cell_id) { - return _cell_id; + cell_id = _cell_id; + return NSAPI_ERROR_OK; } bool AT_CellularNetwork::has_registration(RegistrationType reg_type) From 025e0dfc492325ac5b9125b8ef705496d9325280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Thu, 19 Apr 2018 13:40:33 +0300 Subject: [PATCH 2/2] Cellular: moved one function in cellularnetwork to public as it was accidently set as protected. --- features/cellular/framework/AT/AT_CellularNetwork.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/cellular/framework/AT/AT_CellularNetwork.h b/features/cellular/framework/AT/AT_CellularNetwork.h index b5a3d65485..7138b0f5d0 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.h +++ b/features/cellular/framework/AT/AT_CellularNetwork.h @@ -118,6 +118,7 @@ public: // CellularNetwork virtual nsapi_error_t set_registration_urc(RegistrationType type, bool on); + virtual nsapi_error_t get_operator_names(operator_names_list &op_names); protected: /** Check if modem supports the given stack type. @@ -141,7 +142,6 @@ protected: */ virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology op_rat); - virtual nsapi_error_t get_operator_names(operator_names_list &op_names); private: // "NO CARRIER" urc void urc_no_carrier();