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_cellularsim.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_cellularsim.h" 00019 #include <string.h> 00020 #include "AT_CellularNetwork.h" 00021 #include "EventQueue.h" 00022 #include "ATHandler.h" 00023 #include "AT_CellularSIM.h" 00024 #include "FileHandle_stub.h" 00025 #include "CellularLog.h" 00026 #include "ATHandler_stub.h" 00027 00028 using namespace mbed; 00029 using namespace events; 00030 00031 Test_AT_CellularSIM::Test_AT_CellularSIM() 00032 { 00033 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK ; 00034 ATHandler_stub::read_string_value = NULL; 00035 ATHandler_stub::ssize_value = 0; 00036 } 00037 00038 Test_AT_CellularSIM::~Test_AT_CellularSIM() 00039 { 00040 } 00041 00042 void Test_AT_CellularSIM::test_AT_CellularSIM_constructor() 00043 { 00044 EventQueue que; 00045 FileHandle_stub fh1; 00046 ATHandler at(&fh1, que, 0, ","); 00047 00048 AT_CellularSIM *sim = new AT_CellularSIM(at); 00049 00050 delete sim; 00051 } 00052 00053 void Test_AT_CellularSIM::test_AT_CellularSIM_set_pin() 00054 { 00055 EventQueue que; 00056 FileHandle_stub fh1; 00057 ATHandler at(&fh1, que, 0, ","); 00058 00059 AT_CellularSIM sim(at); 00060 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00061 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.set_pin("12")); 00062 00063 char table2[] = "READY"; 00064 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK ; 00065 ATHandler_stub::read_string_value = table2; 00066 ATHandler_stub::ssize_value = 5; 00067 CHECK(NSAPI_ERROR_OK == sim.set_pin("12")); 00068 00069 CHECK(NSAPI_ERROR_OK == sim.set_pin(NULL)); 00070 } 00071 00072 void Test_AT_CellularSIM::test_AT_CellularSIM_change_pin() 00073 { 00074 EventQueue que; 00075 FileHandle_stub fh1; 00076 ATHandler at(&fh1, que, 0, ","); 00077 00078 AT_CellularSIM sim(at); 00079 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00080 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.change_pin("12", "34")); 00081 00082 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.change_pin(NULL, "34")); 00083 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.change_pin("12", NULL)); 00084 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.change_pin(NULL, NULL)); 00085 } 00086 00087 void Test_AT_CellularSIM::test_AT_CellularSIM_set_pin_query() 00088 { 00089 EventQueue que; 00090 FileHandle_stub fh1; 00091 ATHandler at(&fh1, que, 0, ","); 00092 00093 AT_CellularSIM sim(at); 00094 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00095 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.set_pin_query("12", true)); 00096 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.set_pin_query(NULL, true)); 00097 00098 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00099 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.set_pin_query("12", false)); 00100 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.set_pin_query(NULL, false)); 00101 } 00102 00103 void Test_AT_CellularSIM::test_AT_CellularSIM_get_sim_state() 00104 { 00105 EventQueue que; 00106 FileHandle_stub fh1; 00107 ATHandler at(&fh1, que, 0, ","); 00108 00109 AT_CellularSIM sim(at); 00110 CellularSIM::SimState state; 00111 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00112 ATHandler_stub::ssize_value = -1; 00113 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.get_sim_state(state)); 00114 CHECK(CellularSIM::SimStateUnknown == state); 00115 00116 char table2[] = "READY"; 00117 ATHandler_stub::read_string_value = table2; 00118 ATHandler_stub::ssize_value = 5; 00119 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.get_sim_state(state)); 00120 CHECK(CellularSIM::SimStateReady == state); 00121 00122 char table3[] = "SIM PIN"; 00123 ATHandler_stub::read_string_value = table3; 00124 ATHandler_stub::ssize_value = 7; 00125 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.get_sim_state(state)); 00126 CHECK(CellularSIM::SimStatePinNeeded == state); 00127 00128 char table4[] = "SIM PUK"; 00129 ATHandler_stub::read_string_value = table4; 00130 ATHandler_stub::ssize_value = 7; 00131 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.get_sim_state(state)); 00132 CHECK(CellularSIM::SimStatePukNeeded == state); 00133 00134 char table5[] = "SOME CRAP"; 00135 ATHandler_stub::read_string_value = table5; 00136 ATHandler_stub::ssize_value = 9; 00137 CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.get_sim_state(state)); 00138 CHECK(CellularSIM::SimStateUnknown == state); 00139 } 00140 00141 void Test_AT_CellularSIM::test_AT_CellularSIM_get_imsi() 00142 { 00143 EventQueue que; 00144 FileHandle_stub fh1; 00145 ATHandler at(&fh1, que, 0, ","); 00146 00147 char imsi[16]; 00148 AT_CellularSIM sim(at); 00149 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK ; 00150 ATHandler_stub::read_string_value = "123456789012345"; 00151 ATHandler_stub::ssize_value = 15; 00152 CHECK(NSAPI_ERROR_OK == sim.get_imsi(imsi)); 00153 CHECK(strcmp(ATHandler_stub::read_string_value, imsi) == 0); 00154 00155 CHECK(NSAPI_ERROR_PARAMETER == sim.get_imsi(NULL)); 00156 00157 // this would fail as get_imsi should take another param which is the size of the buffer which we could use for validation. 00158 // Now we have improved documentation that that the given imsi buffer size must be over 15. 00159 //char imsi2[5]; 00160 //CHECK(NSAPI_ERROR_PARAMETER == sim.get_imsi(imsi2)); 00161 }
Generated on Tue Jul 12 2022 12:45:51 by
1.7.2