This is an automated email from the ASF dual-hosted git repository.

jiangtian pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/tsfile.git


The following commit(s) were added to refs/heads/develop by this push:
     new 5dc3ee5e Separate header file dependencies for test and src. (#364)
5dc3ee5e is described below

commit 5dc3ee5e5a31dd5a316597bbbca79635e745599d
Author: Colin Lee <[email protected]>
AuthorDate: Fri Mar 7 16:26:49 2025 +0800

    Separate header file dependencies for test and src. (#364)
    
    * Separate header file dependencies for test and src.
    
    * fix cmake.
    
    * fix asan in mac.
    
    * fix some issue.
    
    * add ci workflow.
    
    * fix asan name.
    
    * fix compile.
    
    * fix compile on win.
    
    * fix some issue.
    
    * delete file.
    
    * fix comments.
    
    * add example to cmakelists.
---
 .../{unit-test-cpp-py.yml => unit-test-cpp.yml}    |  48 +++++--
 .../{unit-test-cpp-py.yml => unit-test-python.yml} |   5 +-
 .gitignore                                         |   2 +
 cpp/CMakeLists.txt                                 |  69 ++++++----
 cpp/cmake/CopyToDir.cmake                          |  38 ++++++
 cpp/examples/CMakeLists.txt                        |  10 +-
 cpp/examples/c_examples/c_examples.h               |   2 +-
 cpp/examples/c_examples/demo_write.c               |   2 +-
 cpp/pom.xml                                        |  14 +-
 cpp/src/CMakeLists.txt                             |  39 ++++--
 cpp/src/common/CMakeLists.txt                      |   3 +
 cpp/src/common/allocator/object_pool.h             | 110 ---------------
 cpp/src/common/allocator/page_arena.cc             |   2 -
 cpp/src/common/allocator/stl_allocator.h           |  90 ------------
 cpp/src/common/allocator/util_define.h             | 152 ---------------------
 cpp/src/common/config/config.h                     |   9 +-
 cpp/src/common/global.cc                           |   5 +-
 cpp/src/common/statistic.h                         |  54 ++++----
 cpp/src/compress/CMakeLists.txt                    |   2 +
 cpp/src/cwrapper/CMakeLists.txt                    |   8 +-
 .../cwrapper/{errno_define.h => errno_define_c.h}  |   0
 cpp/src/cwrapper/tsfile_cwrapper.h                 |  18 +--
 cpp/src/cwrapper/tsfile_cwrapper_expression.cc     |   2 +-
 cpp/src/encoding/CMakeLists.txt                    |  13 +-
 cpp/src/file/CMakeLists.txt                        |   6 +-
 cpp/src/parser/CMakeLists.txt                      |   3 +
 cpp/src/reader/CMakeLists.txt                      |   6 +-
 cpp/src/reader/device_meta_iterator.cc             |  32 +++--
 cpp/src/reader/device_meta_iterator.h              |   9 +-
 .../datatype => reader/filter}/CMakeLists.txt      |   2 +-
 cpp/src/reader/meta_data_querier.cc                |   6 +
 cpp/src/utils/CMakeLists.txt                       |   6 +-
 cpp/src/utils/injection.h                          |   4 -
 cpp/src/utils/storage_utils.h                      |  12 +-
 cpp/src/writer/CMakeLists.txt                      |   6 +-
 cpp/test/CMakeLists.txt                            | 105 +++++++++-----
 cpp/test/cwrapper/cwrapper_test.cc                 |   2 +-
 cpp/test/reader/tsfile_reader_test.cc              |   5 +-
 cpp/test/writer/tsfile_writer_test.cc              |  11 +-
 39 files changed, 350 insertions(+), 562 deletions(-)

diff --git a/.github/workflows/unit-test-cpp-py.yml 
b/.github/workflows/unit-test-cpp.yml
similarity index 66%
copy from .github/workflows/unit-test-cpp-py.yml
copy to .github/workflows/unit-test-cpp.yml
index f4833e1f..1c6e4968 100644
--- a/.github/workflows/unit-test-cpp-py.yml
+++ b/.github/workflows/unit-test-cpp.yml
@@ -1,7 +1,7 @@
 # This workflow will build a Java project with Maven
 # For more information see: 
https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
 
-name: Unit-Test-Cpp-Py
+name: Unit-Test-Cpp
 
 on:
   push:
@@ -15,6 +15,7 @@ on:
   pull_request:
     branches:
       - develop
+      - dev/*
       - iotdb
       - rc/*
     paths-ignore:
@@ -42,7 +43,36 @@ jobs:
       fail-fast: false
       max-parallel: 15
       matrix:
-        os: [ ubuntu-latest, macos-latest, windows-latest ]
+        include:
+          # Linux all
+          - os: ubuntu-latest
+            build_type: Debug
+            enable_asan: Asan
+          - os: ubuntu-latest
+            build_type: Debug
+            enable_asan: NoAsan
+          - os: ubuntu-latest
+            build_type: Release
+            enable_asan: Asan
+          - os: ubuntu-latest
+            build_type: Release
+            enable_asan: NoAsan
+
+          # macOS exclude Release+ASan
+          - os: macos-latest
+            build_type: Debug
+            enable_asan: Asan
+          - os: macos-latest
+            build_type: Debug
+            enable_asan: NoAsan
+          - os: macos-latest
+            build_type: Release
+            enable_asan: NoAsan
+
+          # Windows just Release
+          - os: windows-latest
+            build_type: Release
+            enable_asan: NoAsan
     runs-on: ${{ matrix.os }}
 
     steps:
@@ -78,11 +108,11 @@ jobs:
       - name: Build and test with Maven
         shell: bash
         run: |
-          ./mvnw${{ steps.platform_suffix.outputs.platform_suffix }} -P 
with-cpp,with-python clean verify
+          if [ "${{ matrix.enable_asan }}" = "Asan" ]; then
+            ASAN_VALUE="ON"
+          else
+            ASAN_VALUE="OFF"
+          fi
+          ./mvnw${{ steps.platform_suffix.outputs.platform_suffix }} -P 
with-cpp \
+           -Denable.asan=$ASAN_VALUE -Dbuild.type=${{ matrix.build_type }} 
clean verify
 
-      - name: Upload whl Artifact
-        uses: actions/upload-artifact@v4
-        with:
-          name: tsfile-${{ runner.os }}-whl
-          path: python/dist/tsfile-*.whl
-          retention-days: 1
diff --git a/.github/workflows/unit-test-cpp-py.yml 
b/.github/workflows/unit-test-python.yml
similarity index 95%
rename from .github/workflows/unit-test-cpp-py.yml
rename to .github/workflows/unit-test-python.yml
index f4833e1f..44b7d562 100644
--- a/.github/workflows/unit-test-cpp-py.yml
+++ b/.github/workflows/unit-test-python.yml
@@ -1,7 +1,7 @@
 # This workflow will build a Java project with Maven
 # For more information see: 
https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
 
-name: Unit-Test-Cpp-Py
+name: Unit-Test-Py
 
 on:
   push:
@@ -15,6 +15,7 @@ on:
   pull_request:
     branches:
       - develop
+      - dev/*
       - iotdb
       - rc/*
     paths-ignore:
@@ -78,7 +79,7 @@ jobs:
       - name: Build and test with Maven
         shell: bash
         run: |
-          ./mvnw${{ steps.platform_suffix.outputs.platform_suffix }} -P 
with-cpp,with-python clean verify
+          ./mvnw${{ steps.platform_suffix.outputs.platform_suffix }} -P 
with-python -Denable.asan=OFF -Dbuild.type=Release clean verify
 
       - name: Upload whl Artifact
         uses: actions/upload-artifact@v4
diff --git a/.gitignore b/.gitignore
index e91d02c8..fa3c6a26 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,7 +35,9 @@ python/data
 python/venv/*
 python/tests/__pycache__/*
 python/tests/*.tsfile
+
 cpp/cmake-build-debug-mingw/
+cpp/third_party/googletest-release-1.12.1.zip
 
 .vscode/
 
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index e8bd08ac..d33605bc 100755
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -1,4 +1,4 @@
-#[[
+#[[
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
@@ -23,10 +23,10 @@ cmake_policy(SET CMP0079 NEW)
 set(TsFile_CPP_VERSION 2.1.0.dev)
 set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -Wall")
 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=maybe-uninitialized")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=maybe-uninitialized 
-D__STDC_FORMAT_MACROS")
 endif()
-message("cmake using: USE_CPP11=${USE_CPP11}")
 
+message("cmake using: USE_CPP11=${USE_CPP11}")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 
 if(DEFINED ENV{CXX})
@@ -50,42 +50,59 @@ if (${COV_ENABLED})
   message("add_definitions -DCOV_ENABLED=1")
 endif()
 
-message("build type: ${BUILD_TYPE}")
+
+if (NOT CMAKE_BUILD_TYPE)
+    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." 
FORCE)
+endif ()
+
+message("CMAKE BUILD TYPE " ${CMAKE_BUILD_TYPE})
 if (CMAKE_BUILD_TYPE STREQUAL "Debug")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
-  set(CMAKE_CXX_FLAGS_DEBUG" ${CMAKE_CXX_FLAGS} -O0 -g")
+  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
 elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g") # disable -g
-  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS}")
+  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
 elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g")
-  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS}")
+  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 
-g")
 elseif (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections 
-Os")
-  set(LDFLAGS "-Wl,--gc-sections")
-  set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS}")
-endif()
+  set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} 
-ffunction-sections -fdata-sections -Os")
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
+endif ()
 message("CMAKE DEBUG: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
 
+# disable asan by default.
+option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
+
+if (NOT WIN32)
+  if (ENABLE_ASAN)
+    message("Address Sanitizer is enabled.")
+
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address 
-fno-omit-frame-pointer")
+
+    if (NOT APPLE)
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libasan")
+      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address 
-static-libasan")
+    else ()
+      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} 
-fsanitize=address")
+    endif ()
+  else ()
+    message("Address Sanitizer is disabled.")
+  endif ()
+endif ()
+
+
+# All libs will be stored here, including libtsfile, compress-encoding lib.
 set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
-set(PROJECT_INCLUDE_DIR ${PROJECT_INCLUDE_DIR}
-                        ${PROJECT_SOURCE_DIR}/src
-                        ${PROJECT_SOURCE_DIR}/third_party/lz4
-                        ${PROJECT_SOURCE_DIR}/third_party/lzokay
-                        ${PROJECT_SOURCE_DIR}/third_party/zlib-1.2.13
-                        ${PROJECT_BINARY_DIR}/third_party/zlib-1.2.13
-)
 
-set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
-include_directories(${PROJECT_INCLUDE_DIR})
+# TsFile code will be stored here.
+set(PROJECT_SRC_DIR ${PROJECT_SOURCE_DIR}/src)
 
-include_directories(${PROJECT_SOURCE_DIR}/third_party/antlr4-cpp-runtime-4/runtime/src)
+# All include files will be installed here.
+set(LIBRARY_INCLUDE_DIR ${PROJECT_BINARY_DIR}/include)
+set(THIRD_PARTY_INCLUDE ${PROJECT_BINARY_DIR}/third_party)
 
 add_subdirectory(third_party)
-
 add_subdirectory(src)
-
 add_subdirectory(test)
+add_subdirectory(examples)
 if(TESTS_ENABLED)
     add_dependencies(TsFile_Test tsfile)
 endif()
diff --git a/cpp/cmake/CopyToDir.cmake b/cpp/cmake/CopyToDir.cmake
new file mode 100644
index 00000000..57afa0d9
--- /dev/null
+++ b/cpp/cmake/CopyToDir.cmake
@@ -0,0 +1,38 @@
+#[[
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    https://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+]]
+
+# CopyToDir.cmake
+
+# This function is used to copy files to a directory and it will handle 
relative paths automatically.
+function(copy_to_dir)
+    set(INCLUDE_EXPORT_DR ${LIBRARY_INCLUDE_DIR} CACHE INTERNAL "Include 
export directory")
+    foreach(file ${ARGN})
+        get_filename_component(file_name ${file} NAME)
+        get_filename_component(file_path ${file} PATH)
+        string(REPLACE "${CMAKE_SOURCE_DIR}/src" "" relative_path 
"${file_path}")
+        add_custom_target(
+            copy_${file_name} ALL
+            COMMAND ${CMAKE_COMMAND} -E make_directory 
${INCLUDE_EXPORT_DR}/${relative_path}
+            COMMAND ${CMAKE_COMMAND} -E copy_if_different ${file} 
${INCLUDE_EXPORT_DR}/${relative_path}/${file_name}
+            COMMENT "Copying ${file_name} to 
${INCLUDE_EXPORT_DR}/${relative_path}"
+        )
+    endforeach()
+endfunction()
+
+
diff --git a/cpp/examples/CMakeLists.txt b/cpp/examples/CMakeLists.txt
index 75b92692..51126a31 100644
--- a/cpp/examples/CMakeLists.txt
+++ b/cpp/examples/CMakeLists.txt
@@ -40,15 +40,9 @@ include_directories(${SDK_INCLUDE_DIR})
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
 set(CMAKE_CXX_FLAGS_DEBUG" ${CMAKE_CXX_FLAGS} -O0 -g")
 
-# Find libtsfile in SDK_LIB_RIR
-if (BUILD_TYPE STREQUAL "Release")
-    find_library(my_tsfile_lib NAMES tsfile PATHS ${SDK_LIB_DIR_RELEASE} 
NO_DEFAULT_PATH REQUIRED)
-elseif(BUILD_TYPE STREQUAL "Debug")
-    find_library(my_tsfile_lib NAMES tsfile PATHS ${SDK_LIB_DIR_DEBUG} 
NO_DEFAULT_PATH REQUIRED)
-endif ()
-
 add_subdirectory(cpp_examples)
 add_subdirectory(c_examples)
 
 add_executable(examples examples.cc)
-target_link_libraries(examples ${my_tsfile_lib} cpp_examples_obj 
c_examples_obj)
\ No newline at end of file
+target_link_libraries(examples cpp_examples_obj c_examples_obj)
+target_link_libraries(examples tsfile)
\ No newline at end of file
diff --git a/cpp/examples/c_examples/c_examples.h 
b/cpp/examples/c_examples/c_examples.h
index ba674778..3adcdadf 100644
--- a/cpp/examples/c_examples/c_examples.h
+++ b/cpp/examples/c_examples/c_examples.h
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-#include "cwrapper/errno_define.h"
+#include "cwrapper/errno_define_c.h"
 #include "cwrapper/tsfile_cwrapper.h"
 
 #ifdef __cplusplus
diff --git a/cpp/examples/c_examples/demo_write.c 
b/cpp/examples/c_examples/demo_write.c
index ebfc99df..3197a6d2 100644
--- a/cpp/examples/c_examples/demo_write.c
+++ b/cpp/examples/c_examples/demo_write.c
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-#include <malloc.h>
+#include <stdlib.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/cpp/pom.xml b/cpp/pom.xml
index 8d11a822..9126b7ef 100644
--- a/cpp/pom.xml
+++ b/cpp/pom.xml
@@ -31,7 +31,9 @@
         <!-- Tell Sonar where to find the sources -->
         <sonar.sources>common,examples,tsfile</sonar.sources>
         
<sonar.cfamily.build-wrapper-output>${project.build.directory}/build-wrapper-output</sonar.cfamily.build-wrapper-output>
-        <cmake.addition.option>-DCOV_ENABLED=OFF</cmake.addition.option>
+        <coverage.enabled>OFF</coverage.enabled>
+        <build.type>Release</build.type>
+        <enable.asan>OFF</enable.asan>
     </properties>
     <build>
         <sourceDirectory>${project.basedir}</sourceDirectory>
@@ -69,7 +71,9 @@
                         <configuration>
                             <options>
                                 <option>-DBUILD_PHASE=test-compile</option>
-                                <option>${cmake.addition.option}</option>
+                                
<option>-DCOV_ENABLED=${coverage.enabled}</option>
+                                
<option>-DCMAKE_BUILD_TYPE=${build.type}</option>
+                                <option>-DENABLE_ASAN=${enable.asan}</option>
                             </options>
                             <sourcePath/>
                             <targetPath/>
@@ -180,12 +184,6 @@
                 </plugins>
             </build>
         </profile>
-        <profile>
-            <id>with-code-coverage</id>
-            <properties>
-                <cmake.addition.option>-DCOV_ENABLED=ON</cmake.addition.option>
-            </properties>
-        </profile>
         <!-- When running on jenkins, download the sonar build-wrapper, so we 
can do a code analysis -->
         <profile>
             <id>jenkins-build</id>
diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt
index ecacad70..398c0cfa 100644
--- a/cpp/src/CMakeLists.txt
+++ b/cpp/src/CMakeLists.txt
@@ -16,12 +16,35 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 ]]
-message("Running in src diectory")
+cmake_minimum_required(VERSION 3.11)
+project(TsFile_CPP_SDK)
+
+include (${CMAKE_SOURCE_DIR}/cmake/CopyToDir.cmake)
+
+if(POLICY CMP0079)
+    cmake_policy(SET CMP0079 NEW)
+endif()
+
+message("Running in src directory")
 if (${COV_ENABLED})
     add_compile_options(-fprofile-arcs -ftest-coverage)
 endif ()
 add_definitions(-DANTLR4CPP_STATIC)
 set(ANTLR4_WITH_STATIC_CRT OFF)
+
+
+set(PROJECT_INCLUDE_DIR
+        ${CMAKE_SOURCE_DIR}/src
+        ${THIRD_PARTY_INCLUDE}/google_snappy
+        ${CMAKE_SOURCE_DIR}/third_party/lz4
+        ${CMAKE_SOURCE_DIR}/third_party/lzokay
+        ${CMAKE_SOURCE_DIR}/third_party/zlib-1.2.13
+        ${CMAKE_SOURCE_DIR}/third_party/google_snappy
+        ${CMAKE_SOURCE_DIR}/third_party/antlr4-cpp-runtime-4/runtime/src
+)
+
+include_directories(${PROJECT_INCLUDE_DIR})
+
 add_subdirectory(parser)
 add_subdirectory(common)
 add_subdirectory(compress)
@@ -32,6 +55,7 @@ add_subdirectory(reader)
 add_subdirectory(utils)
 add_subdirectory(writer)
 
+
 set(COMPRESSION_LIBS snappy LZ4 lzokay zlibstatic)
 target_link_libraries(parser_obj antlr4_static)
 target_link_libraries(compress_obj ${COMPRESSION_LIBS})
@@ -53,16 +77,7 @@ set(LIBTSFILE_SO_VERSION ${TsFile_CPP_VERSION})
 set_target_properties(tsfile PROPERTIES VERSION ${LIBTSFILE_PROJECT_VERSION})
 set_target_properties(tsfile PROPERTIES SOVERSION ${LIBTSFILE_SO_VERSION})
 
-set(LIBTSFILE_SDK_DIR ${LIBRARY_OUTPUT_PATH})
-install(TARGETS tsfile LIBRARY DESTINATION ${LIBTSFILE_SDK_DIR})
+install(TARGETS tsfile LIBRARY DESTINATION ${LIBRARY_OUTPUT_PATH})
+
 
-# set(CMAKE_PREFIX_PATH ../../third-party/lz4-dev/lib)
-# set(LZ4_LIB_DIR ../../third-party/lz4-dev/lib)
-# find_library(my_lz4_lib NAMES lz4 PATHS ${LZ4_LIB_DIR} NO_DEFAULT_PATH 
REQUIRED)
-# link_directories(${LZ4_LIB_DIR})
-# target_link_libraries(tsfile ${my_lz4_lib})
 
-# if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
-#   add_custom_command(TARGET tsfile POST_BUILD COMMAND 
${CMAKE_INSTALL_NAME_TOOL} -change `otool -L 
${LIBRARY_OUTPUT_PATH}/libtsfile.dylib | grep liblz4 | sed 's/dylib.*/dylib/g'` 
${my_lz4_lib} ${LIBRARY_OUTPUT_PATH}/libtsfile.dylib)
-#   add_custom_command(TARGET tsfile POST_BUILD COMMAND 
${CMAKE_INSTALL_NAME_TOOL} -change `otool -L 
${LIBRARY_OUTPUT_PATH}/libtsfile.dylib | grep libz | sed 's/dylib.*/dylib/g'` 
${my_z_lib} ${LIBRARY_OUTPUT_PATH}/libtsfile.dylib)
-# endif()
diff --git a/cpp/src/common/CMakeLists.txt b/cpp/src/common/CMakeLists.txt
index 7087d03d..ec285c1d 100644
--- a/cpp/src/common/CMakeLists.txt
+++ b/cpp/src/common/CMakeLists.txt
@@ -33,3 +33,6 @@ add_library(common_obj OBJECT ${common_SRC_LIST}
     ${common_mutex_SRC_LIST} 
     ${common_datatype_SRC_LIST})
 
+# install header files recursively
+file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+copy_to_dir(${HEADERS})
\ No newline at end of file
diff --git a/cpp/src/common/allocator/object_pool.h 
b/cpp/src/common/allocator/object_pool.h
deleted file mode 100644
index 721823a2..00000000
--- a/cpp/src/common/allocator/object_pool.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * License); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef COMMON_ALLOCTOR_OBJECT_POOL_H
-#define COMMON_ALLOCTOR_OBJECT_POOL_H
-
-#include "common/allocator/alloc_base.h"
-#include "common/mutex/mutex.h"
-
-namespace common {
-
-template <class T>
-class ObjectPool {
-   private:
-    struct ObjectPoolNode {
-        T data_;
-        ObjectPoolNode *next_;
-
-        ObjectPoolNode() : data_(), next_(nullptr) {}
-    };
-
-   public:
-    /*
-     * max_cache_count is a soft limitation:
-     */
-    ObjectPool(const uint32_t max_cache_count, const AllocModID mid,
-               BaseAllocator &allocator = g_base_allocator)
-        : max_cache_count_(max_cache_count),
-          cur_alloc_count_(0),
-          mid_(mid),
-          allocator_(allocator),
-          mutex_(),
-          head_(nullptr) {
-        assert(max_cache_count > 1);
-    }
-
-    ~ObjectPool() { destroy(); }
-
-    void destroy() {
-        ObjectPoolNode *cur = head_;
-        while (cur) {
-            head_ = cur->next_;
-            allocator_.free(cur);
-            cur = head_;
-            cur_alloc_count_--;
-        }
-        ASSERT(cur_alloc_count_ == 0);
-    }
-
-    T *alloc() {
-        T *ret_obj = nullptr;
-        common::MutexGuard g(mutex_);
-        if (head_) {
-            ret_obj = &(head_->data_);
-            head_ = head_->next_;
-            return ret_obj;
-        } else {
-            void *buf = allocator_.alloc(sizeof(ObjectPoolNode), mid_);
-            if (UNLIKELY(buf == nullptr)) {
-                return nullptr;
-            }
-            cur_alloc_count_++;
-            ret_obj = &(new (buf) ObjectPoolNode)->data_;
-            return ret_obj;
-        }
-    }
-
-    void free(T *obj) {
-        ASSERT(obj != nullptr);
-        common::MutexGuard g(mutex_);
-        if (cur_alloc_count_ > max_cache_count_) {
-            allocator_.free(obj);
-            cur_alloc_count_--;
-            ASSERT(cur_alloc_count_ >= 0);
-        } else {
-            ObjectPoolNode *n = (ObjectPoolNode *)obj;
-            n->next_ = head_;
-            head_ = n;
-        }
-    }
-
-    uint32_t get_cur_alloc_count() const { return cur_alloc_count_; }
-
-   private:
-    uint32_t max_cache_count_;
-    uint32_t cur_alloc_count_;
-    AllocModID mid_;
-    BaseAllocator allocator_;
-    common::Mutex mutex_;
-    ObjectPoolNode *head_;  // freelist head
-};
-
-}  // namespace common
-#endif  // COMMON_ALLOCTOR_OBJECT_POOL_H
diff --git a/cpp/src/common/allocator/page_arena.cc 
b/cpp/src/common/allocator/page_arena.cc
index 731b0b0b..9cc9cc00 100644
--- a/cpp/src/common/allocator/page_arena.cc
+++ b/cpp/src/common/allocator/page_arena.cc
@@ -18,8 +18,6 @@
  */
 #include "page_arena.h"
 
