Knight KE / Mbed OS Game_Master
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test_at_cellularsms.cpp Source File

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     LONGS_EQUAL(NSAPI_ERROR_PARAMETER , sms.send_sms(NULL, "2", 1));
00072 
00073     sms.initialize(CellularSMS::CellularSMSMmodeText);
00074     ATHandler_stub::size_value = 1;
00075     LONGS_EQUAL(1, sms.send_sms("1", "22", 2));
00076 
00077     ATHandler_stub::size_value = 2;
00078     LONGS_EQUAL(2, sms.send_sms("1", "22", 2));
00079 
00080     ATHandler_stub::return_given_size = true; // PDU mode write is much longer than than msg len
00081     sms.initialize(CellularSMS::CellularSMSMmodePDU);
00082     LONGS_EQUAL(2, sms.send_sms("1", "23", 2));;
00083 
00084     ATHandler_stub::nsapi_error_ok_counter = 1;
00085     ATHandler_stub::size_value = 32;
00086     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ;
00087     LONGS_EQUAL(NSAPI_ERROR_AUTH_FAILURE , sms.send_sms("1", "23232323", 8));
00088 
00089     ATHandler_stub::nsapi_error_ok_counter = 2;
00090     ATHandler_stub::size_value = 32;
00091     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ;
00092     LONGS_EQUAL(NSAPI_ERROR_AUTH_FAILURE , sms.send_sms("1", "23232323", 8));
00093 
00094     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK ;
00095     char table[] = "232323232323232323232323232323232323232323232323232323\
00096                     232323232323232323232323232323232323232323232323232323\
00097                     232323232323232323232323232323232323232323232323232323\
00098                     23232323232323232323232323232323232323\0";
00099 
00100     LONGS_EQUAL(strlen(table), sms.send_sms("1", table, strlen(table)));
00101     LONGS_EQUAL(strlen(table), sms.send_sms("12", table, strlen(table)));
00102 }
00103 
00104 
00105 void Test_AT_CellularSMS::test_AT_CellularSMS_get_sms()
00106 {
00107     EventQueue que;
00108     FileHandle_stub fh1;
00109     ATHandler at(&fh1, que, 0, ",");
00110 
00111     AT_CellularSMS sms(at);
00112     char buf[16];
00113     char phone[21];
00114     char stamp[21];
00115     int size;
00116     CHECK(NSAPI_ERROR_PARAMETER  == sms.get_sms(NULL, 16, phone, 21, stamp, 21, &size));
00117 
00118     ATHandler_stub::resp_info_true_counter = 1;
00119     ATHandler_stub::int_value = 0;
00120     CHECK(-1 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
00121 
00122     ATHandler_stub::resp_info_true_counter = 2;
00123     ATHandler_stub::int_value = 11;
00124     CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
00125     //TODO: Should make add_info to happen, before calling get_sms!
00126 
00127     ATHandler_stub::resp_info_true_counter = 2;
00128     ATHandler_stub::int_value = 11;
00129     sms.initialize(CellularSMS::CellularSMSMmodePDU);
00130     CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
00131 
00132     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ;
00133     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
00134 }
00135 
00136 
00137 void Test_AT_CellularSMS::test_AT_CellularSMS_set_sms_callback()
00138 {
00139     EventQueue que;
00140     FileHandle_stub fh1;
00141     ATHandler at(&fh1, que, 0, ",");
00142 
00143     AT_CellularSMS sms(at);
00144     sms.set_sms_callback(NULL);
00145 }
00146 
00147 
00148 void Test_AT_CellularSMS::test_AT_CellularSMS_set_cpms()
00149 {
00150     EventQueue que;
00151     FileHandle_stub fh1;
00152     ATHandler at(&fh1, que, 0, ",");
00153 
00154     AT_CellularSMS sms(at);
00155     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ;
00156     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sms.set_cpms("2", "3", "4"));
00157 }
00158 
00159 
00160 void Test_AT_CellularSMS::test_AT_CellularSMS_set_csca()
00161 {
00162     EventQueue que;
00163     FileHandle_stub fh1;
00164     ATHandler at(&fh1, que, 0, ",");
00165 
00166     AT_CellularSMS sms(at);
00167     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ;
00168     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sms.set_csca("2", 1));
00169 }
00170 
00171 
00172 void Test_AT_CellularSMS::test_AT_CellularSMS_set_cscs()
00173 {
00174     EventQueue que;
00175     FileHandle_stub fh1;
00176     ATHandler at(&fh1, que, 0, ",");
00177 
00178     AT_CellularSMS sms(at);
00179     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ;
00180     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sms.set_cscs("2"));
00181 }
00182 
00183 
00184 void Test_AT_CellularSMS::test_AT_CellularSMS_delete_all_messages()
00185 {
00186     EventQueue que;
00187     FileHandle_stub fh1;
00188     ATHandler at(&fh1, que, 0, ",");
00189 
00190     AT_CellularSMS sms(at);
00191     ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE ;
00192     CHECK(NSAPI_ERROR_AUTH_FAILURE  == sms.delete_all_messages());
00193 }
00194 
00195 
00196 void Test_AT_CellularSMS::test_AT_CellularSMS_set_extra_sim_wait_time()
00197 {
00198     EventQueue que;
00199     FileHandle_stub fh1;
00200     ATHandler at(&fh1, que, 0, ",");
00201 
00202     AT_CellularSMS sms(at);
00203     sms.set_extra_sim_wait_time(56);
00204 
00205 }
00206