Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/unittests #134

Merged
merged 46 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
29a9a06
bugfix: bitmap clear method
hongzhigao Jun 14, 2024
ea0818c
Merge branch 'apache:develop' into develop
761417898 Jun 17, 2024
5312b8c
Merge branch 'apache:develop' into develop
761417898 Jun 18, 2024
a556cd1
Merge branch 'apache:develop' into develop
761417898 Jun 21, 2024
2962c70
feature/unittests
761417898 Jun 21, 2024
a5510be
add license
761417898 Jun 22, 2024
3ec364f
Merge branch 'apache:develop' into feature/unittests
761417898 Jun 26, 2024
6b0f936
support cmake-maven
761417898 Jun 26, 2024
472c933
support cmake-maven
761417898 Jun 26, 2024
11b6c28
Merge branch 'apache:develop' into feature/unittests
761417898 Jun 27, 2024
a4c7f9b
unittest support cmake-maven
761417898 Jun 27, 2024
51a3748
unittest support cmake-maven
761417898 Jun 27, 2024
73baaca
fix for macos compilation
761417898 Jun 28, 2024
b10fafe
fix for macos compilation
761417898 Jun 28, 2024
3eb753c
fix for macos compilation
761417898 Jun 28, 2024
38c80fd
fix for macos compilation
761417898 Jun 28, 2024
37cf01a
fix unittest dependency
761417898 Jun 29, 2024
62208df
fix macos compilation
761417898 Jun 29, 2024
2a6c306
fix win compilation
761417898 Jun 29, 2024
711315b
fix win compilation
761417898 Jun 29, 2024
b31da4b
fix win compilation
761417898 Jun 29, 2024
d630230
test
761417898 Jun 29, 2024
c6d96bf
test
761417898 Jun 30, 2024
e10ee82
test
761417898 Jun 30, 2024
f32f8e5
fix windows mingw compilation
761417898 Jun 30, 2024
9346d62
fix mingw compilation
761417898 Jun 30, 2024
285f396
test
761417898 Jun 30, 2024
56f7205
fix MinGW compilation
761417898 Jun 30, 2024
ac58c7d
fix MinGW compilation
761417898 Jun 30, 2024
279203b
fix MinGW compilation
761417898 Jun 30, 2024
82e8fba
fix MinGW compilation
761417898 Jun 30, 2024
9783c39
test compress
761417898 Jun 30, 2024
e5cf880
test/encoding
761417898 Jun 30, 2024
82b1786
test/write
761417898 Jun 30, 2024
b934603
testcompress
761417898 Jun 30, 2024
7d231f4
testencoding
761417898 Jun 30, 2024
e021e5f
testcommon
761417898 Jun 30, 2024
6569c7a
testutils
761417898 Jun 30, 2024
313b32e
testfile
761417898 Jun 30, 2024
51fb5b8
fix MinGW compilation
761417898 Jun 30, 2024
ac0b18f
Merge branch 'apache:develop' into feature/unittests
761417898 Jun 30, 2024
c0105ea
support cross platform compilation
761417898 Jul 1, 2024
0ade727
support mingw macos ubuntu compilation
761417898 Jul 1, 2024
8f48e51
fix code formatting issues
761417898 Jul 3, 2024
df3e9a3
Merge branch 'apache:develop' into feature/unittests
761417898 Jul 4, 2024
ec50e7e
fix newly introduced encoding issue(bitpack)
hongzhigao Jul 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ configure_file(
"${PROJECT_SOURCE_DIR}/cmake/config.h.in"
"${PROJECT_BINARY_DIR}/cmake_config.h"
)

