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
e4954773
Commit
e4954773
authored
Nov 09, 2010
by
csharptest
Committed by
unknown
Nov 09, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Testing
parent
7d396f9d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
563 additions
and
6 deletions
+563
-6
ProtocolBuffers.build
ProtocolBuffers.build
+2
-0
unittest_extras_full.proto
protos/extest/unittest_extras_full.proto
+49
-0
unittest_extras_lite.proto
protos/extest/unittest_extras_lite.proto
+39
-1
ExtensionGenerator.cs
src/ProtoGen/ExtensionGenerator.cs
+3
-0
ExtendableMessageTest.cs
src/ProtocolBuffers.Test/ExtendableMessageTest.cs
+5
-0
ProtocolBuffers.sln
src/ProtocolBuffers.sln
+1
-0
GeneratedExtensionLite.cs
src/ProtocolBuffers/GeneratedExtensionLite.cs
+3
-1
AbstractBuilderLiteTest.cs
src/ProtocolBuffersLite.Test/AbstractBuilderLiteTest.cs
+121
-4
AbstractMessageLiteTest.cs
src/ProtocolBuffersLite.Test/AbstractMessageLiteTest.cs
+126
-0
ExtendableMessageLiteTest.cs
src/ProtocolBuffersLite.Test/ExtendableMessageLiteTest.cs
+0
-0
InteropLiteTest.cs
src/ProtocolBuffersLite.Test/InteropLiteTest.cs
+115
-0
ProtocolBuffersLite.Test.csproj
src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj
+1
-0
ProtocolBuffersLiteMixed.Test.csproj
...ocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj
+98
-0
UnitTestExtrasFullProtoFile.cs
...uffersLite.Test/TestProtos/UnitTestExtrasFullProtoFile.cs
+0
-0
UnitTestExtrasLiteProtoFile.cs
...uffersLite.Test/TestProtos/UnitTestExtrasLiteProtoFile.cs
+0
-0
No files found.
ProtocolBuffers.build
View file @
e4954773
...
...
@@ -151,6 +151,7 @@
<arg
file=
"${protos-dir}/google/protobuf/unittest_lite_imports_nonlite.proto"
/>
<arg
file=
"${protos-dir}/google/protobuf/unittest_no_generic_services.proto"
/>
<arg
file=
"${protos-dir}/extest/unittest_extras_full.proto"
/>
<arg
file=
"${protos-dir}/extest/unittest_extras_lite.proto"
/>
<arg
file=
"${protos-dir}/tutorial/addressbook.proto"
/>
</exec>
...
...
@@ -188,6 +189,7 @@
<copy
todir=
"${src}/ProtocolBuffersLite.Test/TestProtos"
>
<fileset
basedir=
"${tmp-dir}"
>
<include
name=
"UnitTestExtrasFullProtoFile.cs"
/>
<include
name=
"UnitTestExtrasLiteProtoFile.cs"
/>
<include
name=
"UnitTestImportLiteProtoFile.cs"
/>
<include
name=
"UnitTestImportProtoFile.cs"
/>
...
...
protos/extest/unittest_extras_full.proto
0 → 100644
View file @
e4954773
// Additional options required for C# generation. File from copyright
// line onwards is as per original distribution.
import
"google/protobuf/csharp_options.proto"
;
option
(
google.protobuf.csharp_file_options
)
.
namespace
=
"Google.ProtocolBuffers.TestProtos"
;
option
(
google.protobuf.csharp_file_options
)
.
umbrella_classname
=
"UnitTestExtrasFullProtoFile"
;
package
protobuf_unittest_extra
;
option
optimize_for
=
CODE_SIZE
;
option
java_package
=
"com.google.protobuf"
;
message
TestInteropPerson
{
required
string
name
=
1
;
required
int32
id
=
2
;
optional
string
email
=
3
;
repeated
int32
codes
=
10
[
packed
=
true
];
enum
PhoneType
{
MOBILE
=
0
;
HOME
=
1
;
WORK
=
2
;
}
message
PhoneNumber
{
required
string
number
=
1
;
optional
PhoneType
type
=
2
[
default
=
HOME
];
}
repeated
PhoneNumber
phone
=
4
;
repeated
group
Addresses
=
5
{
required
string
address
=
1
;
optional
string
address2
=
2
;
required
string
city
=
3
;
required
string
state
=
4
;
required
fixed32
zip
=
5
;
}
extensions
100
to
199
;
}
message
TestInteropEmployeeId
{
required
string
number
=
1
;
}
extend
TestInteropPerson
{
required
TestInteropEmployeeId
employee_id
=
126
;
}
protos/extest/unittest_extras_lite.proto
View file @
e4954773
...
...
@@ -16,8 +16,46 @@ message TestRequiredLite {
}
enum
ExtraEnum
{
DEFAULT
=
1
;
DEFAULT
=
1
0
;
EXLITE_FOO
=
7
;
EXLITE_BAR
=
8
;
EXLITE_BAZ
=
9
;
}
message
TestInteropPersonLite
{
required
string
name
=
1
;
required
int32
id
=
2
;
optional
string
email
=
3
;
repeated
int32
codes
=
10
[
packed
=
true
];
enum
PhoneType
{
MOBILE
=
0
;
HOME
=
1
;
WORK
=
2
;
}
message
PhoneNumber
{
required
string
number
=
1
;
optional
PhoneType
type
=
2
[
default
=
HOME
];
}
repeated
PhoneNumber
phone
=
4
;
repeated
group
Addresses
=
5
{
required
string
address
=
1
;
optional
string
address2
=
2
;
required
string
city
=
3
;
required
string
state
=
4
;
required
fixed32
zip
=
5
;
}
extensions
100
to
199
;
}
message
TestInteropEmployeeIdLite
{
required
string
number
=
1
;
}
extend
TestInteropPersonLite
{
required
TestInteropEmployeeIdLite
employee_id_lite
=
126
;
}
src/ProtoGen/ExtensionGenerator.cs
View file @
e4954773
...
...
@@ -70,6 +70,9 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer
.
WriteLine
(
"public const int {0} = {1};"
,
GetFieldConstantName
(
Descriptor
),
Descriptor
.
FieldNumber
);
if
(
UseLiteRuntime
)
{
if
(
Descriptor
.
MappedType
==
MappedType
.
Message
&&
Descriptor
.
MessageType
.
Options
.
MessageSetWireFormat
)
{
throw
new
ArgumentException
(
"option message_set_wire_format = true; is not supported in Lite runtime extensions."
);
}
if
(!
Descriptor
.
IsCLSCompliant
&&
Descriptor
.
File
.
CSharpOptions
.
ClsCompliance
)
{
writer
.
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
}
...
...
src/ProtocolBuffers.Test/ExtendableMessageTest.cs
View file @
e4954773
...
...
@@ -42,6 +42,11 @@ namespace Google.ProtocolBuffers {
[
TestFixture
]
public
class
ExtendableMessageTest
{
[
Test
,
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
ExtensionWriterInvalidExtension
()
{
TestPackedExtensions
.
CreateBuilder
()[
UnitTestProtoFile
.
OptionalForeignMessageExtension
.
Descriptor
]
=
ForeignMessage
.
DefaultInstance
;
}
[
Test
]
public
void
ExtensionWriterTest
()
{
...
...
src/ProtocolBuffers.sln
View file @
e4954773
...
...
@@ -38,6 +38,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "unittest", "unittest", "{C8
..\protos\google\protobuf\unittest_embed_optimize_for.proto = ..\protos\google\protobuf\unittest_embed_optimize_for.proto
..\protos\google\protobuf\unittest_empty.proto = ..\protos\google\protobuf\unittest_empty.proto
..\protos\google\protobuf\unittest_enormous_descriptor.proto = ..\protos\google\protobuf\unittest_enormous_descriptor.proto
..\protos\extest\unittest_extras_full.proto = ..\protos\extest\unittest_extras_full.proto
..\protos\extest\unittest_extras_lite.proto = ..\protos\extest\unittest_extras_lite.proto
..\protos\google\protobuf\unittest_import.proto = ..\protos\google\protobuf\unittest_import.proto
..\protos\google\protobuf\unittest_import_lite.proto = ..\protos\google\protobuf\unittest_import_lite.proto
...
...
src/ProtocolBuffers/GeneratedExtensionLite.cs
View file @
e4954773
...
...
@@ -82,7 +82,9 @@ namespace Google.ProtocolBuffers {
get
{
return
true
;
}
}
#warning ToDo - Discover the meaning and purpose of this durring serialization and return the correct value
/// <summary>
/// This is not supported and assertions are made to ensure this does not exist on extensions of Lite types
/// </summary>
public
bool
MessageSetWireFormat
{
get
{
return
false
;
}
}
...
...
src/ProtocolBuffersLite.Test/AbstractBuilderLiteTest.cs
View file @
e4954773
...
...
@@ -71,24 +71,128 @@ namespace Google.ProtocolBuffers {
}
[
Test
]
public
void
Test
IBuilderLiteWeakMergeFromByteString
()
{
public
void
Test
BuilderLiteMergeFromCodedInputStream
()
{
TestAllTypesLite
copy
,
msg
=
TestAllTypesLite
.
CreateBuilder
()
.
SetOptionalString
(
"Should be merged."
).
Build
();
copy
=
TestAllTypesLite
.
DefaultInstance
;
Assert
.
AreNotEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
copy
=
(
TestAllTypesLite
)((
IBuilderLite
)
copy
.
ToBuilder
()).
WeakMergeFrom
(
msg
.
ToByteString
()).
WeakBuild
();
copy
=
copy
.
ToBuilder
().
MergeFrom
(
CodedInputStream
.
CreateInstance
(
new
MemoryStream
(
msg
.
ToByteArray
()))).
Build
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
}
[
Test
]
public
void
TestBuilderLiteMergeDelimitedFrom
()
{
TestAllTypesLite
copy
,
msg
=
TestAllTypesLite
.
CreateBuilder
()
.
SetOptionalString
(
"Should be merged."
).
Build
();
copy
=
TestAllTypesLite
.
DefaultInstance
;
Assert
.
AreNotEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
Stream
s
=
new
MemoryStream
();
msg
.
WriteDelimitedTo
(
s
);
s
.
Position
=
0
;
copy
=
copy
.
ToBuilder
().
MergeDelimitedFrom
(
s
).
Build
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
}
[
Test
]
public
void
TestBuilderLiteMergeDelimitedFromExtensions
()
{
TestAllExtensionsLite
copy
,
msg
=
TestAllExtensionsLite
.
CreateBuilder
()
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalStringExtensionLite
,
"Should be merged."
).
Build
();
copy
=
TestAllExtensionsLite
.
DefaultInstance
;
Assert
.
AreNotEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
Stream
s
=
new
MemoryStream
();
msg
.
WriteDelimitedTo
(
s
);
s
.
Position
=
0
;
ExtensionRegistry
registry
=
ExtensionRegistry
.
CreateInstance
();
UnitTestLiteProtoFile
.
RegisterAllExtensions
(
registry
);
copy
=
copy
.
ToBuilder
().
MergeDelimitedFrom
(
s
,
registry
).
Build
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
Assert
.
AreEqual
(
"Should be merged."
,
copy
.
GetExtension
(
UnitTestLiteProtoFile
.
OptionalStringExtensionLite
));
}
[
Test
]
public
void
TestBuilderLiteMergeFromStream
()
{
TestAllTypesLite
copy
,
msg
=
TestAllTypesLite
.
CreateBuilder
()
.
SetOptionalString
(
"Should be merged."
).
Build
();
copy
=
TestAllTypesLite
.
DefaultInstance
;
Assert
.
AreNotEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
Stream
s
=
new
MemoryStream
();
msg
.
WriteTo
(
s
);
s
.
Position
=
0
;
copy
=
copy
.
ToBuilder
().
MergeFrom
(
s
).
Build
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
}
[
Test
]
public
void
TestBuilderLiteMergeFromStreamExtensions
()
{
TestAllExtensionsLite
copy
,
msg
=
TestAllExtensionsLite
.
CreateBuilder
()
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalStringExtensionLite
,
"Should be merged."
).
Build
();
copy
=
TestAllExtensionsLite
.
DefaultInstance
;
Assert
.
AreNotEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
Stream
s
=
new
MemoryStream
();
msg
.
WriteTo
(
s
);
s
.
Position
=
0
;
ExtensionRegistry
registry
=
ExtensionRegistry
.
CreateInstance
();
UnitTestLiteProtoFile
.
RegisterAllExtensions
(
registry
);
copy
=
copy
.
ToBuilder
().
MergeFrom
(
s
,
registry
).
Build
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
Assert
.
AreEqual
(
"Should be merged."
,
copy
.
GetExtension
(
UnitTestLiteProtoFile
.
OptionalStringExtensionLite
));
}
[
Test
]
public
void
TestIBuilderLiteWeakMergeFromIMessageLite
()
{
TestAllTypesLite
copy
,
msg
=
TestAllTypesLite
.
CreateBuilder
()
.
SetOptionalString
(
"Should be merged."
).
Build
();
//again with extension registry
copy
=
TestAllTypesLite
.
DefaultInstance
;
Assert
.
AreNotEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
copy
=
(
TestAllTypesLite
)((
IBuilderLite
)
copy
.
ToBuilder
()).
WeakMergeFrom
(
msg
.
ToByteString
(),
ExtensionRegistry
.
Empty
).
WeakBuild
();
copy
=
(
TestAllTypesLite
)((
IBuilderLite
)
copy
.
ToBuilder
()).
WeakMergeFrom
(
(
IMessageLite
)
msg
).
WeakBuild
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
}
[
Test
]
public
void
TestIBuilderLiteWeakMergeFromByteString
()
{
TestAllTypesLite
copy
,
msg
=
TestAllTypesLite
.
CreateBuilder
()
.
SetOptionalString
(
"Should be merged."
).
Build
();
copy
=
TestAllTypesLite
.
DefaultInstance
;
Assert
.
AreNotEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
copy
=
(
TestAllTypesLite
)((
IBuilderLite
)
copy
.
ToBuilder
()).
WeakMergeFrom
(
msg
.
ToByteString
()).
WeakBuild
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
}
[
Test
]
public
void
TestIBuilderLiteWeakMergeFromByteStringExtensions
()
{
TestAllExtensionsLite
copy
,
msg
=
TestAllExtensionsLite
.
CreateBuilder
()
.
SetExtension
(
UnitTestLiteProtoFile
.
OptionalStringExtensionLite
,
"Should be merged."
).
Build
();
copy
=
TestAllExtensionsLite
.
DefaultInstance
;
Assert
.
AreNotEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
copy
=
(
TestAllExtensionsLite
)((
IBuilderLite
)
copy
.
ToBuilder
()).
WeakMergeFrom
(
msg
.
ToByteString
(),
ExtensionRegistry
.
Empty
).
WeakBuild
();
Assert
.
AreNotEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
ExtensionRegistry
registry
=
ExtensionRegistry
.
CreateInstance
();
UnitTestLiteProtoFile
.
RegisterAllExtensions
(
registry
);
copy
=
(
TestAllExtensionsLite
)((
IBuilderLite
)
copy
.
ToBuilder
()).
WeakMergeFrom
(
msg
.
ToByteString
(),
registry
).
WeakBuild
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
Assert
.
AreEqual
(
"Should be merged."
,
copy
.
GetExtension
(
UnitTestLiteProtoFile
.
OptionalStringExtensionLite
));
}
[
Test
]
public
void
TestIBuilderLiteWeakMergeFromCodedInputStream
()
{
TestAllTypesLite
copy
,
msg
=
TestAllTypesLite
.
CreateBuilder
()
...
...
@@ -147,5 +251,18 @@ namespace Google.ProtocolBuffers {
Assert
.
IsTrue
(
ReferenceEquals
(
TestRequiredLite
.
DefaultInstance
,
((
IBuilderLite
)
TestRequiredLite
.
CreateBuilder
()).
WeakDefaultInstanceForType
));
}
[
Test
]
public
void
TestGeneratedBuilderLiteAddRange
()
{
TestAllTypesLite
copy
,
msg
=
TestAllTypesLite
.
CreateBuilder
()
.
SetOptionalUint32
(
123
)
.
AddRepeatedInt32
(
1
)
.
AddRepeatedInt32
(
2
)
.
AddRepeatedInt32
(
3
)
.
Build
();
copy
=
msg
.
DefaultInstanceForType
.
ToBuilder
().
MergeFrom
(
msg
).
Build
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
}
}
}
src/ProtocolBuffersLite.Test/AbstractMessageLiteTest.cs
0 → 100644
View file @
e4954773
#
region
Copyright
notice
and
license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
Google.ProtocolBuffers
;
using
Google.ProtocolBuffers.TestProtos
;
using
NUnit.Framework
;
namespace
Google.ProtocolBuffers
{
[
TestFixture
]
public
class
AbstractMessageLiteTest
{
[
Test
]
public
void
TestMessageLiteToByteString
()
{
TestRequiredLite
msg
=
TestRequiredLite
.
CreateBuilder
()
.
SetD
(
42
)
.
SetEn
(
ExtraEnum
.
EXLITE_BAZ
)
.
Build
();
ByteString
b
=
msg
.
ToByteString
();
Assert
.
AreEqual
(
4
,
b
.
Length
);
Assert
.
AreEqual
(
TestRequiredLite
.
DFieldNumber
<<
3
,
b
[
0
]);
Assert
.
AreEqual
(
42
,
b
[
1
]);
Assert
.
AreEqual
(
TestRequiredLite
.
EnFieldNumber
<<
3
,
b
[
2
]);
Assert
.
AreEqual
((
int
)
ExtraEnum
.
EXLITE_BAZ
,
b
[
3
]);
}
[
Test
]
public
void
TestMessageLiteToByteArray
()
{
TestRequiredLite
msg
=
TestRequiredLite
.
CreateBuilder
()
.
SetD
(
42
)
.
SetEn
(
ExtraEnum
.
EXLITE_BAZ
)
.
Build
();
ByteString
b
=
msg
.
ToByteString
();
ByteString
copy
=
ByteString
.
CopyFrom
(
msg
.
ToByteArray
());
Assert
.
AreEqual
(
b
,
copy
);
}
[
Test
]
public
void
TestMessageLiteWriteTo
()
{
TestRequiredLite
msg
=
TestRequiredLite
.
CreateBuilder
()
.
SetD
(
42
)
.
SetEn
(
ExtraEnum
.
EXLITE_BAZ
)
.
Build
();
MemoryStream
ms
=
new
MemoryStream
();
msg
.
WriteTo
(
ms
);
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
ms
.
ToArray
());
}
[
Test
]
public
void
TestMessageLiteWriteDelimitedTo
()
{
TestRequiredLite
msg
=
TestRequiredLite
.
CreateBuilder
()
.
SetD
(
42
)
.
SetEn
(
ExtraEnum
.
EXLITE_BAZ
)
.
Build
();
MemoryStream
ms
=
new
MemoryStream
();
msg
.
WriteDelimitedTo
(
ms
);
byte
[]
buffer
=
ms
.
ToArray
();
Assert
.
AreEqual
(
5
,
buffer
.
Length
);
Assert
.
AreEqual
(
4
,
buffer
[
0
]);
byte
[]
msgBytes
=
new
byte
[
4
];
Array
.
Copy
(
buffer
,
1
,
msgBytes
,
0
,
4
);
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
msgBytes
);
}
[
Test
]
public
void
TestIMessageLiteWeakCreateBuilderForType
()
{
IMessageLite
msg
=
TestRequiredLite
.
DefaultInstance
;
Assert
.
AreEqual
(
typeof
(
TestRequiredLite
.
Builder
),
msg
.
WeakCreateBuilderForType
().
GetType
());
}
[
Test
]
public
void
TestMessageLiteWeakToBuilder
()
{
IMessageLite
msg
=
TestRequiredLite
.
CreateBuilder
()
.
SetD
(
42
)
.
SetEn
(
ExtraEnum
.
EXLITE_BAZ
)
.
Build
();
IMessageLite
copy
=
msg
.
WeakToBuilder
().
WeakBuild
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
}
[
Test
]
public
void
TestMessageLiteWeakDefaultInstanceForType
()
{
IMessageLite
msg
=
TestRequiredLite
.
DefaultInstance
;
Assert
.
IsTrue
(
Object
.
ReferenceEquals
(
TestRequiredLite
.
DefaultInstance
,
msg
.
WeakDefaultInstanceForType
));
}
}
}
src/ProtocolBuffersLite.Test/ExtendableMessageLiteTest.cs
View file @
e4954773
This diff is collapsed.
Click to expand it.
src/ProtocolBuffersLite.Test/InteropLiteTest.cs
0 → 100644
View file @
e4954773
#
region
Copyright
notice
and
license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using
System
;
using
System.Collections.Generic
;
using
Google.ProtocolBuffers
;
using
Google.ProtocolBuffers.TestProtos
;
using
NUnit.Framework
;
namespace
Google.ProtocolBuffers
{
[
TestFixture
]
public
class
InteropLiteTest
{
[
Test
]
public
void
TestConvertFromFullMinimal
()
{
TestInteropPerson
person
=
TestInteropPerson
.
CreateBuilder
()
.
SetId
(
123
)
.
SetName
(
"abc"
)
.
Build
();
Assert
.
IsTrue
(
person
.
IsInitialized
);
TestInteropPersonLite
copy
=
TestInteropPersonLite
.
ParseFrom
(
person
.
ToByteArray
());
Assert
.
AreEqual
(
person
.
ToByteArray
(),
copy
.
ToByteArray
());
}
[
Test
]
public
void
TestConvertFromFullComplete
()
{
TestInteropPerson
person
=
TestInteropPerson
.
CreateBuilder
()
.
SetId
(
123
)
.
SetName
(
"abc"
)
.
SetEmail
(
"abc@123.com"
)
.
AddRangeCodes
(
new
[]
{
1
,
2
,
3
})
.
AddPhone
(
TestInteropPerson
.
Types
.
PhoneNumber
.
CreateBuilder
().
SetNumber
(
"555-1234"
).
Build
())
.
AddPhone
(
TestInteropPerson
.
Types
.
PhoneNumber
.
CreateBuilder
().
SetNumber
(
"555-5678"
).
Build
())
.
AddAddresses
(
TestInteropPerson
.
Types
.
Addresses
.
CreateBuilder
().
SetAddress
(
"123 Seseme"
).
SetCity
(
"Wonderland"
).
SetState
(
"NA"
).
SetZip
(
12345
).
Build
())
.
SetExtension
(
UnitTestExtrasFullProtoFile
.
EmployeeId
,
TestInteropEmployeeId
.
CreateBuilder
().
SetNumber
(
"123"
).
Build
())
.
Build
();
Assert
.
IsTrue
(
person
.
IsInitialized
);
ExtensionRegistry
registry
=
ExtensionRegistry
.
CreateInstance
();
UnitTestExtrasLiteProtoFile
.
RegisterAllExtensions
(
registry
);
TestInteropPersonLite
copy
=
TestInteropPersonLite
.
ParseFrom
(
person
.
ToByteArray
(),
registry
);
Assert
.
AreEqual
(
person
.
ToByteArray
(),
copy
.
ToByteArray
());
}
[
Test
]
public
void
TestConvertFromLiteMinimal
()
{
TestInteropPersonLite
person
=
TestInteropPersonLite
.
CreateBuilder
()
.
SetId
(
123
)
.
SetName
(
"abc"
)
.
Build
();
Assert
.
IsTrue
(
person
.
IsInitialized
);
TestInteropPerson
copy
=
TestInteropPerson
.
ParseFrom
(
person
.
ToByteArray
());
Assert
.
AreEqual
(
person
.
ToByteArray
(),
copy
.
ToByteArray
());
}
[
Test
]
public
void
TestConvertFromLiteComplete
()
{
TestInteropPersonLite
person
=
TestInteropPersonLite
.
CreateBuilder
()
.
SetId
(
123
)
.
SetName
(
"abc"
)
.
SetEmail
(
"abc@123.com"
)
.
AddRangeCodes
(
new
[]
{
1
,
2
,
3
})
.
AddPhone
(
TestInteropPersonLite
.
Types
.
PhoneNumber
.
CreateBuilder
().
SetNumber
(
"555-1234"
).
Build
())
.
AddPhone
(
TestInteropPersonLite
.
Types
.
PhoneNumber
.
CreateBuilder
().
SetNumber
(
"555-5678"
).
Build
())
.
AddAddresses
(
TestInteropPersonLite
.
Types
.
Addresses
.
CreateBuilder
().
SetAddress
(
"123 Seseme"
).
SetCity
(
"Wonderland"
).
SetState
(
"NA"
).
SetZip
(
12345
).
Build
())
.
SetExtension
(
UnitTestExtrasLiteProtoFile
.
EmployeeIdLite
,
TestInteropEmployeeIdLite
.
CreateBuilder
().
SetNumber
(
"123"
).
Build
())
.
Build
();
Assert
.
IsTrue
(
person
.
IsInitialized
);
ExtensionRegistry
registry
=
ExtensionRegistry
.
CreateInstance
();
UnitTestExtrasFullProtoFile
.
RegisterAllExtensions
(
registry
);
TestInteropPerson
copy
=
TestInteropPerson
.
ParseFrom
(
person
.
ToByteArray
(),
registry
);
Assert
.
AreEqual
(
person
.
ToByteArray
(),
copy
.
ToByteArray
());
}
}
}
src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj
View file @
e4954773
...
...
@@ -58,6 +58,7 @@
<Link>
Properties\AssemblyInfo.cs
</Link>
</Compile>
<Compile
Include=
"AbstractBuilderLiteTest.cs"
/>
<Compile
Include=
"AbstractMessageLiteTest.cs"
/>
<Compile
Include=
"ExtendableBuilderLiteTest.cs"
/>
<Compile
Include=
"ExtendableMessageLiteTest.cs"
/>
<Compile
Include=
"LiteTest.cs"
/>
...
...
src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj
0 → 100644
View file @
e4954773
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"3.5"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProductVersion>
9.0.30729
</ProductVersion>
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{EEFFED24-3750-4567-9A23-1DB676A15610}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
Google.ProtocolBuffers
</RootNamespace>
<AssemblyName>
Google.ProtocolBuffersMixedLite.Test
</AssemblyName>
<TargetFrameworkVersion>
v2.0
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<SignAssembly>
true
</SignAssembly>
<AssemblyOriginatorKeyFile>
..\ProtocolBuffers.Test\Properties\Google.ProtocolBuffers.Test.snk
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Silverlight2|AnyCPU' "
>
<OutputPath>
bin\Silverlight2\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<Optimize>
true
</Optimize>
<DebugType>
pdbonly
</DebugType>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<ErrorReport>
prompt
</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"
>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
..\..\lib\nunit.framework.dll
</HintPath>
</Reference>
<Reference
Include=
"Rhino.Mocks, Version=3.5.0.2, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL"
>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
..\..\lib\Rhino.Mocks.dll
</HintPath>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"..\ProtocolBuffers.Test\Properties\AssemblyInfo.cs"
>
<Link>
Properties\AssemblyInfo.cs
</Link>
</Compile>
<Compile
Include=
"..\ProtocolBuffers.Test\TestProtos\FIXUP.cs"
>
<Link>
TestProtos\FIXUP.cs
</Link>
</Compile>
<Compile
Include=
"AbstractBuilderLiteTest.cs"
/>
<Compile
Include=
"AbstractMessageLiteTest.cs"
/>
<Compile
Include=
"ExtendableBuilderLiteTest.cs"
/>
<Compile
Include=
"ExtendableMessageLiteTest.cs"
/>
<Compile
Include=
"InteropLiteTest.cs"
/>
<Compile
Include=
"LiteTest.cs"
/>
<Compile
Include=
"TestLiteByApi.cs"
/>
<Compile
Include=
"TestProtos\UnitTestExtrasFullProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestExtrasLiteProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestImportLiteProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestImportProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestLiteImportNonLiteProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestLiteProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestProtoFile.cs"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"..\ProtocolBuffers.Test\Properties\Google.ProtocolBuffers.Test.snk"
>
<Link>
Properties\Google.ProtocolBuffers.Test.snk
</Link>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\ProtocolBuffers\ProtocolBuffers.csproj"
>
<Project>
{6908BDCE-D925-43F3-94AC-A531E6DF2591}
</Project>
<Name>
ProtocolBuffers
</Name>
</ProjectReference>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasFullProtoFile.cs
0 → 100644
View file @
e4954773
This diff is collapsed.
Click to expand it.
src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasLiteProtoFile.cs
View file @
e4954773
This diff is collapsed.
Click to expand it.
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