• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef BASIC_UNIT_TEST_H
17 #define BASIC_UNIT_TEST_H
18 #include <gtest/gtest.h>
19 
20 #include "distributeddb_data_generate_unit_test.h"
21 #include "distributeddb_tools_unit_test.h"
22 #include "virtual_communicator_aggregator.h"
23 
24 namespace DistributedDB {
25 
26 class BasicUnitTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp() override;
31     void TearDown() override;
32 protected:
33     int InitDelegate(const StoreInfo &info, const std::string &deviceId);
34     virtual int InitDelegate(const StoreInfo &info) = 0;
35     virtual int CloseDelegate(const StoreInfo &info) = 0;
36     virtual void CloseAllDelegate() = 0;
37     std::string GetDevice(const StoreInfo &info) const;
38     void SetProcessCommunicator(const std::shared_ptr<IProcessCommunicator> &processCommunicator);
39     uint64_t GetAllSendMsgSize() const;
40     void RegBeforeDispatch(const std::function<void(const std::string &, const Message *)> &beforeDispatch);
41     static StoreInfo GetStoreInfo1();
42     static StoreInfo GetStoreInfo2();
43     static StoreInfo GetStoreInfo3();
44     void SetDevice(const StoreInfo &info, const std::string &device);
45     void SetMtu(const std::string &dev, uint32_t mtu);
46     static std::string GetTestDir();
47     VirtualCommunicatorAggregator *communicatorAggregator_ = nullptr;
48     std::shared_ptr<IProcessCommunicator> processCommunicator_ = nullptr;
49     mutable std::mutex deviceMutex_;
50     std::map<StoreInfo, std::string> deviceMap_;
51 };
52 }
53 #endif // BASIC_UNIT_TEST_H
54