1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <regex>
18 
19 #include <android-base/logging.h>
20 #include <radio_hidl_hal_utils_v1_6.h>
21 
22 /*
23  * Test IRadio.getAvailableNetworks() for the response returned.
24  */
TEST_P(RadioHidlTest_v1_6,getAvailableNetworks)25 TEST_P(RadioHidlTest_v1_6, getAvailableNetworks) {
26     LOG(DEBUG) << "getAvailableNetworks";
27     serial = GetRandomSerialNumber();
28 
29     radio_v1_6->getAvailableNetworks(serial);
30     EXPECT_EQ(std::cv_status::no_timeout, wait());
31     EXPECT_EQ(serial, radioRsp_v1_6->rspInfo_v1_0.serial);
32     ASSERT_TRUE(radioRsp_v1_6->rspInfo_v1_0.type == RadioResponseType::SOLICITED ||
33                 radioRsp_v1_6->rspInfo_v1_0.type == RadioResponseType::SOLICITED_ACK_EXP);
34 
35     if (cardStatus.base.base.base.cardState == CardState::ABSENT) {
36         ASSERT_TRUE(CheckAnyOfErrors(
37                 radioRsp_v1_6->rspInfo_v1_0.error,
38                 {::android::hardware::radio::V1_0::RadioError::NONE,
39                  ::android::hardware::radio::V1_0::RadioError::CANCELLED,
40                  ::android::hardware::radio::V1_0::RadioError::DEVICE_IN_USE,
41                  ::android::hardware::radio::V1_0::RadioError::MODEM_ERR,
42                  ::android::hardware::radio::V1_0::RadioError::OPERATION_NOT_ALLOWED},
43                 CHECK_GENERAL_ERROR));
44     } else if (radioRsp_v1_6->rspInfo_v1_0.error ==
45                ::android::hardware::radio::V1_0::RadioError::NONE) {
46         static const std::regex kOperatorNumericRe("^[0-9]{5,6}$");
47         for (OperatorInfo info : radioRsp_v1_6->networkInfos) {
48             ASSERT_TRUE(
49                     std::regex_match(std::string(info.operatorNumeric), kOperatorNumericRe));
50         }
51     }
52 
53     LOG(DEBUG) << "getAvailableNetworks finished";
54 }
55