Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
a69bc9de
Commit
a69bc9de
authored
Mar 10, 2017
by
Jie Luo
Committed by
GitHub
Mar 10, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2822 from anandolee/master
Detect generated code of WKT, addressbook and conformance protos
parents
f54fb9d7
ae220cda
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
18 deletions
+73
-18
csharp_bootstrap_unittest.cc
...gle/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
+73
-18
No files found.
src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
View file @
a69bc9de
...
@@ -34,8 +34,8 @@
...
@@ -34,8 +34,8 @@
// generated automatically at build time.
// generated automatically at build time.
//
//
// If this test fails, run the script
// If this test fails, run the script
// "generate_descriptor_proto.sh" and add
// "generate_descriptor_proto.sh" and add
the changed files under
// csharp/src/
Google.Protobuf/Reflection/Descriptor.cs
to your changelist.
// csharp/src/ to your changelist.
#include <map>
#include <map>
...
@@ -91,7 +91,8 @@ class MockGeneratorContext : public GeneratorContext {
...
@@ -91,7 +91,8 @@ class MockGeneratorContext : public GeneratorContext {
string
actual_contents
;
string
actual_contents
;
GOOGLE_CHECK_OK
(
GOOGLE_CHECK_OK
(
File
::
GetContents
(
TestSourceDir
()
+
"/"
+
physical_filename
,
File
::
GetContents
(
TestSourceDir
()
+
"/"
+
physical_filename
,
&
actual_contents
,
true
));
&
actual_contents
,
true
))
<<
"Unable to get "
<<
physical_filename
;
EXPECT_TRUE
(
actual_contents
==
*
expected_contents
)
EXPECT_TRUE
(
actual_contents
==
*
expected_contents
)
<<
physical_filename
<<
" needs to be regenerated. Please run "
<<
physical_filename
<<
" needs to be regenerated. Please run "
"generate_descriptor_proto.sh. Then add this file "
"generate_descriptor_proto.sh. Then add this file "
...
@@ -112,26 +113,80 @@ class MockGeneratorContext : public GeneratorContext {
...
@@ -112,26 +113,80 @@ class MockGeneratorContext : public GeneratorContext {
std
::
map
<
string
,
string
*>
files_
;
std
::
map
<
string
,
string
*>
files_
;
};
};
class
GenerateAndTest
{
public
:
GenerateAndTest
()
{}
void
Run
(
const
FileDescriptor
*
proto_file
,
string
file1
,
string
file2
)
{
ASSERT_TRUE
(
proto_file
!=
NULL
)
<<
TestSourceDir
();
ASSERT_TRUE
(
generator_
.
Generate
(
proto_file
,
parameter_
,
&
context_
,
&
error_
));
context_
.
ExpectFileMatches
(
file1
,
file2
);
}
void
SetParameter
(
string
parameter
)
{
parameter_
=
parameter
;
}
private
:
Generator
generator_
;
MockGeneratorContext
context_
;
string
error_
;
string
parameter_
;
};
TEST
(
CsharpBootstrapTest
,
GeneratedCsharpDescriptorMatches
)
{
TEST
(
CsharpBootstrapTest
,
GeneratedCsharpDescriptorMatches
)
{
MockErrorCollector
error_collector
;
MockErrorCollector
error_collector
;
DiskSourceTree
source_tree
;
DiskSourceTree
source_tree
;
source_tree
.
MapPath
(
""
,
TestSourceDir
());
Importer
importer
(
&
source_tree
,
&
error_collector
);
Importer
importer
(
&
source_tree
,
&
error_collector
);
const
FileDescriptor
*
proto_file
=
GenerateAndTest
generate_test
;
importer
.
Import
(
"google/protobuf/descriptor.proto"
);
generate_test
.
SetParameter
(
"base_namespace=Google.Protobuf"
);
source_tree
.
MapPath
(
""
,
TestSourceDir
());
generate_test
.
Run
(
importer
.
Import
(
"google/protobuf/descriptor.proto"
),
"Reflection/Descriptor.cs"
,
"../csharp/src/Google.Protobuf/Reflection/Descriptor.cs"
);
generate_test
.
Run
(
importer
.
Import
(
"google/protobuf/any.proto"
),
"WellKnownTypes/Any.cs"
,
"../csharp/src/Google.Protobuf/WellKnownTypes/Any.cs"
);
generate_test
.
Run
(
importer
.
Import
(
"google/protobuf/api.proto"
),
"WellKnownTypes/Api.cs"
,
"../csharp/src/Google.Protobuf/WellKnownTypes/Api.cs"
);
generate_test
.
Run
(
importer
.
Import
(
"google/protobuf/duration.proto"
),
"WellKnownTypes/Duration.cs"
,
"../csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs"
);
generate_test
.
Run
(
importer
.
Import
(
"google/protobuf/empty.proto"
),
"WellKnownTypes/Empty.cs"
,
"../csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs"
);
generate_test
.
Run
(
importer
.
Import
(
"google/protobuf/field_mask.proto"
),
"WellKnownTypes/FieldMask.cs"
,
"../csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs"
);
generate_test
.
Run
(
importer
.
Import
(
"google/protobuf/source_context.proto"
),
"WellKnownTypes/SourceContext.cs"
,
"../csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs"
);
generate_test
.
Run
(
importer
.
Import
(
"google/protobuf/struct.proto"
),
"WellKnownTypes/Struct.cs"
,
"../csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs"
);
generate_test
.
Run
(
importer
.
Import
(
"google/protobuf/timestamp.proto"
),
"WellKnownTypes/Timestamp.cs"
,
"../csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs"
);
generate_test
.
Run
(
importer
.
Import
(
"google/protobuf/type.proto"
),
"WellKnownTypes/Type.cs"
,
"../csharp/src/Google.Protobuf/WellKnownTypes/Type.cs"
);
generate_test
.
Run
(
importer
.
Import
(
"google/protobuf/wrappers.proto"
),
"WellKnownTypes/Wrappers.cs"
,
"../csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs"
);
generate_test
.
SetParameter
(
""
);
source_tree
.
MapPath
(
""
,
TestSourceDir
()
+
"/../examples"
);
generate_test
.
Run
(
importer
.
Import
(
"addressbook.proto"
),
"Addressbook.cs"
,
"../csharp/src/AddressBook/Addressbook.cs"
);
source_tree
.
MapPath
(
""
,
TestSourceDir
()
+
"/../conformance"
);
generate_test
.
Run
(
importer
.
Import
(
"conformance.proto"
),
"Conformance.cs"
,
"../csharp/src/Google.Protobuf.Conformance/Conformance.cs"
);
EXPECT_EQ
(
""
,
error_collector
.
text_
);
EXPECT_EQ
(
""
,
error_collector
.
text_
);
ASSERT_TRUE
(
proto_file
!=
NULL
);
Generator
generator
;
MockGeneratorContext
context
;
string
error
;
string
parameter
=
"base_namespace=Google.Protobuf"
;
ASSERT_TRUE
(
generator
.
Generate
(
proto_file
,
parameter
,
&
context
,
&
error
));
context
.
ExpectFileMatches
(
"Reflection/Descriptor.cs"
,
"../csharp/src/Google.Protobuf/Reflection/Descriptor.cs"
);
}
}
}
// namespace
}
// namespace
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment