1 /*
2 * Copyright (c) 2023 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 "store/general_store.h"
17 
18 #include <gtest/gtest.h>
19 
20 using namespace testing::ext;
21 using namespace OHOS::DistributedData;
22 namespace OHOS::Test {
23 class GeneralStoreTest : public testing::Test {};
24 
25 /**
26 * @tc.name: MixMode
27 * @tc.desc: mix mode.
28 * @tc.type: FUNC
29 */
30 HWTEST_F(GeneralStoreTest, MixMode, TestSize.Level1)
31 {
32     uint32_t syncMode = GeneralStore::SyncMode::NEARBY_BEGIN;
33     uint32_t highMode = GeneralStore::HighMode::MANUAL_SYNC_MODE;
34     auto ret = GeneralStore::MixMode(syncMode, highMode);
35     ASSERT_EQ(ret, 0);
36 }
37 
38 /**
39 * @tc.name: GetSyncMode
40 * @tc.desc: get sync mode.
41 * @tc.type: FUNC
42 */
43 HWTEST_F(GeneralStoreTest, GetSyncMode, TestSize.Level1)
44 {
45     uint32_t syncMode = GeneralStore::SyncMode::NEARBY_PULL;
46     uint32_t highMode = GeneralStore::HighMode::MANUAL_SYNC_MODE;
47     auto mixMode = GeneralStore::MixMode(syncMode, highMode);
48     auto ret = GeneralStore::GetSyncMode(mixMode);
49     ASSERT_EQ(ret, syncMode);
50 
51     syncMode = GeneralStore::SyncMode::NEARBY_SUBSCRIBE_REMOTE;
52     mixMode = GeneralStore::MixMode(syncMode, highMode);
53     ret = GeneralStore::GetSyncMode(mixMode);
54     ASSERT_EQ(ret, syncMode);
55 
56     syncMode = GeneralStore::SyncMode::NEARBY_UNSUBSCRIBE_REMOTE;
57     mixMode = GeneralStore::MixMode(syncMode, highMode);
58     ret = GeneralStore::GetSyncMode(mixMode);
59     ASSERT_EQ(ret, syncMode);
60 }
61 
62 /**
63 * @tc.name: GetHighMode
64 * @tc.desc: get high mode.
65 * @tc.type: FUNC
66 */
67 HWTEST_F(GeneralStoreTest, GetHighMode, TestSize.Level1)
68 {
69     uint32_t syncMode = GeneralStore::SyncMode::NEARBY_PULL;
70     uint32_t highMode = GeneralStore::HighMode::MANUAL_SYNC_MODE;
71     auto mixMode = GeneralStore::MixMode(syncMode, highMode);
72     auto ret = GeneralStore::GetHighMode(mixMode);
73     ASSERT_EQ(ret, highMode);
74 }
75 
76 /**
77 * @tc.name: BindInfo
78 * @tc.desc: bind info.
79 * @tc.type: FUNC
80 */
81 HWTEST_F(GeneralStoreTest, BindInfo, TestSize.Level1)
82 {
83     std::shared_ptr<CloudDB> db;
84     std::shared_ptr<AssetLoader> loader;
85     GeneralStore::BindInfo bindInfo(db, loader);
86     ASSERT_EQ(bindInfo.db_, db);
87     ASSERT_EQ(bindInfo.loader_, loader);
88 
89     std::shared_ptr<CloudDB> db1 = db;
90     std::shared_ptr<AssetLoader> loader1 = loader;
91     GeneralStore::BindInfo bindInfo1(db1, loader1);
92     ASSERT_EQ(bindInfo1.db_, db1);
93     ASSERT_EQ(bindInfo1.loader_, loader1);
94     EXPECT_FALSE(bindInfo < bindInfo1);
95 }
96 } // namespace OHOS::Test