tests.cmake 11.3 KB
Newer Older
1 2 3 4
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../gmock/CMakeLists.txt")
  message(FATAL_ERROR "Cannot find gmock directory.")
endif()

5 6
option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH
  "Using absolute test_plugin path in tests" ON)
7
mark_as_advanced(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)
8

9
include_directories(
Feng Xiao's avatar
Feng Xiao committed
10 11
  ${protobuf_source_dir}/gmock
  ${protobuf_source_dir}/gmock/gtest
12 13 14
  ${protobuf_source_dir}/gmock/gtest/include
  ${protobuf_source_dir}/gmock/include
)
Feng Xiao's avatar
Feng Xiao committed
15

Feng Xiao's avatar
Feng Xiao committed
16 17 18 19
add_library(gmock STATIC
  ${protobuf_source_dir}/gmock/src/gmock-all.cc
  ${protobuf_source_dir}/gmock/gtest/src/gtest-all.cc
)
20
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
Feng Xiao's avatar
Feng Xiao committed
21 22 23
add_library(gmock_main STATIC ${protobuf_source_dir}/gmock/src/gmock_main.cc)
target_link_libraries(gmock_main gmock)

Feng Xiao's avatar
Feng Xiao committed
24 25 26 27 28
set(lite_test_protos
  google/protobuf/map_lite_unittest.proto
  google/protobuf/unittest_import_lite.proto
  google/protobuf/unittest_import_public_lite.proto
  google/protobuf/unittest_lite.proto
29
  google/protobuf/unittest_no_arena_lite.proto
Feng Xiao's avatar
Feng Xiao committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
)

set(tests_protos
  google/protobuf/any_test.proto
  google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto
  google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto
  google/protobuf/map_proto2_unittest.proto
  google/protobuf/map_unittest.proto
  google/protobuf/unittest.proto
  google/protobuf/unittest_arena.proto
  google/protobuf/unittest_custom_options.proto
  google/protobuf/unittest_drop_unknown_fields.proto
  google/protobuf/unittest_embed_optimize_for.proto
  google/protobuf/unittest_empty.proto
  google/protobuf/unittest_import.proto
  google/protobuf/unittest_import_public.proto
46 47 48
  google/protobuf/unittest_lazy_dependencies.proto
  google/protobuf/unittest_lazy_dependencies_custom_option.proto
  google/protobuf/unittest_lazy_dependencies_enum.proto
Feng Xiao's avatar
Feng Xiao committed
49 50
  google/protobuf/unittest_lite_imports_nonlite.proto
  google/protobuf/unittest_mset.proto
51
  google/protobuf/unittest_mset_wire_format.proto
Feng Xiao's avatar
Feng Xiao committed
52 53 54 55 56 57 58 59
  google/protobuf/unittest_no_arena.proto
  google/protobuf/unittest_no_arena_import.proto
  google/protobuf/unittest_no_field_presence.proto
  google/protobuf/unittest_no_generic_services.proto
  google/protobuf/unittest_optimize_for.proto
  google/protobuf/unittest_preserve_unknown_enum.proto
  google/protobuf/unittest_preserve_unknown_enum2.proto
  google/protobuf/unittest_proto3_arena.proto
Jisi Liu's avatar
Jisi Liu committed
60 61
  google/protobuf/unittest_proto3_arena_lite.proto
  google/protobuf/unittest_proto3_lite.proto
Feng Xiao's avatar
Feng Xiao committed
62
  google/protobuf/unittest_well_known_types.proto
63 64 65 66 67 68
  google/protobuf/util/internal/testdata/anys.proto
  google/protobuf/util/internal/testdata/books.proto
  google/protobuf/util/internal/testdata/default_value.proto
  google/protobuf/util/internal/testdata/default_value_test.proto
  google/protobuf/util/internal/testdata/field_mask.proto
  google/protobuf/util/internal/testdata/maps.proto
69
  google/protobuf/util/internal/testdata/oneofs.proto
70
  google/protobuf/util/internal/testdata/proto3.proto
71 72
  google/protobuf/util/internal/testdata/struct.proto
  google/protobuf/util/internal/testdata/timestamp_duration.proto
73
  google/protobuf/util/internal/testdata/wrappers.proto
74
  google/protobuf/util/json_format_proto3.proto
Feng Xiao's avatar
Feng Xiao committed
75
  google/protobuf/util/message_differencer_unittest.proto
Feng Xiao's avatar
Feng Xiao committed
76 77 78 79 80 81 82
)

