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_cellularsms.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_cellularsms.h" 00019 #include <string.h> 00020 #include "AT_CellularNetwork.h" 00021 #include "EventQueue.h" 00022 #include "ATHandler.h" 00023 #include "ATHandler_stub.h" 00024 #include "AT_CellularSMS.h" 00025 #include "FileHandle_stub.h" 00026 #include "CellularLog.h" 00027 00028 using namespace mbed; 00029 using namespace events; 00030 00031 Test_AT_CellularSMS::Test_AT_CellularSMS() 00032 { 00033 ATHandler_stub::return_given_size = false; 00034 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK ; 00035 } 00036 00037 Test_AT_CellularSMS::~Test_AT_CellularSMS() 00038 { 00039 } 00040 00041 void Test_AT_CellularSMS::test_AT_CellularSMS_constructor() 00042 { 00043 EventQueue que; 00044 FileHandle_stub fh1; 00045 ATHandler at(&fh1, que, 0, ","); 00046 00047 AT_CellularSMS *sms = new AT_CellularSMS(at); 00048 00049 delete sms; 00050 } 00051 00052 void Test_AT_CellularSMS::test_AT_CellularSMS_initialize() 00053 { 00054 EventQueue que; 00055 FileHandle_stub fh1; 00056 ATHandler at(&fh1, que, 0, ","); 00057 00058 AT_CellularSMS sms(at); 00059 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00060 CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.initialize(CellularSMS::CellularSMSMmodeText)); 00061 } 00062 00063 00064 void Test_AT_CellularSMS::test_AT_CellularSMS_send_sms() 00065 { 00066 EventQueue que; 00067 FileHandle_stub fh1; 00068 ATHandler at(&fh1, que, 0, ","); 00069 00070 AT_CellularSMS sms(at); 00071 CHECK(NSAPI_ERROR_PARAMETER == sms.send_sms(NULL, "2", 1)); 00072 00073 sms.initialize(CellularSMS::CellularSMSMmodeText); 00074 ATHandler_stub::size_value = 1; 00075 CHECK(1 == sms.send_sms("1", "22", 2)); 00076 00077 ATHandler_stub::size_value = 2; 00078 CHECK(2 == sms.send_sms("1", "22", 2)); 00079 00080 sms.initialize(CellularSMS::CellularSMSMmodePDU); 00081 CHECK(2 == sms.send_sms("1", "23", 2)); 00082 00083 ATHandler_stub::nsapi_error_ok_counter = 1; 00084 ATHandler_stub::size_value = 32; 00085 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00086 CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.send_sms("1", "23232323", 8)); 00087 00088 ATHandler_stub::nsapi_error_ok_counter = 2; 00089 ATHandler_stub::size_value = 32; 00090 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00091 CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.send_sms("1", "23232323", 8)); 00092 00093 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK ; 00094 char table[] = "232323232323232323232323232323232323232323232323232323\ 00095 232323232323232323232323232323232323232323232323232323\ 00096 232323232323232323232323232323232323232323232323232323\ 00097 23232323232323232323232323232323232323\0"; 00098 ATHandler_stub::size_value = 0; 00099 ATHandler_stub::return_given_size = true; 00100 CHECK(218 == sms.send_sms("1", table, strlen(table))); 00101 00102 CHECK(218 == sms.send_sms("12", table, strlen(table))); 00103 } 00104 00105 00106 void Test_AT_CellularSMS::test_AT_CellularSMS_get_sms() 00107 { 00108 EventQueue que; 00109 FileHandle_stub fh1; 00110 ATHandler at(&fh1, que, 0, ","); 00111 00112 AT_CellularSMS sms(at); 00113 char buf[16]; 00114 char phone[21]; 00115 char stamp[21]; 00116 int size; 00117 CHECK(NSAPI_ERROR_PARAMETER == sms.get_sms(NULL, 16, phone, 21, stamp, 21, &size)); 00118 00119 ATHandler_stub::resp_info_true_counter = 1; 00120 ATHandler_stub::int_value = 0; 00121 CHECK(-1 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); 00122 00123 ATHandler_stub::resp_info_true_counter = 2; 00124 ATHandler_stub::int_value = 11; 00125 CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); 00126 //TODO: Should make add_info to happen, before calling get_sms! 00127 00128 ATHandler_stub::resp_info_true_counter = 2; 00129 ATHandler_stub::int_value = 11; 00130 sms.initialize(CellularSMS::CellularSMSMmodePDU); 00131 CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); 00132 00133 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00134 CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); 00135 } 00136 00137 00138 void Test_AT_CellularSMS::test_AT_CellularSMS_set_sms_callback() 00139 { 00140 EventQueue que; 00141 FileHandle_stub fh1; 00142 ATHandler at(&fh1, que, 0, ","); 00143 00144 AT_CellularSMS sms(at); 00145 sms.set_sms_callback(NULL); 00146 } 00147 00148 00149 void Test_AT_CellularSMS::test_AT_CellularSMS_set_cpms() 00150 { 00151 EventQueue que; 00152 FileHandle_stub fh1; 00153 ATHandler at(&fh1, que, 0, ","); 00154 00155 AT_CellularSMS sms(at); 00156 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00157 CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_cpms("2", "3", "4")); 00158 } 00159 00160 00161 void Test_AT_CellularSMS::test_AT_CellularSMS_set_csca() 00162 { 00163 EventQueue que; 00164 FileHandle_stub fh1; 00165 ATHandler at(&fh1, que, 0, ","); 00166 00167 AT_CellularSMS sms(at); 00168 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00169 CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_csca("2", 1)); 00170 } 00171 00172 00173 void Test_AT_CellularSMS::test_AT_CellularSMS_set_cscs() 00174 { 00175 EventQueue que; 00176 FileHandle_stub fh1; 00177 ATHandler at(&fh1, que, 0, ","); 00178 00179 AT_CellularSMS sms(at); 00180 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00181 CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_cscs("2")); 00182 } 00183 00184 00185 void Test_AT_CellularSMS::test_AT_CellularSMS_delete_all_messages() 00186 { 00187 EventQueue que; 00188 FileHandle_stub fh1; 00189 ATHandler at(&fh1, que, 0, ","); 00190 00191 AT_CellularSMS sms(at); 00192 ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ; 00193 CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.delete_all_messages()); 00194 } 00195 00196 00197 void Test_AT_CellularSMS::test_AT_CellularSMS_set_extra_sim_wait_time() 00198 { 00199 EventQueue que; 00200 FileHandle_stub fh1; 00201 ATHandler at(&fh1, que, 0, ","); 00202 00203 AT_CellularSMS sms(at); 00204 sms.set_extra_sim_wait_time(56); 00205 00206 } 00207
Generated on Tue Jul 12 2022 13:31:33 by