add_subdirectory(test)
add_dependencies(TsFile_Test tsfile)
2 changes: 1 addition & 1 deletion cpp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<goal>test</goal>
</goals>
<configuration>
<buildDirectory>${project.build.directory}/build</buildDirectory>
<buildDirectory>${project.build.directory}/build/test</buildDirectory>
</configuration>
</execution>
</executions>
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/common/allocator/byte_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ FORCE_INLINE double bytes_to_double(uint8_t bytes[8]) {

// follow jdk implementation style.
union {
long l;
long long l;
double d;
} u;

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/common/container/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class Array {
}

bool contain(const ValueType &value) {
for (int i = 0; i < size_; i++) {
for (size_t i = 0; i < size_; i++) {
if (array_[i] == value) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/common/container/hash_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class HashTable {

if (ATOMIC_LOAD(&size_) > ATOMIC_LOAD(&new_table_capacity_) *
SEGMENT_CAPACITY * TABLE_GROWTH) {
int tmp = 0;
uint8_t tmp = 0;
if (ATOMIC_CAS(&is_extending_, &tmp, 1)) {
ret = extend();
if (ret != E_OK) {
Expand Down Expand Up @@ -437,7 +437,7 @@ class HashTable {

if (ATOMIC_LOAD(&size_) > ATOMIC_LOAD(&new_table_capacity_) *
SEGMENT_CAPACITY * TABLE_GROWTH) {
int tmp = 0;
uint8_t tmp = 0;
if (ATOMIC_CAS(&is_extending_, &tmp, 1)) {
ret = extend();
if (ret != E_OK) {
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/common/container/simple_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef COMMON_CONTAINER_VECTOR_H
#define COMMON_CONTAINER_VECTOR_H

#include <vector>

#include "utils/util_define.h"

namespace common {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/common/datatype/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,4 @@ FORCE_INLINE int get_typed_data_from_value<double>(Value *value,

} // namespace common

#endif // COMMON_DATATYPE_VALUE_H
#endif // COMMON_DATATYPE_VALUE_H
4 changes: 2 additions & 2 deletions cpp/src/encoding/bitpack_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class BitPackDecoder {

public:
BitPackDecoder()
: byte_cache_(1024, common::MOD_DECODER_OBJ),
current_count_(0),
: current_count_(0),
byte_cache_(1024, common::MOD_DECODER_OBJ),
current_buffer_(nullptr),
packer_(nullptr),
tmp_buf_(nullptr) {}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/encoding/plain_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef ENCODING_PLAIN_DECODER_H
#define ENCODING_PLAIN_DECODER_H

#include "decoder.h"
#include "encoding/decoder.h"

namespace storage {

Expand Down
54 changes: 54 additions & 0 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#[[
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.
]]
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.12.0.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

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}")

include_directories(${SDK_INCLUDE_DIR})

enable_testing()

file(GLOB_RECURSE TEST_SRCS
"common/*_test.cc"
"encoding/*_test.cc"
"utils/*_test.cc"
"file/*_test.cc"
"compress/*_test.cc"
"writer/*_test.cc"
)
add_executable(TsFile_Test ${TEST_SRCS})
target_link_libraries(
TsFile_Test
GTest::gtest_main
GTest::gmock
tsfile
)
set_target_properties(TsFile_Test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${LIBTSFILE_SDK_DIR})

include(GoogleTest)
gtest_discover_tests(TsFile_Test)
64 changes: 64 additions & 0 deletions cpp/test/common/allocator/alloc_base_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 a
*
* 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.
*/
#include "common/allocator/alloc_base.h"

#include <gtest/gtest.h>

namespace common {

const uint32_t HEADER_SIZE_4B = 4;
const uint32_t HEADER_SIZE_8B = 8;

TEST(AllocBaseTest, BaseAllocator) {
BaseAllocator allocator;
for (AllocModID mod_id = MOD_DEFAULT; mod_id <= MOD_ZIGZAG_OBJ;
mod_id = (AllocModID)(mod_id + 1)) {
void *ptr = allocator.alloc(100, mod_id);
ASSERT_NE(ptr, nullptr);
allocator.free(ptr);
}
}

TEST(AllocBaseTest, AllocSmallSize) {
uint32_t size = 1024;
AllocModID mid = MOD_DEFAULT;
void *ptr = mem_alloc(size, mid);
ASSERT_NE(ptr, nullptr);
char *p = (char *)ptr - HEADER_SIZE_4B;
uint32_t header = *((uint32_t *)p);
EXPECT_EQ(header >> 8, size);
EXPECT_EQ(header & 0x7F, mid);
mem_free(ptr);
}

TEST(AllocBaseTest, AllocLargeSize) {
uint32_t size = 0x1000000;
AllocModID mid = MOD_DEFAULT;
void *ptr = mem_alloc(size, mid);
ASSERT_NE(ptr, nullptr);
char *p = (char *)ptr - HEADER_SIZE_8B;
uint32_t high4b = *(uint32_t *)p;
uint32_t low4b = *(uint32_t *)(p + 4);
uint64_t header = ((uint64_t)high4b << 32) | low4b;
EXPECT_EQ((header >> 8), size);
EXPECT_EQ((header & 0x7F), mid);
mem_free(ptr);
}

} // namespace common
Loading