• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #define private public
16 #define protected public
17 #include <gtest/gtest.h>
18 #include <string_ex.h>
19 
20 #include "core_manager_inner.h"
21 #include "core_service.h"
22 #include "icc_dialling_numbers_handler.h"
23 #include "icc_dialling_numbers_manager.h"
24 #include "icc_file_controller.h"
25 #include "icc_operator_privilege_controller.h"
26 #include "mcc_pool.h"
27 #include "operator_config_cache.h"
28 #include "operator_config_loader.h"
29 #include "parcel.h"
30 #include "plmn_file.h"
31 #include "sim_account_manager.h"
32 #include "sim_data_type.h"
33 #include "sim_file_controller.h"
34 #include "sim_manager.h"
35 #include "sim_rdb_helper.h"
36 #include "sim_sms_manager.h"
37 #include "usim_dialling_numbers_service.h"
38 #include "want.h"
39 #include "sim_constant.h"
40 #include "tel_ril_manager.h"
41 
42 namespace OHOS {
43 namespace Telephony {
44 using namespace testing::ext;
45 
46 class OperatorConfigLoaderTest : public testing::Test {
47 public:
48     static void SetUpTestCase();
49     static void TearDownTestCase();
50     void SetUp();
51     void TearDown();
52 };
SetUpTestCase()53 void OperatorConfigLoaderTest::SetUpTestCase() {}
54 
TearDownTestCase()55 void OperatorConfigLoaderTest::TearDownTestCase() {}
56 
SetUp()57 void OperatorConfigLoaderTest::SetUp() {}
58 
TearDown()59 void OperatorConfigLoaderTest::TearDown() {}
60 
61 /**
62  * @tc.number   Telephony_GetMccFromMccMnc_001
63  * @tc.name     test error branch
64  * @tc.desc     Function test
65  */
66 HWTEST_F(OperatorConfigLoaderTest, Telephony_GetMccFromMccMnc_001, Function | MediumTest | Level1)
67 {
68     auto telRilManager = std::make_shared<TelRilManager>();
69     auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
70     EventFwk::MatchingSkills matchingSkills;
71     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
72     EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
73     auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
74     auto operatorConfigCache = std::make_shared<OperatorConfigCache>(simFileManager, simStateManager, 0);
75     auto operatorConfigLoader = std::make_shared<OperatorConfigLoader>(simFileManager, operatorConfigCache);
76     std::string mccmnc = Str16ToStr8(simFileManager->GetSimOperatorNumeric());
77     std::string ret = operatorConfigLoader->GetMccFromMccMnc(mccmnc);
78     std::string result = operatorConfigLoader->GetMncFromMccMnc(mccmnc);
79     EXPECT_EQ(ret, "");
80 }
81 
82 /**
83  * @tc.number   Telephony_SetMatchResultToSimFileManager_001
84  * @tc.name     test error branch
85  * @tc.desc     Function test
86  */
87 HWTEST_F(OperatorConfigLoaderTest, Telephony_SetMatchResultToSimFileManager_001, Function | MediumTest | Level1)
88 {
89     auto telRilManager = std::make_shared<TelRilManager>();
90     auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
91     EventFwk::MatchingSkills matchingSkills;
92     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
93     EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
94     auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
95     auto operatorConfigCache = std::make_shared<OperatorConfigCache>(simFileManager, simStateManager, 0);
96     auto operatorConfigLoader = std::make_shared<OperatorConfigLoader>(simFileManager, operatorConfigCache);
97     operatorConfigLoader->mccmncFromSim_ = Str16ToStr8(simFileManager->GetSimOperatorNumeric());
98     std::string opKeyVal = operatorConfigLoader->mccmncFromSim_;
99     std::string opNameVal = "COMMON";
100     std::string opKeyExtVal = "";
101     int32_t slotId = 0;
102     operatorConfigLoader->SetMatchResultToSimFileManager(opKeyVal, opNameVal, opKeyExtVal, slotId, simFileManager);
103     EXPECT_EQ(operatorConfigLoader->mccmncFromSim_, "");
104 }
105 
106 /**
107  * @tc.number   Telephony_CreateSimHelper_001
108  * @tc.name     test error branch
109  * @tc.desc     Function test
110  */
111 HWTEST_F(OperatorConfigLoaderTest, Telephony_CreateSimHelper_001, Function | MediumTest | Level1)
112 {
113     auto telRilManager = std::make_shared<TelRilManager>();
114     auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
115     EventFwk::MatchingSkills matchingSkills;
116     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
117     EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
118     auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
119     auto operatorConfigCache = std::make_shared<OperatorConfigCache>(simFileManager, simStateManager, 0);
120     auto operatorConfigLoader = std::make_shared<OperatorConfigLoader>(simFileManager, operatorConfigCache);
121     auto result = operatorConfigLoader->CreateSimHelper();
122     EXPECT_EQ(result, nullptr);
123 }
124 
125 /**
126  * @tc.number   Telephony_UpdateIccidCache_001
127  * @tc.name     test UpdateIccidCache
128  * @tc.desc     Function test
129  */
130 HWTEST_F(OperatorConfigLoaderTest, Telephony_UpdateIccidCache_001, Function | MediumTest | Level1)
131 {
132     auto telRilManager = std::make_shared<TelRilManager>();
133     auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
134     simStateManager->Init(0);
135     simStateManager->simStateHandle_->iccid_ = "86890000000000000001";
136     EventFwk::MatchingSkills matchingSkills;
137     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
138     EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
139     auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
140     auto operatorConfigCache = std::make_shared<OperatorConfigCache>(simFileManager, simStateManager, 0);
141     auto operatorConfigLoader = std::make_shared<OperatorConfigLoader>(simFileManager, operatorConfigCache);
142     operatorConfigCache->iccidCache_ = "";
143     operatorConfigCache->UpdateIccidCache(0);
144     operatorConfigCache->UpdateIccidCache(1);
145     EXPECT_EQ(operatorConfigCache->iccidCache_, "86890000000000000001");
146     operatorConfigCache->UpdateIccidCache(0);
147     simFileManager = nullptr;
148     operatorConfigCache->UpdateIccidCache(0);
149 }
150 
151 /**
152  * @tc.number   Telephony_GetMccFromMccMnc_002
153  * @tc.name     test error branch
154  * @tc.desc     Function test
155  */
156 HWTEST_F(OperatorConfigLoaderTest, Telephony_GetMccFromMccMnc_002, Function | MediumTest | Level1)
157 {
158     auto telRilManager = std::make_shared<TelRilManager>();
159     auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
160     EventFwk::MatchingSkills matchingSkills;
161     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
162     EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
163     auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
164     auto operatorConfigCache = std::make_shared<OperatorConfigCache>(simFileManager, simStateManager, 0);
165     auto operatorConfigLoader = std::make_shared<OperatorConfigLoader>(simFileManager, operatorConfigCache);
166     std::string mccmnc = "123456";
167     std::string ret = operatorConfigLoader->GetMccFromMccMnc(mccmnc);
168     EXPECT_EQ(ret, "123");
169 
170     mccmnc = "1234";
171     ret = operatorConfigLoader->GetMccFromMccMnc(mccmnc);
172     EXPECT_EQ(ret, "");
173 
174     mccmnc = "1234567890123456";
175     std::string result = operatorConfigLoader->GetMncFromMccMnc(mccmnc);
176     EXPECT_EQ(ret, "");
177 }
178 } // namespace Telephony
179 } // namespace OHOS