A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/protocolbuffers/protobuf/commit/c51df736505595461a0ce4c2ca703d08744a8e5e below:

Add generated message reflection unittest for `import option` and `op… · protocolbuffers/protobuf@c51df73 · GitHub

File tree Expand file treeCollapse file tree 5 files changed

+139

-0

lines changed

Filter options

Expand file treeCollapse file tree 5 files changed

+139

-0

lines changed Original file line number Diff line number Diff line change

@@ -0,0 +1,20 @@

1 +

"""This module defines a wrapper around proto_library for Bazel versions that do not support certain attributes yet."""

2 + 3 +

load("//bazel:proto_library.bzl", "proto_library")

4 + 5 +

def protobuf_test_proto_library(**kwattrs):

6 +

"""

7 +

Creates a proto library, handling any attributes that are not supported by the proto_library rule.

8 + 9 +

Args:

10 +

**kwattrs: Additional arguments to pass to the proto_library rule.

11 +

"""

12 +

kwargs = dict(kwattrs)

13 + 14 +

# TODO: Bazel 7's proto_library rule does not support option_deps, so we handle it by putting it in deps instead.

15 +

if "option_deps" in kwargs and hasattr(native, "proto_library"):

16 +

deps = kwargs.pop("deps", [])

17 +

option_deps = kwargs.pop("option_deps")

18 +

kwargs["deps"] = deps + option_deps

19 + 20 +

proto_library(**kwargs)

Original file line number Diff line number Diff line change

@@ -9,6 +9,10 @@ load("//bazel:proto_library.bzl", "proto_library")

9 9

load("//bazel:upb_c_proto_library.bzl", "upb_c_proto_library")

10 10

load("//bazel:upb_minitable_proto_library.bzl", "upb_minitable_proto_library")

11 11

load("//bazel:upb_proto_reflection_library.bzl", "upb_proto_reflection_library")

12 +

load(

13 +

"//bazel/tests:protobuf_test_proto_library.bzl",

14 +

"protobuf_test_proto_library",

15 +

)

12 16

load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")

13 17

load("//upb/cmake:build_defs.bzl", "staleness_test")

14 18

@@ -980,11 +984,13 @@ filegroup(

980 984

"map_unittest.proto",

981 985

"unittest.proto",

982 986

"unittest_custom_options.proto",

987 +

"unittest_custom_options_unlinked.proto",

983 988

"unittest_embed_optimize_for.proto",

984 989

"unittest_empty.proto",

985 990

"unittest_enormous_descriptor.proto",

986 991

"unittest_features.proto",

987 992

"unittest_import.proto",

993 +

"unittest_import_option.proto",

988 994

"unittest_import_public.proto",

989 995

"unittest_invalid_features.proto",

990 996

"unittest_lite_imports_nonlite.proto",

@@ -1300,6 +1306,31 @@ cc_proto_library(

1300 1306

deps = [":unittest_string_view_proto"],

1301 1307

)

1302 1308 1309 +

proto_library(

1310 +

name = "unittest_custom_options_unlinked_proto",

1311 +

srcs = ["unittest_custom_options_unlinked.proto"],

1312 +

strip_import_prefix = "/src",

1313 +

deps = [

1314 +

"//:any_proto",

1315 +

"//:descriptor_proto",

1316 +

],

1317 +

)

1318 + 1319 +

protobuf_test_proto_library(

1320 +

name = "unittest_import_option_proto",

1321 +

srcs = ["unittest_import_option.proto"],

1322 +

option_deps = [

1323 +

":test_protos",

1324 +

":unittest_custom_options_unlinked_proto",

1325 +

],

1326 +

strip_import_prefix = "/src",

1327 +

)

1328 + 1329 +

cc_proto_library(

1330 +

name = "unittest_import_option_cc_proto",

1331 +

deps = [":unittest_import_option_proto"],

1332 +

)

1333 + 1303 1334

cc_test(

1304 1335

name = "string_view_test",

1305 1336

srcs = ["string_view_test.cc"],

@@ -1755,6 +1786,7 @@ cc_test(

1755 1786

":port",

1756 1787

":protobuf",

1757 1788

":test_util",

1789 +

":unittest_import_option_cc_proto",

1758 1790

":unittest_proto3_cc_proto",

1759 1791

"//src/google/protobuf/stubs",

1760 1792

"//src/google/protobuf/testing",

Original file line number Diff line number Diff line change

@@ -40,7 +40,9 @@

40 40

#include "google/protobuf/test_util.h"

41 41

#include "google/protobuf/text_format.h"

42 42

#include "google/protobuf/unittest.pb.h"

43 +

#include "google/protobuf/unittest_custom_options.pb.h"

43 44

#include "google/protobuf/unittest_import.pb.h"

45 +

#include "google/protobuf/unittest_import_option.pb.h"

44 46

#include "google/protobuf/unittest_mset.pb.h"

45 47

#include "google/protobuf/unittest_mset_wire_format.pb.h"

46 48

#include "google/protobuf/unittest_proto3.pb.h"

@@ -1825,6 +1827,23 @@ TEST(GeneratedMessageReflection, UnvalidatedStringsAreDowngradedToBytes) {

1825 1827

msg.mutable_optional_extension());

1826 1828

}

1827 1829 1830 +

TEST(GeneratedMessageReflection, ImportOption) {

1831 +

proto2_unittest_import_option::TestMessage message;

1832 +

google::protobuf::FileDescriptor const* file_descriptor =

1833 +

message.GetDescriptor()->file();

1834 +

google::protobuf::Descriptor const* message_descriptor = message.GetDescriptor();

1835 +

google::protobuf::FieldDescriptor const* field_descriptor =

1836 +

message_descriptor->FindFieldByName("field1");

1837 + 1838 +

EXPECT_EQ(

1839 +

1, file_descriptor->options().GetExtension(proto2_unittest::file_opt1));

1840 +

EXPECT_EQ(2, message_descriptor->options().GetExtension(

1841 +

proto2_unittest::message_opt1));

1842 +

EXPECT_EQ(

1843 +

3, field_descriptor->options().GetExtension(proto2_unittest::field_opt1));

1844 + 1845 +

}

1846 + 1828 1847

} // namespace

1829 1848

} // namespace protobuf

1830 1849

} // namespace google

Original file line number Diff line number Diff line change

@@ -0,0 +1,37 @@

1 +

// Protocol Buffers - Google's data interchange format

2 +

// Copyright 2008 Google Inc. All rights reserved.

3 +

//

4 +

// Use of this source code is governed by a BSD-style

5 +

// license that can be found in the LICENSE file or at

6 +

// https://developers.google.com/open-source/licenses/bsd

7 + 8 +

// Author: benjy@google.com (Benjy Weinberger)

9 +

// Based on original Protocol Buffers design by

10 +

// Sanjay Ghemawat, Jeff Dean, and others.

11 +

//

12 +

// A proto file used to test the "custom options" feature when not linked in.

13 + 14 +

edition = "2024";

15 + 16 +

// A custom file option (defined below).

17 +

option (file_opt1) = 9876543210;

18 + 19 +

import "google/protobuf/descriptor.proto";

20 + 21 +

// We don't put this in a package within proto2 because we need to make sure

22 +

// that the generated code doesn't depend on being in the proto2 namespace.

23 +

package proto2_unittest_unlinked;

24 + 25 +

// Some simple test custom options of various types.

26 + 27 +

extend google.protobuf.FileOptions {

28 +

uint64 file_opt1 = 7736975;

29 +

}

30 + 31 +

extend google.protobuf.MessageOptions {

32 +

int32 message_opt1 = 7739037;

33 +

}

34 + 35 +

extend google.protobuf.FieldOptions {

36 +

fixed64 field_opt1 = 7740937;

37 +

}

Original file line number Diff line number Diff line change

@@ -0,0 +1,31 @@

1 +

// Protocol Buffers - Google's data interchange format

2 +

// Copyright 2008 Google Inc. All rights reserved.

3 +

//

4 +

// Use of this source code is governed by a BSD-style

5 +

// license that can be found in the LICENSE file or at

6 +

// https://developers.google.com/open-source/licenses/bsd

7 +

// Author: kenton@google.com (Kenton Varda)

8 +

// Based on original Protocol Buffers design by

9 +

// Sanjay Ghemawat, Jeff Dean, and others.

10 +

//

11 +

// A proto file to test options importing.

12 +

edition = "2024";

13 + 14 +

package proto2_unittest_import_option;

15 + 16 +

// Test option import

17 +

import option "google/protobuf/unittest_custom_options.proto";

18 +

import option "google/protobuf/unittest_custom_options_unlinked.proto";

19 + 20 +

option (proto2_unittest.file_opt1) = 1;

21 +

option (proto2_unittest_unlinked.file_opt1) = 1;

22 + 23 +

message TestMessage {

24 +

option (proto2_unittest.message_opt1) = 2;

25 +

option (proto2_unittest_unlinked.message_opt1) = 2;

26 + 27 +

int32 field1 = 1 [

28 +

(proto2_unittest.field_opt1) = 3,

29 +

(proto2_unittest_unlinked.field_opt1) = 3

30 +

];

31 +

}

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4