Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
Signed-off-by: sunby <[email protected]>
  • Loading branch information
sunby committed Dec 11, 2024
1 parent d174ec2 commit fbd0726
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ void free_rust_result(RustResult result);

void free_rust_error(const char *error);

RustResult test_enum_with_array();

RustResult test_enum_with_ptr();

void print_vector_of_strings(const char *const *ptr, uintptr_t len);

void *create_hashmap();
Expand Down
14 changes: 14 additions & 0 deletions internal/core/thirdparty/tantivy/tantivy-binding/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,17 @@ macro_rules! cstr_to_str {
}
};
}


#[no_mangle]
pub extern "C" fn test_enum_with_array() -> RustResult {
let array = vec![1, 2, 3];
RustResult::from(Result::Ok(array))
}

#[no_mangle]
pub extern "C" fn test_enum_with_ptr() -> RustResult {
let ptr = Box::into_raw(Box::new(1));
RustResult::from(Result::Ok(ptr as *mut c_void))
}

1 change: 1 addition & 0 deletions internal/core/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ set(MILVUS_TEST_FILES
test_utils.cpp
test_chunked_segment.cpp
test_chunked_column.cpp
test_rust_result.cpp
)

if ( INDEX_ENGINE STREQUAL "cardinal" )
Expand Down
14 changes: 14 additions & 0 deletions internal/core/unittest/test_rust_result.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#include <cstdint>
#include "gtest/gtest.h"
#include "tantivy-binding.h"
TEST(RustResultTest, TestResult) {
auto arr = test_enum_with_array();
auto len = arr.value.rust_array._0.len;
for (size_t i = 0; i < len; i++) {
EXPECT_EQ(i + 1, arr.value.rust_array._0.array[i]);
}

auto ptr = test_enum_with_ptr();
EXPECT_EQ(1, *static_cast<uint32_t*>(ptr.value.ptr._0));
}

0 comments on commit fbd0726

Please sign in to comment.