macro(compile_proto_file filename)
  get_filename_component(dirname ${filename} PATH)
  get_filename_component(basename ${filename} NAME_WE)
  add_custom_command(
    OUTPUT ${protobuf_source_dir}/src/${dirname}/${basename}.pb.cc
83
    DEPENDS protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto
Feng Xiao's avatar
Feng Xiao committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    COMMAND protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto
        --proto_path=${protobuf_source_dir}/src
        --cpp_out=${protobuf_source_dir}/src
  )
endmacro(compile_proto_file)

set(lite_test_proto_files)
foreach(proto_file ${lite_test_protos})
  compile_proto_file(${proto_file})
  string(REPLACE .proto .pb.cc pb_file ${proto_file})
  set(lite_test_proto_files ${lite_test_proto_files}
      ${protobuf_source_dir}/src/${pb_file})
endforeach(proto_file)

set(tests_proto_files)
foreach(proto_file ${tests_protos})
  compile_proto_file(${proto_file})
  string(REPLACE .proto .pb.cc pb_file ${proto_file})
  set(tests_proto_files ${tests_proto_files}
      ${protobuf_source_dir}/src/${pb_file})
endforeach(proto_file)

set(common_test_files
  ${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc
  ${protobuf_source_dir}/src/google/protobuf/map_test_util.cc
  ${protobuf_source_dir}/src/google/protobuf/test_util.cc
  ${protobuf_source_dir}/src/google/protobuf/testing/file.cc
  ${protobuf_source_dir}/src/google/protobuf/testing/googletest.cc
)

114 115 116 117 118 119
set(common_lite_test_files
  ${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc
  ${protobuf_source_dir}/src/google/protobuf/map_lite_test_util.cc
  ${protobuf_source_dir}/src/google/protobuf/test_util_lite.cc
)

Feng Xiao's avatar
Feng Xiao committed
120 121 122 123
set(tests_files
  ${protobuf_source_dir}/src/google/protobuf/any_test.cc
  ${protobuf_source_dir}/src/google/protobuf/arena_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/arenastring_unittest.cc
Jisi Liu's avatar
Jisi Liu committed
124
  ${protobuf_source_dir}/src/google/protobuf/compiler/annotation_test_util.cc
Feng Xiao's avatar
Feng Xiao committed
125 126
  ${protobuf_source_dir}/src/google/protobuf/compiler/command_line_interface_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
127
  ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_move_unittest.cc
Feng Xiao's avatar
Feng Xiao committed
128 129
  ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_unittest.cc
Jisi Liu's avatar
Jisi Liu committed
130
  ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/metadata_test.cc
131
  ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
Feng Xiao's avatar
Feng Xiao committed
132 133 134 135
  ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/compiler/importer_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_plugin_unittest.cc
Feng Xiao's avatar
Feng Xiao committed
136
  ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc
Feng Xiao's avatar
Feng Xiao committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
  ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/compiler/parser_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/compiler/python/python_plugin_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/descriptor_database_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/descriptor_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/drop_unknown_fields_test.cc
  ${protobuf_source_dir}/src/google/protobuf/dynamic_message_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/extension_set_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/io/coded_stream_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/io/printer_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/io/tokenizer_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/map_field_test.cc
  ${protobuf_source_dir}/src/google/protobuf/map_test.cc
  ${protobuf_source_dir}/src/google/protobuf/message_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/no_field_presence_test.cc
  ${protobuf_source_dir}/src/google/protobuf/preserve_unknown_enum_test.cc
Jisi Liu's avatar
Jisi Liu committed
156
  ${protobuf_source_dir}/src/google/protobuf/proto3_arena_lite_unittest.cc
Feng Xiao's avatar
Feng Xiao committed
157
  ${protobuf_source_dir}/src/google/protobuf/proto3_arena_unittest.cc
Jisi Liu's avatar
Jisi Liu committed
158
  ${protobuf_source_dir}/src/google/protobuf/proto3_lite_unittest.cc
Feng Xiao's avatar
Feng Xiao committed
159 160 161
  ${protobuf_source_dir}/src/google/protobuf/reflection_ops_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/repeated_field_reflection_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/repeated_field_unittest.cc
162
  ${protobuf_source_dir}/src/google/protobuf/stubs/bytestream_unittest.cc
Feng Xiao's avatar
Feng Xiao committed
163
  ${protobuf_source_dir}/src/google/protobuf/stubs/common_unittest.cc
164
  ${protobuf_source_dir}/src/google/protobuf/stubs/int128_unittest.cc
Jisi Liu's avatar
Jisi Liu committed
165
  ${protobuf_source_dir}/src/google/protobuf/stubs/io_win32_unittest.cc
Feng Xiao's avatar
Feng Xiao committed
166
  ${protobuf_source_dir}/src/google/protobuf/stubs/once_unittest.cc
167 168 169
  ${protobuf_source_dir}/src/google/protobuf/stubs/status_test.cc
  ${protobuf_source_dir}/src/google/protobuf/stubs/statusor_test.cc
  ${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece_unittest.cc
Feng Xiao's avatar
Feng Xiao committed
170 171 172 173
  ${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/stubs/structurally_valid_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/stubs/strutil_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/stubs/template_util_unittest.cc
174
  ${protobuf_source_dir}/src/google/protobuf/stubs/time_test.cc
Feng Xiao's avatar
Feng Xiao committed
175 176 177
  ${protobuf_source_dir}/src/google/protobuf/stubs/type_traits_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/text_format_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/unknown_field_set_unittest.cc
178
  ${protobuf_source_dir}/src/google/protobuf/util/delimited_message_util_test.cc
179
  ${protobuf_source_dir}/src/google/protobuf/util/field_comparator_test.cc
180
  ${protobuf_source_dir}/src/google/protobuf/util/field_mask_util_test.cc
181 182 183 184 185
  ${protobuf_source_dir}/src/google/protobuf/util/internal/default_value_objectwriter_test.cc
  ${protobuf_source_dir}/src/google/protobuf/util/internal/json_objectwriter_test.cc
  ${protobuf_source_dir}/src/google/protobuf/util/internal/json_stream_parser_test.cc
  ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectsource_test.cc
  ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
Feng Xiao's avatar
Feng Xiao committed
186
  ${protobuf_source_dir}/src/google/protobuf/util/internal/type_info_test_helper.cc
187
  ${protobuf_source_dir}/src/google/protobuf/util/json_util_test.cc
Feng Xiao's avatar
Feng Xiao committed
188
  ${protobuf_source_dir}/src/google/protobuf/util/message_differencer_unittest.cc
189
  ${protobuf_source_dir}/src/google/protobuf/util/time_util_test.cc
190
  ${protobuf_source_dir}/src/google/protobuf/util/type_resolver_util_test.cc
Feng Xiao's avatar
Feng Xiao committed
191 192 193 194
  ${protobuf_source_dir}/src/google/protobuf/well_known_types_unittest.cc
  ${protobuf_source_dir}/src/google/protobuf/wire_format_unittest.cc
)

195 196 197 198 199 200
if(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)
  add_compile_options(-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH="$<TARGET_FILE:test_plugin>")
endif()

add_executable(tests ${tests_files} ${common_test_files} ${tests_proto_files} ${lite_test_proto_files})
target_link_libraries(tests libprotoc libprotobuf gmock_main)
Feng Xiao's avatar
Feng Xiao committed
201 202 203 204 205 206 207

set(test_plugin_files
  ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc
  ${protobuf_source_dir}/src/google/protobuf/testing/file.cc
  ${protobuf_source_dir}/src/google/protobuf/testing/file.h
  ${protobuf_source_dir}/src/google/protobuf/compiler/test_plugin.cc
)
208

Feng Xiao's avatar
Feng Xiao committed
209
add_executable(test_plugin ${test_plugin_files})
210
target_link_libraries(test_plugin libprotoc libprotobuf gmock)
Feng Xiao's avatar
Feng Xiao committed
211 212 213 214

set(lite_test_files
  ${protobuf_source_dir}/src/google/protobuf/lite_unittest.cc
)
215
add_executable(lite-test ${lite_test_files} ${common_lite_test_files} ${lite_test_proto_files})
216
target_link_libraries(lite-test libprotobuf-lite gmock_main)
217 218 219 220 221 222

set(lite_arena_test_files
  ${protobuf_source_dir}/src/google/protobuf/lite_arena_unittest.cc
)
add_executable(lite-arena-test ${lite_arena_test_files} ${common_lite_test_files} ${lite_test_proto_files})
target_link_libraries(lite-arena-test libprotobuf-lite gmock_main)
223

224 225
add_custom_target(check
  COMMAND tests
226
  DEPENDS tests test_plugin
227
  WORKING_DIRECTORY ${protobuf_source_dir})