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