• 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 #include <gtest/gtest.h>
17 #include <unistd.h>
18 
19 #include <thread>
20 #include <unordered_set>
21 
22 #include "hitrace.h"
23 #include "distributed_object_impl.h"
24 #include "distributed_objectstore_impl.h"
25 #include "objectstore_errors.h"
26 #include "softbus_adapter.h"
27 #include "string_utils.h"
28 #include "asset_change_timer.h"
29 #include "object_radar_reporter.h"
30 #include "mock_object_watcher.h"
31 
32 using namespace testing::ext;
33 using namespace OHOS::ObjectStore;
34 using namespace OHOS;
35 using namespace std;
36 
37 namespace {
38 class DistributedObjectStoreImplTest : public testing::Test {
39 public:
40     static void SetUpTestCase(void);
41     static void TearDownTestCase(void);
42     void SetUp();
43     void TearDown();
44 };
45 
SetUpTestCase(void)46 void DistributedObjectStoreImplTest::SetUpTestCase(void)
47 {
48     // input testsuit setup step,setup invoked before all testcases
49 }
50 
TearDownTestCase(void)51 void DistributedObjectStoreImplTest::TearDownTestCase(void)
52 {
53     // input testsuit teardown step,teardown invoked after all testcases
54 }
55 
SetUp(void)56 void DistributedObjectStoreImplTest::SetUp(void)
57 {
58     // input testcase setup step,setup invoked before each testcases
59 }
60 
TearDown(void)61 void DistributedObjectStoreImplTest::TearDown(void)
62 {
63     // input testcase teardown step,teardown invoked after each testcases
64 }
65 
66 /**
67  * @tc.name: OnChanged_001
68  * @tc.desc: Normal test for OnChanged
69  * @tc.type: FUNC
70  */
71 
72 HWTEST_F(DistributedObjectStoreImplTest, OnChanged_001, TestSize.Level1)
73 {
74     string sessionId = "sessionId";
75     std::vector<std::string> changedData = {};
76     bool enableTransfer = false;
77     std::shared_ptr<MockObjectWatcher> objectWatcher = std::make_shared<MockObjectWatcher>();
78     WatcherProxy watcherProxy(objectWatcher, sessionId);
79     watcherProxy.objectWatcher_ = nullptr;
80     watcherProxy.OnChanged(sessionId, changedData, enableTransfer);
81     EXPECT_EQ(watcherProxy.objectWatcher_, nullptr);
82 }
83 
84 /**
85  * @tc.name: FindChangedAssetKey_001
86  * @tc.desc: Abnormal test for FindChangedAssetKey, changedKey.size() is less than MODIFY_TIME_SUFFIX
87  * @tc.type: FUNC
88  */
89 
90 HWTEST_F(DistributedObjectStoreImplTest, FindChangedAssetKey_001, TestSize.Level1)
91 {
92     string changedKey = "sessionId.";
93     string assetKey = "assetKey";
94     std::shared_ptr<MockObjectWatcher> objectWatcher = std::make_shared<MockObjectWatcher>();
95     WatcherProxy watcherProxy(objectWatcher, changedKey);
96     bool ret = watcherProxy.FindChangedAssetKey(changedKey, assetKey);
97     EXPECT_EQ(ret, false);
98 }
99 }
100