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
25981d40
Commit
25981d40
authored
Aug 09, 2011
by
Nathan Brown
Committed by
Nathan Brown
Aug 09, 2011
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
e8c76bd8
d4b3859b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
3 deletions
+91
-3
TestPreprocessing.cs
src/ProtoGen.Test/TestPreprocessing.cs
+87
-0
ServiceGenerator.cs
src/ProtoGen/ServiceGenerator.cs
+4
-3
No files found.
src/ProtoGen.Test/TestPreprocessing.cs
View file @
25981d40
...
@@ -673,5 +673,91 @@ message MyMessageList {
...
@@ -673,5 +673,91 @@ message MyMessageList {
a
.
GetType
(
"nunit.simple.Proto.MyMessageList"
,
true
,
true
);
a
.
GetType
(
"nunit.simple.Proto.MyMessageList"
,
true
,
true
);
}
}
}
}
[
Test
]
public
void
TestProtoFileWithService
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
@"
import ""google/protobuf/csharp_options.proto"";
option (google.protobuf.csharp_file_options).service_generator_type = GENERIC;
package nunit.simple;
// Test a very simple message.
message MyMessage {
optional string name = 1;
}
// test a very simple service.
service TestService {
rpc Execute (MyMessage) returns (MyMessage);
}"
))
{
CopyInGoogleProtoFiles
();
RunProtoGen
(
0
,
proto
.
TempPath
,
"-ignore_google_protobuf:true"
,
"-nest_classes=false"
);
Assert
.
AreEqual
(
1
,
Directory
.
GetFiles
(
TempPath
,
"*.cs"
).
Length
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the service type is in the expected namespace
Type
t1
=
a
.
GetType
(
"nunit.simple.TestService"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IService
).
IsAssignableFrom
(
t1
),
"Expect an IService"
);
Assert
.
IsTrue
(
t1
.
IsAbstract
,
"Expect abstract class"
);
//assert that the Stub subclass type is in the expected namespace
Type
t2
=
a
.
GetType
(
"nunit.simple.TestService+Stub"
,
true
,
true
);
Assert
.
IsTrue
(
t1
.
IsAssignableFrom
(
t2
),
"Expect a sub of TestService"
);
Assert
.
IsFalse
(
t2
.
IsAbstract
,
"Expect concrete class"
);
}
}
[
Test
]
public
void
TestProtoFileWithServiceInternal
()
{
string
test
=
new
StackFrame
(
false
).
GetMethod
().
Name
;
Setup
();
using
(
TempFile
source
=
TempFile
.
Attach
(
test
+
".cs"
))
using
(
ProtoFile
proto
=
new
ProtoFile
(
test
+
".proto"
,
@"
import ""google/protobuf/csharp_options.proto"";
option (google.protobuf.csharp_file_options).service_generator_type = GENERIC;
package nunit.simple;
// Test a very simple message.
message MyMessage {
optional string name = 1;
}
// test a very simple service.
service TestService {
rpc Execute (MyMessage) returns (MyMessage);
}"
))
{
CopyInGoogleProtoFiles
();
RunProtoGen
(
0
,
proto
.
TempPath
,
"-ignore_google_protobuf:true"
,
"-nest_classes=false"
,
"-public_classes=false"
);
Assert
.
AreEqual
(
1
,
Directory
.
GetFiles
(
TempPath
,
"*.cs"
).
Length
);
Assembly
a
=
RunCsc
(
0
,
source
.
TempPath
);
//assert that the service type is in the expected namespace
Type
t1
=
a
.
GetType
(
"nunit.simple.TestService"
,
true
,
true
);
Assert
.
IsTrue
(
typeof
(
IService
).
IsAssignableFrom
(
t1
),
"Expect an IService"
);
Assert
.
IsTrue
(
t1
.
IsAbstract
,
"Expect abstract class"
);
//assert that the Stub subclass type is in the expected namespace
Type
t2
=
a
.
GetType
(
"nunit.simple.TestService+Stub"
,
true
,
true
);
Assert
.
IsTrue
(
t1
.
IsAssignableFrom
(
t2
),
"Expect a sub of TestService"
);
Assert
.
IsFalse
(
t2
.
IsAbstract
,
"Expect concrete class"
);
}
}
private
static
void
CopyInGoogleProtoFiles
()
{
string
google
=
Path
.
Combine
(
TempPath
,
"google\\protobuf"
);
Directory
.
CreateDirectory
(
google
);
foreach
(
string
file
in
Directory
.
GetFiles
(
Path
.
Combine
(
OriginalWorkingDirectory
,
"google\\protobuf"
)))
{
File
.
Copy
(
file
,
Path
.
Combine
(
google
,
Path
.
GetFileName
(
file
)));
}
}
}
}
}
}
\ No newline at end of file
src/ProtoGen/ServiceGenerator.cs
View file @
25981d40
...
@@ -76,7 +76,7 @@ namespace Google.ProtocolBuffers.ProtoGen
...
@@ -76,7 +76,7 @@ namespace Google.ProtocolBuffers.ProtoGen
DescriptorUtil
.
GetQualifiedUmbrellaClassName
(
Descriptor
.
File
.
CSharpOptions
),
DescriptorUtil
.
GetQualifiedUmbrellaClassName
(
Descriptor
.
File
.
CSharpOptions
),
Descriptor
.
Index
);
Descriptor
.
Index
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"
{0} pbd::ServiceDescriptor DescriptorForType {{"
,
ClassAccessLevel
);
writer
.
WriteLine
(
"
public pbd::ServiceDescriptor DescriptorForType {"
);
writer
.
WriteLine
(
" get { return Descriptor; }"
);
writer
.
WriteLine
(
" get { return Descriptor; }"
);
writer
.
WriteLine
(
"}"
);
writer
.
WriteLine
(
"}"
);
...
@@ -92,7 +92,7 @@ namespace Google.ProtocolBuffers.ProtoGen
...
@@ -92,7 +92,7 @@ namespace Google.ProtocolBuffers.ProtoGen
private
void
GenerateCallMethod
(
TextGenerator
writer
)
private
void
GenerateCallMethod
(
TextGenerator
writer
)
{
{
writer
.
WriteLine
();
writer
.
WriteLine
();
writer
.
WriteLine
(
"public void CallMethod("
,
ClassAccessLevel
);
writer
.
WriteLine
(
"public void CallMethod("
);
writer
.
WriteLine
(
" pbd::MethodDescriptor method,"
);
writer
.
WriteLine
(
" pbd::MethodDescriptor method,"
);
writer
.
WriteLine
(
" pb::IRpcController controller,"
);
writer
.
WriteLine
(
" pb::IRpcController controller,"
);
writer
.
WriteLine
(
" pb::IMessage request,"
);
writer
.
WriteLine
(
" pb::IMessage request,"
);
...
@@ -174,7 +174,8 @@ namespace Google.ProtocolBuffers.ProtoGen
...
@@ -174,7 +174,8 @@ namespace Google.ProtocolBuffers.ProtoGen
foreach
(
MethodDescriptor
method
in
Descriptor
.
Methods
)
foreach
(
MethodDescriptor
method
in
Descriptor
.
Methods
)
{
{
writer
.
WriteLine
();
writer
.
WriteLine
();
writer
.
WriteLine
(
"public override void {0}("
,
NameHelpers
.
UnderscoresToPascalCase
(
method
.
Name
));
writer
.
WriteLine
(
"{0} override void {1}("
,
ClassAccessLevel
,
NameHelpers
.
UnderscoresToPascalCase
(
method
.
Name
));
writer
.
WriteLine
(
" pb::IRpcController controller,"
);
writer
.
WriteLine
(
" pb::IRpcController controller,"
);
writer
.
WriteLine
(
" {0} request,"
,
GetClassName
(
method
.
InputType
));
writer
.
WriteLine
(
" {0} request,"
,
GetClassName
(
method
.
InputType
));
writer
.
WriteLine
(
" global::System.Action<{0}> done) {{"
,
GetClassName
(
method
.
OutputType
));
writer
.
WriteLine
(
" global::System.Action<{0}> done) {{"
,
GetClassName
(
method
.
OutputType
));
...
...
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