• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef GOOGLE_PROTOBUF_REFLECTION_TESTER_H__
9 #define GOOGLE_PROTOBUF_REFLECTION_TESTER_H__
10 
11 #include "google/protobuf/map_field.h"
12 #include "google/protobuf/message.h"
13 
14 // Must be included last.
15 #include "google/protobuf/port_def.inc"
16 
17 namespace google {
18 namespace protobuf {
19 
20 // Provides APIs to test protocol buffers reflectively.
21 class MapReflectionTester {
22  public:
23   // base_descriptor must be a descriptor for TestMap, which is used for
24   // MapReflectionTester to fetch the FieldDescriptors needed to use the
25   // reflection interface.
26   explicit MapReflectionTester(const Descriptor* base_descriptor);
27 
28   void SetMapFieldsViaReflection(Message* message);
29   void SetMapFieldsViaMapReflection(Message* message);
30   void ClearMapFieldsViaReflection(Message* message);
31   void ModifyMapFieldsViaReflection(Message* message);
32   void RemoveLastMapsViaReflection(Message* message);
33   void ReleaseLastMapsViaReflection(Message* message);
34   void SwapMapsViaReflection(Message* message);
35   void MutableUnknownFieldsOfMapFieldsViaReflection(Message* message);
36   void ExpectMapFieldsSetViaReflection(const Message& message);
37   void ExpectMapFieldsSetViaReflectionIterator(Message* message);
38   void ExpectClearViaReflection(const Message& message);
39   void ExpectClearViaReflectionIterator(Message* message);
40   void GetMapValueViaMapReflection(Message* message,
41                                    const std::string& field_name,
42                                    const MapKey& map_key, MapValueRef* map_val);
43   Message* GetMapEntryViaReflection(Message* message,
44                                     const std::string& field_name, int index);
45   MapIterator MapBegin(Message* message, const std::string& field_name);
46   MapIterator MapEnd(Message* message, const std::string& field_name);
47   int MapSize(const Message& message, const std::string& field_name);
48 
LookupMapValue(const Reflection & reflection,const Message & message,const FieldDescriptor & descriptor,const MapKey & map_key)49   static MapValueConstRef LookupMapValue(const Reflection& reflection,
50                                          const Message& message,
51                                          const FieldDescriptor& descriptor,
52                                          const MapKey& map_key) {
53     MapValueConstRef map_val_const;
54     reflection.LookupMapValue(message, &descriptor, map_key, &map_val_const);
55     return map_val_const;
56   }
57 
long_string()58   static std::string long_string() {
59     return "This is a very long string that goes in the heap";
60   }
long_string_2()61   static std::string long_string_2() {
62     return "This is another very long string that goes in the heap";
63   }
64 
65  private:
66   const FieldDescriptor* F(const std::string& name);
67 
68   const Descriptor* base_descriptor_;
69 
70   const EnumValueDescriptor* map_enum_bar_;
71   const EnumValueDescriptor* map_enum_baz_;
72   const EnumValueDescriptor* map_enum_foo_;
73 
74   const FieldDescriptor* foreign_c_;
75   const FieldDescriptor* map_int32_int32_key_;
76   const FieldDescriptor* map_int32_int32_val_;
77   const FieldDescriptor* map_int64_int64_key_;
78   const FieldDescriptor* map_int64_int64_val_;
79   const FieldDescriptor* map_uint32_uint32_key_;
80   const FieldDescriptor* map_uint32_uint32_val_;
81   const FieldDescriptor* map_uint64_uint64_key_;
82   const FieldDescriptor* map_uint64_uint64_val_;
83   const FieldDescriptor* map_sint32_sint32_key_;
84   const FieldDescriptor* map_sint32_sint32_val_;
85   const FieldDescriptor* map_sint64_sint64_key_;
86   const FieldDescriptor* map_sint64_sint64_val_;
87   const FieldDescriptor* map_fixed32_fixed32_key_;
88   const FieldDescriptor* map_fixed32_fixed32_val_;
89   const FieldDescriptor* map_fixed64_fixed64_key_;
90   const FieldDescriptor* map_fixed64_fixed64_val_;
91   const FieldDescriptor* map_sfixed32_sfixed32_key_;
92   const FieldDescriptor* map_sfixed32_sfixed32_val_;
93   const FieldDescriptor* map_sfixed64_sfixed64_key_;
94   const FieldDescriptor* map_sfixed64_sfixed64_val_;
95   const FieldDescriptor* map_int32_float_key_;
96   const FieldDescriptor* map_int32_float_val_;
97   const FieldDescriptor* map_int32_double_key_;
98   const FieldDescriptor* map_int32_double_val_;
99   const FieldDescriptor* map_bool_bool_key_;
100   const FieldDescriptor* map_bool_bool_val_;
101   const FieldDescriptor* map_string_string_key_;
102   const FieldDescriptor* map_string_string_val_;
103   const FieldDescriptor* map_int32_bytes_key_;
104   const FieldDescriptor* map_int32_bytes_val_;
105   const FieldDescriptor* map_int32_enum_key_;
106   const FieldDescriptor* map_int32_enum_val_;
107   const FieldDescriptor* map_int32_foreign_message_key_;
108   const FieldDescriptor* map_int32_foreign_message_val_;
109 };
110 
111 }  // namespace protobuf
112 }  // namespace google
113 
114 #include "google/protobuf/port_undef.inc"
115 
116 #endif  // GOOGLE_PROTOBUF_REFLECTION_TESTER_H__
117