Knight KE / Mbed OS Game_Master
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test_at_cellulardevice.cpp Source File

test_at_cellulardevice.cpp

00001 /*
00002  * Copyright (c) 2018, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #include "CppUTest/TestHarness.h"
00018 #include "test_at_cellulardevice.h"
00019 #include "AT_CellularDevice.h"
00020 #include "ATHandler_stub.h"
00021 #include "AT_CellularBase_stub.h"
00022 #include <string.h>
00023 
00024 using namespace mbed;
00025 using namespace events;
00026 
00027 Test_AT_CellularDevice::Test_AT_CellularDevice()
00028 {
00029 
00030 }
00031 
00032 Test_AT_CellularDevice::~Test_AT_CellularDevice()
00033 {
00034 }
00035 
00036 void Test_AT_CellularDevice::test_AT_CellularDevice_constructor()
00037 {
00038     EventQueue que;
00039     AT_CellularDevice dev(que);
00040 
00041     CellularDevice *dev2 = new AT_CellularDevice(que);
00042     delete dev2;
00043 }
00044 
00045 void Test_AT_CellularDevice::test_AT_CellularDevice_get_at_handler()
00046 {
00047     EventQueue que;
00048     AT_CellularDevice dev(que);
00049     FileHandle_stub fh1;
00050     FileHandle_stub fh2;
00051     FileHandle_stub fh3;
00052 
00053     dev.open_network(&fh1);
00054     dev.open_sms(&fh2);
00055     AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
00056     dev.open_sim(&fh3);
00057     ATHandler_stub::fh_value = &fh1;
00058     dev.open_power(&fh1);
00059 
00060     ATHandler_stub::fh_value = NULL;
00061 }
00062 
00063 void Test_AT_CellularDevice::test_AT_CellularDevice_open_network()
00064 {
00065     EventQueue que;
00066     AT_CellularDevice dev(que);
00067     FileHandle_stub fh1;
00068 
00069     CHECK(!dev.open_network(NULL));
00070     CHECK(dev.open_network(&fh1));
00071 }
00072 
00073 void Test_AT_CellularDevice::test_AT_CellularDevice_open_sms()
00074 {
00075     EventQueue que;
00076     AT_CellularDevice dev(que);
00077     FileHandle_stub fh1;
00078 
00079     CHECK(!dev.open_sms(NULL));
00080     CHECK(dev.open_sms(&fh1));
00081 }
00082 
00083 void Test_AT_CellularDevice::test_AT_CellularDevice_open_power()
00084 {
00085     EventQueue que;
00086     AT_CellularDevice dev(que);
00087     FileHandle_stub fh1;
00088 
00089     CHECK(!dev.open_power(NULL));
00090     CHECK(dev.open_power(&fh1));
00091 }
00092 
00093 void Test_AT_CellularDevice::test_AT_CellularDevice_open_sim()
00094 {
00095     EventQueue que;
00096     AT_CellularDevice dev(que);
00097     FileHandle_stub fh1;
00098 
00099     CHECK(! dev.open_sim(NULL));
00100     CHECK(dev.open_sim(&fh1));
00101 }
00102 
00103 void Test_AT_CellularDevice::test_AT_CellularDevice_open_information()
00104 {
00105     EventQueue que;
00106     AT_CellularDevice dev(que);
00107     FileHandle_stub fh1;
00108 
00109     CHECK(!dev.open_information(NULL));
00110     CHECK(dev.open_information(&fh1));
00111 }
00112 
00113 void Test_AT_CellularDevice::test_AT_CellularDevice_close_network()
00114 {
00115     EventQueue que;
00116     AT_CellularDevice dev(que);
00117     FileHandle_stub fh1;
00118     ATHandler_stub::ref_count = 0;
00119 
00120     CHECK(dev.open_network(&fh1));
00121     CHECK(ATHandler_stub::ref_count == 1);
00122 
00123     dev.close_network();
00124 }
00125 
00126 void Test_AT_CellularDevice::test_AT_CellularDevice_close_sms()
00127 {
00128     EventQueue que;
00129     AT_CellularDevice dev(que);
00130     FileHandle_stub fh1;
00131     ATHandler_stub::ref_count = 0;
00132 
00133     CHECK(dev.open_sms(&fh1));
00134     CHECK(ATHandler_stub::ref_count == 1);
00135 
00136     dev.close_sms();
00137 }
00138 
00139 void Test_AT_CellularDevice::test_AT_CellularDevice_close_power()
00140 {
00141     EventQueue que;
00142     AT_CellularDevice dev(que);
00143     FileHandle_stub fh1;
00144     ATHandler_stub::ref_count = 0;
00145 
00146     CHECK(dev.open_power(&fh1));
00147     CHECK(ATHandler_stub::ref_count == 1);
00148 
00149     dev.close_power();
00150 }
00151 
00152 void Test_AT_CellularDevice::test_AT_CellularDevice_close_sim()
00153 {
00154     EventQueue que;
00155     AT_CellularDevice dev(que);
00156     FileHandle_stub fh1;
00157     ATHandler_stub::ref_count = 0;
00158 
00159 
00160     CHECK(dev.open_sim(&fh1));
00161     dev.close_sms(); // this should not affect to refcount as it's not opened
00162     CHECK(ATHandler_stub::ref_count == 1);
00163 
00164     dev.close_sim();
00165 }
00166 
00167 void Test_AT_CellularDevice::test_AT_CellularDevice_close_information()
00168 {
00169     EventQueue que;
00170     AT_CellularDevice dev(que);
00171     FileHandle_stub fh1;
00172     ATHandler_stub::int_value = 0;
00173 
00174     CHECK(dev.open_information(&fh1));
00175 
00176     ATHandler_stub::fh_value = NULL;
00177     AT_CellularBase_stub::handler_value = NULL;
00178     dev.close_information();
00179 
00180     ATHandler_stub::fh_value = &fh1;
00181     ATHandler at(&fh1, que, 0, ",");
00182     AT_CellularBase_stub::handler_value = &at;
00183 
00184     CHECK(dev.open_information(&fh1));
00185     AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
00186 
00187     dev.close_information();
00188 
00189     ATHandler_stub::fh_value = NULL;
00190 }
00191 
00192 void Test_AT_CellularDevice::test_AT_CellularDevice_set_timeout()
00193 {
00194     EventQueue que;
00195     AT_CellularDevice dev(que);
00196     FileHandle_stub fh1;
00197     ATHandler_stub::timeout = 0;
00198     ATHandler_stub::default_timeout = false;
00199 
00200     // no interfaces open so settings timeout should not change anything
00201     dev.set_timeout(5000);
00202     CHECK(ATHandler_stub::timeout == 0);
00203     CHECK(ATHandler_stub::default_timeout == false);
00204 
00205     CHECK(dev.open_sim(&fh1));
00206     CHECK(ATHandler_stub::ref_count == 1);
00207 
00208     dev.set_timeout(5000);
00209     CHECK(ATHandler_stub::timeout == 5000);
00210     CHECK(ATHandler_stub::default_timeout == true);
00211 
00212     dev.close_sim();
00213 }
00214 
00215 void Test_AT_CellularDevice::test_AT_CellularDevice_modem_debug_on()
00216 {
00217     EventQueue que;
00218     AT_CellularDevice dev(que);
00219     FileHandle_stub fh1;
00220     ATHandler_stub::debug_on = false;
00221 
00222     // no interfaces open so debug toggling should not affect
00223     dev.modem_debug_on(true);
00224     CHECK(ATHandler_stub::debug_on == false);
00225 
00226     CHECK(dev.open_sim(&fh1));
00227     CHECK(ATHandler_stub::ref_count == 1);
00228 
00229     dev.modem_debug_on(true);
00230     CHECK(ATHandler_stub::debug_on == true);
00231 
00232     dev.close_sim();
00233 }
00234 
00235 void Test_AT_CellularDevice::test_AT_CellularDevice_get_stack()
00236 {
00237     EventQueue que;
00238     AT_CellularDevice dev(que);
00239     FileHandle_stub fh1;
00240 
00241     NetworkStack *stack = dev.get_stack();
00242     CHECK(stack == NULL);
00243 
00244     CHECK(dev.open_network(&fh1));
00245 
00246     stack = dev.get_stack();
00247     CHECK(stack == NULL); // Not in PPP so also null but this is got from the network class
00248 }
00249