OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 message, F("map_int32_foreign_message"), map_key, &map_val)); | 860 message, F("map_int32_foreign_message"), map_key, &map_val)); |
861 sub_foreign_message = map_val.MutableMessageValue(); | 861 sub_foreign_message = map_val.MutableMessageValue(); |
862 sub_foreign_message->GetReflection()->SetInt32( | 862 sub_foreign_message->GetReflection()->SetInt32( |
863 sub_foreign_message, foreign_c_, 2); | 863 sub_foreign_message, foreign_c_, 2); |
864 } | 864 } |
865 | 865 |
866 void MapReflectionTester::RemoveLastMapsViaReflection( | 866 void MapReflectionTester::RemoveLastMapsViaReflection( |
867 Message* message) { | 867 Message* message) { |
868 const Reflection* reflection = message->GetReflection(); | 868 const Reflection* reflection = message->GetReflection(); |
869 | 869 |
870 std::vector<const FieldDescriptor*> output; | 870 vector<const FieldDescriptor*> output; |
871 reflection->ListFields(*message, &output); | 871 reflection->ListFields(*message, &output); |
872 for (int i = 0; i < output.size(); ++i) { | 872 for (int i = 0; i < output.size(); ++i) { |
873 const FieldDescriptor* field = output[i]; | 873 const FieldDescriptor* field = output[i]; |
874 if (!field->is_repeated()) continue; | 874 if (!field->is_repeated()) continue; |
875 reflection->RemoveLast(message, field); | 875 reflection->RemoveLast(message, field); |
876 } | 876 } |
877 } | 877 } |
878 | 878 |
879 void MapReflectionTester::ReleaseLastMapsViaReflection( | 879 void MapReflectionTester::ReleaseLastMapsViaReflection( |
880 Message* message) { | 880 Message* message) { |
881 const Reflection* reflection = message->GetReflection(); | 881 const Reflection* reflection = message->GetReflection(); |
882 | 882 |
883 std::vector<const FieldDescriptor*> output; | 883 vector<const FieldDescriptor*> output; |
884 reflection->ListFields(*message, &output); | 884 reflection->ListFields(*message, &output); |
885 for (int i = 0; i < output.size(); ++i) { | 885 for (int i = 0; i < output.size(); ++i) { |
886 const FieldDescriptor* field = output[i]; | 886 const FieldDescriptor* field = output[i]; |
887 if (!field->is_repeated()) continue; | 887 if (!field->is_repeated()) continue; |
888 if (field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) continue; | 888 if (field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) continue; |
889 | 889 |
890 Message* released = reflection->ReleaseLast(message, field); | 890 Message* released = reflection->ReleaseLast(message, field); |
891 ASSERT_TRUE(released != NULL) << "ReleaseLast returned NULL for: " | 891 ASSERT_TRUE(released != NULL) << "ReleaseLast returned NULL for: " |
892 << field->name(); | 892 << field->name(); |
893 delete released; | 893 delete released; |
894 } | 894 } |
895 } | 895 } |
896 | 896 |
897 void MapReflectionTester::SwapMapsViaReflection(Message* message) { | 897 void MapReflectionTester::SwapMapsViaReflection(Message* message) { |
898 const Reflection* reflection = message->GetReflection(); | 898 const Reflection* reflection = message->GetReflection(); |
899 std::vector<const FieldDescriptor*> output; | 899 vector<const FieldDescriptor*> output; |
900 reflection->ListFields(*message, &output); | 900 reflection->ListFields(*message, &output); |
901 for (int i = 0; i < output.size(); ++i) { | 901 for (int i = 0; i < output.size(); ++i) { |
902 const FieldDescriptor* field = output[i]; | 902 const FieldDescriptor* field = output[i]; |
903 if (!field->is_repeated()) continue; | 903 if (!field->is_repeated()) continue; |
904 reflection->SwapElements(message, field, 0, 1); | 904 reflection->SwapElements(message, field, 0, 1); |
905 } | 905 } |
906 } | 906 } |
907 | 907 |
908 void MapReflectionTester:: | 908 void MapReflectionTester:: |
909 MutableUnknownFieldsOfMapFieldsViaReflection(Message* message) { | 909 MutableUnknownFieldsOfMapFieldsViaReflection(Message* message) { |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 EXPECT_EQ(0, sub_message->GetReflection() | 1792 EXPECT_EQ(0, sub_message->GetReflection() |
1793 ->GetEnum(*sub_message, value_descriptor) | 1793 ->GetEnum(*sub_message, value_descriptor) |
1794 ->number()); | 1794 ->number()); |
1795 } | 1795 } |
1796 // Map using message as value has been tested in other place. Thus, we don't | 1796 // Map using message as value has been tested in other place. Thus, we don't |
1797 // test it here. | 1797 // test it here. |
1798 } | 1798 } |
1799 | 1799 |
1800 } // namespace protobuf | 1800 } // namespace protobuf |
1801 } // namespace google | 1801 } // namespace google |
OLD | NEW |