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.
at_cellulardevicetest.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 "gtest/gtest.h" 00018 #include "AT_CellularDevice.h" 00019 #include "ATHandler_stub.h" 00020 #include "AT_CellularBase_stub.h" 00021 #include <string.h> 00022 00023 using namespace mbed; 00024 using namespace events; 00025 00026 class TestAT_CellularDevice : public testing::Test { 00027 protected: 00028 00029 void SetUp() { 00030 } 00031 00032 void TearDown() { 00033 } 00034 }; 00035 00036 TEST_F(TestAT_CellularDevice, Create) 00037 { 00038 EventQueue que; 00039 AT_CellularDevice dev(que); 00040 00041 CellularDevice *dev2 = new AT_CellularDevice(que); 00042 00043 EXPECT_TRUE(dev2 != NULL); 00044 delete dev2; 00045 } 00046 00047 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler) 00048 { 00049 EventQueue que; 00050 AT_CellularDevice dev(que); 00051 FileHandle_stub fh1; 00052 FileHandle_stub fh2; 00053 FileHandle_stub fh3; 00054 00055 EXPECT_TRUE(dev.open_network(&fh1)); 00056 EXPECT_TRUE(dev.open_sms(&fh2)); 00057 AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; 00058 EXPECT_TRUE(dev.open_sim(&fh3)); 00059 ATHandler_stub::fh_value = &fh1; 00060 EXPECT_TRUE(dev.open_power(&fh1)); 00061 00062 ATHandler_stub::fh_value = NULL; 00063 } 00064 00065 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network) 00066 { 00067 EventQueue que; 00068 AT_CellularDevice dev(que); 00069 FileHandle_stub fh1; 00070 00071 EXPECT_TRUE(!dev.open_network(NULL)); 00072 EXPECT_TRUE(dev.open_network(&fh1)); 00073 } 00074 00075 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms) 00076 { 00077 EventQueue que; 00078 AT_CellularDevice dev(que); 00079 FileHandle_stub fh1; 00080 00081 EXPECT_TRUE(!dev.open_sms(NULL)); 00082 EXPECT_TRUE(dev.open_sms(&fh1)); 00083 } 00084 00085 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power) 00086 { 00087 EventQueue que; 00088 AT_CellularDevice dev(que); 00089 FileHandle_stub fh1; 00090 00091 EXPECT_TRUE(!dev.open_power(NULL)); 00092 EXPECT_TRUE(dev.open_power(&fh1)); 00093 } 00094 00095 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim) 00096 { 00097 EventQueue que; 00098 AT_CellularDevice dev(que); 00099 FileHandle_stub fh1; 00100 00101 EXPECT_TRUE(! dev.open_sim(NULL)); 00102 EXPECT_TRUE(dev.open_sim(&fh1)); 00103 } 00104 00105 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information) 00106 { 00107 EventQueue que; 00108 AT_CellularDevice dev(que); 00109 FileHandle_stub fh1; 00110 00111 EXPECT_TRUE(!dev.open_information(NULL)); 00112 EXPECT_TRUE(dev.open_information(&fh1)); 00113 } 00114 00115 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network) 00116 { 00117 EventQueue que; 00118 AT_CellularDevice dev(que); 00119 FileHandle_stub fh1; 00120 ATHandler_stub::ref_count = 0; 00121 00122 EXPECT_TRUE(dev.open_network(&fh1)); 00123 AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; 00124 EXPECT_TRUE(ATHandler_stub::ref_count == 1); 00125 00126 dev.close_network(); 00127 EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); 00128 } 00129 00130 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms) 00131 { 00132 EventQueue que; 00133 AT_CellularDevice dev(que); 00134 FileHandle_stub fh1; 00135 ATHandler_stub::ref_count = 0; 00136 00137 EXPECT_TRUE(dev.open_sms(&fh1)); 00138 AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; 00139 EXPECT_TRUE(ATHandler_stub::ref_count == 1); 00140 00141 dev.close_sms(); 00142 EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); 00143 } 00144 00145 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power) 00146 { 00147 EventQueue que; 00148 AT_CellularDevice dev(que); 00149 FileHandle_stub fh1; 00150 ATHandler_stub::ref_count = 0; 00151 00152 EXPECT_TRUE(dev.open_power(&fh1)); 00153 AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; 00154 EXPECT_TRUE(ATHandler_stub::ref_count == 1); 00155 00156 dev.close_power(); 00157 EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); 00158 } 00159 00160 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim) 00161 { 00162 EventQueue que; 00163 AT_CellularDevice dev(que); 00164 FileHandle_stub fh1; 00165 ATHandler_stub::ref_count = 0; 00166 int ana = 0; 00167 00168 EXPECT_TRUE(dev.open_sim(&fh1)); 00169 AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; 00170 00171 ana = ATHandler_stub::ref_count; 00172 00173 dev.close_sms(); // this should not affect to refcount as it's not opened 00174 EXPECT_TRUE(ATHandler_stub::ref_count == 1); 00175 ana = ATHandler_stub::ref_count; 00176 00177 dev.close_sim(); 00178 EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); 00179 } 00180 00181 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information) 00182 { 00183 EventQueue que; 00184 AT_CellularDevice dev(que); 00185 FileHandle_stub fh1; 00186 ATHandler_stub::int_value = 0; 00187 00188 EXPECT_TRUE(dev.open_information(&fh1)); 00189 00190 ATHandler_stub::fh_value = NULL; 00191 AT_CellularBase_stub::handler_value = NULL; 00192 dev.close_information(); 00193 00194 ATHandler_stub::fh_value = &fh1; 00195 ATHandler at(&fh1, que, 0, ","); 00196 AT_CellularBase_stub::handler_value = &at; 00197 00198 EXPECT_TRUE(dev.open_information(&fh1)); 00199 AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; 00200 00201 dev.close_information(); 00202 EXPECT_TRUE(ATHandler_stub::ref_count == 1); 00203 00204 ATHandler_stub::fh_value = NULL; 00205 } 00206 00207 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout) 00208 { 00209 EventQueue que; 00210 AT_CellularDevice dev(que); 00211 FileHandle_stub fh1; 00212 ATHandler_stub::timeout = 0; 00213 ATHandler_stub::default_timeout = false; 00214 00215 // no interfaces open so settings timeout should not change anything 00216 dev.set_timeout(5000); 00217 EXPECT_TRUE(ATHandler_stub::timeout == 0); 00218 EXPECT_TRUE(ATHandler_stub::default_timeout == false); 00219 00220 EXPECT_TRUE(dev.open_sim(&fh1)); 00221 EXPECT_TRUE(ATHandler_stub::ref_count == 1); 00222 00223 dev.set_timeout(5000); 00224 EXPECT_TRUE(ATHandler_stub::timeout == 5000); 00225 EXPECT_TRUE(ATHandler_stub::default_timeout == true); 00226 00227 dev.close_sim(); 00228 } 00229 00230 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on) 00231 { 00232 EventQueue que; 00233 AT_CellularDevice dev(que); 00234 FileHandle_stub fh1; 00235 ATHandler_stub::debug_on = false; 00236 00237 // no interfaces open so debug toggling should not affect 00238 dev.modem_debug_on(true); 00239 EXPECT_TRUE(ATHandler_stub::debug_on == false); 00240 00241 EXPECT_TRUE(dev.open_sim(&fh1)); 00242 EXPECT_TRUE(ATHandler_stub::ref_count == 1); 00243 00244 dev.modem_debug_on(true); 00245 EXPECT_TRUE(ATHandler_stub::debug_on == true); 00246 00247 dev.close_sim(); 00248 } 00249 00250 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_stack) 00251 { 00252 EventQueue que; 00253 AT_CellularDevice dev(que); 00254 FileHandle_stub fh1; 00255 00256 NetworkStack *stack = dev.get_stack(); 00257 EXPECT_TRUE(stack == NULL); 00258 00259 EXPECT_TRUE(dev.open_network(&fh1)); 00260 00261 stack = dev.get_stack(); 00262 EXPECT_TRUE(stack == NULL); // Not in PPP so also null but this is got from the network class 00263 } 00264 00265 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay) 00266 { 00267 EventQueue que; 00268 AT_CellularDevice dev(que); 00269 EXPECT_TRUE(0 == dev.get_send_delay()); 00270 } 00271 00272 TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init_module) 00273 { 00274 EventQueue que; 00275 AT_CellularDevice dev(que); 00276 EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module(NULL)); 00277 }
Generated on Tue Aug 9 2022 00:37:02 by
1.7.2