BA / Mbed OS BaBoRo1
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test_at_cellularsim.cpp Source File

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 
00070 void Test_AT_CellularSIM::test_AT_CellularSIM_change_pin()
00071 {
00072     EventQueue que;
00073     FileHandle_stub fh1;
00074     ATHandler at(&fh1, que, 0, ",");
00075 
00076     AT_CellularSIM sim(at);
00077     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ;
00078     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sim.change_pin("12", "34"));
00079 }
00080 
00081 void Test_AT_CellularSIM::test_AT_CellularSIM_set_pin_query()
00082 {
00083     EventQueue que;
00084     FileHandle_stub fh1;
00085     ATHandler at(&fh1, que, 0, ",");
00086 
00087     AT_CellularSIM sim(at);
00088     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ;
00089     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sim.set_pin_query("12", true));
00090 
00091     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ;
00092     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sim.set_pin_query("12", false));
00093 }
00094 
00095 void Test_AT_CellularSIM::test_AT_CellularSIM_get_sim_state()
00096 {
00097     EventQueue que;
00098     FileHandle_stub fh1;
00099     ATHandler at(&fh1, que, 0, ",");
00100 
00101     AT_CellularSIM sim(at);
00102     CellularSIM::SimState state;
00103     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ;
00104     ATHandler_stub::ssize_value = -1;
00105     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sim.get_sim_state(state));
00106     CHECK(CellularSIM::SimStateUnknown == state);
00107 
00108     char table2[] = "READY";
00109     ATHandler_stub::read_string_value = table2;
00110     ATHandler_stub::ssize_value = 5;
00111     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sim.get_sim_state(state));
00112     CHECK(CellularSIM::SimStateReady == state);
00113 
00114     char table3[] = "SIM PIN";
00115     ATHandler_stub::read_string_value = table3;
00116     ATHandler_stub::ssize_value = 7;
00117     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sim.get_sim_state(state));
00118     CHECK(CellularSIM::SimStatePinNeeded == state);
00119 
00120     char table4[] = "SIM PUK";
00121     ATHandler_stub::read_string_value = table4;
00122     ATHandler_stub::ssize_value = 7;
00123     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sim.get_sim_state(state));
00124     CHECK(CellularSIM::SimStatePukNeeded == state);
00125 
00126     char table5[] = "SOME CRAP";
00127     ATHandler_stub::read_string_value = table5;
00128     ATHandler_stub::ssize_value = 9;
00129     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sim.get_sim_state(state));
00130     CHECK(CellularSIM::SimStateUnknown == state);
00131 }