• 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 <gtest/gtest.h>
17 #include "entry_getter.h"
18 #include "pasteboard_entry_getter_client.h"
19 #include "pasteboard_error.h"
20 
21 using namespace OHOS;
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace OHOS::MiscServices;
25 
26 namespace OHOS {
27 namespace MiscServices {
28 class PasteboardEntryGetterClientTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 };
35 
SetUpTestCase(void)36 void PasteboardEntryGetterClientTest::SetUpTestCase(void) { }
37 
TearDownTestCase(void)38 void PasteboardEntryGetterClientTest::TearDownTestCase(void) { }
39 
SetUp(void)40 void PasteboardEntryGetterClientTest::SetUp(void) { }
41 
TearDown(void)42 void PasteboardEntryGetterClientTest::TearDown(void) { }
43 
44 class EntryGetterImpl : public UDMF::EntryGetter {
45 public:
GetValueByType(const std::string & utdid)46     UDMF::ValueType GetValueByType(const std::string &utdid) override
47     {
48         return nullptr;
49     }
50 };
51 
52 /**
53  * @tc.name: GetRecordValueByTypeTest001
54  * @tc.desc: Test function GetRecordValueByType
55  * @tc.type: FUNC
56  */
57 HWTEST_F(PasteboardEntryGetterClientTest, GetRecordValueByTypeTest001, TestSize.Level0)
58 {
59     std::map<uint32_t, std::shared_ptr<UDMF::EntryGetter>> entryGetters;
60     auto entryGetter = std::make_shared<EntryGetterImpl>();
61     entryGetters.insert({0, entryGetter});
62     auto pasteboardEntryGetterClient = std::make_shared<PasteboardEntryGetterClient>(entryGetters);
63     PasteDataEntry pasteDataEntry;
64     int32_t result = pasteboardEntryGetterClient->GetRecordValueByType(1, pasteDataEntry);
65     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_DATA_ERROR));
66 }
67 
68 /**
69  * @tc.name: GetRecordValueByTypeTest002
70  * @tc.desc: Test function GetRecordValueByType
71  * @tc.type: FUNC
72  */
73 HWTEST_F(PasteboardEntryGetterClientTest, GetRecordValueByTypeTest002, TestSize.Level0)
74 {
75     std::map<uint32_t, std::shared_ptr<UDMF::EntryGetter>> entryGetters;
76     std::shared_ptr<UDMF::EntryGetter> entryGetter = nullptr;
77     entryGetters.insert({0, entryGetter});
78     auto pasteboardEntryGetterClient = std::make_shared<PasteboardEntryGetterClient>(entryGetters);
79     PasteDataEntry pasteDataEntry;
80     int32_t result = pasteboardEntryGetterClient->GetRecordValueByType(0, pasteDataEntry);
81     EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::E_OK));
82 }
83 }
84 } // namespace OHOS::MiscServices