• 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 
41 namespace OHOS {
42 namespace Telephony {
43 using namespace testing::ext;
44 
45 class OperatorConfigLoaderTest : public testing::Test {
46 public:
47     static void SetUpTestCase();
48     static void TearDownTestCase();
49     void SetUp();
50     void TearDown();
51 };
SetUpTestCase()52 void OperatorConfigLoaderTest::SetUpTestCase() {}
53 
TearDownTestCase()54 void OperatorConfigLoaderTest::TearDownTestCase() {}
55 
SetUp()56 void OperatorConfigLoaderTest::SetUp() {}
57 
TearDown()58 void OperatorConfigLoaderTest::TearDown() {}
59 
60 /**
61  * @tc.number   Telephony_GetMccFromMccMnc_001
62  * @tc.name     test error branch
63  * @tc.desc     Function test
64  */
65 HWTEST_F(OperatorConfigLoaderTest, Telephony_GetMccFromMccMnc_001, Function | MediumTest | Level1)
66 {
67     auto telRilManager = std::make_shared<TelRilManager>();
68     auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
69     EventFwk::MatchingSkills matchingSkills;
70     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
71     EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
72     auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
73     auto operatorConfigCache = std::make_shared<OperatorConfigCache>(simFileManager, 0);
74     auto operatorConfigLoader = std::make_shared<OperatorConfigLoader>(simFileManager, operatorConfigCache);
75     std::string mccmnc = Str16ToStr8(simFileManager->GetSimOperatorNumeric());
76     std::string ret = operatorConfigLoader->GetMccFromMccMnc(mccmnc);
77     std::string result = operatorConfigLoader->GetMncFromMccMnc(mccmnc);
78     EXPECT_EQ(ret, "");
79 }
80 
81 /**
82  * @tc.number   Telephony_SetMatchResultToSimFileManager_001
83  * @tc.name     test error branch
84  * @tc.desc     Function test
85  */
86 HWTEST_F(OperatorConfigLoaderTest, Telephony_SetMatchResultToSimFileManager_001, Function | MediumTest | Level1)
87 {
88     auto telRilManager = std::make_shared<TelRilManager>();
89     auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
90     EventFwk::MatchingSkills matchingSkills;
91     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
92     EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
93     auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
94     auto operatorConfigCache = std::make_shared<OperatorConfigCache>(simFileManager, 0);
95     auto operatorConfigLoader = std::make_shared<OperatorConfigLoader>(simFileManager, operatorConfigCache);
96     operatorConfigLoader->mccmncFromSim_ = Str16ToStr8(simFileManager->GetSimOperatorNumeric());
97     std::string opKeyVal = operatorConfigLoader->mccmncFromSim_;
98     std::string opNameVal = "COMMON";
99     std::string opKeyExtVal = "";
100     int32_t slotId = 0;
101     operatorConfigLoader->SetMatchResultToSimFileManager(opKeyVal, opNameVal, opKeyExtVal, slotId, simFileManager);
102     EXPECT_EQ(operatorConfigLoader->mccmncFromSim_, "");
103 }
104 
105 /**
106  * @tc.number   Telephony_CreateSimHelper_001
107  * @tc.name     test error branch
108  * @tc.desc     Function test
109  */
110 HWTEST_F(OperatorConfigLoaderTest, Telephony_CreateSimHelper_001, Function | MediumTest | Level1)
111 {
112     auto telRilManager = std::make_shared<TelRilManager>();
113     auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
114     EventFwk::MatchingSkills matchingSkills;
115     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
116     EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
117     auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
118     auto operatorConfigCache = std::make_shared<OperatorConfigCache>(simFileManager, 0);
119     auto operatorConfigLoader = std::make_shared<OperatorConfigLoader>(simFileManager, operatorConfigCache);
120     auto result = operatorConfigLoader->CreateSimHelper();
121     EXPECT_EQ(result, nullptr);
122 }
123 
124 } // namespace Telephony
125 } // namespace OHOS