-#include <stdio.h>
-
 #include <new>
 
 namespace common {
diff --git a/cpp/src/common/allocator/stl_allocator.h 
b/cpp/src/common/allocator/stl_allocator.h
deleted file mode 100644
index e8583985..00000000
--- a/cpp/src/common/allocator/stl_allocator.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * License); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef COMMON_ALLOCATOR_STL_ALLOCATOR_H
-#define COMMON_ALLOCATOR_STL_ALLOCATOR_H
-
-#include "alloc_base.h"
-
-namespace common {
-
-template <class T, AllocModID Mid, class TAllocator = BaseAllocator>
-class StlAllocator {
-   public:
-    typedef size_t size_type;
-    typedef ptrdiff_t difference_type;
-    typedef T *pointer;
-    typedef const T *const_pointer;
-    typedef T &reference;
-    typedef const T &const_reference;
-    typedef T value_type;
-
-    /*
-     * rebind provides a way to obtain an allocator for a different type.
-     * For example, std::list will alloc object Node<T> beside alloc object T.
-     */
-    template <class U>
-    struct rebind {
-        typedef StlAllocator<U, Mid, TAllocator> other;
-    };
-
-    StlAllocator() {}
-    StlAllocator(const StlAllocator &) {}
-
-    template <class T2, AllocModID Mid2>
-    StlAllocator(const StlAllocator<T2, Mid2, TAllocator> &) {}
-
-    StlAllocator(TAllocator base_allocator) : base_allocator_(base_allocator) 
{}
-
-    pointer address(reference x) const { return &x; }
-    const_pointer address(const_reference x) { return &x; }
-
-    pointer allocate(size_type n, const void *hint = 0) {
-        return (pointer)base_allocator_.alloc(n * sizeof(T), Mid);
-    };
-    void deallocate(void *p, size_type) { base_allocator_.free(p); }
-    size_type max_size() const { return uint32_t(-1); }
-
-    void construct(pointer p, const T &val) { new ((T *)p) T(val); }
-    void destroy(pointer p) { p->~T(); }
-
-   private:
-    TAllocator base_allocator_;
-};
-
-/*
- * According to the manual, allocator is stateless.
- * Although we define a base_allocator_ here, but base_allocator_ is also
- * stateless. so '==' is always true and '!=' is always false. refer to
- * https://en.cppreference.com/w/cpp/memory/allocator/operator_cmp.
- */
-template <class T1, AllocModID Mid1, class T2, AllocModID Mid2>
-bool operator==(const StlAllocator<T1, Mid1> &a1,
-                const StlAllocator<T2, Mid2> &a2) {
-    return true;
-}
-
-template <class T1, AllocModID Mid1, class T2, AllocModID Mid2>
-bool operator!=(const StlAllocator<T1, Mid1> &a1,
-                const StlAllocator<T2, Mid2> &a2) {
-    return false;
-}
-
-}  // end namespace common
-#endif  // COMMON_ALLOCATOR_STL_ALLOCATOR_H
diff --git a/cpp/src/common/allocator/util_define.h 
b/cpp/src/common/allocator/util_define.h
deleted file mode 100644
index 0526c08b..00000000
--- a/cpp/src/common/allocator/util_define.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * License); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- * This file defines some basic macros
- */
-
-#ifndef COMMON_UTIL_DEFINE_H
-#define COMMON_UTIL_DEFINE_H
-
-#include <assert.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-/* ======== cmake config define ======== */
-
-/* ======== unsued ======== */
-#define UNUSED(v) ((void)(v))
-
-/* ======== inline ======== */
-#ifdef __GNUC__
-#define FORCE_INLINE inline __attribute__((always_inline))
-#else
-#define FORCE_INLINE inline
-#endif  // __GNUC__
-
-#ifdef BUILD_FOR_SMALL_BINARY
-#define INLINE FORCE_INLINE
-#else
-#define INLINE
-#endif  // BUILD_FOR_SMALL_BINARY
-
-/* ======== likely ======== */
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define LIKELY(x) (__builtin_expect((x), 1))
-#define UNLIKELY(x) (__builtin_expect((x), 0))
-#else
-#define LIKELY(x) (x)
-#define UNLIKELY(x) (x)
-#endif  // __GNUC__ >= 4
-
-/* ======== nullptr ======== */
-#if __cplusplus < 201103L
-#ifndef nullptr
-#define nullptr NULL
-#endif
-#define OVERRIDE
-#else
-#define OVERRIDE override
-#endif  // __cplusplus < 201103L
-
-/* ======== cache line ======== */
-#ifndef CACHE_LINE_SIZE
-#define CACHE_LINE_SIZE 64
-#endif  // CACHE_LINE_SIZE
-
-/* ======== assert ======== */
-#ifdef NDEBUG
-#define ASSERT(condition) ((void)0)
-#else
-#define ASSERT(condition) assert((condition))
-#endif  // NDEBUG
-
-/* ======== statis assert ======== */
-/*
- * To be compatible with C++ before C++11,
- * @msg should be a single word (use -/_ to concat)
- * such as This_should_be_TRUE
- */
-#if __cplusplus < 201103L
-// TODO only define this when DEBUG
-#define STATIC_ASSERT(cond, msg) \
-    typedef char static_assertion_##msg[(cond) ? 1 : -1] 
__attribute__((unused))
-#else
-#define STATIC_ASSERT(cond, msg) static_assert((cond), #msg)
-#endif  // __cplusplus < 201103L
-
-/* ======== atomic operation ======== */
-#define ATOMIC_FAA(val_addr, addv) \
-    __atomic_fetch_add((val_addr), (addv), __ATOMIC_SEQ_CST)
-#define ATOMIC_AAF(val_addr, addv) \
-    __atomic_add_fetch((val_addr), (addv), __ATOMIC_SEQ_CST)
-/*
- * It implements an atomic compare and exchange operation.
- * This compares the contents of *ptr with the contents of *expected.
- * - If equal, the operation is a reader-modify-writer operation that writes
- * desired into *ptr.
- * - If they are not equal, the operation is a reader and the current contents
- * of *ptr are written into *expected
- */
-#define ATOMIC_CAS(val_addr, expected, desired)                            \
-    __atomic_compare_exchange_n((val_addr), (expected), (desired),         \
-                                /* weak = */ false,                        \
-                                /* success_memorder = */ __ATOMIC_SEQ_CST, \
-                                /* failure_memorder = */ __ATOMIC_SEQ_CST)
-#define ATOMIC_LOAD(val_addr) __atomic_load_n((val_addr), __ATOMIC_SEQ_CST)
-#define ATOMIC_STORE(val_addr, val) \
-    __atomic_store_n((val_addr), (val), __ATOMIC_SEQ_CST)
-
-/* ======== align ======== */
-#define ALIGNED(a) __attribute__((aligned(a)))
-#define ALIGNED_4 ALIGNED(4)
-#define ALIGNED_8 ALIGNED(8)
-
-/* ======== disallow copy and assign ======== */
-#if __cplusplus < 201103L
-#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
-    TypeName(const TypeName&);             \
-    void operator=(const TypeName&)
-#else
-#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
-    TypeName(const TypeName&) = delete;    \
-    TypeName& operator=(const TypeName&) = delete;
-#endif
-
-/* ======== return value check ======== */
-#define RET_FAIL(expr) UNLIKELY(common::E_OK != (ret = (expr)))
-#define RFAIL(expr) UNLIKELY(common::E_OK != (ret = (expr)))
-#define RET_SUCC(expr) LIKELY(common::E_OK != (ret = (exprt)))
-#define RSUCC(expr) LIKELY(common::E_OK != (ret = (exprt)))
-#define IS_SUCC(ret) LIKELY(common::E_OK == (ret))
-#define IS_FAIL(ret) UNLIKELY(common::E_OK != (ret))
-
-#define IS_NULL(ptr) UNLIKELY((ptr) == nullptr)
-
-/* ======== min/max ======== */
-#define UTIL_MAX(a, b) ((a) > (b) ? (a) : (b))
-#define UTIL_MIN(a, b) ((a) > (b) ? (b) : (a))
-
-/*
- * int64_max < 10^20
- * consider +/- and the '\0' tail. 24 is enough
- */
-#define INT64_TO_BASE10_MAX_LEN 24
-
-#endif  // COMMON_UTIL_DEFINE_H
diff --git a/cpp/src/common/config/config.h b/cpp/src/common/config/config.h
index 258165b3..1b9b27d2 100644
--- a/cpp/src/common/config/config.h
+++ b/cpp/src/common/config/config.h
@@ -21,9 +21,7 @@
 
 #include <cstdint>
 
-#include "common/mutex/mutex.h"
 #include "utils/db_utils.h"
-#include "utils/util_define.h"
 
 namespace common {
 enum ConfigLevel {
@@ -55,15 +53,10 @@ extern CompressionType get_default_compressor();
 // In the future, configuration items need to be dynamically adjusted according
 // to the level
 extern void set_config_value();
-extern void config_set_page_max_point_count(uint32_t page_max_ponint_count);
+extern void config_set_page_max_point_count(uint32_t page_max_point_count);
 extern void config_set_max_degree_of_index_node(
     uint32_t max_degree_of_index_node);
 
-// FORCE_INLINE bool wal_cfg_enabled() { return
-// g_config_value_.wal_flush_policy_ != WAL_DISABLED; } FORCE_INLINE bool
-// wal_cfg_should_wait_persisted() { return g_config_value_.wal_flush_policy_ 
>=
-// WAL_FLUSH; }
-
 }  // namespace common
 
 #endif  // COMMON_CONFIG_CONFIG_H
diff --git a/cpp/src/common/global.cc b/cpp/src/common/global.cc
index 7196633b..c8ea574c 100644
--- a/cpp/src/common/global.cc
+++ b/cpp/src/common/global.cc
@@ -78,8 +78,8 @@ extern CompressionType get_default_compressor() {
     return LZ4;
 }
 
-void config_set_page_max_point_count(uint32_t page_max_ponint_count) {
-    g_config_value_.page_writer_max_point_num_ = page_max_ponint_count;
+void config_set_page_max_point_count(uint32_t page_max_point_count) {
+    g_config_value_.page_writer_max_point_num_ = page_max_point_count;
 }
 
 void config_set_max_degree_of_index_node(uint32_t max_degree_of_index_node) {
@@ -185,7 +185,6 @@ void print_backtrace() {
 }
 #endif
 
-Mutex g_all_inject_points_mutex;
 std::map<std::string, InjectPoint> g_all_inject_points;
 
 }  // namespace common
diff --git a/cpp/src/common/statistic.h b/cpp/src/common/statistic.h
index c886b63d..77c62223 100644
--- a/cpp/src/common/statistic.h
+++ b/cpp/src/common/statistic.h
@@ -21,6 +21,7 @@
 #define COMMON_STATISTIC_H
 
 #include <inttypes.h>
+#include <sstream>
 
 #include "common/allocator/alloc_base.h"
 #include "common/allocator/byte_stream.h"
@@ -544,15 +545,17 @@ class Int32Statistic : public Statistic {
     }
 
     std::string to_string() const {
-        const int buf_len = 256;
-        char buf[buf_len];
-        snprintf(buf, buf_len,
-                 "{count=%d, start_time=%" PRId64 ", end_time=%" PRId64
-                 ", first_val=%d, last_val=%d, sum_value=%" PRId64
-                 ", min_value=%d, max_value=%d}",
-                 count_, start_time_, end_time_, first_value_, last_value_,
-                 sum_value_, min_value_, max_value_);
-        return std::string(buf);
+        std::ostringstream oss;
+        oss << "{count=" << count_
+            << ", start_time=" << start_time_
+            << ", end_time=" << end_time_
+            << ", first_val=" << first_value_
+            << ", last_val=" << last_value_
+            << ", sum_value=" << sum_value_
+            << ", min_value=" << min_value_
+            << ", max_value=" << max_value_
+            << "}";
+        return oss.str();
     }
 };
 
@@ -627,16 +630,17 @@ class Int64Statistic : public Statistic {
     }
 
     std::string to_string() const {
-        const int buf_len = 256;
-        char buf[buf_len];
-        snprintf(buf, buf_len,
-                 "{count=%d, start_time=%" PRId64 ", end_time=%" PRId64
-                 ", first_val=%" PRId64 ", last_val=%" PRId64
-                 ", sum_value=%lf, min_value=%" PRId64 ", max_value=%" PRId64
-                 "}",
-                 count_, start_time_, end_time_, first_value_, last_value_,
-                 sum_value_, min_value_, max_value_);
-        return std::string(buf);
+        std::ostringstream oss;
+        oss << "{count=" << count_
+            << ", start_time=" << start_time_
+            << ", end_time=" << end_time_
+            << ", first_val=" << first_value_
+            << ", last_val=" << last_value_
+            << ", sum_value=" << sum_value_
+            << ", min_value=" << min_value_
+            << ", max_value=" << max_value_
+            << "}";
+        return oss.str();
     }
 };
 
