ruby_memprofiler_pprof 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/ruby_memprofiler_pprof/backtrace.c +429 -0
- data/ext/ruby_memprofiler_pprof/collector.c +1055 -0
- data/ext/ruby_memprofiler_pprof/compat.c +182 -0
- data/ext/ruby_memprofiler_pprof/extconf.rb +72 -0
- data/ext/ruby_memprofiler_pprof/pprof.upb.c +170 -0
- data/ext/ruby_memprofiler_pprof/pprof.upb.h +848 -0
- data/ext/ruby_memprofiler_pprof/pprof_out.c +285 -0
- data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.c +11 -0
- data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.h +301 -0
- data/ext/ruby_memprofiler_pprof/strtab.c +391 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/BUILD +719 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/CONTRIBUTING.md +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/DESIGN.md +201 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/LICENSE +26 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/README.md +78 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/WORKSPACE +58 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/BUILD +53 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/amalgamate.py +129 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/build_defs.bzl +160 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/lua.BUILD +127 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/protobuf.patch +54 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/py_proto_library.bzl +137 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/python_downloads.bzl +84 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/system_python.bzl +101 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/upb_proto_library.bzl +388 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/workspace_deps.bzl +89 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD +252 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD.googleapis +54 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/benchmark.cc +333 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/build_defs.bzl +88 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/compare.py +118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor.proto +888 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor_sv.proto +890 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/empty.proto +6 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_protobuf_binary_cc.py +64 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_synthetic_protos.py +118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_upb_binary_c.py +65 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/BUILD.bazel +102 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/README.md +23 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/build_defs.bzl +73 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/make_cmakelists.py +340 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test.py +57 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test_lib.py +186 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/render.py +43 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/style-guide.md +65 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/vs-cpp-protos.md +255 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/wrapping-upb.md +444 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/BUILD +216 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.c +394 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.h +63 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.c +1694 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.h +80 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.c +704 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.h +114 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.c +650 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.h +48 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/BUILD.bazel +193 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/dist.bzl +190 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.c +247 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.h +39 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.c +522 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.h +66 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.c +1909 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.h +101 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/minimal_test.py +183 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/BUILD +70 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/README.md +11 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_database_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_pool_test_wrapper.py +45 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_test_wrapper.py +46 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/generator_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/json_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/keywords_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_factory_test_wrapper.py +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_test_wrapper.py +52 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/proto_builder_test_wrapper.py +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/pyproto_test_wrapper.bzl +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/reflection_test_wrapper.py +45 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/service_reflection_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/symbol_database_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_encoding_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/unknown_fields_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/well_known_types_test_wrapper.py +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/wire_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.c +350 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.h +230 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/py_extension.bzl +55 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/python_api.h +61 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.c +828 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.h +69 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.c +404 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.h +39 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/version_script.lds +6 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/LICENSE +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/README.google +9 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/console.lua +156 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/lunit.lua +725 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/BUILD +19 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/LICENSE +21 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/naive.c +92 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-neon.c +157 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-sse.c +170 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/utf8_range.h +9 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/BUILD.bazel +129 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/README.md +8 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/def.c +939 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/lua_proto_library.bzl +138 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/main.c +83 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/msg.c +1118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test.proto +69 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test_upb.lua +846 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.c +258 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.h +132 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.lua +58 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upbc.cc +134 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.c +192 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.h +174 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb.c +346 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb_failures.txt +1 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.c +1221 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.h +94 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.c +1055 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.h +153 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_internal.h +211 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.c +3262 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.h +414 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.hpp +438 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/empty.proto +1 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.c +604 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.h +71 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/BUILD +13 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/file_descriptor_parsenew_fuzzer.cc +43 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.c +1509 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.h +47 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.c +776 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.h +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.c +1147 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.h +189 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.hpp +112 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.c +363 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.h +263 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_internal.h +59 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_test.cc +425 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_test.cc +230 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.c +428 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.h +114 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_internal.h +836 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.cc +491 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.proto +195 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_def.inc +261 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_undef.inc +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.c +323 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.h +109 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.hpp +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table.c +926 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table_internal.h +385 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test.proto +74 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.cc +186 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.proto +12 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_generated_code.cc +977 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_table.cc +580 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.c +472 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.h +64 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.c +362 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.h +378 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.hpp +115 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb_internal.h +68 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/BUILD +121 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/README.md +7 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.c +300 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.h +66 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare_test.cc +236 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.c +572 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.h +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_public_import_test.proto +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_regular_import_test.proto +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.cc +143 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.proto +119 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_weak_import_test.proto +28 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_wweak_import_test.proto +28 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.c +311 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.h +94 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.cc +202 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.proto +48 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/BUILD +78 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.cc +77 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.h +112 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upb.cc +1997 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upbdefs.cc +193 -0
- data/lib/ruby_memprofiler_pprof/atfork.rb +77 -0
- data/lib/ruby_memprofiler_pprof/block_flusher.rb +61 -0
- data/lib/ruby_memprofiler_pprof/file_flusher.rb +45 -0
- data/lib/ruby_memprofiler_pprof/profile_app.rb +30 -0
- data/lib/ruby_memprofiler_pprof/profile_data.rb +18 -0
- data/lib/ruby_memprofiler_pprof/version.rb +5 -0
- data/lib/ruby_memprofiler_pprof.rb +8 -0
- data/libexec/ruby_memprofiler_pprof_profile +16 -0
- metadata +257 -0
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2009-2021, Google LLC
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
|
7
|
+
* * Redistributions of source code must retain the above copyright
|
|
8
|
+
* notice, this list of conditions and the following disclaimer.
|
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
* documentation and/or other materials provided with the distribution.
|
|
12
|
+
* * Neither the name of Google LLC nor the
|
|
13
|
+
* names of its contributors may be used to endorse or promote products
|
|
14
|
+
* derived from this software without specific prior written permission.
|
|
15
|
+
*
|
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
19
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
|
|
20
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
21
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
22
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
23
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
24
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#include "gmock/gmock.h"
|
|
29
|
+
#include "gtest/gtest.h"
|
|
30
|
+
#include "google/protobuf/test_messages_proto3.upb.h"
|
|
31
|
+
#include "upb/def.hpp"
|
|
32
|
+
#include "upb/json_decode.h"
|
|
33
|
+
#include "upb/json_encode.h"
|
|
34
|
+
#include "upb/msg_test.upb.h"
|
|
35
|
+
#include "upb/msg_test.upbdefs.h"
|
|
36
|
+
#include "upb/upb.hpp"
|
|
37
|
+
|
|
38
|
+
void VerifyMessage(const upb_test_TestExtensions* ext_msg) {
|
|
39
|
+
EXPECT_TRUE(upb_test_TestExtensions_has_optional_int32_ext(ext_msg));
|
|
40
|
+
// EXPECT_FALSE(upb_test_TestExtensions_Nested_has_optional_int32_ext(ext_msg));
|
|
41
|
+
EXPECT_TRUE(upb_test_has_optional_msg_ext(ext_msg));
|
|
42
|
+
|
|
43
|
+
EXPECT_EQ(123, upb_test_TestExtensions_optional_int32_ext(ext_msg));
|
|
44
|
+
const protobuf_test_messages_proto3_TestAllTypesProto3* ext_submsg =
|
|
45
|
+
upb_test_optional_msg_ext(ext_msg);
|
|
46
|
+
EXPECT_TRUE(ext_submsg != nullptr);
|
|
47
|
+
EXPECT_EQ(456,
|
|
48
|
+
protobuf_test_messages_proto3_TestAllTypesProto3_optional_int32(
|
|
49
|
+
ext_submsg));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
TEST(MessageTest, Extensions) {
|
|
53
|
+
upb::Arena arena;
|
|
54
|
+
upb_test_TestExtensions* ext_msg = upb_test_TestExtensions_new(arena.ptr());
|
|
55
|
+
|
|
56
|
+
EXPECT_FALSE(upb_test_TestExtensions_has_optional_int32_ext(ext_msg));
|
|
57
|
+
// EXPECT_FALSE(upb_test_TestExtensions_Nested_has_optional_int32_ext(ext_msg));
|
|
58
|
+
EXPECT_FALSE(upb_test_has_optional_msg_ext(ext_msg));
|
|
59
|
+
|
|
60
|
+
upb::SymbolTable symtab;
|
|
61
|
+
upb::MessageDefPtr m(upb_test_TestExtensions_getmsgdef(symtab.ptr()));
|
|
62
|
+
EXPECT_TRUE(m.ptr() != nullptr);
|
|
63
|
+
|
|
64
|
+
std::string json = R"json(
|
|
65
|
+
{
|
|
66
|
+
"[upb_test.TestExtensions.optional_int32_ext]": 123,
|
|
67
|
+
"[upb_test.TestExtensions.Nested.repeated_int32_ext]": [2, 4, 6],
|
|
68
|
+
"[upb_test.optional_msg_ext]": {"optional_int32": 456}
|
|
69
|
+
}
|
|
70
|
+
)json";
|
|
71
|
+
upb::Status status;
|
|
72
|
+
EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), ext_msg, m.ptr(),
|
|
73
|
+
symtab.ptr(), 0, arena.ptr(), status.ptr()))
|
|
74
|
+
<< status.error_message();
|
|
75
|
+
|
|
76
|
+
VerifyMessage(ext_msg);
|
|
77
|
+
|
|
78
|
+
// Test round-trip through binary format.
|
|
79
|
+
size_t size;
|
|
80
|
+
char* serialized =
|
|
81
|
+
upb_test_TestExtensions_serialize(ext_msg, arena.ptr(), &size);
|
|
82
|
+
ASSERT_TRUE(serialized != nullptr);
|
|
83
|
+
ASSERT_GE(size, 0);
|
|
84
|
+
|
|
85
|
+
upb_test_TestExtensions* ext_msg2 = upb_test_TestExtensions_parse_ex(
|
|
86
|
+
serialized, size, upb_DefPool_ExtensionRegistry(symtab.ptr()), 0,
|
|
87
|
+
arena.ptr());
|
|
88
|
+
VerifyMessage(ext_msg2);
|
|
89
|
+
|
|
90
|
+
// Test round-trip through JSON format.
|
|
91
|
+
size_t json_size =
|
|
92
|
+
upb_JsonEncode(ext_msg, m.ptr(), symtab.ptr(), 0, NULL, 0, status.ptr());
|
|
93
|
+
char* json_buf =
|
|
94
|
+
static_cast<char*>(upb_Arena_Malloc(arena.ptr(), json_size + 1));
|
|
95
|
+
upb_JsonEncode(ext_msg, m.ptr(), symtab.ptr(), 0, json_buf, json_size + 1,
|
|
96
|
+
status.ptr());
|
|
97
|
+
upb_test_TestExtensions* ext_msg3 = upb_test_TestExtensions_new(arena.ptr());
|
|
98
|
+
EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, ext_msg3, m.ptr(),
|
|
99
|
+
symtab.ptr(), 0, arena.ptr(), status.ptr()))
|
|
100
|
+
<< status.error_message();
|
|
101
|
+
VerifyMessage(ext_msg3);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
void VerifyMessageSet(const upb_test_TestMessageSet* mset_msg) {
|
|
105
|
+
ASSERT_TRUE(mset_msg != nullptr);
|
|
106
|
+
bool has = upb_test_MessageSetMember_has_message_set_extension(mset_msg);
|
|
107
|
+
EXPECT_TRUE(has);
|
|
108
|
+
if (!has) return;
|
|
109
|
+
const upb_test_MessageSetMember* member =
|
|
110
|
+
upb_test_MessageSetMember_message_set_extension(mset_msg);
|
|
111
|
+
EXPECT_TRUE(member != nullptr);
|
|
112
|
+
EXPECT_TRUE(upb_test_MessageSetMember_has_optional_int32(member));
|
|
113
|
+
EXPECT_EQ(234, upb_test_MessageSetMember_optional_int32(member));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
TEST(MessageTest, MessageSet) {
|
|
117
|
+
upb::Arena arena;
|
|
118
|
+
upb_test_TestMessageSet* ext_msg = upb_test_TestMessageSet_new(arena.ptr());
|
|
119
|
+
|
|
120
|
+
EXPECT_FALSE(upb_test_MessageSetMember_has_message_set_extension(ext_msg));
|
|
121
|
+
|
|
122
|
+
upb::SymbolTable symtab;
|
|
123
|
+
upb::MessageDefPtr m(upb_test_TestMessageSet_getmsgdef(symtab.ptr()));
|
|
124
|
+
EXPECT_TRUE(m.ptr() != nullptr);
|
|
125
|
+
|
|
126
|
+
std::string json = R"json(
|
|
127
|
+
{
|
|
128
|
+
"[upb_test.MessageSetMember]": {"optional_int32": 234}
|
|
129
|
+
}
|
|
130
|
+
)json";
|
|
131
|
+
upb::Status status;
|
|
132
|
+
EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), ext_msg, m.ptr(),
|
|
133
|
+
symtab.ptr(), 0, arena.ptr(), status.ptr()))
|
|
134
|
+
<< status.error_message();
|
|
135
|
+
|
|
136
|
+
VerifyMessageSet(ext_msg);
|
|
137
|
+
|
|
138
|
+
// Test round-trip through binary format.
|
|
139
|
+
size_t size;
|
|
140
|
+
char* serialized =
|
|
141
|
+
upb_test_TestMessageSet_serialize(ext_msg, arena.ptr(), &size);
|
|
142
|
+
ASSERT_TRUE(serialized != nullptr);
|
|
143
|
+
ASSERT_GE(size, 0);
|
|
144
|
+
|
|
145
|
+
upb_test_TestMessageSet* ext_msg2 = upb_test_TestMessageSet_parse_ex(
|
|
146
|
+
serialized, size, upb_DefPool_ExtensionRegistry(symtab.ptr()), 0,
|
|
147
|
+
arena.ptr());
|
|
148
|
+
VerifyMessageSet(ext_msg2);
|
|
149
|
+
|
|
150
|
+
// Test round-trip through JSON format.
|
|
151
|
+
size_t json_size =
|
|
152
|
+
upb_JsonEncode(ext_msg, m.ptr(), symtab.ptr(), 0, NULL, 0, status.ptr());
|
|
153
|
+
char* json_buf =
|
|
154
|
+
static_cast<char*>(upb_Arena_Malloc(arena.ptr(), json_size + 1));
|
|
155
|
+
upb_JsonEncode(ext_msg, m.ptr(), symtab.ptr(), 0, json_buf, json_size + 1,
|
|
156
|
+
status.ptr());
|
|
157
|
+
upb_test_TestMessageSet* ext_msg3 = upb_test_TestMessageSet_new(arena.ptr());
|
|
158
|
+
EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, ext_msg3, m.ptr(),
|
|
159
|
+
symtab.ptr(), 0, arena.ptr(), status.ptr()))
|
|
160
|
+
<< status.error_message();
|
|
161
|
+
VerifyMessageSet(ext_msg3);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
TEST(MessageTest, UnknownMessageSet) {
|
|
165
|
+
static const char data[] = "ABCDE";
|
|
166
|
+
upb_StringView data_view = upb_StringView_FromString(data);
|
|
167
|
+
upb::Arena arena;
|
|
168
|
+
upb_test_FakeMessageSet* fake = upb_test_FakeMessageSet_new(arena.ptr());
|
|
169
|
+
|
|
170
|
+
// Add a MessageSet item that is unknown (there is no matching extension in
|
|
171
|
+
// the .proto file)
|
|
172
|
+
upb_test_FakeMessageSet_Item* item =
|
|
173
|
+
upb_test_FakeMessageSet_add_item(fake, arena.ptr());
|
|
174
|
+
upb_test_FakeMessageSet_Item_set_type_id(item, 12345);
|
|
175
|
+
upb_test_FakeMessageSet_Item_set_message(item, data_view);
|
|
176
|
+
|
|
177
|
+
// Set unknown fields inside the message set to test that we can skip them.
|
|
178
|
+
upb_test_FakeMessageSet_Item_set_unknown_varint(item, 12345678);
|
|
179
|
+
upb_test_FakeMessageSet_Item_set_unknown_fixed32(item, 12345678);
|
|
180
|
+
upb_test_FakeMessageSet_Item_set_unknown_fixed64(item, 12345678);
|
|
181
|
+
upb_test_FakeMessageSet_Item_set_unknown_bytes(item, data_view);
|
|
182
|
+
upb_test_FakeMessageSet_Item_mutable_unknowngroup(item, arena.ptr());
|
|
183
|
+
|
|
184
|
+
// Round trip through a true MessageSet where this item_id is unknown.
|
|
185
|
+
size_t size;
|
|
186
|
+
char* serialized =
|
|
187
|
+
upb_test_FakeMessageSet_serialize(fake, arena.ptr(), &size);
|
|
188
|
+
ASSERT_TRUE(serialized != nullptr);
|
|
189
|
+
ASSERT_GE(size, 0);
|
|
190
|
+
|
|
191
|
+
upb::SymbolTable symtab;
|
|
192
|
+
upb::MessageDefPtr m(upb_test_TestMessageSet_getmsgdef(symtab.ptr()));
|
|
193
|
+
EXPECT_TRUE(m.ptr() != nullptr);
|
|
194
|
+
upb_test_TestMessageSet* message_set = upb_test_TestMessageSet_parse_ex(
|
|
195
|
+
serialized, size, upb_DefPool_ExtensionRegistry(symtab.ptr()), 0,
|
|
196
|
+
arena.ptr());
|
|
197
|
+
ASSERT_TRUE(message_set != nullptr);
|
|
198
|
+
|
|
199
|
+
char* serialized2 =
|
|
200
|
+
upb_test_TestMessageSet_serialize(message_set, arena.ptr(), &size);
|
|
201
|
+
ASSERT_TRUE(serialized2 != nullptr);
|
|
202
|
+
ASSERT_GE(size, 0);
|
|
203
|
+
|
|
204
|
+
// Parse back into a fake MessageSet and verify that the unknown MessageSet
|
|
205
|
+
// item was preserved in full (both type_id and message).
|
|
206
|
+
upb_test_FakeMessageSet* fake2 =
|
|
207
|
+
upb_test_FakeMessageSet_parse(serialized2, size, arena.ptr());
|
|
208
|
+
ASSERT_TRUE(fake2 != nullptr);
|
|
209
|
+
|
|
210
|
+
const upb_test_FakeMessageSet_Item* const* items =
|
|
211
|
+
upb_test_FakeMessageSet_item(fake2, &size);
|
|
212
|
+
ASSERT_EQ(1, size);
|
|
213
|
+
EXPECT_EQ(12345, upb_test_FakeMessageSet_Item_type_id(items[0]));
|
|
214
|
+
EXPECT_TRUE(upb_StringView_IsEqual(
|
|
215
|
+
data_view, upb_test_FakeMessageSet_Item_message(items[0])));
|
|
216
|
+
|
|
217
|
+
// The non-MessageSet unknown fields should have been discarded.
|
|
218
|
+
EXPECT_FALSE(upb_test_FakeMessageSet_Item_has_unknown_varint(items[0]));
|
|
219
|
+
EXPECT_FALSE(upb_test_FakeMessageSet_Item_has_unknown_fixed32(items[0]));
|
|
220
|
+
EXPECT_FALSE(upb_test_FakeMessageSet_Item_has_unknown_fixed64(items[0]));
|
|
221
|
+
EXPECT_FALSE(upb_test_FakeMessageSet_Item_has_unknown_bytes(items[0]));
|
|
222
|
+
EXPECT_FALSE(upb_test_FakeMessageSet_Item_has_unknowngroup(items[0]));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
TEST(MessageTest, Proto2Enum) {
|
|
226
|
+
upb::Arena arena;
|
|
227
|
+
upb_test_Proto2FakeEnumMessage* fake_msg =
|
|
228
|
+
upb_test_Proto2FakeEnumMessage_new(arena.ptr());
|
|
229
|
+
|
|
230
|
+
upb_test_Proto2FakeEnumMessage_set_optional_enum(fake_msg, 999);
|
|
231
|
+
|
|
232
|
+
int32_t* vals = upb_test_Proto2FakeEnumMessage_resize_repeated_enum(
|
|
233
|
+
fake_msg, 6, arena.ptr());
|
|
234
|
+
vals[0] = upb_test_Proto2EnumMessage_ZERO;
|
|
235
|
+
vals[1] = 7; // Unknown small.
|
|
236
|
+
vals[2] = upb_test_Proto2EnumMessage_SMALL;
|
|
237
|
+
vals[3] = 888; // Unknown large.
|
|
238
|
+
vals[4] = upb_test_Proto2EnumMessage_LARGE;
|
|
239
|
+
vals[5] = upb_test_Proto2EnumMessage_NEGATIVE;
|
|
240
|
+
|
|
241
|
+
vals = upb_test_Proto2FakeEnumMessage_resize_packed_enum(fake_msg, 6,
|
|
242
|
+
arena.ptr());
|
|
243
|
+
vals[0] = upb_test_Proto2EnumMessage_ZERO;
|
|
244
|
+
vals[1] = 7; // Unknown small.
|
|
245
|
+
vals[2] = upb_test_Proto2EnumMessage_SMALL;
|
|
246
|
+
vals[3] = 888; // Unknown large.
|
|
247
|
+
vals[4] = upb_test_Proto2EnumMessage_LARGE;
|
|
248
|
+
vals[5] = upb_test_Proto2EnumMessage_NEGATIVE;
|
|
249
|
+
|
|
250
|
+
size_t size;
|
|
251
|
+
char* pb =
|
|
252
|
+
upb_test_Proto2FakeEnumMessage_serialize(fake_msg, arena.ptr(), &size);
|
|
253
|
+
|
|
254
|
+
// Parsing as enums puts unknown values into unknown fields.
|
|
255
|
+
upb_test_Proto2EnumMessage* enum_msg =
|
|
256
|
+
upb_test_Proto2EnumMessage_parse(pb, size, arena.ptr());
|
|
257
|
+
ASSERT_TRUE(enum_msg != nullptr);
|
|
258
|
+
|
|
259
|
+
EXPECT_EQ(false, upb_test_Proto2EnumMessage_has_optional_enum(enum_msg));
|
|
260
|
+
const int32_t* vals_const =
|
|
261
|
+
upb_test_Proto2EnumMessage_repeated_enum(enum_msg, &size);
|
|
262
|
+
EXPECT_EQ(4, size); // Two unknown values moved to the unknown field set.
|
|
263
|
+
|
|
264
|
+
// Parsing back into the fake message shows the original data, except the
|
|
265
|
+
// repeated enum is rearranged.
|
|
266
|
+
pb = upb_test_Proto2EnumMessage_serialize(enum_msg, arena.ptr(), &size);
|
|
267
|
+
upb_test_Proto2FakeEnumMessage* fake_msg2 =
|
|
268
|
+
upb_test_Proto2FakeEnumMessage_parse(pb, size, arena.ptr());
|
|
269
|
+
|
|
270
|
+
EXPECT_EQ(true, upb_test_Proto2FakeEnumMessage_has_optional_enum(fake_msg2));
|
|
271
|
+
EXPECT_EQ(999, upb_test_Proto2FakeEnumMessage_optional_enum(fake_msg2));
|
|
272
|
+
|
|
273
|
+
int32_t expected[] = {
|
|
274
|
+
upb_test_Proto2EnumMessage_ZERO,
|
|
275
|
+
upb_test_Proto2EnumMessage_SMALL,
|
|
276
|
+
upb_test_Proto2EnumMessage_LARGE,
|
|
277
|
+
upb_test_Proto2EnumMessage_NEGATIVE,
|
|
278
|
+
7,
|
|
279
|
+
888,
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
vals_const = upb_test_Proto2FakeEnumMessage_repeated_enum(fake_msg2, &size);
|
|
283
|
+
EXPECT_EQ(6, size);
|
|
284
|
+
EXPECT_THAT(std::vector<int32_t>(vals_const, vals_const + size),
|
|
285
|
+
::testing::ElementsAreArray(expected));
|
|
286
|
+
|
|
287
|
+
vals_const = upb_test_Proto2FakeEnumMessage_packed_enum(fake_msg2, &size);
|
|
288
|
+
EXPECT_EQ(6, size);
|
|
289
|
+
EXPECT_THAT(std::vector<int32_t>(vals_const, vals_const + size),
|
|
290
|
+
::testing::ElementsAreArray(expected));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
TEST(MessageTest, TestBadUTF8) {
|
|
294
|
+
upb::Arena arena;
|
|
295
|
+
std::string serialized("r\x03\xed\xa0\x81");
|
|
296
|
+
EXPECT_EQ(nullptr, protobuf_test_messages_proto3_TestAllTypesProto3_parse(
|
|
297
|
+
serialized.data(), serialized.size(), arena.ptr()));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) {
|
|
301
|
+
upb::Arena arena;
|
|
302
|
+
upb_test_TestRequiredFields* test_msg;
|
|
303
|
+
upb_test_EmptyMessage* empty_msg;
|
|
304
|
+
|
|
305
|
+
// Succeeds, because we did not request required field checks.
|
|
306
|
+
test_msg = upb_test_TestRequiredFields_parse(NULL, 0, arena.ptr());
|
|
307
|
+
EXPECT_NE(nullptr, test_msg);
|
|
308
|
+
|
|
309
|
+
// Fails, because required fields are missing.
|
|
310
|
+
EXPECT_EQ(kUpb_DecodeStatus_MissingRequired,
|
|
311
|
+
upb_Decode(NULL, 0, test_msg, &upb_test_TestRequiredFields_msginit,
|
|
312
|
+
NULL, kUpb_DecodeOption_CheckRequired, arena.ptr()));
|
|
313
|
+
|
|
314
|
+
upb_test_TestRequiredFields_set_required_int32(test_msg, 1);
|
|
315
|
+
size_t size;
|
|
316
|
+
char* serialized =
|
|
317
|
+
upb_test_TestRequiredFields_serialize(test_msg, arena.ptr(), &size);
|
|
318
|
+
ASSERT_TRUE(serialized != nullptr);
|
|
319
|
+
EXPECT_NE(0, size);
|
|
320
|
+
|
|
321
|
+
// Fails, but the code path is slightly different because the serialized
|
|
322
|
+
// payload is not empty.
|
|
323
|
+
EXPECT_EQ(kUpb_DecodeStatus_MissingRequired,
|
|
324
|
+
upb_Decode(serialized, size, test_msg,
|
|
325
|
+
&upb_test_TestRequiredFields_msginit, NULL,
|
|
326
|
+
kUpb_DecodeOption_CheckRequired, arena.ptr()));
|
|
327
|
+
|
|
328
|
+
empty_msg = upb_test_EmptyMessage_new(arena.ptr());
|
|
329
|
+
upb_test_TestRequiredFields_set_required_int32(test_msg, 1);
|
|
330
|
+
upb_test_TestRequiredFields_set_required_int64(test_msg, 2);
|
|
331
|
+
upb_test_TestRequiredFields_set_required_message(test_msg, empty_msg);
|
|
332
|
+
|
|
333
|
+
// Succeeds, because required fields are present (though not in the input).
|
|
334
|
+
EXPECT_EQ(kUpb_DecodeStatus_Ok,
|
|
335
|
+
upb_Decode(NULL, 0, test_msg, &upb_test_TestRequiredFields_msginit,
|
|
336
|
+
NULL, kUpb_DecodeOption_CheckRequired, arena.ptr()));
|
|
337
|
+
|
|
338
|
+
// Serialize a complete payload.
|
|
339
|
+
serialized =
|
|
340
|
+
upb_test_TestRequiredFields_serialize(test_msg, arena.ptr(), &size);
|
|
341
|
+
ASSERT_TRUE(serialized != nullptr);
|
|
342
|
+
EXPECT_NE(0, size);
|
|
343
|
+
|
|
344
|
+
upb_test_TestRequiredFields* test_msg2 = upb_test_TestRequiredFields_parse_ex(
|
|
345
|
+
serialized, size, NULL, kUpb_DecodeOption_CheckRequired, arena.ptr());
|
|
346
|
+
EXPECT_NE(nullptr, test_msg2);
|
|
347
|
+
|
|
348
|
+
// When we add an incomplete sub-message, this is not flagged by the parser.
|
|
349
|
+
// This makes parser checking unsuitable for MergeFrom().
|
|
350
|
+
upb_test_TestRequiredFields_set_optional_message(
|
|
351
|
+
test_msg2, upb_test_TestRequiredFields_new(arena.ptr()));
|
|
352
|
+
EXPECT_EQ(kUpb_DecodeStatus_Ok,
|
|
353
|
+
upb_Decode(serialized, size, test_msg2,
|
|
354
|
+
&upb_test_TestRequiredFields_msginit, NULL,
|
|
355
|
+
kUpb_DecodeOption_CheckRequired, arena.ptr()));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
TEST(MessageTest, DecodeRequiredFieldsSubMessage) {
|
|
359
|
+
upb::Arena arena;
|
|
360
|
+
upb_test_TestRequiredFields* test_msg =
|
|
361
|
+
upb_test_TestRequiredFields_new(arena.ptr());
|
|
362
|
+
upb_test_SubMessageHasRequired* sub_msg =
|
|
363
|
+
upb_test_SubMessageHasRequired_new(arena.ptr());
|
|
364
|
+
upb_test_EmptyMessage* empty_msg = upb_test_EmptyMessage_new(arena.ptr());
|
|
365
|
+
|
|
366
|
+
upb_test_SubMessageHasRequired_set_optional_message(sub_msg, test_msg);
|
|
367
|
+
size_t size;
|
|
368
|
+
char* serialized =
|
|
369
|
+
upb_test_SubMessageHasRequired_serialize(sub_msg, arena.ptr(), &size);
|
|
370
|
+
EXPECT_NE(0, size);
|
|
371
|
+
|
|
372
|
+
// No parse error when parsing normally.
|
|
373
|
+
EXPECT_NE(nullptr, upb_test_SubMessageHasRequired_parse(serialized, size,
|
|
374
|
+
arena.ptr()));
|
|
375
|
+
|
|
376
|
+
// Parse error when verifying required fields, due to incomplete sub-message.
|
|
377
|
+
EXPECT_EQ(nullptr, upb_test_SubMessageHasRequired_parse_ex(
|
|
378
|
+
serialized, size, NULL,
|
|
379
|
+
kUpb_DecodeOption_CheckRequired, arena.ptr()));
|
|
380
|
+
|
|
381
|
+
upb_test_TestRequiredFields_set_required_int32(test_msg, 1);
|
|
382
|
+
upb_test_TestRequiredFields_set_required_int64(test_msg, 2);
|
|
383
|
+
upb_test_TestRequiredFields_set_required_message(test_msg, empty_msg);
|
|
384
|
+
|
|
385
|
+
serialized =
|
|
386
|
+
upb_test_SubMessageHasRequired_serialize(sub_msg, arena.ptr(), &size);
|
|
387
|
+
EXPECT_NE(0, size);
|
|
388
|
+
|
|
389
|
+
// No parse error; sub-message now is complete.
|
|
390
|
+
EXPECT_NE(nullptr, upb_test_SubMessageHasRequired_parse_ex(
|
|
391
|
+
serialized, size, NULL,
|
|
392
|
+
kUpb_DecodeOption_CheckRequired, arena.ptr()));
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
TEST(MessageTest, EncodeRequiredFields) {
|
|
396
|
+
upb::Arena arena;
|
|
397
|
+
upb_test_TestRequiredFields* test_msg =
|
|
398
|
+
upb_test_TestRequiredFields_new(arena.ptr());
|
|
399
|
+
|
|
400
|
+
// Succeeds, we didn't ask for required field checking.
|
|
401
|
+
size_t size;
|
|
402
|
+
char* serialized =
|
|
403
|
+
upb_test_TestRequiredFields_serialize_ex(test_msg, 0, arena.ptr(), &size);
|
|
404
|
+
ASSERT_TRUE(serialized != nullptr);
|
|
405
|
+
EXPECT_EQ(size, 0);
|
|
406
|
+
|
|
407
|
+
// Fails, we asked for required field checking but the required field is
|
|
408
|
+
// missing.
|
|
409
|
+
serialized = upb_test_TestRequiredFields_serialize_ex(
|
|
410
|
+
test_msg, kUpb_Encode_CheckRequired, arena.ptr(), &size);
|
|
411
|
+
ASSERT_TRUE(serialized == nullptr);
|
|
412
|
+
|
|
413
|
+
// Fails, some required fields are present but not others.
|
|
414
|
+
upb_test_TestRequiredFields_set_required_int32(test_msg, 1);
|
|
415
|
+
serialized = upb_test_TestRequiredFields_serialize_ex(
|
|
416
|
+
test_msg, kUpb_Encode_CheckRequired, arena.ptr(), &size);
|
|
417
|
+
ASSERT_TRUE(serialized == nullptr);
|
|
418
|
+
|
|
419
|
+
// Succeeds, all required fields are set.
|
|
420
|
+
upb_test_EmptyMessage* empty_msg = upb_test_EmptyMessage_new(arena.ptr());
|
|
421
|
+
upb_test_TestRequiredFields_set_required_int64(test_msg, 2);
|
|
422
|
+
upb_test_TestRequiredFields_set_required_message(test_msg, empty_msg);
|
|
423
|
+
serialized = upb_test_TestRequiredFields_serialize_ex(
|
|
424
|
+
test_msg, kUpb_Encode_CheckRequired, arena.ptr(), &size);
|
|
425
|
+
ASSERT_TRUE(serialized != nullptr);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
TEST(MessageTest, MaxRequiredFields) {
|
|
429
|
+
upb::Arena arena;
|
|
430
|
+
upb_test_TestMaxRequiredFields* test_msg =
|
|
431
|
+
upb_test_TestMaxRequiredFields_new(arena.ptr());
|
|
432
|
+
|
|
433
|
+
// Fails, we asked for required field checking but the required field is
|
|
434
|
+
// missing.
|
|
435
|
+
size_t size;
|
|
436
|
+
char* serialized = upb_test_TestMaxRequiredFields_serialize_ex(
|
|
437
|
+
test_msg, kUpb_Encode_CheckRequired, arena.ptr(), &size);
|
|
438
|
+
ASSERT_TRUE(serialized == nullptr);
|
|
439
|
+
|
|
440
|
+
upb::SymbolTable symtab;
|
|
441
|
+
upb::MessageDefPtr m(upb_test_TestMaxRequiredFields_getmsgdef(symtab.ptr()));
|
|
442
|
+
upb_MessageValue val;
|
|
443
|
+
val.int32_val = 1;
|
|
444
|
+
for (int i = 1; i <= 61; i++) {
|
|
445
|
+
upb::FieldDefPtr f = m.FindFieldByNumber(i);
|
|
446
|
+
ASSERT_TRUE(f);
|
|
447
|
+
upb_Message_Set(test_msg, f.ptr(), val, arena.ptr());
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// Fails, field 63 still isn't set.
|
|
451
|
+
serialized = upb_test_TestMaxRequiredFields_serialize_ex(
|
|
452
|
+
test_msg, kUpb_Encode_CheckRequired, arena.ptr(), &size);
|
|
453
|
+
ASSERT_TRUE(serialized == nullptr);
|
|
454
|
+
|
|
455
|
+
// Succeeds, all required fields are set.
|
|
456
|
+
upb::FieldDefPtr f = m.FindFieldByNumber(62);
|
|
457
|
+
ASSERT_TRUE(f);
|
|
458
|
+
upb_Message_Set(test_msg, f.ptr(), val, arena.ptr());
|
|
459
|
+
serialized = upb_test_TestMaxRequiredFields_serialize_ex(
|
|
460
|
+
test_msg, kUpb_Encode_CheckRequired, arena.ptr(), &size);
|
|
461
|
+
ASSERT_TRUE(serialized != nullptr);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
TEST(MessageTest, MapField) {
|
|
465
|
+
upb::Arena arena;
|
|
466
|
+
upb_test_TestMapFieldExtra* test_msg_extra =
|
|
467
|
+
upb_test_TestMapFieldExtra_new(arena.ptr());
|
|
468
|
+
|
|
469
|
+
ASSERT_TRUE(upb_test_TestMapFieldExtra_map_field_set(
|
|
470
|
+
test_msg_extra, 0, upb_test_TestMapFieldExtra_THREE, arena.ptr()));
|
|
471
|
+
|
|
472
|
+
size_t size;
|
|
473
|
+
char* serialized = upb_test_TestMapFieldExtra_serialize_ex(
|
|
474
|
+
test_msg_extra, 0, arena.ptr(), &size);
|
|
475
|
+
ASSERT_NE(nullptr, serialized);
|
|
476
|
+
ASSERT_NE(0, size);
|
|
477
|
+
|
|
478
|
+
upb_test_TestMapField* test_msg =
|
|
479
|
+
upb_test_TestMapField_parse(serialized, size, arena.ptr());
|
|
480
|
+
ASSERT_NE(nullptr, test_msg);
|
|
481
|
+
|
|
482
|
+
ASSERT_FALSE(upb_test_TestMapField_map_field_get(test_msg, 0, nullptr));
|
|
483
|
+
serialized =
|
|
484
|
+
upb_test_TestMapField_serialize_ex(test_msg, 0, arena.ptr(), &size);
|
|
485
|
+
ASSERT_NE(0, size);
|
|
486
|
+
// parse into second instance
|
|
487
|
+
upb_test_TestMapFieldExtra* test_msg_extra2 =
|
|
488
|
+
upb_test_TestMapFieldExtra_parse(serialized, size, arena.ptr());
|
|
489
|
+
ASSERT_TRUE(
|
|
490
|
+
upb_test_TestMapFieldExtra_map_field_get(test_msg_extra2, 0, nullptr));
|
|
491
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2009-2021, Google LLC
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
|
7
|
+
* * Redistributions of source code must retain the above copyright
|
|
8
|
+
* notice, this list of conditions and the following disclaimer.
|
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
* documentation and/or other materials provided with the distribution.
|
|
12
|
+
* * Neither the name of Google LLC nor the
|
|
13
|
+
* names of its contributors may be used to endorse or promote products
|
|
14
|
+
* derived from this software without specific prior written permission.
|
|
15
|
+
*
|
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
19
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
|
|
20
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
21
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
22
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
23
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
24
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
// LINT: ALLOW_GROUPS
|
|
29
|
+
|
|
30
|
+
syntax = "proto2";
|
|
31
|
+
|
|
32
|
+
package upb_test;
|
|
33
|
+
|
|
34
|
+
import "google/protobuf/test_messages_proto3.proto";
|
|
35
|
+
|
|
36
|
+
message TestExtensions {
|
|
37
|
+
extensions 1000 to max;
|
|
38
|
+
extend TestExtensions {
|
|
39
|
+
optional int32 optional_int32_ext = 1000;
|
|
40
|
+
}
|
|
41
|
+
message Nested {
|
|
42
|
+
extend TestExtensions {
|
|
43
|
+
repeated int32 repeated_int32_ext = 1001;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
extend TestExtensions {
|
|
49
|
+
optional protobuf_test_messages.proto3.TestAllTypesProto3 optional_msg_ext =
|
|
50
|
+
1002;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
message TestMessageSet {
|
|
54
|
+
option message_set_wire_format = true;
|
|
55
|
+
|
|
56
|
+
extensions 4 to max;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
message MessageSetMember {
|
|
60
|
+
optional int32 optional_int32 = 1;
|
|
61
|
+
extend TestMessageSet {
|
|
62
|
+
optional MessageSetMember message_set_extension = 4;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
message FakeMessageSet {
|
|
67
|
+
repeated group Item = 1 {
|
|
68
|
+
optional int32 type_id = 2;
|
|
69
|
+
optional bytes message = 3;
|
|
70
|
+
optional int32 unknown_varint = 4;
|
|
71
|
+
optional fixed32 unknown_fixed32 = 5;
|
|
72
|
+
optional fixed64 unknown_fixed64 = 6;
|
|
73
|
+
optional bytes unknown_bytes = 7;
|
|
74
|
+
optional group UnknownGroup = 8 {}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
message Proto2EnumMessage {
|
|
79
|
+
enum Proto2TestEnum {
|
|
80
|
+
ZERO = 0;
|
|
81
|
+
NEGATIVE = -1;
|
|
82
|
+
SMALL = 15;
|
|
83
|
+
LARGE = 12345;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
optional Proto2TestEnum optional_enum = 1;
|
|
87
|
+
repeated Proto2TestEnum repeated_enum = 2;
|
|
88
|
+
repeated Proto2TestEnum packed_enum = 3 [packed = true];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The same fields as Proto2EnumMessage, but with int32 fields so we can fake
|
|
92
|
+
// wire format.
|
|
93
|
+
message Proto2FakeEnumMessage {
|
|
94
|
+
optional int32 optional_enum = 1;
|
|
95
|
+
repeated int32 repeated_enum = 2;
|
|
96
|
+
repeated int32 packed_enum = 3 [packed = true];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
message EmptyMessage {}
|
|
100
|
+
|
|
101
|
+
message TestRequiredFields {
|
|
102
|
+
required int32 required_int32 = 1;
|
|
103
|
+
optional int32 optional_int32 = 2;
|
|
104
|
+
required int64 required_int64 = 3;
|
|
105
|
+
optional TestRequiredFields optional_message = 4;
|
|
106
|
+
required EmptyMessage required_message = 5;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
message SubMessageHasRequired {
|
|
110
|
+
optional TestRequiredFields optional_message = 1;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
message TestMaxRequiredFields {
|
|
114
|
+
required int32 required_int32_1 = 1;
|
|
115
|
+
required int32 required_int32_2 = 2;
|
|
116
|
+
required int32 required_int32_3 = 3;
|
|
117
|
+
required int32 required_int32_4 = 4;
|
|
118
|
+
required int32 required_int32_5 = 5;
|
|
119
|
+
required int32 required_int32_6 = 6;
|
|
120
|
+
required int32 required_int32_7 = 7;
|
|
121
|
+
required int32 required_int32_8 = 8;
|
|
122
|
+
required int32 required_int32_9 = 9;
|
|
123
|
+
required int32 required_int32_10 = 10;
|
|
124
|
+
required int32 required_int32_11 = 11;
|
|
125
|
+
required int32 required_int32_12 = 12;
|
|
126
|
+
required int32 required_int32_13 = 13;
|
|
127
|
+
required int32 required_int32_14 = 14;
|
|
128
|
+
required int32 required_int32_15 = 15;
|
|
129
|
+
required int32 required_int32_16 = 16;
|
|
130
|
+
required int32 required_int32_17 = 17;
|
|
131
|
+
required int32 required_int32_18 = 18;
|
|
132
|
+
required int32 required_int32_19 = 19;
|
|
133
|
+
required int32 required_int32_20 = 20;
|
|
134
|
+
required int32 required_int32_21 = 21;
|
|
135
|
+
required int32 required_int32_22 = 22;
|
|
136
|
+
required int32 required_int32_23 = 23;
|
|
137
|
+
required int32 required_int32_24 = 24;
|
|
138
|
+
required int32 required_int32_25 = 25;
|
|
139
|
+
required int32 required_int32_26 = 26;
|
|
140
|
+
required int32 required_int32_27 = 27;
|
|
141
|
+
required int32 required_int32_28 = 28;
|
|
142
|
+
required int32 required_int32_29 = 29;
|
|
143
|
+
required int32 required_int32_30 = 30;
|
|
144
|
+
required int32 required_int32_31 = 31;
|
|
145
|
+
required int32 required_int32_32 = 32;
|
|
146
|
+
required int32 required_int32_33 = 33;
|
|
147
|
+
required int32 required_int32_34 = 34;
|
|
148
|
+
required int32 required_int32_35 = 35;
|
|
149
|
+
required int32 required_int32_36 = 36;
|
|
150
|
+
required int32 required_int32_37 = 37;
|
|
151
|
+
required int32 required_int32_38 = 38;
|
|
152
|
+
required int32 required_int32_39 = 39;
|
|
153
|
+
required int32 required_int32_40 = 40;
|
|
154
|
+
required int32 required_int32_41 = 41;
|
|
155
|
+
required int32 required_int32_42 = 42;
|
|
156
|
+
required int32 required_int32_43 = 43;
|
|
157
|
+
required int32 required_int32_44 = 44;
|
|
158
|
+
required int32 required_int32_45 = 45;
|
|
159
|
+
required int32 required_int32_46 = 46;
|
|
160
|
+
required int32 required_int32_47 = 47;
|
|
161
|
+
required int32 required_int32_48 = 48;
|
|
162
|
+
required int32 required_int32_49 = 49;
|
|
163
|
+
required int32 required_int32_50 = 50;
|
|
164
|
+
required int32 required_int32_51 = 51;
|
|
165
|
+
required int32 required_int32_52 = 52;
|
|
166
|
+
required int32 required_int32_53 = 53;
|
|
167
|
+
required int32 required_int32_54 = 54;
|
|
168
|
+
required int32 required_int32_55 = 55;
|
|
169
|
+
required int32 required_int32_56 = 56;
|
|
170
|
+
required int32 required_int32_57 = 57;
|
|
171
|
+
required int32 required_int32_58 = 58;
|
|
172
|
+
required int32 required_int32_59 = 59;
|
|
173
|
+
required int32 required_int32_60 = 60;
|
|
174
|
+
required int32 required_int32_61 = 61;
|
|
175
|
+
required int32 required_int32_62 = 62;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
message TestMapField {
|
|
179
|
+
enum EnumMap {
|
|
180
|
+
ZERO = 0;
|
|
181
|
+
ONE = 1;
|
|
182
|
+
TWO = 2;
|
|
183
|
+
}
|
|
184
|
+
map<int32, EnumMap> map_field = 1;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
message TestMapFieldExtra {
|
|
188
|
+
enum EnumMap {
|
|
189
|
+
ZERO = 0;
|
|
190
|
+
ONE = 1;
|
|
191
|
+
TWO = 2;
|
|
192
|
+
THREE = 3;
|
|
193
|
+
}
|
|
194
|
+
map<int32, EnumMap> map_field = 1;
|
|
195
|
+
}
|