| 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 // http://code.google.com/p/protobuf/ |
| 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. |
| 11 // * Redistributions in binary form must reproduce the above | 11 // * Redistributions in binary form must reproduce the above |
| 12 // copyright notice, this list of conditions and the following disclaimer | 12 // copyright notice, this list of conditions and the following disclaimer |
| 13 // in the documentation and/or other materials provided with the | 13 // in the documentation and/or other materials provided with the |
| (...skipping 27 matching lines...) Expand all Loading... |
| 41 // If this test fails, run the script | 41 // If this test fails, run the script |
| 42 // "generate_descriptor_proto.sh" and add | 42 // "generate_descriptor_proto.sh" and add |
| 43 // descriptor.pb.{h,cc} to your changelist. | 43 // descriptor.pb.{h,cc} to your changelist. |
| 44 | 44 |
| 45 #include <map> | 45 #include <map> |
| 46 | 46 |
| 47 #include <google/protobuf/compiler/cpp/cpp_generator.h> | 47 #include <google/protobuf/compiler/cpp/cpp_generator.h> |
| 48 #include <google/protobuf/compiler/importer.h> | 48 #include <google/protobuf/compiler/importer.h> |
| 49 #include <google/protobuf/descriptor.h> | 49 #include <google/protobuf/descriptor.h> |
| 50 #include <google/protobuf/io/zero_copy_stream_impl.h> | 50 #include <google/protobuf/io/zero_copy_stream_impl.h> |
| 51 #include <google/protobuf/stubs/map_util.h> | 51 #include <google/protobuf/stubs/map-util.h> |
| 52 #include <google/protobuf/stubs/stl_util.h> | 52 #include <google/protobuf/stubs/stl_util.h> |
| 53 #include <google/protobuf/stubs/strutil.h> | 53 #include <google/protobuf/stubs/strutil.h> |
| 54 #include <google/protobuf/stubs/substitute.h> | 54 #include <google/protobuf/stubs/substitute.h> |
| 55 | 55 |
| 56 #include <google/protobuf/testing/file.h> | 56 #include <google/protobuf/testing/file.h> |
| 57 #include <google/protobuf/testing/googletest.h> | 57 #include <google/protobuf/testing/googletest.h> |
| 58 #include <gtest/gtest.h> | 58 #include <gtest/gtest.h> |
| 59 | 59 |
| 60 namespace google { | 60 namespace google { |
| 61 namespace protobuf { | 61 namespace protobuf { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 86 STLDeleteValues(&files_); | 86 STLDeleteValues(&files_); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void ExpectFileMatches(const string& virtual_filename, | 89 void ExpectFileMatches(const string& virtual_filename, |
| 90 const string& physical_filename) { | 90 const string& physical_filename) { |
| 91 string* expected_contents = FindPtrOrNull(files_, virtual_filename); | 91 string* expected_contents = FindPtrOrNull(files_, virtual_filename); |
| 92 ASSERT_TRUE(expected_contents != NULL) | 92 ASSERT_TRUE(expected_contents != NULL) |
| 93 << "Generator failed to generate file: " << virtual_filename; | 93 << "Generator failed to generate file: " << virtual_filename; |
| 94 | 94 |
| 95 string actual_contents; | 95 string actual_contents; |
| 96 GOOGLE_CHECK_OK( | 96 File::ReadFileToStringOrDie( |
| 97 File::GetContents(TestSourceDir() + "/" + physical_filename, | 97 TestSourceDir() + "/" + physical_filename, |
| 98 &actual_contents, true)); | 98 &actual_contents); |
| 99 EXPECT_TRUE(actual_contents == *expected_contents) | 99 EXPECT_TRUE(actual_contents == *expected_contents) |
| 100 << physical_filename << " needs to be regenerated. Please run " | 100 << physical_filename << " needs to be regenerated. Please run " |
| 101 "google/protobuf/compiler/release_compiler.sh and " | 101 "generate_descriptor_proto.sh and add this file " |
| 102 "generate_descriptor_proto.sh. Then add this file " | |
| 103 "to your CL."; | 102 "to your CL."; |
| 104 } | 103 } |
| 105 | 104 |
| 106 // implements GeneratorContext -------------------------------------- | 105 // implements GeneratorContext -------------------------------------- |
| 107 | 106 |
| 108 virtual io::ZeroCopyOutputStream* Open(const string& filename) { | 107 virtual io::ZeroCopyOutputStream* Open(const string& filename) { |
| 109 string** map_slot = &files_[filename]; | 108 string** map_slot = &files_[filename]; |
| 110 if (*map_slot != NULL) delete *map_slot; | 109 if (*map_slot != NULL) delete *map_slot; |
| 111 *map_slot = new string; | 110 *map_slot = new string; |
| 112 | 111 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 context.ExpectFileMatches("google/protobuf/compiler/plugin.pb.cc", | 149 context.ExpectFileMatches("google/protobuf/compiler/plugin.pb.cc", |
| 151 "google/protobuf/compiler/plugin.pb.cc"); | 150 "google/protobuf/compiler/plugin.pb.cc"); |
| 152 } | 151 } |
| 153 | 152 |
| 154 } // namespace | 153 } // namespace |
| 155 | 154 |
| 156 } // namespace cpp | 155 } // namespace cpp |
| 157 } // namespace compiler | 156 } // namespace compiler |
| 158 } // namespace protobuf | 157 } // namespace protobuf |
| 159 } // namespace google | 158 } // namespace google |
| OLD | NEW |