1 /*
2 * Copyright (C) 2024 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
21 #include "asn1_node.h"
22 #include "common_event_manager.h"
23 #include "common_event_support.h"
24 #include "esim_file.h"
25 #include "icc_file.h"
26 #include "sim_file_manager.h"
27 #include "sim_constant.h"
28 #include "sim_file_manager.h"
29 #include "tel_ril_manager.h"
30 #include "telephony_tag_def.h"
31 #include "gtest/gtest.h"
32
33 namespace OHOS {
34 namespace Telephony {
35 using namespace testing::ext;
36 class EsimPartOneTest : public testing::Test {
37 public:
38 static void SetUpTestCase();
39 static void TearDownTestCase();
40 void SetUp();
41 void TearDown();
42 };
43
TearDownTestCase()44 void EsimPartOneTest::TearDownTestCase() {}
45
SetUp()46 void EsimPartOneTest::SetUp() {}
47
TearDown()48 void EsimPartOneTest::TearDown() {}
49
SetUpTestCase()50 void EsimPartOneTest::SetUpTestCase() {}
51
52 HWTEST_F(EsimPartOneTest, IsSameAid_001, Function | MediumTest | Level2)
53 {
54 std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
55 std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
56 std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(telRilManager);
57 const std::u16string aid = u"112223334444555";
58 EXPECT_FALSE(esimFile->IsSameAid(aid));
59 esimFile->aidStr_ = u"112223334444556";
60 EXPECT_FALSE(esimFile->IsValidAidForAllowSameAidReuseChannel(aid));
61 }
62
63 HWTEST_F(EsimPartOneTest, ResetEuiccNotification_001, Function | MediumTest | Level2)
64 {
65 std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
66 std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
67 std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(telRilManager);
68 std::shared_ptr<Asn1Builder> devCapsBuilder = nullptr;
69 esimFile->ResetEuiccNotification();
70 const std::u16string aid = u"112223334444555";
71 EXPECT_FALSE(esimFile->IsSameAid(aid));
72 }
73
74 HWTEST_F(EsimPartOneTest, ProcessObtainEuiccInfo2Done_001, Function | MediumTest | Level2)
75 {
76 std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
77 std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
78 std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(telRilManager);
79 auto event = AppExecFwk::InnerEvent::Get(0);
80 EXPECT_FALSE(esimFile->ProcessObtainEuiccInfo2Done(event));
81 std::shared_ptr<IccControllerHolder> holder = nullptr;
82 std::unique_ptr<Telephony::IccFromRilMsg> rcvMsg = std::make_unique<Telephony::IccFromRilMsg>(holder);
83 rcvMsg->fileData.resultData = "BF2B0101";
84 event = AppExecFwk::InnerEvent::Get(0, rcvMsg);
85 EXPECT_FALSE(esimFile->ProcessObtainEuiccInfo2Done(event));
86 rcvMsg = nullptr;
87 event = AppExecFwk::InnerEvent::Get(0, rcvMsg);
88 EXPECT_FALSE(esimFile->ProcessObtainEuiccInfo2Done(event));
89 }
90
91 HWTEST_F(EsimPartOneTest, RetrieveNotificatioParseTagCtxComp0_001, Function | MediumTest | Level2)
92 {
93 std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
94 std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
95 std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(telRilManager);
96 std::string resultData = "BF2B16A014BF2F118001010C08646464642E63606081020410";
97 std::vector<uint8_t> responseByte = Asn1Utils::HexStrToBytes(resultData);
98 std::shared_ptr<Asn1Node> root = esimFile->Asn1ParseResponse(responseByte, responseByte.size());
99 EXPECT_FALSE(esimFile->RetrieveNotificatioParseTagCtxComp0(root));
100 }
101
102 HWTEST_F(EsimPartOneTest, ProcessRetrieveNotificationDone_001, Function | MediumTest | Level2)
103 {
104 std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
105 std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
106 std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(telRilManager);
107 std::shared_ptr<IccControllerHolder> holder = nullptr;
108 std::unique_ptr<Telephony::IccFromRilMsg> rcvMsg = std::make_unique<Telephony::IccFromRilMsg>(holder);
109 rcvMsg->fileData.resultData = "BF2B0101";
110 auto event = AppExecFwk::InnerEvent::Get(0, rcvMsg);
111 EXPECT_FALSE(esimFile->ProcessRetrieveNotificationDone(event));
112 event = nullptr;
113 EXPECT_FALSE(esimFile->ProcessRetrieveNotificationDone(event));
114 rcvMsg = nullptr;
115 event = AppExecFwk::InnerEvent::Get(0, rcvMsg);
116 EXPECT_FALSE(esimFile->ProcessRetrieveNotificationDone(event));
117 }
118
119 HWTEST_F(EsimPartOneTest, RealProcessLoadBoundProfilePackageDone_003, Function | MediumTest | Level2)
120 {
121 std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
122 std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
123 std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(telRilManager);
124 ResponseEsimInnerResult dst;
125 AuthServerResponse src;
126 esimFile->CovertAuthToApiStruct(dst, src);
127
128 EXPECT_FALSE(esimFile->RealProcessLoadBoundProfilePackageDone());
129 }
130 HWTEST_F(EsimPartOneTest, RealProcessPrepareDownloadDone_001, Function | MediumTest | Level2)
131 {
132 std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
133 std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
134 std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(telRilManager);
135 EXPECT_FALSE(esimFile->RealProcessPrepareDownloadDone());
136 }
137
138 HWTEST_F(EsimPartOneTest, AddCtxParams1_001, Function | MediumTest | Level2)
139 {
140 std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
141 std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
142 std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(telRilManager);
143 std::shared_ptr<Asn1Builder> ctxParams1Builder = nullptr;
144 Es9PlusInitAuthResp authRespData;
145 esimFile->AddCtxParams1(ctxParams1Builder, authRespData);
146 EXPECT_EQ(ctxParams1Builder, nullptr);
147 }
148
149 HWTEST_F(EsimPartOneTest, LoadBoundProfilePackageParseNotificationMetadata_001, Function | MediumTest | Level2)
150 {
151 std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
152 std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
153 std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(telRilManager);
154 std::shared_ptr<Asn1Node> notificationMetadata = nullptr;
155 EXPECT_FALSE(esimFile->LoadBoundProfilePackageParseNotificationMetadata(notificationMetadata));
156 }
157 }
158 // namespace Telephony
159 } // namespace OHOS