TD-12194 pull-in cpp-stub
This commit is contained in:
parent
5787ec5b8e
commit
70279eeb3f
|
@ -0,0 +1,12 @@
|
|||
|
||||
# stub
|
||||
ExternalProject_Add(stub
|
||||
GIT_REPOSITORY https://github.com/coolxv/cpp-stub.git
|
||||
GIT_SUBMODULES "src"
|
||||
SOURCE_DIR "${CMAKE_CONTRIB_DIR}/cpp-stub"
|
||||
BINARY_DIR "${CMAKE_CONTRIB_DIR}/cpp-stub/src"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
|
@ -12,6 +12,7 @@ configure_file("${CMAKE_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}
|
|||
# googletest
|
||||
if(${BUILD_TEST})
|
||||
cat("${CMAKE_SUPPORT_DIR}/gtest_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
cat("${CMAKE_SUPPORT_DIR}/stub_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif(${BUILD_TEST})
|
||||
|
||||
# lz4
|
||||
|
@ -73,6 +74,11 @@ execute_process(COMMAND "${CMAKE_COMMAND}" --build .
|
|||
# googletest
|
||||
if(${BUILD_TEST})
|
||||
add_subdirectory(googletest)
|
||||
target_include_directories(
|
||||
gtest
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src>
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_linux>
|
||||
)
|
||||
endif(${BUILD_TEST})
|
||||
|
||||
# cJson
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#include "stub.h"
|
||||
#include "addr_any.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void generateTestT1(MockCatalogService* mcs) {
|
||||
|
@ -38,16 +41,36 @@ void generateTestST1(MockCatalogService* mcs) {
|
|||
|
||||
}
|
||||
|
||||
int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) {
|
||||
int32_t __catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) {
|
||||
return mockCatalogService->catalogGetHandle(clusterId, catalogHandle);
|
||||
}
|
||||
|
||||
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta) {
|
||||
int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta) {
|
||||
return mockCatalogService->catalogGetTableMeta(pCatalog, pRpc, pMgmtEps, pDBName, pTableName, pTableMeta);
|
||||
}
|
||||
|
||||
void initMetaDataEnv() {
|
||||
mockCatalogService.reset(new MockCatalogService());
|
||||
|
||||
static Stub stub;
|
||||
stub.set(catalogGetHandle, __catalogGetHandle);
|
||||
stub.set(catalogGetTableMeta, __catalogGetTableMeta);
|
||||
{
|
||||
AddrAny any("libcatalog.so");
|
||||
std::map<std::string,void*> result;
|
||||
any.get_global_func_addr_dynsym("^catalogGetHandle$", result);
|
||||
for (const auto& f : result) {
|
||||
stub.set(f.second, __catalogGetHandle);
|
||||
}
|
||||
}
|
||||
{
|
||||
AddrAny any("libcatalog.so");
|
||||
std::map<std::string,void*> result;
|
||||
any.get_global_func_addr_dynsym("^catalogGetTableMeta$", result);
|
||||
for (const auto& f : result) {
|
||||
stub.set(f.second, __catalogGetTableMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void generateMetaData() {
|
||||
|
|
|
@ -23,7 +23,7 @@ void generateMetaData();
|
|||
void destroyMetaDataEnv();
|
||||
|
||||
// mock
|
||||
int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle);
|
||||
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta);
|
||||
// int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle);
|
||||
// int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
#endif // MOCK_CATALOG_H
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
|
||||
class ParserEnv : public testing::Environment {
|
||||
class PlannerEnv : public testing::Environment {
|
||||
public:
|
||||
virtual void SetUp() {
|
||||
initMetaDataEnv();
|
||||
|
@ -39,12 +39,12 @@ public:
|
|||
destroyMetaDataEnv();
|
||||
}
|
||||
|
||||
ParserEnv() {}
|
||||
virtual ~ParserEnv() {}
|
||||
PlannerEnv() {}
|
||||
virtual ~PlannerEnv() {}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
testing::AddGlobalTestEnvironment(new ParserEnv());
|
||||
testing::AddGlobalTestEnvironment(new PlannerEnv());
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue