Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed May 22, 2024
1 parent 766910b commit 83dcc56
Show file tree
Hide file tree
Showing 6 changed files with 1,810 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/subdir.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if (NOT ENABLE_CPP_20)
Set(BUILD_STRUCT_JSON ON)
Set(BUILD_STRUCT_XML ON)
Set(BUILD_STRUCT_YAML ON)
Set(BUILD_STRUCT_PB ON)
endif()

foreach(child ${children})
Expand Down
37 changes: 37 additions & 0 deletions src/struct_pb/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
find_package(Protobuf QUIET)
if("${yaLanTingLibs_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
# If this is a subproject in ylt
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/tests)
else()
# else find installed yalantinglibs
cmake_minimum_required(VERSION 3.15)
project(struct_pb_test)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# if you have install ylt
find_package(yalantinglibs REQUIRED)
link_libraries(yalantinglibs::yalantinglibs)
# else
# include_directories(include)
# include_directories(include/ylt/thirdparty)
endif()

set(TEST_PROTO main.cpp)

if (Protobuf_FOUND)
add_definitions(-DSTRUCT_PB_WITH_PROTO)
message(STATUS "Found Protobuf: ${Protobuf_VERSION}")
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(PROTO_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/)
file(GLOB PROTO_FILES ${PROTO_SRC_DIR}/*.proto)

protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES})
# message(STATUS "Proto source files: ${PROTO_SRCS}")
# message(STATUS "Proto header files: ${PROTO_HDRS}")
add_executable(struct_pb_test ${PROTO_SRCS} ${TEST_PROTO})
target_link_libraries(struct_pb_test PRIVATE protobuf::libprotobuf)
else()
add_executable(struct_pb_test ${TEST_PROTO})
endif()
56 changes: 56 additions & 0 deletions src/struct_pb/tests/data_def.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
syntax = "proto3";

package mygame;

option optimize_for = SPEED;
option cc_enable_arenas = true;

message Vec3 {
float x = 1;
float y = 2;
float z = 3;
}

message Weapon {
string name = 1;
int32 damage = 2;
}

message Monster {
Vec3 pos = 1;
int32 mana = 2;
int32 hp = 3;
string name = 4;
bytes inventory = 5;
enum Color {
Red = 0;
Green = 1;
Blue = 2;
}
Color color = 6;
repeated Weapon weapons = 7;
Weapon equipped = 8;
repeated Vec3 path = 9;
}

message Monsters {
repeated Monster monsters = 1;
}

message person {
int32 id = 1;
string name = 2;
int32 age = 3;
double salary = 4;
}

message persons {
repeated person person_list = 1;
}

message bench_int32 {
int32 a = 1;
int32 b = 2;
int32 c = 3;
int32 d = 4;
}
Loading

0 comments on commit 83dcc56

Please sign in to comment.