• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>(simStateManager);
57     const std::u16string aid = u"112223334444555";
58     EXPECT_FALSE(esimFile->IsSameAid(aid));
59     esimFile->aidStr_ = u"112223334444556";
60     esimFile->OnAllFilesFetched();
61     esimFile->ProcessFileLoaded(true);
62     esimFile->OnAllFilesFetched();
63     esimFile->ProcessIccRefresh(1);
64     esimFile->StartLoad();
65     EXPECT_FALSE(esimFile->IsValidAidForAllowSameAidReuseChannel(aid));
66 }
67 
68 HWTEST_F(EsimPartOneTest, ResetEuiccNotification_001, Function | MediumTest | Level2)
69 {
70     std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
71     std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
72     std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(simStateManager);
73     std::shared_ptr<Asn1Builder> devCapsBuilder = nullptr;
74     esimFile->ResetEuiccNotification();
75     const std::u16string aid = u"112223334444555";
76     EXPECT_FALSE(esimFile->IsSameAid(aid));
77 }
78 
79 HWTEST_F(EsimPartOneTest, ProcessObtainEuiccInfo2Done_001, Function | MediumTest | Level2)
80 {
81     std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
82     std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
83     std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(simStateManager);
84     auto event = AppExecFwk::InnerEvent::Get(0);
85     EXPECT_FALSE(esimFile->ProcessObtainEuiccInfo2Done(event));
86     std::shared_ptr<IccControllerHolder> holder = nullptr;
87     std::unique_ptr<Telephony::IccFromRilMsg> rcvMsg = std::make_unique<Telephony::IccFromRilMsg>(holder);
88     rcvMsg->fileData.resultData = "BF2B0101";
89     event = AppExecFwk::InnerEvent::Get(0, rcvMsg);
90     EXPECT_FALSE(esimFile->ProcessObtainEuiccInfo2Done(event));
91     rcvMsg = nullptr;
92     event = AppExecFwk::InnerEvent::Get(0, rcvMsg);
93     EXPECT_FALSE(esimFile->ProcessObtainEuiccInfo2Done(event));
94 }
95 
96 HWTEST_F(EsimPartOneTest, RetrieveNotificatioParseTagCtxComp0_001, Function | MediumTest | Level2)
97 {
98     std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
99     std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
100     std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(simStateManager);
101     std::string resultData = "BF2B16A014BF2F118001010C08646464642E63606081020410";
102     std::vector<uint8_t> responseByte = Asn1Utils::HexStrToBytes(resultData);
103     std::shared_ptr<Asn1Node> root = esimFile->Asn1ParseResponse(responseByte, responseByte.size());
104     EXPECT_FALSE(esimFile->RetrieveNotificatioParseTagCtxComp0(root));
105 }
106 
107 HWTEST_F(EsimPartOneTest, ProcessRetrieveNotificationDone_001, Function | MediumTest | Level2)
108 {
109     std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
110     std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
111     std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(simStateManager);
112     std::shared_ptr<IccControllerHolder> holder = nullptr;
113     std::unique_ptr<Telephony::IccFromRilMsg> rcvMsg = std::make_unique<Telephony::IccFromRilMsg>(holder);
114     rcvMsg->fileData.resultData = "BF2B0101";
115     auto event = AppExecFwk::InnerEvent::Get(0, rcvMsg);
116     EXPECT_FALSE(esimFile->ProcessRetrieveNotificationDone(event));
117     event = nullptr;
118     EXPECT_FALSE(esimFile->ProcessRetrieveNotificationDone(event));
119     rcvMsg = nullptr;
120     event = AppExecFwk::InnerEvent::Get(0, rcvMsg);
121     EXPECT_FALSE(esimFile->ProcessRetrieveNotificationDone(event));
122 }
123 
124 HWTEST_F(EsimPartOneTest, RealProcessLoadBoundProfilePackageDone_003, Function | MediumTest | Level2)
125 {
126     std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
127     std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
128     std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(simStateManager);
129     std::string combineHexStr = "1222333";
130     ResponseEsimInnerResult dst;
131     AuthServerResponse src;
132     esimFile->CovertAuthToApiStruct(dst, src);
133 
134     EXPECT_FALSE(esimFile->RealProcessLoadBoundProfilePackageDone(combineHexStr));
135 }
136 HWTEST_F(EsimPartOneTest, RealProcessPrepareDownloadDone_001, Function | MediumTest | Level2)
137 {
138     std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
139     std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
140     std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(simStateManager);
141     std::string combineHexStr = "1222333";
142     EXPECT_FALSE(esimFile->RealProcessPrepareDownloadDone(combineHexStr));
143 }
144 
145 HWTEST_F(EsimPartOneTest, AddCtxParams1_001, Function | MediumTest | Level2)
146 {
147     std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
148     std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
149     std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(simStateManager);
150     std::shared_ptr<Asn1Builder> ctxParams1Builder = nullptr;
151     Es9PlusInitAuthResp authRespData;
152     esimFile->AddCtxParams1(ctxParams1Builder, authRespData);
153     EXPECT_EQ(ctxParams1Builder, nullptr);
154 }
155 
156 HWTEST_F(EsimPartOneTest, LoadBoundProfilePackageParseNotificationMetadata_001, Function | MediumTest | Level2)
157 {
158     std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
159     std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
160     std::shared_ptr<Telephony::EsimFile> esimFile = std::make_shared<EsimFile>(simStateManager);
161     std::shared_ptr<Asn1Node> notificationMetadata = nullptr;
162     EXPECT_FALSE(esimFile->LoadBoundProfilePackageParseNotificationMetadata(notificationMetadata));
163 }
164 }
165 // namespace Telephony
166 } // namespace OHOS