• 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 
18 #include <string>
19 #include <unistd.h>
20 #include "core_manager_inner.h"
21 #include "core_service.h"
22 #include "core_service_client.h"
23 #include "enum_convert.h"
24 #include "operator_config_cache.h"
25 #include "operator_file_parser.h"
26 #include "sim_manager.h"
27 #include "sim_state_type.h"
28 #include "str_convert.h"
29 #include "string_ex.h"
30 #include "tel_profile_util.h"
31 #include "telephony_ext_wrapper.h"
32 #include "gtest/gtest.h"
33 #include "tel_ril_manager.h"
34 #include "mock_tel_ril_manager.h"
35 #include "sim_constant.h"
36 #include "icc_dialling_numbers_handler.h"
37 #include "icc_file_controller.h"
38 #include "isim_file.h"
39 #include "isim_file_controller.h"
40 
41 namespace OHOS {
42 namespace Telephony {
43 using namespace testing::ext;
44 using namespace testing;
45 
46 class ISimFileTest : public testing::Test {
47 public:
48     static void SetUpTestCase();
49     static void TearDownTestCase();
50     void SetUp();
51     void TearDown();
52 };
53 
54 
SetUpTestCase()55 void ISimFileTest::SetUpTestCase() {}
56 
TearDownTestCase()57 void ISimFileTest::TearDownTestCase() {}
58 
SetUp()59 void ISimFileTest::SetUp() {}
60 
TearDown()61 void ISimFileTest::TearDown() {}
62 
63 HWTEST_F(ISimFileTest, ISimFileTest001, Function | MediumTest | Level1)
64 {
65     int32_t slotId = 0;
66     std::shared_ptr<ITelRilManager> telRilManager = std::make_shared<TelRilManager>();
67     std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
68     std::shared_ptr<IsimFile> iSimFile = std::make_shared<IsimFile>(simStateManager);
69     std::shared_ptr<IccFileController> file = std::make_shared<SimFileController>(slotId);
70     std::shared_ptr<IccDiallingNumbersHandler> handler = std::make_shared<IccDiallingNumbersHandler>(file);
71     iSimFile->SetRilAndFileController(telRilManager, file, handler);
72     int32_t validEventId = 0x03;
73     int32_t invalidEventId = 0xFFFF78;
74     iSimFile->StartLoad();
75     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(validEventId);
76     iSimFile->ProcessEvent(event);
77     event = AppExecFwk::InnerEvent::Get(invalidEventId);
78     iSimFile->ProcessEvent(event);
79     iSimFile->ProcessFileLoaded(true);
80     iSimFile->ProcessFileLoaded(false);
81     iSimFile->ProcessLockedAllFilesFetched();
82     iSimFile->OnAllFilesFetched();
83     EXPECT_FALSE(iSimFile->ProcessIccReady(event));
84 }
85 
86 HWTEST_F(ISimFileTest, ISimFileTest002, Function | MediumTest | Level1)
87 {
88     int32_t slotId = 0;
89     std::shared_ptr<ITelRilManager> telRilManager = std::make_shared<TelRilManager>();
90     std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
91     std::shared_ptr<IsimFile> iSimFile = std::make_shared<IsimFile>(simStateManager);
92     std::shared_ptr<IccFileController> file = std::make_shared<SimFileController>(slotId);
93     std::shared_ptr<IccDiallingNumbersHandler> handler = std::make_shared<IccDiallingNumbersHandler>(file);
94     iSimFile->SetRilAndFileController(telRilManager, file, handler);
95     iSimFile->LoadIsimFiles();
96     int32_t validEventId = 0x03;
97     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(validEventId);
98     auto nullEvent = AppExecFwk::InnerEvent::Pointer(nullptr, nullptr);
99     iSimFile->ProcessGetIccidDone(event);
100     iSimFile->ProcessGetIccidDone(nullEvent);
101     iSimFile->ProcessGetImsiDone(event);
102     iSimFile->ProcessGetImsiDone(nullEvent);
103     iSimFile->ProcessGetImpiDone(event);
104     iSimFile->ProcessGetImpiDone(nullEvent);
105     iSimFile->ProcessGetIstDone(event);
106     iSimFile->ProcessGetIstDone(nullEvent);
107     iSimFile->ObtainIsimImpi();
108     iSimFile->ObtainIsimDomain();
109     iSimFile->ObtainIsimImpu();
110     iSimFile->ObtainIsimPcscf();
111     std::string mailName, mailNumber;
112     iSimFile->UpdateVoiceMail(mailName, mailNumber);
113     iSimFile->SetVoiceMailCount(0);
114     iSimFile->SetVoiceCallForwarding(true, mailNumber);
115     iSimFile->ObtainSpnCondition(true, mailNumber);
116     iSimFile->ObtainIsoCountryCode();
117     iSimFile->SetVoiceMailNumber(mailNumber);
118     iSimFile->GetVoiceMailNumber();
119     EXPECT_FALSE(iSimFile->ProcessIsimRefresh(nullEvent));
120 }
121 
122 HWTEST_F(ISimFileTest, ISimFileControllerTest001, Function | MediumTest | Level1)
123 {
124     int32_t slotId = 0;
125     std::shared_ptr<ITelRilManager> telRilManager = std::make_shared<TelRilManager>();
126     std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
127     std::shared_ptr<IsimFile> iSimFile = std::make_shared<IsimFile>(simStateManager);
128     std::shared_ptr<IccFileController> file = std::make_shared<SimFileController>(slotId);
129     std::shared_ptr<IccDiallingNumbersHandler> handler = std::make_shared<IccDiallingNumbersHandler>(file);
130     iSimFile->SetRilAndFileController(telRilManager, file, handler);
131     std::shared_ptr<IsimFileController> iSimFileController = std::make_shared<IsimFileController>(slotId);
132     iSimFileController->ObtainElementFilePath(ELEMENTARY_FILE_USIM_ADN);
133     EXPECT_NE(iSimFileController->ObtainElementFilePath(ELEMENTARY_FILE_IMPI).c_str(), nullptr);
134 }
135 
136 }
137 }
138