• 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 
16 #define private public
17 #define protected public
18 
19 #include <chrono>
20 #include <thread>
21 
22 #include "core_service_proxy.h"
23 #include "esim_state_type.h"
24 #include "gmock/gmock.h"
25 #include "iremote_broker.h"
26 #include "iremote_object.h"
27 #include "string_ex.h"
28 #include "telephony_errors.h"
29 #include "telephony_log_wrapper.h"
30 #include "gtest/gtest.h"
31 
32 namespace OHOS {
33 class MockIRemoteObject : public IRemoteObject {
34 public:
MockIRemoteObject()35     MockIRemoteObject() : IRemoteObject(u"mock_i_remote_object") {}
36 
~MockIRemoteObject()37     ~MockIRemoteObject() {}
38 
GetObjectRefCount()39     int32_t GetObjectRefCount() override
40     {
41         return 0;
42     }
43 
44     MOCK_METHOD4(SendRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option));
45 
IsProxyObject() const46     bool IsProxyObject() const override
47     {
48         return true;
49     }
50 
CheckObjectLegality() const51     bool CheckObjectLegality() const override
52     {
53         return true;
54     }
55 
AddDeathRecipient(const sptr<DeathRecipient> & recipient)56     bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) override
57     {
58         return true;
59     }
60 
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)61     bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) override
62     {
63         return true;
64     }
65 
Marshalling(Parcel & parcel) const66     bool Marshalling(Parcel &parcel) const override
67     {
68         return true;
69     }
70 
AsInterface()71     sptr<IRemoteBroker> AsInterface() override
72     {
73         return nullptr;
74     }
75 
Dump(int fd,const std::vector<std::u16string> & args)76     int Dump(int fd, const std::vector<std::u16string> &args) override
77     {
78         return 0;
79     }
80 
GetObjectDescriptor() const81     std::u16string GetObjectDescriptor() const
82     {
83         std::u16string descriptor = std::u16string();
84         return descriptor;
85     }
86 };
87 } // namespace OHOS
88 
89 namespace OHOS {
90 namespace Telephony {
91 using namespace testing::ext;
92 constexpr int32_t SLOT_ID = 0;
93 class EsimCoreServiceProxyTest : public testing::Test {
94 public:
95     int32_t slotId_ = 0;
96     static void SetUpTestCase();
97     static void TearDownTestCase();
98     void SetUp();
99     void TearDown();
100 };
101 
TearDownTestCase()102 void EsimCoreServiceProxyTest::TearDownTestCase() {}
103 
SetUp()104 void EsimCoreServiceProxyTest::SetUp() {}
105 
TearDown()106 void EsimCoreServiceProxyTest::TearDown() {}
107 
SetUpTestCase()108 void EsimCoreServiceProxyTest::SetUpTestCase() {}
109 
110 HWTEST_F(EsimCoreServiceProxyTest, SendApduData_001, Function | MediumTest | Level2)
111 {
112     sptr<MockIRemoteObject> remote = nullptr;
113     CoreServiceProxy proxy(remote);
114     std::u16string aid = Str8ToStr16("aid test");
115     EsimApduData apduData;
116     ResponseEsimResult responseResult;
117     std::u16string eId;
118     EXPECT_EQ(proxy.SendApduData(SLOT_ID, aid, apduData, responseResult), TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL);
119 }
120 
121 HWTEST_F(EsimCoreServiceProxyTest, SendApduData_002, Function | MediumTest | Level2)
122 {
123     sptr<MockIRemoteObject> remote = new (std::nothrow) MockIRemoteObject();
124     CoreServiceProxy proxy(remote);
125     std::u16string aid = Str8ToStr16("aid test");
126     EsimApduData apduData;
127     ResponseEsimResult responseResult;
128     std::u16string eId;
129     EXPECT_CALL(*remote, SendRequest(testing::_, testing::_, testing::_, testing::_)).WillOnce(testing::Return(-500));
130     EXPECT_EQ(proxy.SendApduData(SLOT_ID, aid, apduData, responseResult), TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL);
131 }
132 
133 HWTEST_F(EsimCoreServiceProxyTest, SendApduData_003, Function | MediumTest | Level2)
134 {
135     sptr<MockIRemoteObject> remote = new (std::nothrow) MockIRemoteObject();
136     CoreServiceProxy proxy(remote);
137     std::u16string aid = Str8ToStr16("aid test");
138     EsimApduData apduData;
139     ResponseEsimResult responseResult;
140     std::u16string eId;
141     EXPECT_CALL(*remote, SendRequest(testing::_, testing::_, testing::_, testing::_)).WillOnce(testing::Return(0));
142     EXPECT_EQ(proxy.SendApduData(SLOT_ID, aid, apduData, responseResult), 0);
143 }
144 
145 } // namespace Telephony
146 } // namespace OHOS
147