Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 CHECK(dev.open_network(&fh1)); 00054 CHECK(dev.open_sms(&fh2)); 00055 AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; 00056 CHECK(dev.open_sim(&fh3)); 00057 ATHandler_stub::fh_value = &fh1; 00058 CHECK(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 AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; 00122 CHECK(ATHandler_stub::ref_count == 1); 00123 00124 dev.close_network(); 00125 CHECK(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); 00126 } 00127 00128 void Test_AT_CellularDevice::test_AT_CellularDevice_close_sms() 00129 { 00130 EventQueue que; 00131 AT_CellularDevice dev(que); 00132 FileHandle_stub fh1; 00133 ATHandler_stub::ref_count = 0; 00134 00135 CHECK(dev.open_sms(&fh1)); 00136 AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; 00137 CHECK(ATHandler_stub::ref_count == 1); 00138 00139 dev.close_sms(); 00140 CHECK(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); 00141 } 00142 00143 void Test_AT_CellularDevice::test_AT_CellularDevice_close_power() 00144 { 00145 EventQueue que; 00146 AT_CellularDevice dev(que); 00147 FileHandle_stub fh1; 00148 ATHandler_stub::ref_count = 0; 00149 00150 CHECK(dev.open_power(&fh1)); 00151 AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; 00152 CHECK(ATHandler_stub::ref_count == 1); 00153 00154 dev.close_power(); 00155 CHECK(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); 00156 } 00157 00158 void Test_AT_CellularDevice::test_AT_CellularDevice_close_sim() 00159 { 00160 EventQueue que; 00161 AT_CellularDevice dev(que); 00162 FileHandle_stub fh1; 00163 ATHandler_stub::ref_count = 0; 00164 00165 00166 CHECK(dev.open_sim(&fh1)); 00167 AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; 00168 00169 dev.close_sms(); // this should not affect to refcount as it's not opened 00170 CHECK(ATHandler_stub::ref_count == 1); 00171 00172 dev.close_sim(); 00173 CHECK(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); 00174 } 00175 00176 void Test_AT_CellularDevice::test_AT_CellularDevice_close_information() 00177 { 00178 EventQueue que; 00179 AT_CellularDevice dev(que); 00180 FileHandle_stub fh1; 00181 ATHandler_stub::int_value = 0; 00182 ATHandler_stub::ref_count = 0; 00183 ATHandler_stub::fh_value = NULL; 00184 AT_CellularBase_stub::handler_value = NULL; 00185 00186 CHECK(dev.open_information(&fh1)); 00187 CHECK(ATHandler_stub::ref_count == 1); 00188 00189 // at handler is not found as it's NULL (e.g. AT_CellularBase_stub::handler_value is NULL) 00190 dev.close_information(); 00191 CHECK(ATHandler_stub::ref_count == 1); 00192 00193 // same filehandle but different at 00194 ATHandler_stub::fh_value = &fh1; 00195 ATHandler at(&fh1, que, 0, ","); 00196 AT_CellularBase_stub::handler_value = &at; 00197 00198 CHECK(dev.open_information(&fh1)); 00199 // refcount is two it's one when we create athandler and then in open_information it's incremented by one 00200 CHECK(ATHandler_stub::ref_count == 2); 00201 00202 dev.close_information(); 00203 CHECK(ATHandler_stub::ref_count == 1); 00204 00205 ATHandler_stub::fh_value = NULL; 00206 } 00207 00208 void Test_AT_CellularDevice::test_AT_CellularDevice_set_timeout() 00209 { 00210 EventQueue que; 00211 AT_CellularDevice dev(que); 00212 FileHandle_stub fh1; 00213 ATHandler_stub::timeout = 0; 00214 ATHandler_stub::default_timeout = false; 00215 00216 // no interfaces open so settings timeout should not change anything 00217 dev.set_timeout(5000); 00218 CHECK(ATHandler_stub::timeout == 0); 00219 CHECK(ATHandler_stub::default_timeout == false); 00220 00221 CHECK(dev.open_sim(&fh1)); 00222 CHECK(ATHandler_stub::ref_count == 1); 00223 00224 dev.set_timeout(5000); 00225 CHECK(ATHandler_stub::timeout == 5000); 00226 CHECK(ATHandler_stub::default_timeout == true); 00227 00228 dev.close_sim(); 00229 } 00230 00231 void Test_AT_CellularDevice::test_AT_CellularDevice_get_send_delay() 00232 { 00233 EventQueue que; 00234 AT_CellularDevice dev(que); 00235 CHECK(0 == dev.get_send_delay()); 00236 } 00237 00238 void Test_AT_CellularDevice::test_AT_CellularDevice_modem_debug_on() 00239 { 00240 EventQueue que; 00241 AT_CellularDevice dev(que); 00242 FileHandle_stub fh1; 00243 ATHandler_stub::debug_on = false; 00244 00245 // no interfaces open so debug toggling should not affect 00246 dev.modem_debug_on(true); 00247 CHECK(ATHandler_stub::debug_on == false); 00248 00249 CHECK(dev.open_sim(&fh1)); 00250 CHECK(ATHandler_stub::ref_count == 1); 00251 00252 dev.modem_debug_on(true); 00253 CHECK(ATHandler_stub::debug_on == true); 00254 00255 dev.close_sim(); 00256 } 00257 00258 void Test_AT_CellularDevice::test_AT_CellularDevice_get_stack() 00259 { 00260 EventQueue que; 00261 AT_CellularDevice dev(que); 00262 FileHandle_stub fh1; 00263 00264 NetworkStack *stack = dev.get_stack(); 00265 CHECK(stack == NULL); 00266 00267 CHECK(dev.open_network(&fh1)); 00268 00269 stack = dev.get_stack(); 00270 CHECK(stack == NULL); // Not in PPP so also null but this is got from the network class 00271 } 00272
Generated on Tue Aug 9 2022 00:37:21 by
1.7.2