• 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 
16 #include <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 
19 #include "ipc_object_stub.h"
20 #include "message_parcel_warp.h"
21 #include "pasteboard_entry_getter_proxy.h"
22 #include "pasteboard_error.h"
23 
24 using namespace OHOS;
25 using namespace testing;
26 using namespace testing::ext;
27 using namespace OHOS::MiscServices;
28 
29 namespace OHOS {
30 namespace {
31     const int64_t INT64_NEGATIVE_NUMBER = -1;
32     const int64_t INT64_POSITIVE_NUMBER = 1;
33     const uint32_t UINT32_RANDOM = 333;
34     const uint8_t UINT8_RANDOM = 0x01;
35     const int HANDEL_AND_PROTO = 1;
36     const int SENDREQUEST_ONE = 1;
37     const int SENDREQUEST_TWO = 2;
38     const int SENDREQUEST_ZERO = 0;
39     const std::u16string DESCRIPTOR_TEST = u"test_descriptor";
40 }
41 
42 class PasteboardEntryGetterProxyInterface {
43 public:
PasteboardEntryGetterProxyInterface()44     PasteboardEntryGetterProxyInterface() {};
~PasteboardEntryGetterProxyInterface()45     virtual ~PasteboardEntryGetterProxyInterface() {};
46 
47     virtual bool WriteInterfaceToken(std::u16string name) = 0;
48     virtual bool WriteUint32(uint32_t value) = 0;
49     virtual bool Encode(std::vector<uint8_t> &buffer) = 0;
50     virtual bool WriteInt64(int64_t value) = 0;
51     virtual bool WriteRawData(MessageParcel &parcelPata, const void *data, size_t size) = 0;
52     virtual bool WriteUnpadBuffer(const void *data, size_t size) = 0;
53     virtual int64_t ReadInt64() = 0;
54     virtual bool Decode(const std::vector<std::uint8_t> &buffer) = 0;
55     virtual uint8_t *ReadUnpadBuffer(size_t length) = 0;
56 };
57 
58 class PasteboardEntryGetterProxyMock : public PasteboardEntryGetterProxyInterface {
59 public:
60     PasteboardEntryGetterProxyMock();
61     ~PasteboardEntryGetterProxyMock() override;
62 
63     MOCK_METHOD1(WriteInterfaceToken, bool(std::u16string name));
64     MOCK_METHOD1(WriteUint32, bool(uint32_t value));
65     MOCK_METHOD1(Encode, bool(std::vector<uint8_t> &buffer));
66     MOCK_METHOD1(Decode, bool(const std::vector<std::uint8_t> &buffer));
67     MOCK_METHOD1(WriteInt64, bool(int64_t value));
68     MOCK_METHOD3(WriteRawData, bool(MessageParcel &parcelPata, const void *data, size_t size));
69     MOCK_METHOD2(WriteUnpadBuffer, bool(const void *data, size_t size));
70     MOCK_METHOD0(ReadInt64, int64_t());
71     MOCK_METHOD1(ReadUnpadBuffer, uint8_t *(size_t length));
72 };
73 
74 static void *g_interface = nullptr;
75 static bool g_writeRawData = false;
76 static bool g_sendrequest = false;
77 
PasteboardEntryGetterProxyMock()78 PasteboardEntryGetterProxyMock::PasteboardEntryGetterProxyMock()
79 {
80     g_interface = reinterpret_cast<void *>(this);
81 }
82 
~PasteboardEntryGetterProxyMock()83 PasteboardEntryGetterProxyMock::~PasteboardEntryGetterProxyMock()
84 {
85     g_interface = nullptr;
86 }
87 
GetPasteboardEntryGetterProxyInterface()88 static PasteboardEntryGetterProxyInterface *GetPasteboardEntryGetterProxyInterface()
89 {
90     return reinterpret_cast<PasteboardEntryGetterProxyInterface *>(g_interface);
91 }
92 
93 class TestIRemoteObject : public IRemoteObject {
TestIRemoteObject()94     TestIRemoteObject(): IRemoteObject(DESCRIPTOR_TEST) {}
95 
GetObjectRefCount()96     int32_t GetObjectRefCount()
97     {
98         return 0;
99     }
100 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)101     int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
102     {
103         return g_sendrequest ? 0 : 1;
104     }
105 
AddDeathRecipient(const sptr<DeathRecipient> & recipient)106     bool AddDeathRecipient(const sptr<DeathRecipient> &recipient)
107     {
108         return true;
109     }
110 
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)111     bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient)
112     {
113         return true;
114     }
115 
Dump(int fd,const std::vector<std::u16string> & args)116     int Dump(int fd, const std::vector<std::u16string> &args)
117     {
118         return 0;
119     }
120 };
121 
122 extern "C" {
ReadUnpadBuffer(size_t length)123     const uint8_t *Parcel::ReadUnpadBuffer(size_t length)
124     {
125         if (GetPasteboardEntryGetterProxyInterface() == nullptr) {
126             return nullptr;
127         }
128         return GetPasteboardEntryGetterProxyInterface()->ReadUnpadBuffer(length);
129     }
130 
Decode(const std::vector<std::uint8_t> & buffer)131     bool TLVReadable::Decode(const std::vector<std::uint8_t> &buffer)
132     {
133         if (GetPasteboardEntryGetterProxyInterface() == nullptr) {
134             return false;
135         }
136         return GetPasteboardEntryGetterProxyInterface()->Decode(buffer);
137     }
138 
ReadInt64()139     int64_t Parcel::ReadInt64()
140     {
141         if (GetPasteboardEntryGetterProxyInterface() == nullptr) {
142             return 0;
143         }
144         return GetPasteboardEntryGetterProxyInterface()->ReadInt64();
145     }
146 
WriteUnpadBuffer(const void * data,size_t size)147     bool Parcel::WriteUnpadBuffer(const void *data, size_t size)
148     {
149         if (GetPasteboardEntryGetterProxyInterface() == nullptr) {
150             return false;
151         }
152         return GetPasteboardEntryGetterProxyInterface()->WriteUnpadBuffer(data, size);
153     }
154 
WriteInterfaceToken(std::u16string name)155     bool MessageParcel::WriteInterfaceToken(std::u16string name)
156     {
157         if (GetPasteboardEntryGetterProxyInterface() == nullptr) {
158             return false;
159         }
160         return GetPasteboardEntryGetterProxyInterface()->WriteInterfaceToken(name);
161     }
162 
WriteInt64(int64_t value)163     bool Parcel::WriteInt64(int64_t value)
164     {
165         if (GetPasteboardEntryGetterProxyInterface() == nullptr) {
166             return false;
167         }
168         return GetPasteboardEntryGetterProxyInterface()->WriteInt64(value);
169     }
170 
WriteUint32(uint32_t value)171     bool Parcel::WriteUint32(uint32_t value)
172     {
173         if (GetPasteboardEntryGetterProxyInterface() == nullptr) {
174             return false;
175         }
176         return GetPasteboardEntryGetterProxyInterface()->WriteUint32(value);
177     }
178 
Encode(std::vector<uint8_t> & buffer,bool isRemote) const179     bool TLVWriteable::Encode(std::vector<uint8_t> &buffer, bool isRemote) const
180     {
181         (void)isRemote;
182         if (GetPasteboardEntryGetterProxyInterface() == nullptr) {
183             return false;
184         }
185         buffer.clear();
186         if (g_writeRawData) {
187             buffer.push_back(UINT8_RANDOM);
188         }
189         return GetPasteboardEntryGetterProxyInterface()->Encode(buffer);
190     }
191 };
192 
193 class PasteboardEntryGetterProxyTest : public testing::Test {
194 public:
195     static void SetUpTestCase(void);
196     static void TearDownTestCase(void);
197     void SetUp();
198     void TearDown();
199 };
200 
SetUpTestCase(void)201 void PasteboardEntryGetterProxyTest::SetUpTestCase(void) { }
202 
TearDownTestCase(void)203 void PasteboardEntryGetterProxyTest::TearDownTestCase(void) { }
204 
SetUp(void)205 void PasteboardEntryGetterProxyTest::SetUp(void) { }
206 
TearDown(void)207 void PasteboardEntryGetterProxyTest::TearDown(void) { }
208 
209 namespace MiscServices {
210 /**
211  * @tc.name: MakeRequestTest001
212  * @tc.desc: Test function MakeRequest when WriteInterfaceToken return false
213  * @tc.type: FUNC
214  */
215 HWTEST_F(PasteboardEntryGetterProxyTest, MakeRequestTest001, TestSize.Level0)
216 {
217     sptr<IRemoteObject> rObject = nullptr;
218     PasteboardEntryGetterProxy proxy(rObject);
219     PasteDataEntry entry;
220     MessageParcel parcel;
221     NiceMock<PasteboardEntryGetterProxyMock> mock;
222     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(false));
223     int32_t result = proxy.MakeRequest(UINT32_RANDOM, entry, parcel);
224     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR));
225 }
226 
227 /**
228  * @tc.name: MakeRequestTest002
229  * @tc.desc: Test function MakeRequest when WriteUint32 return false
230  * @tc.type: FUNC
231  */
232 HWTEST_F(PasteboardEntryGetterProxyTest, MakeRequestTest002, TestSize.Level0)
233 {
234     sptr<IRemoteObject> rObject = nullptr;
235     PasteboardEntryGetterProxy proxy(rObject);
236     PasteDataEntry entry;
237     MessageParcel parcel;
238     NiceMock<PasteboardEntryGetterProxyMock> mock;
239     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(true));
240     EXPECT_CALL(mock, WriteUint32(testing::_)).WillOnce(Return(false));
241     int32_t result = proxy.MakeRequest(UINT32_RANDOM, entry, parcel);
242     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR));
243 }
244 
245 /**
246  * @tc.name: MakeRequestTest003
247  * @tc.desc: Test function MakeRequest when Encode return false
248  * @tc.type: FUNC
249  */
250 HWTEST_F(PasteboardEntryGetterProxyTest, MakeRequestTest003, TestSize.Level0)
251 {
252     sptr<IRemoteObject> rObject = nullptr;
253     PasteboardEntryGetterProxy proxy(rObject);
254     PasteDataEntry entry;
255     MessageParcel parcel;
256     NiceMock<PasteboardEntryGetterProxyMock> mock;
257     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(true));
258     EXPECT_CALL(mock, WriteUint32(testing::_)).WillOnce(Return(true));
259     EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(false));
260     int32_t result = proxy.MakeRequest(UINT32_RANDOM, entry, parcel);
261     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR));
262 }
263 
264 /**
265  * @tc.name: MakeRequestTest004
266  * @tc.desc: Test function MakeRequest when WriteInt64 return false
267  * @tc.type: FUNC
268  */
269 HWTEST_F(PasteboardEntryGetterProxyTest, MakeRequestTest004, TestSize.Level0)
270 {
271     sptr<IRemoteObject> rObject = nullptr;
272     PasteboardEntryGetterProxy proxy(rObject);
273     PasteDataEntry entry;
274     MessageParcel parcel;
275     NiceMock<PasteboardEntryGetterProxyMock> mock;
276     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(true));
277     EXPECT_CALL(mock, WriteUint32(testing::_)).WillOnce(Return(true));
278     EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
279     EXPECT_CALL(mock, WriteInt64(testing::_)).WillOnce(Return(false));
280     int32_t result = proxy.MakeRequest(UINT32_RANDOM, entry, parcel);
281     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR));
282 }
283 
284 /**
285  * @tc.name: MakeRequestTest005
286  * @tc.desc: Test function MakeRequest when sendEntryTLV.size() == 0
287  * @tc.type: FUNC
288  */
289 HWTEST_F(PasteboardEntryGetterProxyTest, MakeRequestTest005, TestSize.Level0)
290 {
291     sptr<IRemoteObject> rObject = nullptr;
292     PasteboardEntryGetterProxy proxy(rObject);
293     PasteDataEntry entry;
294     MessageParcel parcel;
295     NiceMock<PasteboardEntryGetterProxyMock> mock;
296     g_writeRawData = false;
297     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(true));
298     EXPECT_CALL(mock, WriteUint32(testing::_)).WillOnce(Return(true));
299     EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
300     EXPECT_CALL(mock, WriteInt64(testing::_)).WillOnce(Return(true));
301     int32_t result = proxy.MakeRequest(UINT32_RANDOM, entry, parcel);
302     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR));
303 }
304 
305 /**
306  * @tc.name: MakeRequestTest006
307  * @tc.desc: Test function MakeRequest when done
308  * @tc.type: FUNC
309  */
310 HWTEST_F(PasteboardEntryGetterProxyTest, MakeRequestTest006, TestSize.Level0)
311 {
312     sptr<IRemoteObject> rObject = nullptr;
313     PasteboardEntryGetterProxy proxy(rObject);
314     NiceMock<PasteboardEntryGetterProxyMock> mock;
315     PasteDataEntry entry;
316     MessageParcel parcel;
317     g_writeRawData = true;
318     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(true));
319     EXPECT_CALL(mock, WriteUint32(testing::_)).WillOnce(Return(true));
320     EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
321     EXPECT_CALL(mock, WriteInt64(testing::_)).WillOnce(Return(true)).WillOnce(Return(true));
322     EXPECT_CALL(mock, WriteUnpadBuffer(testing::_, testing::_)).WillOnce(Return(true));
323     int32_t result = proxy.MakeRequest(UINT32_RANDOM, entry, parcel);
324     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::E_OK));
325 }
326 
327 /**
328  * @tc.name: GetRecordValueByTypeTest001
329  * @tc.desc: Test function GetRecordValueByType when MakeRequest return false
330  * @tc.type: FUNC
331  */
332 HWTEST_F(PasteboardEntryGetterProxyTest, GetRecordValueByTypeTest001, TestSize.Level0)
333 {
334     sptr<IRemoteObject> rObject = nullptr;
335     PasteDataEntry entry;
336     PasteboardEntryGetterProxy proxy(rObject);
337     NiceMock<PasteboardEntryGetterProxyMock> mock;
338     MessageParcel parcel;
339     g_writeRawData = true;
340     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(true));
341     EXPECT_CALL(mock, WriteUint32(testing::_)).WillOnce(Return(true));
342     EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
343     EXPECT_CALL(mock, WriteInt64(testing::_)).WillOnce(Return(true)).WillOnce(Return(true));
344     EXPECT_CALL(mock, WriteUnpadBuffer(testing::_, testing::_)).WillOnce(Return(false));
345     int32_t result = proxy.GetRecordValueByType(UINT32_RANDOM, entry);
346     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR));
347 }
348 
349 /**
350  * @tc.name: GetRecordValueByTypeTest002
351  * @tc.desc: Test function GetRecordValueByType when SendRequest return SENDREQUEST_ONE
352  * @tc.type: FUNC
353  */
354 HWTEST_F(PasteboardEntryGetterProxyTest, GetRecordValueByTypeTest002, TestSize.Level0)
355 {
356     sptr<IRemoteObject> rObject = sptr<TestIRemoteObject>::MakeSptr();
357     PasteDataEntry entry;
358     PasteboardEntryGetterProxy proxy(rObject);
359     g_sendrequest = false;
360     NiceMock<PasteboardEntryGetterProxyMock> mock;
361     MessageParcel parcel;
362     g_writeRawData = true;
363     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(true));
364     EXPECT_CALL(mock, WriteUint32(testing::_)).WillOnce(Return(true));
365     EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
366     EXPECT_CALL(mock, WriteInt64(testing::_)).WillOnce(Return(true)).WillOnce(Return(true));
367     EXPECT_CALL(mock, WriteUnpadBuffer(testing::_, testing::_)).WillOnce(Return(true));
368     int32_t result = proxy.GetRecordValueByType(UINT32_RANDOM, entry);
369     EXPECT_EQ(result, SENDREQUEST_ONE);
370 }
371 
372 /**
373  * @tc.name: GetRecordValueByTypeTest003
374  * @tc.desc: Test function GetRecordValueByType when rawDataSize <= 0
375  * @tc.type: FUNC
376  */
377 HWTEST_F(PasteboardEntryGetterProxyTest, GetRecordValueByTypeTest003, TestSize.Level0)
378 {
379     sptr<IRemoteObject> rObject = sptr<TestIRemoteObject>::MakeSptr();
380     PasteDataEntry entry;
381     PasteboardEntryGetterProxy proxy(rObject);
382     g_sendrequest = true;
383     NiceMock<PasteboardEntryGetterProxyMock> mock;
384     MessageParcel parcel;
385     g_writeRawData = true;
386     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(true));
387     EXPECT_CALL(mock, WriteUint32(testing::_)).WillOnce(Return(true));
388     EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
389     EXPECT_CALL(mock, WriteInt64(testing::_)).WillOnce(Return(true)).WillOnce(Return(true));
390     EXPECT_CALL(mock, WriteUnpadBuffer(testing::_, testing::_)).WillOnce(Return(true));
391     EXPECT_CALL(mock, ReadInt64()).WillOnce(Return(INT64_NEGATIVE_NUMBER));
392     int32_t result = proxy.GetRecordValueByType(UINT32_RANDOM, entry);
393     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::DESERIALIZATION_ERROR));
394 }
395 
396 /**
397  * @tc.name: GetRecordValueByTypeTest004
398  * @tc.desc: Test function GetRecordValueByType when rawDataSize >
399  *           DEFAULT_MAX_RAW_DATA_SIZE (128 * 1024 * 1024; // 128M)
400  * @tc.type: FUNC
401  */
402 HWTEST_F(PasteboardEntryGetterProxyTest, GetRecordValueByTypeTest004, TestSize.Level0)
403 {
404     sptr<IRemoteObject> rObject = sptr<TestIRemoteObject>::MakeSptr();
405     PasteDataEntry entry;
406     PasteboardEntryGetterProxy proxy(rObject);
407     g_sendrequest = true;
408     NiceMock<PasteboardEntryGetterProxyMock> mock;
409     MessageParcel parcel;
410     g_writeRawData = true;
411     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(true));
412     EXPECT_CALL(mock, WriteUint32(testing::_)).WillOnce(Return(true));
413     EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
414     EXPECT_CALL(mock, WriteInt64(testing::_)).WillOnce(Return(true)).WillOnce(Return(true));
415     EXPECT_CALL(mock, WriteUnpadBuffer(testing::_, testing::_)).WillOnce(Return(true));
416     EXPECT_CALL(mock, ReadInt64()).WillRepeatedly(Return(DEFAULT_MAX_RAW_DATA_SIZE + DEFAULT_MAX_RAW_DATA_SIZE));
417     int32_t result = proxy.GetRecordValueByType(UINT32_RANDOM, entry);
418     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::DESERIALIZATION_ERROR));
419 }
420 
421 /**
422  * @tc.name: GetRecordValueByTypeTest005
423  * @tc.desc: Test function GetRecordValueByType when Decode return false
424  * @tc.type: FUNC
425  */
426 HWTEST_F(PasteboardEntryGetterProxyTest, GetRecordValueByTypeTest005, TestSize.Level0)
427 {
428     sptr<IRemoteObject> rObject = sptr<TestIRemoteObject>::MakeSptr();
429     PasteDataEntry entry;
430     PasteboardEntryGetterProxy proxy(rObject);
431     g_sendrequest = true;
432     NiceMock<PasteboardEntryGetterProxyMock> mock;
433     uint8_t randomValue = UINT8_RANDOM;
434     MessageParcel parcel;
435     g_writeRawData = true;
436     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(true));
437     EXPECT_CALL(mock, WriteUint32(testing::_)).WillOnce(Return(true));
438     EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
439     EXPECT_CALL(mock, WriteInt64(testing::_)).WillOnce(Return(true)).WillOnce(Return(true));
440     EXPECT_CALL(mock, WriteUnpadBuffer(testing::_, testing::_)).WillOnce(Return(true));
441     EXPECT_CALL(mock, ReadInt64()).WillOnce(Return(INT64_POSITIVE_NUMBER)).WillOnce(Return(INT64_POSITIVE_NUMBER));
442     EXPECT_CALL(mock, Decode(testing::_)).WillOnce(Return(false));
443     EXPECT_CALL(mock, ReadUnpadBuffer(testing::_)).WillOnce(Return(&randomValue));
444     int32_t result = proxy.GetRecordValueByType(UINT32_RANDOM, entry);
445     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::DESERIALIZATION_ERROR));
446 }
447 
448 /**
449  * @tc.name: GetRecordValueByTypeTest006
450  * @tc.desc: Test function GetRecordValueByType when done
451  * @tc.type: FUNC
452  */
453 HWTEST_F(PasteboardEntryGetterProxyTest, GetRecordValueByTypeTest006, TestSize.Level0)
454 {
455     sptr<IRemoteObject> rObject = sptr<TestIRemoteObject>::MakeSptr();
456     PasteDataEntry entry;
457     PasteboardEntryGetterProxy proxy(rObject);
458     g_sendrequest = true;
459     NiceMock<PasteboardEntryGetterProxyMock> mock;
460     MessageParcel parcel;
461     uint8_t randomValue = UINT8_RANDOM;
462     g_writeRawData = true;
463     EXPECT_CALL(mock, WriteInterfaceToken(testing::_)).WillOnce(Return(true));
464     EXPECT_CALL(mock, WriteUint32(testing::_)).WillOnce(Return(true));
465     EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
466     EXPECT_CALL(mock, WriteInt64(testing::_)).WillOnce(Return(true)).WillOnce(Return(true));
467     EXPECT_CALL(mock, WriteUnpadBuffer(testing::_, testing::_)).WillOnce(Return(true));
468     EXPECT_CALL(mock, ReadInt64()).WillOnce(Return(INT64_POSITIVE_NUMBER)).WillOnce(Return(INT64_POSITIVE_NUMBER));
469     EXPECT_CALL(mock, ReadUnpadBuffer(testing::_)).WillOnce(Return(&randomValue));
470     EXPECT_CALL(mock, Decode(testing::_)).WillOnce(Return(true));
471     int32_t result = proxy.GetRecordValueByType(UINT32_RANDOM, entry);
472     EXPECT_EQ(result, ERR_OK);
473 }
474 }
475 } // namespace OHOS::MiscServices