• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     TableInfo tableInfo;
64     auto tableManager = LogTableManagerFactory::GetTableManager(tableInfo, mode, tableSyncType);
65     EXPECT_TRUE(tableManager != nullptr);
66 }
67 
68 /**
69   * @tc.name: DeviceLogTest001
70   * @tc.desc: Calc primary key hash
71   * @tc.type: FUNC
72   * @tc.require:
73   * @tc.author: bty
74   */
75 HWTEST_F(DistributedDBInterfacesLogTest, DeviceLogTest001, TestSize.Level1)
76 {
77     string key1 = "NEW.";
78     TableInfo tableInfo;
79     tableInfo.SetPrimaryKey("key2", 1);
80     tableInfo.SetPrimaryKey("key3", 2);
81     string key4 = "hashKey";
82     SplitDeviceLogTableManager manager;
83     string value = manager.CalcPrimaryKeyHash(key1, tableInfo, key4);
84     EXPECT_EQ(value, "calc_hash(calc_hash(NEW.'key2', 0)||calc_hash(NEW.'key3', 0), 0)");
85 }
86