1 /*
2 * Copyright (c) 2022 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 "cloud_store_types.h"
19 #include "log_table_manager_factory.h"
20 #include "native_sqlite.h"
21 #include "split_device_log_table_manager.h"
22
23 using namespace testing::ext;
24 using namespace DistributedDB;
25 using namespace std;
26
27 class DistributedDBInterfacesLogTest : public testing::Test {
28 public:
29 static void SetUpTestCase(void);
30 static void TearDownTestCase(void);
31 void SetUp() override;
32 void TearDown() override;
33 protected:
34 };
35
SetUpTestCase(void)36 void DistributedDBInterfacesLogTest::SetUpTestCase(void)
37 {
38 }
39
TearDownTestCase(void)40 void DistributedDBInterfacesLogTest::TearDownTestCase(void)
41 {
42 }
43
SetUp()44 void DistributedDBInterfacesLogTest::SetUp()
45 {
46 }
47
TearDown()48 void DistributedDBInterfacesLogTest::TearDown()
49 {
50 }
51
52 /**
53 * @tc.name: DBFactoryTest001
54 * @tc.desc: check table manager with mode
55 * @tc.type: FUNC
56 * @tc.require:
57 * @tc.author: bty
58 */
59 HWTEST_F(DistributedDBInterfacesLogTest, DBFactoryTest001, TestSize.Level1)
60 {
61 DistributedTableMode mode = DistributedTableMode::COLLABORATION;
62 TableSyncType tableSyncType = TableSyncType::DEVICE_COOPERATION;
63 auto tableManager = LogTableManagerFactory::GetTableManager(mode, tableSyncType);
64 EXPECT_TRUE(tableManager != nullptr);
65 }
66
67 /**
68 * @tc.name: DeviceLogTest001
69 * @tc.desc: Calc primary key hash
70 * @tc.type: FUNC
71 * @tc.require:
72 * @tc.author: bty
73 */
74 HWTEST_F(DistributedDBInterfacesLogTest, DeviceLogTest001, TestSize.Level1)
75 {
76 string key1 = "NEW.";
77 TableInfo tableInfo;
78 tableInfo.SetPrimaryKey("key2", 1);
79 tableInfo.SetPrimaryKey("key3", 2);
80 string key4 = "hashKey";
81 SplitDeviceLogTableManager manager;
82 string value = manager.CalcPrimaryKeyHash(key1, tableInfo, key4);
83 EXPECT_EQ(value, "calc_hash(calc_hash(NEW.'key2', 0)||calc_hash(NEW.'key3', 0), 0)");
84 }
85