gtestify test/core/slice (#30198)

* gtestify test/core/slice

* Fix

* fix

* fix
pull/30295/head
Esun Kim 2 years ago committed by GitHub
parent 34b380697d
commit 6bdc1810c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 262
      CMakeLists.txt
  2. 92
      build_autogenerated.yaml
  3. 4
      test/core/slice/BUILD
  4. 92
      test/core/slice/b64_test.cc
  5. 90
      test/core/slice/c_slice_buffer_test.cc
  6. 21
      test/core/slice/percent_encoding_test.cc
  7. 12
      test/core/slice/slice_string_helpers_test.cc
  8. 192
      tools/run_tests/generated/tests.json

262
CMakeLists.txt generated

@ -776,7 +776,6 @@ protobuf_generate_grpc_cpp_with_import_path_correction(
if(gRPC_BUILD_TESTS)
add_custom_target(buildtests_c)
add_dependencies(buildtests_c b64_test)
add_dependencies(buildtests_c bad_server_response_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c bad_ssl_alpn_test)
@ -785,7 +784,6 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_c bad_ssl_cert_test)
endif()
add_dependencies(buildtests_c buffer_list_test)
add_dependencies(buildtests_c c_slice_buffer_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c combiner_test)
endif()
@ -814,7 +812,6 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_c minimal_stack_is_minimal_test)
add_dependencies(buildtests_c multiple_server_queues_test)
add_dependencies(buildtests_c no_server_test)
add_dependencies(buildtests_c percent_encoding_test)
add_dependencies(buildtests_c public_headers_must_be_c89)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c resolve_address_using_ares_resolver_posix_test)
@ -822,7 +819,6 @@ if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c resolve_address_using_native_resolver_posix_test)
endif()
add_dependencies(buildtests_c slice_string_helpers_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c socket_utils_test)
endif()
@ -877,6 +873,7 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx authorization_policy_provider_test)
add_dependencies(buildtests_cxx avl_test)
add_dependencies(buildtests_cxx aws_request_signer_test)
add_dependencies(buildtests_cxx b64_test)
add_dependencies(buildtests_cxx backoff_test)
add_dependencies(buildtests_cxx bad_streaming_id_bad_client_test)
add_dependencies(buildtests_cxx badreq_bad_client_test)
@ -890,6 +887,7 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx binder_transport_test)
add_dependencies(buildtests_cxx bitset_test)
add_dependencies(buildtests_cxx byte_buffer_test)
add_dependencies(buildtests_cxx c_slice_buffer_test)
add_dependencies(buildtests_cxx call_finalization_test)
add_dependencies(buildtests_cxx call_push_pull_test)
add_dependencies(buildtests_cxx cancel_ares_query_test)
@ -1077,6 +1075,7 @@ if(gRPC_BUILD_TESTS)
endif()
add_dependencies(buildtests_cxx parsed_metadata_test)
add_dependencies(buildtests_cxx parser_test)
add_dependencies(buildtests_cxx percent_encoding_test)
add_dependencies(buildtests_cxx periodic_update_test)
add_dependencies(buildtests_cxx pid_controller_test)
add_dependencies(buildtests_cxx pipe_test)
@ -1137,6 +1136,7 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx simple_request_bad_client_test)
add_dependencies(buildtests_cxx single_set_ptr_test)
add_dependencies(buildtests_cxx sleep_test)
add_dependencies(buildtests_cxx slice_string_helpers_test)
add_dependencies(buildtests_cxx smoke_test)
add_dependencies(buildtests_cxx sockaddr_resolver_test)
add_dependencies(buildtests_cxx sockaddr_utils_test)
@ -4283,33 +4283,6 @@ target_link_libraries(gen_hpack_tables
if(gRPC_BUILD_TESTS)
add_executable(b64_test
test/core/slice/b64_test.cc
)
target_include_directories(b64_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(b64_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(bad_server_response_test
test/core/end2end/bad_server_response_test.cc
test/core/end2end/cq_verifier.cc
@ -4422,33 +4395,6 @@ target_link_libraries(buffer_list_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(c_slice_buffer_test
test/core/slice/c_slice_buffer_test.cc
)
target_include_directories(c_slice_buffer_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(c_slice_buffer_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
@ -4908,33 +4854,6 @@ target_link_libraries(no_server_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(percent_encoding_test
test/core/slice/percent_encoding_test.cc
)
target_include_directories(percent_encoding_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(percent_encoding_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
@ -5022,36 +4941,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
endif()
endif()
if(gRPC_BUILD_TESTS)
add_executable(slice_string_helpers_test
src/core/lib/slice/slice.cc
src/core/lib/slice/slice_refcount.cc
src/core/lib/slice/slice_string_helpers.cc
test/core/slice/slice_string_helpers_test.cc
)
target_include_directories(slice_string_helpers_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
)
target_link_libraries(slice_string_helpers_test
${_gRPC_ALLTARGETS_LIBRARIES}
gpr
)
endif()
if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
@ -6438,6 +6327,41 @@ target_link_libraries(aws_request_signer_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(b64_test
test/core/slice/b64_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(b64_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(b64_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
@ -6904,6 +6828,41 @@ target_link_libraries(byte_buffer_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(c_slice_buffer_test
test/core/slice/c_slice_buffer_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(c_slice_buffer_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(c_slice_buffer_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
@ -13624,6 +13583,41 @@ target_link_libraries(parser_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(percent_encoding_test
test/core/slice/percent_encoding_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(percent_encoding_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(percent_encoding_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
)
endif()
if(gRPC_BUILD_TESTS)
@ -15856,6 +15850,44 @@ target_link_libraries(sleep_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(slice_string_helpers_test
src/core/lib/slice/slice.cc
src/core/lib/slice/slice_refcount.cc
src/core/lib/slice/slice_string_helpers.cc
test/core/slice/slice_string_helpers_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(slice_string_helpers_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(slice_string_helpers_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
gpr
)
endif()
if(gRPC_BUILD_TESTS)

@ -3192,15 +3192,6 @@ libs:
deps:
- grpc++
targets:
- name: b64_test
build: test
language: c
headers: []
src:
- test/core/slice/b64_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: bad_server_response_test
build: test
language: c
@ -3247,15 +3238,6 @@ targets:
- test/core/iomgr/buffer_list_test.cc
deps:
- grpc_test_util
- name: c_slice_buffer_test
build: test
language: c
headers: []
src:
- test/core/slice/c_slice_buffer_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: combiner_test
build: test
language: c
@ -3435,15 +3417,6 @@ targets:
- test/core/end2end/no_server_test.cc
deps:
- grpc_test_util
- name: percent_encoding_test
build: test
language: c
headers: []
src:
- test/core/slice/percent_encoding_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: public_headers_must_be_c89
build: test
language: c
@ -3484,23 +3457,6 @@ targets:
- linux
- posix
- mac
- name: slice_string_helpers_test
build: test
language: c
headers:
- src/core/lib/slice/slice.h
- src/core/lib/slice/slice_internal.h
- src/core/lib/slice/slice_refcount.h
- src/core/lib/slice/slice_refcount_base.h
- src/core/lib/slice/slice_string_helpers.h
src:
- src/core/lib/slice/slice.cc
- src/core/lib/slice/slice_refcount.cc
- src/core/lib/slice/slice_string_helpers.cc
- test/core/slice/slice_string_helpers_test.cc
deps:
- gpr
uses_polling: false
- name: socket_utils_test
build: test
language: c
@ -4100,6 +4056,16 @@ targets:
- test/core/security/aws_request_signer_test.cc
deps:
- grpc_test_util
- name: b64_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/slice/b64_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: backoff_test
gtest: true
build: test
@ -4313,6 +4279,16 @@ targets:
deps:
- grpc++_test_util
uses_polling: false
- name: c_slice_buffer_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/slice/c_slice_buffer_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: call_finalization_test
gtest: true
build: test
@ -7075,6 +7051,16 @@ targets:
deps:
- grpc_test_util
uses_polling: false
- name: percent_encoding_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/slice/percent_encoding_test.cc
deps:
- grpc_test_util
uses_polling: false
- name: periodic_update_test
gtest: true
build: test
@ -8027,6 +8013,24 @@ targets:
deps:
- grpc
uses_polling: false
- name: slice_string_helpers_test
gtest: true
build: test
language: c++
headers:
- src/core/lib/slice/slice.h
- src/core/lib/slice/slice_internal.h
- src/core/lib/slice/slice_refcount.h
- src/core/lib/slice/slice_refcount_base.h
- src/core/lib/slice/slice_string_helpers.h
src:
- src/core/lib/slice/slice.cc
- src/core/lib/slice/slice_refcount.cc
- src/core/lib/slice/slice_string_helpers.cc
- test/core/slice/slice_string_helpers_test.cc
deps:
- gpr
uses_polling: false
- name: smoke_test
gtest: true
build: test

@ -72,6 +72,7 @@ grpc_fuzzer(
grpc_cc_test(
name = "percent_encoding_test",
srcs = ["percent_encoding_test.cc"],
external_deps = ["gtest"],
language = "C++",
uses_event_engine = False,
uses_polling = False,
@ -103,6 +104,7 @@ grpc_cc_test(
grpc_cc_test(
name = "slice_string_helpers_test",
srcs = ["slice_string_helpers_test.cc"],
external_deps = ["gtest"],
language = "C++",
uses_event_engine = False,
uses_polling = False,
@ -128,6 +130,7 @@ grpc_cc_test(
grpc_cc_test(
name = "c_slice_buffer_test",
srcs = ["c_slice_buffer_test.cc"],
external_deps = ["gtest"],
language = "C++",
uses_event_engine = False,
uses_polling = False,
@ -141,6 +144,7 @@ grpc_cc_test(
grpc_cc_test(
name = "b64_test",
srcs = ["b64_test.cc"],
external_deps = ["gtest"],
language = "C++",
uses_event_engine = False,
uses_polling = False,

@ -20,6 +20,8 @@
#include <string.h>
#include <gtest/gtest.h>
#include <grpc/grpc.h>
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
@ -48,10 +50,8 @@ static void test_simple_encode_decode_b64(int url_safe, int multiline) {
grpc_base64_encode(hello, strlen(hello), url_safe, multiline);
grpc_core::ExecCtx exec_ctx;
grpc_slice hello_slice = grpc_base64_decode(hello_b64, url_safe);
GPR_ASSERT(GRPC_SLICE_LENGTH(hello_slice) == strlen(hello));
GPR_ASSERT(strncmp((const char*)GRPC_SLICE_START_PTR(hello_slice), hello,
GRPC_SLICE_LENGTH(hello_slice)) == 0);
ASSERT_EQ(grpc_core::StringViewFromSlice(hello_slice),
absl::string_view(hello));
grpc_slice_unref_internal(hello_slice);
gpr_free(hello_b64);
@ -69,47 +69,47 @@ static void test_full_range_encode_decode_b64(int url_safe, int multiline) {
grpc_core::ExecCtx exec_ctx;
b64 = grpc_base64_encode(orig, sizeof(orig) - i, url_safe, multiline);
orig_decoded = grpc_base64_decode(b64, url_safe);
GPR_ASSERT(GRPC_SLICE_LENGTH(orig_decoded) == (sizeof(orig) - i));
GPR_ASSERT(buffers_are_equal(orig, GRPC_SLICE_START_PTR(orig_decoded),
sizeof(orig) - i));
ASSERT_EQ(
grpc_core::StringViewFromSlice(orig_decoded),
absl::string_view(reinterpret_cast<char*>(orig), sizeof(orig) - i));
grpc_slice_unref_internal(orig_decoded);
gpr_free(b64);
}
}
static void test_simple_encode_decode_b64_no_multiline(void) {
TEST(B64Test, SimpleEncodeDecodeB64NoMultiline) {
test_simple_encode_decode_b64(0, 0);
}
static void test_simple_encode_decode_b64_multiline(void) {
TEST(B64Test, SimpleEncodeDecodeB64Multiline) {
test_simple_encode_decode_b64(0, 1);
}
static void test_simple_encode_decode_b64_urlsafe_no_multiline(void) {
TEST(B64Test, SimpleEncodeDecodeB64UrlsafeNoMultiline) {
test_simple_encode_decode_b64(1, 0);
}
static void test_simple_encode_decode_b64_urlsafe_multiline(void) {
TEST(B64Test, SimpleEncodeDecodeB64UrlsafeMultiline) {
test_simple_encode_decode_b64(1, 1);
}
static void test_full_range_encode_decode_b64_no_multiline(void) {
TEST(B64Test, FullRangeEncodeDecodeB64NoMultiline) {
test_full_range_encode_decode_b64(0, 0);
}
static void test_full_range_encode_decode_b64_multiline(void) {
TEST(B64Test, FullRangeEncodeDecodeB64Multiline) {
test_full_range_encode_decode_b64(0, 1);
}
static void test_full_range_encode_decode_b64_urlsafe_no_multiline(void) {
TEST(B64Test, FullRangeEncodeDecodeB64UrlsafeNoMultiline) {
test_full_range_encode_decode_b64(1, 0);
}
static void test_full_range_encode_decode_b64_urlsafe_multiline(void) {
TEST(B64Test, FullRangeEncodeDecodeB64UrlsafeMultiline) {
test_full_range_encode_decode_b64(1, 1);
}
static void test_url_safe_unsafe_mismatch_failure(void) {
TEST(B64Test, UrlSafeUnsafeMismatchFailure) {
unsigned char orig[256];
size_t i;
char* b64;
@ -120,101 +120,85 @@ static void test_url_safe_unsafe_mismatch_failure(void) {
grpc_core::ExecCtx exec_ctx;
b64 = grpc_base64_encode(orig, sizeof(orig), url_safe, 0);
orig_decoded = grpc_base64_decode(b64, !url_safe);
GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded));
ASSERT_TRUE(GRPC_SLICE_IS_EMPTY(orig_decoded));
gpr_free(b64);
grpc_slice_unref_internal(orig_decoded);
b64 = grpc_base64_encode(orig, sizeof(orig), !url_safe, 0);
orig_decoded = grpc_base64_decode(b64, url_safe);
GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded));
ASSERT_TRUE(GRPC_SLICE_IS_EMPTY(orig_decoded));
gpr_free(b64);
grpc_slice_unref_internal(orig_decoded);
}
static void test_rfc4648_test_vectors(void) {
TEST(B64Test, Rfc4648TestVectors) {
char* b64;
b64 = grpc_base64_encode("", 0, 0, 0);
GPR_ASSERT(strcmp("", b64) == 0);
ASSERT_STREQ("", b64);
gpr_free(b64);
b64 = grpc_base64_encode("f", 1, 0, 0);
GPR_ASSERT(strcmp("Zg==", b64) == 0);
ASSERT_STREQ("Zg==", b64);
gpr_free(b64);
b64 = grpc_base64_encode("fo", 2, 0, 0);
GPR_ASSERT(strcmp("Zm8=", b64) == 0);
ASSERT_STREQ("Zm8=", b64);
gpr_free(b64);
b64 = grpc_base64_encode("foo", 3, 0, 0);
GPR_ASSERT(strcmp("Zm9v", b64) == 0);
ASSERT_STREQ("Zm9v", b64);
gpr_free(b64);
b64 = grpc_base64_encode("foob", 4, 0, 0);
GPR_ASSERT(strcmp("Zm9vYg==", b64) == 0);
ASSERT_STREQ("Zm9vYg==", b64);
gpr_free(b64);
b64 = grpc_base64_encode("fooba", 5, 0, 0);
GPR_ASSERT(strcmp("Zm9vYmE=", b64) == 0);
ASSERT_STREQ("Zm9vYmE=", b64);
gpr_free(b64);
b64 = grpc_base64_encode("foobar", 6, 0, 0);
GPR_ASSERT(strcmp("Zm9vYmFy", b64) == 0);
ASSERT_STREQ("Zm9vYmFy", b64);
gpr_free(b64);
}
static void test_unpadded_decode(void) {
TEST(B64Test, UnpaddedDecode) {
grpc_slice decoded;
grpc_core::ExecCtx exec_ctx;
decoded = grpc_base64_decode("Zm9vYmFy", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "foobar") == 0);
ASSERT_EQ(grpc_core::StringViewFromSlice(decoded), "foobar");
grpc_slice_unref(decoded);
decoded = grpc_base64_decode("Zm9vYmE", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "fooba") == 0);
ASSERT_EQ(grpc_core::StringViewFromSlice(decoded), "fooba");
grpc_slice_unref(decoded);
decoded = grpc_base64_decode("Zm9vYg", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "foob") == 0);
ASSERT_EQ(grpc_core::StringViewFromSlice(decoded), "foob");
grpc_slice_unref(decoded);
decoded = grpc_base64_decode("Zm9v", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "foo") == 0);
ASSERT_EQ(grpc_core::StringViewFromSlice(decoded), "foo");
grpc_slice_unref(decoded);
decoded = grpc_base64_decode("Zm8", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "fo") == 0);
ASSERT_EQ(grpc_core::StringViewFromSlice(decoded), "fo");
grpc_slice_unref(decoded);
decoded = grpc_base64_decode("Zg", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "f") == 0);
ASSERT_EQ(grpc_core::StringViewFromSlice(decoded), "f");
grpc_slice_unref(decoded);
decoded = grpc_base64_decode("", 0);
GPR_ASSERT(GRPC_SLICE_IS_EMPTY(decoded));
ASSERT_TRUE(GRPC_SLICE_IS_EMPTY(decoded));
}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
grpc_init();
test_simple_encode_decode_b64_no_multiline();
test_simple_encode_decode_b64_multiline();
test_simple_encode_decode_b64_urlsafe_no_multiline();
test_simple_encode_decode_b64_urlsafe_multiline();
test_full_range_encode_decode_b64_no_multiline();
test_full_range_encode_decode_b64_multiline();
test_full_range_encode_decode_b64_urlsafe_no_multiline();
test_full_range_encode_decode_b64_urlsafe_multiline();
test_url_safe_unsafe_mismatch_failure();
test_rfc4648_test_vectors();
test_unpadded_decode();
grpc_shutdown();
return 0;
::testing::InitGoogleTest(&argc, argv);
grpc::testing::TestGrpcScope grpc_scope;
return RUN_ALL_TESTS();
}

@ -16,6 +16,8 @@
*
*/
#include <gtest/gtest.h>
#include <grpc/grpc.h>
#include <grpc/slice_buffer.h>
#include <grpc/support/log.h>
@ -38,31 +40,31 @@ void test_slice_buffer_add() {
grpc_slice_buffer_add(&buf, aaa);
grpc_slice_buffer_add(&buf, bb);
}
GPR_ASSERT(buf.count > 0);
GPR_ASSERT(buf.length == 50);
ASSERT_GT(buf.count, 0);
ASSERT_EQ(buf.length, 50);
grpc_slice_buffer_reset_and_unref(&buf);
GPR_ASSERT(buf.count == 0);
GPR_ASSERT(buf.length == 0);
ASSERT_EQ(buf.count, 0);
ASSERT_EQ(buf.length, 0);
for (i = 0; i < 10; i++) {
grpc_slice_ref(aaa);
grpc_slice_ref(bb);
grpc_slice_buffer_add(&buf, aaa);
grpc_slice_buffer_add(&buf, bb);
}
GPR_ASSERT(buf.count > 0);
GPR_ASSERT(buf.length == 50);
ASSERT_GT(buf.count, 0);
ASSERT_EQ(buf.length, 50);
for (i = 0; i < 10; i++) {
grpc_slice_buffer_pop(&buf);
grpc_slice_unref(aaa);
grpc_slice_unref(bb);
}
GPR_ASSERT(buf.count == 0);
GPR_ASSERT(buf.length == 0);
ASSERT_EQ(buf.count, 0);
ASSERT_EQ(buf.length, 0);
grpc_slice_buffer_destroy(&buf);
}
static void free_data(void* data, size_t len) {
GPR_ASSERT(len == kTotalDataLength);
ASSERT_EQ(len, kTotalDataLength);
gpr_free(data);
}
@ -70,23 +72,23 @@ void test_slice_buffer_add_contiguous_slices() {
grpc_slice_buffer buf;
grpc_slice_buffer_init(&buf);
char* data = reinterpret_cast<char*>(gpr_malloc(kTotalDataLength));
GPR_ASSERT(data != nullptr);
ASSERT_NE(data, nullptr);
grpc_slice a = grpc_slice_new_with_len(data, kTotalDataLength, free_data);
grpc_slice s1 = grpc_slice_split_head(&a, kTotalDataLength / 4);
grpc_slice s2 = grpc_slice_split_head(&a, kTotalDataLength / 4);
grpc_slice s3 = grpc_slice_split_head(&a, kTotalDataLength / 4);
grpc_slice_buffer_add(&buf, s1);
GPR_ASSERT(buf.count == 1);
GPR_ASSERT(buf.length == kTotalDataLength / 4);
ASSERT_EQ(buf.count, 1);
ASSERT_EQ(buf.length, kTotalDataLength / 4);
grpc_slice_buffer_add(&buf, s2);
GPR_ASSERT(buf.count == 1);
GPR_ASSERT(buf.length == kTotalDataLength / 2);
ASSERT_EQ(buf.count, 1);
ASSERT_EQ(buf.length, kTotalDataLength / 2);
grpc_slice_buffer_add(&buf, s3);
GPR_ASSERT(buf.count == 1);
GPR_ASSERT(buf.length == 3 * kTotalDataLength / 4);
ASSERT_EQ(buf.count, 1);
ASSERT_EQ(buf.length, 3 * kTotalDataLength / 4);
grpc_slice_buffer_add(&buf, a);
GPR_ASSERT(buf.count == 1);
GPR_ASSERT(buf.length == kTotalDataLength);
ASSERT_EQ(buf.count, 1);
ASSERT_EQ(buf.length, kTotalDataLength);
grpc_slice_buffer_destroy(&buf);
}
@ -118,24 +120,24 @@ void test_slice_buffer_move_first() {
grpc_slice_buffer_move_first(&src, 4, &dst);
src_len -= 4;
dst_len += 4;
GPR_ASSERT(src.length == src_len);
GPR_ASSERT(dst.length == dst_len);
ASSERT_EQ(src.length, src_len);
ASSERT_EQ(dst.length, dst_len);
/* src now has two slices ["bbb"] and ["ccc"] */
/* Case 2: Move the first slice from src to dst */
grpc_slice_buffer_move_first(&src, 3, &dst);
src_len -= 3;
dst_len += 3;
GPR_ASSERT(src.length == src_len);
GPR_ASSERT(dst.length == dst_len);
ASSERT_EQ(src.length, src_len);
ASSERT_EQ(dst.length, dst_len);
/* src now has one slice ["ccc"] */
/* Case 3: Move less than the first slice's length from src to dst*/
grpc_slice_buffer_move_first(&src, 2, &dst);
src_len -= 2;
dst_len += 2;
GPR_ASSERT(src.length == src_len);
GPR_ASSERT(dst.length == dst_len);
ASSERT_EQ(src.length, src_len);
ASSERT_EQ(dst.length, dst_len);
}
void test_slice_buffer_first() {
@ -152,42 +154,36 @@ void test_slice_buffer_first() {
}
grpc_slice* first = grpc_slice_buffer_peek_first(&buf);
GPR_ASSERT(GPR_SLICE_LENGTH(*first) == GPR_SLICE_LENGTH(slices[0]));
GPR_ASSERT(buf.count == 3);
GPR_ASSERT(buf.length == 12);
ASSERT_EQ(GPR_SLICE_LENGTH(*first), GPR_SLICE_LENGTH(slices[0]));
ASSERT_EQ(buf.count, 3);
ASSERT_EQ(buf.length, 12);
grpc_slice_buffer_sub_first(&buf, 1, 2);
first = grpc_slice_buffer_peek_first(&buf);
GPR_ASSERT(GPR_SLICE_LENGTH(*first) == 1);
GPR_ASSERT(buf.count == 3);
GPR_ASSERT(buf.length == 10);
ASSERT_EQ(GPR_SLICE_LENGTH(*first), 1);
ASSERT_EQ(buf.count, 3);
ASSERT_EQ(buf.length, 10);
grpc_slice_buffer_remove_first(&buf);
first = grpc_slice_buffer_peek_first(&buf);
GPR_ASSERT(GPR_SLICE_LENGTH(*first) == GPR_SLICE_LENGTH(slices[1]));
GPR_ASSERT(buf.count == 2);
GPR_ASSERT(buf.length == 9);
ASSERT_EQ(GPR_SLICE_LENGTH(*first), GPR_SLICE_LENGTH(slices[1]));
ASSERT_EQ(buf.count, 2);
ASSERT_EQ(buf.length, 9);
grpc_slice_buffer_remove_first(&buf);
first = grpc_slice_buffer_peek_first(&buf);
GPR_ASSERT(GPR_SLICE_LENGTH(*first) == GPR_SLICE_LENGTH(slices[2]));
GPR_ASSERT(buf.count == 1);
GPR_ASSERT(buf.length == 5);
ASSERT_EQ(GPR_SLICE_LENGTH(*first), GPR_SLICE_LENGTH(slices[2]));
ASSERT_EQ(buf.count, 1);
ASSERT_EQ(buf.length, 5);
grpc_slice_buffer_remove_first(&buf);
GPR_ASSERT(buf.count == 0);
GPR_ASSERT(buf.length == 0);
ASSERT_EQ(buf.count, 0);
ASSERT_EQ(buf.length, 0);
}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
grpc_init();
test_slice_buffer_add();
test_slice_buffer_add_contiguous_slices();
test_slice_buffer_move_first();
test_slice_buffer_first();
grpc_shutdown();
return 0;
::testing::InitGoogleTest(&argc, argv);
grpc::testing::TestGrpcScope grpc_scope;
return RUN_ALL_TESTS();
}

@ -18,6 +18,8 @@
#include "src/core/lib/slice/percent_encoding.h"
#include <gtest/gtest.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -62,8 +64,8 @@ static void test_vector(const char* raw, size_t raw_length, const char* encoded,
gpr_free(raw2encoded_msg);
gpr_free(encoded2raw_permissive_msg);
GPR_ASSERT(raw_slice == encoded2raw_permissive_slice);
GPR_ASSERT(encoded_slice == raw2encoded_slice);
ASSERT_EQ(raw_slice, encoded2raw_permissive_slice);
ASSERT_EQ(encoded_slice, raw2encoded_slice);
}
static void test_nonconformant_vector(const char* encoded,
@ -93,12 +95,10 @@ static void test_nonconformant_vector(const char* encoded,
encoded2raw_permissive_msg);
gpr_free(encoded2raw_permissive_msg);
GPR_ASSERT(permissive_unencoded_slice == encoded2raw_permissive_slice);
ASSERT_EQ(permissive_unencoded_slice, encoded2raw_permissive_slice);
}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
grpc_init();
TEST(PercentEncodingTest, MainTest) {
TEST_VECTOR(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~",
@ -117,6 +117,11 @@ int main(int argc, char** argv) {
TEST_NONCONFORMANT_VECTOR("%A", "%A");
TEST_NONCONFORMANT_VECTOR("%AG", "%AG");
TEST_NONCONFORMANT_VECTOR("\0", "\0");
grpc_shutdown();
return 0;
}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
grpc::testing::TestGrpcScope grpc_scope;
return RUN_ALL_TESTS();
}

@ -23,6 +23,8 @@
#include <stdlib.h>
#include <string.h>
#include <gtest/gtest.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
@ -35,12 +37,12 @@
static void expect_slice_dump(grpc_slice slice, uint32_t flags,
const char* result) {
char* got = grpc_dump_slice(slice, flags);
GPR_ASSERT(0 == strcmp(got, result));
ASSERT_STREQ(got, result);
gpr_free(got);
grpc_slice_unref_internal(slice);
}
static void test_dump_slice(void) {
TEST(SliceStringHelpersTest, DumpSlice) {
static const char* text = "HELLO WORLD!";
static const char* long_text =
"It was a bright cold day in April, and the clocks were striking "
@ -60,7 +62,7 @@ static void test_dump_slice(void) {
GPR_DUMP_HEX | GPR_DUMP_ASCII, "01 '.'");
}
int main(int, char**) {
test_dump_slice();
return 0;
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -1,30 +1,6 @@
[
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "b64_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -117,30 +93,6 @@
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "c_slice_buffer_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -513,30 +465,6 @@
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "percent_encoding_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -609,30 +537,6 @@
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "slice_string_helpers_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -1477,6 +1381,30 @@
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "b64_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -1739,6 +1667,30 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "c_slice_buffer_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -5113,6 +5065,30 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "percent_encoding_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
@ -6207,6 +6183,30 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "slice_string_helpers_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,

Loading…
Cancel
Save