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 #include <gtest/gtest.h>
17
18 #include "pasteboard_error.h"
19 #include "pasteboard_hilog.h"
20 #include "pasteboard_service.h"
21
22 namespace OHOS::MiscServices {
23 using namespace testing::ext;
24 class PasteboardServiceTest : public testing::Test {
25 public:
26 static void SetUpTestCase(void);
27 static void TearDownTestCase(void);
28 void SetUp();
29 void TearDown();
30 };
31
SetUpTestCase(void)32 void PasteboardServiceTest::SetUpTestCase(void) { }
33
TearDownTestCase(void)34 void PasteboardServiceTest::TearDownTestCase(void) { }
35
SetUp(void)36 void PasteboardServiceTest::SetUp(void) { }
37
TearDown(void)38 void PasteboardServiceTest::TearDown(void) { }
39
40 /**
41 * @tc.name: IncreaseChangeCountTest001
42 * @tc.desc: IncreaseChangeCount should reset to 0 after reach maximum limit.
43 * @tc.type: FUNC
44 */
45 HWTEST_F(PasteboardServiceTest, IncreaseChangeCountTest001, TestSize.Level0)
46 {
47 auto tempPasteboard = std::make_shared<PasteboardService>();
48 int32_t userId = 10;
__anon75948de20102(auto, uint32_t &changeCount) 49 tempPasteboard->clipChangeCount_.Compute(userId, [](auto, uint32_t &changeCount) {
50 changeCount = UINT32_MAX;
51 return true;
52 });
53 uint32_t testCount = 0;
54 auto it = tempPasteboard->clipChangeCount_.Find(userId);
55 if (it.first) {
56 testCount = it.second;
57 }
58 ASSERT_EQ(testCount, UINT32_MAX);
59 tempPasteboard->IncreaseChangeCount(userId);
60 it = tempPasteboard->clipChangeCount_.Find(userId);
61 if (it.first) {
62 testCount = it.second;
63 }
64 ASSERT_EQ(testCount, 0);
65 }
66
67 /**
68 * @tc.name: IncreaseChangeCountTest002
69 * @tc.desc: IncreaseChangeCount should reset to 0 after switch to a new user.
70 * @tc.type: FUNC
71 */
72 HWTEST_F(PasteboardServiceTest, IncreaseChangeCountTest002, TestSize.Level0)
73 {
74 auto tempPasteboard = std::make_shared<PasteboardService>();
75 uint32_t testCount = 0;
76 tempPasteboard->GetChangeCount(testCount);
77 ASSERT_EQ(testCount, 0);
78 tempPasteboard->currentUserId_ = 10;
79 auto userId = tempPasteboard->GetCurrentAccountId();
80 tempPasteboard->IncreaseChangeCount(userId);
81 tempPasteboard->GetChangeCount(testCount);
82 ASSERT_EQ(testCount, 1);
83 tempPasteboard->currentUserId_ = 100;
84 tempPasteboard->GetChangeCount(testCount);
85 ASSERT_EQ(testCount, 0);
86 }
87
88 /**
89 * @tc.name: IsDisallowDistributedTest
90 * @tc.desc: IsDisallowDistributed Check CallingUID contral collaboration.
91 * @tc.type: FUNC
92 */
93 HWTEST_F(PasteboardServiceTest, IsDisallowDistributedTest, TestSize.Level0)
94 {
95 auto tempPasteboard = std::make_shared<PasteboardService>();
96 ASSERT_NE(tempPasteboard, nullptr);
97 ASSERT_EQ(tempPasteboard->IsDisallowDistributed(), false);
98 }
99 } // namespace OHOS::MiscServices