@@ -812,12 +816,12 @@ class TimeStatistic : public Statistic {
     }
 
     std::string to_string() const {
-        const int buf_len = 256;
-        char buf[buf_len];
-        snprintf(buf, buf_len,
-                 "{count=%d, start_time=%" PRId64 ", end_time=%" PRId64 "}",
-                 count_, start_time_, end_time_);
-        return std::string(buf);
+        std::ostringstream oss;
+        oss << "{count=" << count_
+            << ", start_time=" << start_time_
+            << ", end_time=" << end_time_
+            << "}";
+        return oss.str();
     }
 };
 
diff --git a/cpp/src/compress/CMakeLists.txt b/cpp/src/compress/CMakeLists.txt
index dbc8e5c3..99bc0cc2 100644
--- a/cpp/src/compress/CMakeLists.txt
+++ b/cpp/src/compress/CMakeLists.txt
@@ -21,3 +21,5 @@ message("Running in src/storage/tsfile/compress directory")
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 aux_source_directory(. compress_SRC_LIST)
 add_library(compress_obj OBJECT ${compress_SRC_LIST})
+file(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+copy_to_dir(${HEADERS})
diff --git a/cpp/src/cwrapper/CMakeLists.txt b/cpp/src/cwrapper/CMakeLists.txt
index 27fd9f3e..d401fddc 100644
--- a/cpp/src/cwrapper/CMakeLists.txt
+++ b/cpp/src/cwrapper/CMakeLists.txt
@@ -18,5 +18,9 @@ under the License.
 ]]
 message("Running in cwrapper directory")
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
-aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} CWRAPPER_SRC_LIST)
-add_library(cwrapper_obj OBJECT ${CWRAPPER_SRC_LIST})
\ No newline at end of file
+aux_source_directory(. CWRAPPER_SRC_LIST)
+add_library(cwrapper_obj OBJECT ${CWRAPPER_SRC_LIST})
+
+# install header files
+file(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+copy_to_dir(${HEADERS})
diff --git a/cpp/src/cwrapper/errno_define.h b/cpp/src/cwrapper/errno_define_c.h
similarity index 100%
rename from cpp/src/cwrapper/errno_define.h
rename to cpp/src/cwrapper/errno_define_c.h
diff --git a/cpp/src/cwrapper/tsfile_cwrapper.h 
b/cpp/src/cwrapper/tsfile_cwrapper.h
index 6b2c2b2f..16b2cd21 100644
--- a/cpp/src/cwrapper/tsfile_cwrapper.h
+++ b/cpp/src/cwrapper/tsfile_cwrapper.h
@@ -126,7 +126,7 @@ typedef int64_t Timestamp;
  * @brief Creates a file for writing.
  *
  * @param pathname     Target file path to create.
- * @param err_code     [out] E_OK(0), or check error code in errno_define.h.
+ * @param err_code     [out] E_OK(0), or check error code in errno_define_c.h.
  *
  * @return WriteFile Valid handle on success.
  *
@@ -142,7 +142,7 @@ WriteFile write_file_new(const char* pathname, ERRNO* 
err_code);
  * @param file     Target file where the table data will be written.
  * @param schema       Table schema definition.
  *                     - Ownership: Should be free it by Caller.
- * @param err_code     [out] E_OK(0), or check error code in errno_define.h.
+ * @param err_code     [out] E_OK(0), or check error code in errno_define_c.h.
  *
  * @return TsFileWriter Valid handle on success, NULL on failure.
  *
@@ -155,7 +155,7 @@ TsFileWriter tsfile_writer_new(WriteFile file, TableSchema* 
schema,
  * @brief Creates a TsFileReader for reading a TsFile.
  *
  * @param pathname     Source TsFiles path. Must be a valid path.
- * @param err_code     E_OK(0), or check error code in errno_define.h.
+ * @param err_code     E_OK(0), or check error code in errno_define_c.h.
  * @return TsFileReader Valid handle on success, NULL on failure.
  *
  * @note Call tsfile_reader_close() to release resources.
@@ -168,7 +168,7 @@ TsFileReader tsfile_reader_new(const char* pathname, ERRNO* 
err_code);
  *
  * @param writer [in] Writer handle obtained from tsfile_writer_new().
  *                    After call: handle becomes invalid and must not be 
reused.
- * @return ERRNO - E_OK(0) on success, check error code in errno_define.h.
+ * @return ERRNO - E_OK(0) on success, check error code in errno_define_c.h.
  */
 ERRNO tsfile_writer_close(TsFileWriter writer);
 
@@ -179,7 +179,7 @@ ERRNO tsfile_writer_close(TsFileWriter writer);
  *                    After call:
  *                      Handle becomes invalid and must not be reused.
  *                      Result_set obtained by this handle becomes invalid.
- * @return ERRNO - E_OK(0) on success, or check error code in errno_define.h.
+ * @return ERRNO - E_OK(0) on success, or check error code in errno_define_c.h.
  */
 ERRNO tsfile_reader_close(TsFileReader reader);
 
@@ -212,7 +212,7 @@ uint32_t tablet_get_cur_row_size(Tablet tablet);
  * @param tablet [in] Valid Tablet handle.
  * @param row_index [in] Target row (0 ≤ index < max_rows).
  * @param timestamp [in] Timestamp with int64_t type.
- * @return ERRNO - E_OK(0)/E_OUT_OF_RANGE(5) or check errno_define.h.
+ * @return ERRNO - E_OK(0)/E_OUT_OF_RANGE(5) or check errno_define_c.h.
  */
 ERRNO tablet_add_timestamp(Tablet tablet, uint32_t row_index,
                            Timestamp timestamp);
@@ -224,7 +224,7 @@ ERRNO tablet_add_timestamp(Tablet tablet, uint32_t 
row_index,
  * @param row_index [in] Target row (0 ≤ index < max_rows).
  * @param column_name [in] Existing column name from Tablet schema.
  * @param value [in] Value to add. Type must match column schema.
- * @return ERRNO - E_OK(0) or check errno_define.h.
+ * @return ERRNO - E_OK(0) or check errno_define_c.h.
  *
  * @note Generated for types: int32_t, int64_t, float, double, bool
  */
@@ -252,7 +252,7 @@ ERRNO tablet_add_value_by_name_string(Tablet tablet, 
uint32_t row_index,
  * @brief Adds a value to a Tablet row by column index (generic types).
  *
  * @param column_index [in] Column position (0 ≤ index < column_num).
- * @return ERRNO - E_OK(0) or check errno_define.h.
+ * @return ERRNO - E_OK(0) or check errno_define_c.h.
  *
  * @note Generated for types: int32_t, int64_t, float, double, bool
  */
@@ -310,7 +310,7 @@ ERRNO tsfile_writer_register_device(TsFileWriter writer,
  * @param writer [in] Valid TsFileWriter handle. Must be initialized.
  * @param tablet [in] Tablet containing data. Should be freed after successful
  * write.
- * @return ERRNO - E_OK(0), or check error code in errno_define.h.
+ * @return ERRNO - E_OK(0), or check error code in errno_define_c.h.
  *
  */
 
diff --git a/cpp/src/cwrapper/tsfile_cwrapper_expression.cc 
b/cpp/src/cwrapper/tsfile_cwrapper_expression.cc
index 338ff2c2..d9b622a1 100644
--- a/cpp/src/cwrapper/tsfile_cwrapper_expression.cc
+++ b/cpp/src/cwrapper/tsfile_cwrapper_expression.cc
@@ -26,7 +26,7 @@
 // #include "reader/filter/time_operator.h"
 // #include "reader/result_set.h"
 // #include "reader/tsfile_reader.h"
-// #include "utils/errno_define.h"
+// #include "utils/errno_define_c.h"
 // #include "writer/tsfile_writer.h"
 //
 // #define E_OK common::E_OK
diff --git a/cpp/src/encoding/CMakeLists.txt b/cpp/src/encoding/CMakeLists.txt
index d1091969..4611b747 100644
--- a/cpp/src/encoding/CMakeLists.txt
+++ b/cpp/src/encoding/CMakeLists.txt
@@ -19,14 +19,5 @@ under the License.
 
 message("Running in src/encoding directory")
 
-# aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} 
storage_tsfile_encode_SRC_LIST)
-# set(storage_tsfile_encode_INC_LIST )
-# set(storage_tsfile_encode_DEFINE_OPTIONS )
-# set(storage_tsfile_encode_COMPILE_OPTIONS )
-# set(storage_tsfile_encode_LINK_OPTIONS )
-# 
-# add_statis_objtarget(storage_tsfile_encoding storage_tsfile_encode_SRC_LIST
-#                                              storage_tsfile_encode_INC_LIST
-#                                           
"${storage_tsfile_encode_DEFINE_OPTIONS}"
-#                                           
"${storage_tsfile_encode_COMPILE_OPTIONS}"
-#                                           
"${storage_tsfile_encode_LINK_OPTIONS}")
+file(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+copy_to_dir(${HEADERS})
\ No newline at end of file
diff --git a/cpp/src/file/CMakeLists.txt b/cpp/src/file/CMakeLists.txt
index e0d86311..5c5296b9 100644
--- a/cpp/src/file/CMakeLists.txt
+++ b/cpp/src/file/CMakeLists.txt
@@ -21,4 +21,8 @@ message("running in src/file diectory")
 message("CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} file_SRC_LIST)
-add_library(file_obj OBJECT ${file_SRC_LIST})
\ No newline at end of file
+add_library(file_obj OBJECT ${file_SRC_LIST})
+
+# install header files
+file(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+copy_to_dir(${HEADERS})
\ No newline at end of file
diff --git a/cpp/src/parser/CMakeLists.txt b/cpp/src/parser/CMakeLists.txt
index 92694434..56cf40ae 100644
--- a/cpp/src/parser/CMakeLists.txt
+++ b/cpp/src/parser/CMakeLists.txt
@@ -20,3 +20,6 @@ message("Running in src/parser directory")
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 file(GLOB_RECURSE PARSER_SRC_LIST "*.cpp")
 add_library(parser_obj OBJECT ${PARSER_SRC_LIST})
+
+file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+copy_to_dir(${HEADERS})
\ No newline at end of file
diff --git a/cpp/src/reader/CMakeLists.txt b/cpp/src/reader/CMakeLists.txt
index 1bbc8af0..a3e3b97e 100644
--- a/cpp/src/reader/CMakeLists.txt
+++ b/cpp/src/reader/CMakeLists.txt
@@ -20,4 +20,8 @@ message("Running in src/read directory")
 message("CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 file(GLOB_RECURSE read_SRC_LIST "*.cc")
-add_library(read_obj OBJECT ${read_SRC_LIST})
\ No newline at end of file
+add_library(read_obj OBJECT ${read_SRC_LIST})
+
+# install header files
+file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+copy_to_dir(${HEADERS})
\ No newline at end of file
diff --git a/cpp/src/reader/device_meta_iterator.cc 
b/cpp/src/reader/device_meta_iterator.cc
index fd3de7ae..90bcdc10 100644
--- a/cpp/src/reader/device_meta_iterator.cc
+++ b/cpp/src/reader/device_meta_iterator.cc
@@ -32,7 +32,8 @@ bool DeviceMetaIterator::has_next() {
     return !result_cache_.empty();
 }
 
-int DeviceMetaIterator::next(std::pair<std::shared_ptr<IDeviceID>, 
MetaIndexNode *>& ret_meta) {
+int DeviceMetaIterator::next(
+    std::pair<std::shared_ptr<IDeviceID>, MetaIndexNode*>& ret_meta) {
     if (!has_next()) {
         return common::E_NO_MORE_DATA;
     }
@@ -44,7 +45,10 @@ int 
DeviceMetaIterator::next(std::pair<std::shared_ptr<IDeviceID>, MetaIndexNode
 
 int DeviceMetaIterator::load_results() {
     while (!meta_index_nodes_.empty()) {
-        const auto& meta_data_index_node = meta_index_nodes_.front();
+        // To avoid ASan overflow.
+        // using `const auto&` creates a reference
+        // to a queue element that may become invalid.
+        auto meta_data_index_node = meta_index_nodes_.front();
         meta_index_nodes_.pop();
         const auto& node_type = meta_data_index_node->node_type_;
         if (node_type == MetaIndexNodeType::LEAF_DEVICE) {
@@ -59,7 +63,7 @@ int DeviceMetaIterator::load_results() {
     return common::E_OK;
 }
 
-int DeviceMetaIterator::load_leaf_device(MetaIndexNode *meta_index_node) {
+int DeviceMetaIterator::load_leaf_device(MetaIndexNode* meta_index_node) {
     int ret = common::E_OK;
     const auto& leaf_children = meta_index_node->children_;
     for (size_t i = 0; i < leaf_children.size(); i++) {
@@ -73,36 +77,36 @@ int DeviceMetaIterator::load_leaf_device(MetaIndexNode 
*meta_index_node) {
                                  ? leaf_children[i + 1]->get_offset()
                                  : meta_index_node->end_offset_;
         MetaIndexNode* child_node = nullptr;
-        if (RET_FAIL(io_reader_->read_device_meta_index(start_offset, 
end_offset,
-                                                       pa_, child_node))) {
+        if (RET_FAIL(io_reader_->read_device_meta_index(
+                start_offset, end_offset, pa_, child_node))) {
             return ret;
         } else {
             result_cache_.push(
-                std::make_pair(child->get_device_id(),
-                          child_node));
+                std::make_pair(child->get_device_id(), child_node));
         }
     }
     return ret;
 }
 
-int DeviceMetaIterator::load_internal_node(MetaIndexNode *meta_index_node) {
-    int ret = common::E_OK; 
+int DeviceMetaIterator::load_internal_node(MetaIndexNode* meta_index_node) {
+    int ret = common::E_OK;
     const auto& internal_children = meta_index_node->children_;
-    
+
     for (size_t i = 0; i < internal_children.size(); i++) {
         std::shared_ptr<IMetaIndexEntry> child = internal_children[i];
         int32_t start_offset = child->get_offset();
         int32_t end_offset = (i + 1 < internal_children.size())
                                  ? internal_children[i + 1]->get_offset()
                                  : meta_index_node->end_offset_;
-        
+
         MetaIndexNode* child_node = nullptr;
-        if (RET_FAIL(io_reader_->read_device_meta_index(start_offset, 
end_offset, pa_, child_node))) {
-            return ret; 
+        if (RET_FAIL(io_reader_->read_device_meta_index(
+                start_offset, end_offset, pa_, child_node))) {
+            return ret;
         } else {
             meta_index_nodes_.push(child_node);
         }
     }
-    return ret;  
+    return ret;
 }
 }  // namespace storage
\ No newline at end of file
diff --git a/cpp/src/reader/device_meta_iterator.h 
b/cpp/src/reader/device_meta_iterator.h
index 6bb9e38e..55f20913 100644
--- a/cpp/src/reader/device_meta_iterator.h
+++ b/cpp/src/reader/device_meta_iterator.h
@@ -37,9 +37,7 @@ class DeviceMetaIterator {
         pa_.init(512, common::MOD_DEVICE_META_ITER);
     }
 
-    ~DeviceMetaIterator() {
-        pa_.destroy();
-    }
+    ~DeviceMetaIterator() { pa_.destroy(); }
 
     bool has_next();
 
@@ -49,9 +47,10 @@ class DeviceMetaIterator {
     int load_results();
     int load_leaf_device(MetaIndexNode *meta_index_node);
     int load_internal_node(MetaIndexNode *meta_index_node);
-    TsFileIOReader* io_reader_;
+    TsFileIOReader *io_reader_;
     std::queue<MetaIndexNode *> meta_index_nodes_;
-    std::queue<std::pair<std::shared_ptr<IDeviceID>, MetaIndexNode *>> 
result_cache_;
+    std::queue<std::pair<std::shared_ptr<IDeviceID>, MetaIndexNode *>>
+        result_cache_;
     const Filter *id_filter_;
     common::PageArena pa_;
 };
diff --git a/cpp/src/common/datatype/CMakeLists.txt 
b/cpp/src/reader/filter/CMakeLists.txt
similarity index 99%
rename from cpp/src/common/datatype/CMakeLists.txt
rename to cpp/src/reader/filter/CMakeLists.txt
index f7db3afc..5860be1f 100644
--- a/cpp/src/common/datatype/CMakeLists.txt
+++ b/cpp/src/reader/filter/CMakeLists.txt
@@ -15,4 +15,4 @@ software distributed under the License is distributed on an
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-]]
+]]
\ No newline at end of file
diff --git a/cpp/src/reader/meta_data_querier.cc 
b/cpp/src/reader/meta_data_querier.cc
index 6fd5cea7..72246435 100644
--- a/cpp/src/reader/meta_data_querier.cc
+++ b/cpp/src/reader/meta_data_querier.cc
@@ -47,6 +47,7 @@ std::vector<std::shared_ptr<ChunkMeta>> 
MetadataQuerier::get_chunk_metadata_list
     // }
     // return io_reader_->get_chunk_metadata_list(path);
     ASSERT(false);
+    return {};
 }
 
 std::vector<std::vector<std::shared_ptr<ChunkMeta>>> 
MetadataQuerier::get_chunk_metadata_lists(
@@ -54,11 +55,13 @@ std::vector<std::vector<std::shared_ptr<ChunkMeta>>> 
MetadataQuerier::get_chunk_
     const MetaIndexNode* field_node) const {
     // return io_reader_->get_chunk_metadata_lists(device_id, field_names, 
field_node);
     ASSERT(false);
+    return {};
 }
 
 std::map<Path, std::vector<std::shared_ptr<ChunkMeta>>> 
MetadataQuerier::get_chunk_metadata_map(const std::vector<Path>& paths) const {
     // return io_reader_->get_chunk_metadata_map(paths);
     ASSERT(false);
+    return {};
 }
 
 int MetadataQuerier::get_whole_file_metadata(TsFileMeta* tsfile_meta) const {
@@ -73,12 +76,14 @@ void MetadataQuerier::load_chunk_metadatas(const 
std::vector<Path>& paths) {
 
 common::TSDataType MetadataQuerier::get_data_type(const Path& path) const {
     ASSERT(false);
+    return common::INVALID_DATATYPE;
 }
 
 std::vector<TimeRange> MetadataQuerier::convert_space_to_time_partition(
     const std::vector<Path>& paths, int64_t spacePartitionStartPos,
     int64_t spacePartitionEndPos) const {
     ASSERT(false);
+    return {};
 }
 
 void MetadataQuerier::clear() {
@@ -94,6 +99,7 @@ int MetadataQuerier::load_chunk_meta(const 
std::pair<IDeviceID, std::string>& ke
                         std::vector<ChunkMeta*>& chunk_meta_list) {
     // return io_reader_->load_chunk_meta(key, chunk_meta_list);
     ASSERT(false);
+    return common::E_NOT_SUPPORT;
 }
 
 }  // end namespace storage
diff --git a/cpp/src/utils/CMakeLists.txt b/cpp/src/utils/CMakeLists.txt
index 5f8e8372..0a3594c8 100644
--- a/cpp/src/utils/CMakeLists.txt
+++ b/cpp/src/utils/CMakeLists.txt
@@ -16,4 +16,8 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 ]]
-message("Running in src/utils directory")
\ No newline at end of file
+message("Running in src/utils directory")
+
+# install header files
+file(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+copy_to_dir(${HEADERS})
\ No newline at end of file
diff --git a/cpp/src/utils/injection.h b/cpp/src/utils/injection.h
index 76c5aa66..3175a2ab 100644
--- a/cpp/src/utils/injection.h
+++ b/cpp/src/utils/injection.h
@@ -33,7 +33,6 @@ struct InjectPoint {
 // define DBUG_EXECUTE_IF
 #define DBUG_EXECUTE_IF(inject_point_name, code)           \
     do {                                                   \
-        common::MutexGuard mg(g_all_inject_points_mutex);  \
         if (g_all_inject_points.find(inject_point_name) != \
             g_all_inject_points.end()) {                   \
             InjectPoint& inject_point =                    \
@@ -48,19 +47,16 @@ struct InjectPoint {
 // open injection
 #define ENABLE_INJECTION(inject_point_name, count)        \
     do {                                                  \
-        common::MutexGuard mg(g_all_inject_points_mutex); \
         g_all_inject_points[inject_point_name] = {count}; \
     } while (0)
 
 // close injection
 #define DISABLE_INJECTION(inject_point_name)              \
     do {                                                  \
-        common::MutexGuard mg(g_all_inject_points_mutex); \
         g_all_inject_points.erase(inject_point_name);     \
     } while (0)
 
 // the map save all inject points
-extern Mutex g_all_inject_points_mutex;
 extern std::map<std::string, InjectPoint> g_all_inject_points;
 
 }  // end namespace common
diff --git a/cpp/src/utils/storage_utils.h b/cpp/src/utils/storage_utils.h
index 0d3f5a95..53e45400 100644
--- a/cpp/src/utils/storage_utils.h
+++ b/cpp/src/utils/storage_utils.h
@@ -70,14 +70,10 @@ struct InsertResult {
 
 FORCE_INLINE std::string get_file_path_from_file_id(
     const common::FileID &file_id) {
-    // TODO prefix len + number len
-    const int len = 256;
-    char path_buf[len];
-    memset(path_buf, 0, len);
-    // TODO config
-    snprintf(path_buf, len, "./%" PRId64 "-%d-%d.tsfile", file_id.seq_,
-             file_id.version_, file_id.merge_);
-    return std::string(path_buf);
+    std::ostringstream oss;
+    oss << "./" << file_id.seq_ << "-" << file_id.version_ << "-"
+        << file_id.merge_ << ".tsfile";
+    return oss.str();
 }
 
 }  // end namespace storage
diff --git a/cpp/src/writer/CMakeLists.txt b/cpp/src/writer/CMakeLists.txt
index 30b031de..aee6ad5a 100644
--- a/cpp/src/writer/CMakeLists.txt
+++ b/cpp/src/writer/CMakeLists.txt
@@ -21,4 +21,8 @@ message("running in src/write diectory")
 message("CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} write_SRC_LIST)
-add_library(write_obj OBJECT ${write_SRC_LIST})
\ No newline at end of file
+add_library(write_obj OBJECT ${write_SRC_LIST})
+
+# install header files
+file(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+copy_to_dir(${HEADERS})
\ No newline at end of file
diff --git a/cpp/test/CMakeLists.txt b/cpp/test/CMakeLists.txt
index a17b1e3c..1beb310d 100644
--- a/cpp/test/CMakeLists.txt
+++ b/cpp/test/CMakeLists.txt
@@ -16,53 +16,76 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 ]]
+cmake_minimum_required(VERSION 3.11)
+project(TsFile_CPP_TEST)
 include(FetchContent)
 
-set(URL_LIST
-    "https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip";
-    
"https://hub.nuaa.cf/google/googletest/archive/refs/tags/release-1.12.1.zip";
-    
"https://hub.yzuu.cf/google/googletest/archive/refs/tags/release-1.12.1.zip";
+set(CMAKE_VERBOSE_MAKEFILE ON)
+
+set(GTEST_URL_LIST
+        
"https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip";
+        
"https://hub.nuaa.cf/google/googletest/archive/refs/tags/release-1.12.1.zip";
+        
"https://hub.yzuu.cf/google/googletest/archive/refs/tags/release-1.12.1.zip";
 )
 
+set(GTEST_ZIP_PATH 
"${CMAKE_SOURCE_DIR}/third_party/googletest-release-1.12.1.zip")
 set(DOWNLOADED 0)
 set(GTEST_URL "")
 set(TIMEOUT 30)
 
-foreach(URL ${URL_LIST})
-    message(STATUS "Trying to download from ${URL}")
-    file(DOWNLOAD ${URL} "${CMAKE_BINARY_DIR}/googletest-release-1.12.1.zip" 
STATUS DOWNLOAD_STATUS TIMEOUT ${TIMEOUT})
+if (EXISTS ${GTEST_ZIP_PATH})
+    message(STATUS "Using local gtest zip file: ${GTEST_ZIP_PATH}")
+    set(DOWNLOADED 1)
+    set(GTEST_URL ${GTEST_ZIP_PATH})
+else ()
+    message(STATUS "Local gtest zip file not found, trying to download from 
network...")
+endif ()
 
-    list(GET DOWNLOAD_STATUS 0 DOWNLOAD_RESULT)
-    if(${DOWNLOAD_RESULT} EQUAL 0)
-        set(DOWNLOADED 1)
-        set(GTEST_URL ${URL})
-        break()
-    endif()
-endforeach()
+if (NOT DOWNLOADED)
+    foreach (URL ${GTEST_URL_LIST})
+        message(STATUS "Trying to download from ${URL}")
+        file(DOWNLOAD ${URL} 
"${CMAKE_SOURCE_DIR}/third_party/googletest-release-1.12.1.zip" STATUS 
DOWNLOAD_STATUS TIMEOUT ${TIMEOUT})
+
+        list(GET DOWNLOAD_STATUS 0 DOWNLOAD_RESULT)
+        if (${DOWNLOAD_RESULT} EQUAL 0)
+            set(DOWNLOADED 1)
+            set(GTEST_URL ${GTEST_ZIP_PATH})
+            break()
+        endif ()
+    endforeach ()
+endif ()
 
-if(${DOWNLOADED})
-    message(STATUS "Successfully downloaded googletest from ${GTEST_URL}")
+if (${DOWNLOADED})
+    message(STATUS "Successfully get googletest from ${GTEST_URL}")
     FetchContent_Declare(
-      googletest
-      URL ${GTEST_URL}
+            googletest
+            URL ${GTEST_URL}
     )
     set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
     FetchContent_MakeAvailable(googletest)
     set(TESTS_ENABLED ON PARENT_SCOPE)
-else()
+else ()
     message(WARNING "Failed to download googletest from all provided URLs, 
setting TESTS_ENABLED to OFF")
     set(TESTS_ENABLED OFF PARENT_SCOPE)
     return()
-endif()
+endif ()
 
-message(STATUS "Adding test configurations...")
 
-set(SDK_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/../src)
-message("SDK_INCLUDE_DIR: ${SDK_INCLUDE_DIR}")
-set(LIBTSFILE_SDK_DIR ${PROJECT_BINARY_DIR}/lib)
-message("LIBTSFILE_SDK_DIR: ${LIBTSFILE_SDK_DIR}")
+message(STATUS "Adding test configurations...")
 
-include_directories(${SDK_INCLUDE_DIR})
+set(LIB_TSFILE_SDK_DIR ${PROJECT_BINARY_DIR}/lib)
+message("LIB_TSFILE_SDK_DIR: ${LIB_TSFILE_SDK_DIR}")
+
+include_directories(
+        ${LIBRARY_INCLUDE_DIR}
+        ${THIRD_PARTY_INCLUDE}
+        ${THIRD_PARTY_INCLUDE}/google_snappy
+        ${CMAKE_SOURCE_DIR}/third_party/lz4
+        ${CMAKE_SOURCE_DIR}/third_party/google_snappy
+        ${CMAKE_SOURCE_DIR}/third_party/lzokay
+        ${CMAKE_SOURCE_DIR}/third_party/zlib-1.2.13
+        ${CMAKE_SOURCE_DIR}/third_party/antlr4-cpp-runtime-4/runtime/src
+)
 
 enable_testing()
 
@@ -76,27 +99,35 @@ file(GLOB_RECURSE TEST_SRCS
         "reader/*_test.cc"
         "writer/*_test.cc"
         "cwrapper/*_test.cc"
-        )
+)
+
 if (${COV_ENABLED})
     message("Enable code cov...")
     add_compile_options(-fprofile-arcs -ftest-coverage)
 endif ()
 
-if(NOT WIN32)
-#enable address sanitizer default
-    set(ENV{ASAN_OPTIONS} "detect_container_overflow=0")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
-endif()
+add_definitions(-DANTLR4CPP_STATIC)
+set(ANTLR4_WITH_STATIC_CRT OFF)
 
 add_executable(TsFile_Test ${TEST_SRCS})
 target_link_libraries(
-  TsFile_Test
-  GTest::gtest_main
-  GTest::gmock
-  tsfile
+        TsFile_Test
+        GTest::gtest_main
+        GTest::gmock
+        tsfile
 )
-set_target_properties(TsFile_Test PROPERTIES RUNTIME_OUTPUT_DIRECTORY 
${LIBTSFILE_SDK_DIR})
 
+set_target_properties(TsFile_Test PROPERTIES RUNTIME_OUTPUT_DIRECTORY 
${LIB_TSFILE_SDK_DIR})
+
+if (WIN32)
+    add_custom_command(TARGET TsFile_Test POST_BUILD
+            COMMAND ${CMAKE_COMMAND} -E copy
+            "${LIBRARY_OUTPUT_PATH}/libtsfile.dll"
+            "$<TARGET_FILE_DIR:TsFile_Test>"
+            COMMENT "Copying libtsfile.dll to test executable directory"
+            VERBATIM
+    )
+endif ()
 
 include(GoogleTest)
 gtest_discover_tests(TsFile_Test)
diff --git a/cpp/test/cwrapper/cwrapper_test.cc 
b/cpp/test/cwrapper/cwrapper_test.cc
index 224257e2..0cd6b325 100644
--- a/cpp/test/cwrapper/cwrapper_test.cc
+++ b/cpp/test/cwrapper/cwrapper_test.cc
@@ -20,7 +20,7 @@
 #include <unistd.h>
 #include <utils/db_utils.h>
 extern "C" {
-#include "cwrapper/errno_define.h"
+#include "cwrapper/errno_define_c.h"
 #include "cwrapper/tsfile_cwrapper.h"
 }
 
diff --git a/cpp/test/reader/tsfile_reader_test.cc 
b/cpp/test/reader/tsfile_reader_test.cc
index c90ebb4e..a52eec7a 100644
--- a/cpp/test/reader/tsfile_reader_test.cc
+++ b/cpp/test/reader/tsfile_reader_test.cc
@@ -23,7 +23,6 @@
 #include <random>
 #include <vector>
 
-#include "common/path.h"
 #include "common/record.h"
 #include "common/schema.h"
 #include "common/tablet.h"
@@ -61,8 +60,8 @@ protected:
 
 public:
     static std::string generate_random_string(int length) {
-        std::random_device rd;
-        std::mt19937 gen(rd());
+        std::mt19937 gen(static_cast<unsigned int>(
+            std::chrono::system_clock::now().time_since_epoch().count()));
         std::uniform_int_distribution<> dis(0, 61);
 
         const std::string chars =
diff --git a/cpp/test/writer/tsfile_writer_test.cc 
b/cpp/test/writer/tsfile_writer_test.cc
index dcd96db3..b17a126c 100644
--- a/cpp/test/writer/tsfile_writer_test.cc
+++ b/cpp/test/writer/tsfile_writer_test.cc
@@ -47,11 +47,13 @@ class TsFileWriterTest : public ::testing::Test {
         flags |= O_BINARY;
 #endif
         mode_t mode = 0666;
-        EXPECT_EQ(tsfile_writer_->open(file_name_, flags, mode), common::E_OK);
+        ASSERT_EQ(tsfile_writer_->open(file_name_, flags, mode), common::E_OK);
     }
     void TearDown() override {
+        tsfile_writer_->close();
         delete tsfile_writer_;
-        remove(file_name_.c_str());
+        int ret = remove(file_name_.c_str());
+        ASSERT_EQ(0, ret);
     }
 
     std::string file_name_;
@@ -59,8 +61,8 @@ class TsFileWriterTest : public ::testing::Test {
 
    public:
     static std::string generate_random_string(int length) {
-        std::random_device rd;
-        std::mt19937 gen(rd());
+        std::mt19937 gen(static_cast<unsigned int>(
+            std::chrono::system_clock::now().time_since_epoch().count()));
         std::uniform_int_distribution<> dis(0, 61);
 
         const std::string chars =
@@ -73,7 +75,6 @@ class TsFileWriterTest : public ::testing::Test {
         for (int i = 0; i < length; ++i) {
             random_string += chars[dis(gen)];
         }
-
         return random_string;
     }
 

Reply via email to