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
c2a1f9b5
Commit
c2a1f9b5
authored
Jun 06, 2011
by
csharptest
Committed by
rogerk
Jun 06, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit testing of Packed/Unpacked parsing in Lite
parent
6da3170a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
37 deletions
+121
-37
unittest_lite.proto
protos/google/protobuf/unittest_lite.proto
+38
-0
ExtendableMessageLiteTest.cs
src/ProtocolBuffersLite.Test/ExtendableMessageLiteTest.cs
+83
-37
UnitTestLiteProtoFile.cs
...tocolBuffersLite.Test/TestProtos/UnitTestLiteProtoFile.cs
+0
-0
No files found.
protos/google/protobuf/unittest_lite.proto
View file @
c2a1f9b5
...
...
@@ -178,6 +178,23 @@ message TestPackedTypesLite {
repeated
ForeignEnumLite
packed_enum
=
103
[
packed
=
true
];
}
message
TestUnpackedTypesLite
{
repeated
int32
unpacked_int32
=
90
;
repeated
int64
unpacked_int64
=
91
;
repeated
uint32
unpacked_uint32
=
92
;
repeated
uint64
unpacked_uint64
=
93
;
repeated
sint32
unpacked_sint32
=
94
;
repeated
sint64
unpacked_sint64
=
95
;
repeated
fixed32
unpacked_fixed32
=
96
;
repeated
fixed64
unpacked_fixed64
=
97
;
repeated
sfixed32
unpacked_sfixed32
=
98
;
repeated
sfixed64
unpacked_sfixed64
=
99
;
repeated
float
unpacked_float
=
100
;
repeated
double
unpacked_double
=
101
;
repeated
bool
unpacked_bool
=
102
;
repeated
ForeignEnumLite
unpacked_enum
=
103
;
}
message
TestAllExtensionsLite
{
extensions
1
to
max
;
}
...
...
@@ -305,6 +322,27 @@ extend TestPackedExtensionsLite {
repeated
ForeignEnumLite
packed_enum_extension_lite
=
103
[
packed
=
true
];
}
message
TestUnpackedExtensionsLite
{
extensions
1
to
max
;
}
extend
TestUnpackedExtensionsLite
{
repeated
int32
unpacked_int32_extension_lite
=
90
;
repeated
int64
unpacked_int64_extension_lite
=
91
;
repeated
uint32
unpacked_uint32_extension_lite
=
92
;
repeated
uint64
unpacked_uint64_extension_lite
=
93
;
repeated
sint32
unpacked_sint32_extension_lite
=
94
;
repeated
sint64
unpacked_sint64_extension_lite
=
95
;
repeated
fixed32
unpacked_fixed32_extension_lite
=
96
;
repeated
fixed64
unpacked_fixed64_extension_lite
=
97
;
repeated
sfixed32
unpacked_sfixed32_extension_lite
=
98
;
repeated
sfixed64
unpacked_sfixed64_extension_lite
=
99
;
repeated
float
unpacked_float_extension_lite
=
100
;
repeated
double
unpacked_double_extension_lite
=
101
;
repeated
bool
unpacked_bool_extension_lite
=
102
;
repeated
ForeignEnumLite
unpacked_enum_extension_lite
=
103
;
}
message
TestNestedExtensionLite
{
extend
TestAllExtensionsLite
{
optional
int32
nested_extension
=
12345
;
...
...
src/ProtocolBuffersLite.Test/ExtendableMessageLiteTest.cs
View file @
c2a1f9b5
...
...
@@ -258,48 +258,42 @@ namespace Google.ProtocolBuffers
Assert
.
AreEqual
(
123u
,
copy
.
GetExtension
(
UnitTestLiteProtoFile
.
RepeatedUint64ExtensionLite
,
0
));
}
[
Test
]
public
void
ExtensionWriterTestPacked
()
private
TestPackedExtensionsLite
BuildPackedExtensions
()
{
TestPackedExtensionsLite
.
Builder
builder
=
TestPackedExtensionsLite
.
CreateBuilder
()
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedBoolExtensionLite
,
true
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedDoubleExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFixed32ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFixed64ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFloatExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedInt32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedInt64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSfixed32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSfixed64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSint32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSint64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedUint32ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedUint64ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedBoolExtensionLite
,
true
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedDoubleExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFixed32ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFixed64ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFloatExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedInt32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedInt64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSfixed32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSfixed64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSint32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSint64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedUint32ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedUint64ExtensionLite
,
123u
);
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedBoolExtensionLite
,
true
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedDoubleExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFixed32ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFixed64ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFloatExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedInt32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedInt64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSfixed32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSfixed64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSint32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSint64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedUint32ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedUint64ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedBoolExtensionLite
,
true
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedDoubleExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFixed32ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFixed64ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedFloatExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedInt32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedInt64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSfixed32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSfixed64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSint32ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedSint64ExtensionLite
,
123
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedUint32ExtensionLite
,
123u
)
.
AddExtension
(
UnitTestLiteProtoFile
.
PackedUint64ExtensionLite
,
123u
);
TestPackedExtensionsLite
msg
=
builder
.
Build
();
return
msg
;
}
ExtensionRegistry
registry
=
ExtensionRegistry
.
CreateInstance
();
UnitTestLiteProtoFile
.
RegisterAllExtensions
(
registry
);
TestPackedExtensionsLite
.
Builder
copyBuilder
=
TestPackedExtensionsLite
.
CreateBuilder
().
MergeFrom
(
msg
.
ToByteArray
(),
registry
);
TestPackedExtensionsLite
copy
=
copyBuilder
.
Build
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
private
void
AssertPackedExtensions
(
TestPackedExtensionsLite
copy
)
{
Assert
.
AreEqual
(
true
,
copy
.
GetExtension
(
UnitTestLiteProtoFile
.
PackedBoolExtensionLite
,
0
));
Assert
.
AreEqual
(
123
,
copy
.
GetExtension
(
UnitTestLiteProtoFile
.
PackedDoubleExtensionLite
,
0
));
Assert
.
AreEqual
(
123u
,
copy
.
GetExtension
(
UnitTestLiteProtoFile
.
PackedFixed32ExtensionLite
,
0
));
...
...
@@ -328,5 +322,56 @@ namespace Google.ProtocolBuffers
Assert
.
AreEqual
(
123u
,
copy
.
GetExtension
(
UnitTestLiteProtoFile
.
PackedUint32ExtensionLite
,
1
));
Assert
.
AreEqual
(
123u
,
copy
.
GetExtension
(
UnitTestLiteProtoFile
.
PackedUint64ExtensionLite
,
1
));
}
[
Test
]
public
void
ExtensionWriterTestPacked
()
{
TestPackedExtensionsLite
msg
=
BuildPackedExtensions
();
ExtensionRegistry
registry
=
ExtensionRegistry
.
CreateInstance
();
UnitTestLiteProtoFile
.
RegisterAllExtensions
(
registry
);
TestPackedExtensionsLite
.
Builder
copyBuilder
=
TestPackedExtensionsLite
.
CreateBuilder
().
MergeFrom
(
msg
.
ToByteArray
(),
registry
);
TestPackedExtensionsLite
copy
=
copyBuilder
.
Build
();
Assert
.
AreEqual
(
msg
.
ToByteArray
(),
copy
.
ToByteArray
());
AssertPackedExtensions
(
copy
);
}
[
Test
]
public
void
TestUnpackedAndPackedExtensions
()
{
TestPackedExtensionsLite
original
=
BuildPackedExtensions
();
AssertPackedExtensions
(
original
);
ExtensionRegistry
registry
=
ExtensionRegistry
.
CreateInstance
();
UnitTestLiteProtoFile
.
RegisterAllExtensions
(
registry
);
TestUnpackedExtensionsLite
unpacked
=
TestUnpackedExtensionsLite
.
ParseFrom
(
original
.
ToByteArray
(),
registry
);
TestPackedExtensionsLite
packed
=
TestPackedExtensionsLite
.
ParseFrom
(
unpacked
.
ToByteArray
(),
registry
);
Assert
.
AreEqual
(
original
,
packed
);
Assert
.
AreEqual
(
original
.
ToByteArray
(),
packed
.
ToByteArray
());
AssertPackedExtensions
(
packed
);
}
[
Test
]
public
void
TestUnpackedFromPackedInput
()
{
byte
[]
packedData
=
BuildPackedExtensions
().
ToByteArray
();
TestUnpackedTypesLite
unpacked
=
TestUnpackedTypesLite
.
ParseFrom
(
packedData
);
TestPackedTypesLite
packed
=
TestPackedTypesLite
.
ParseFrom
(
unpacked
.
ToByteArray
());
Assert
.
AreEqual
(
packedData
,
packed
.
ToByteArray
());
unpacked
=
TestUnpackedTypesLite
.
ParseFrom
(
packed
.
ToByteArray
());
ExtensionRegistry
registry
=
ExtensionRegistry
.
CreateInstance
();
UnitTestLiteProtoFile
.
RegisterAllExtensions
(
registry
);
AssertPackedExtensions
(
TestPackedExtensionsLite
.
ParseFrom
(
unpacked
.
ToByteArray
(),
registry
));
}
}
}
\ No newline at end of file
src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteProtoFile.cs
View file @
c2a1f9b5
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