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
18bf22c2
Commit
18bf22c2
authored
Sep 16, 2011
by
csharptest
Committed by
rogerk
Sep 16, 2011
Browse files
Options
Browse Files
Download
Plain Diff
merge issue-19
parents
cc5f7818
a105eac5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
212 additions
and
4 deletions
+212
-4
unittest_issues.proto
protos/extest/unittest_issues.proto
+15
-0
CodedInputStreamTest.cs
src/ProtocolBuffers.Test/CodedInputStreamTest.cs
+74
-0
CodedOutputStreamTest.cs
src/ProtocolBuffers.Test/CodedOutputStreamTest.cs
+80
-0
ProtocolBuffers.Test.csproj
src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
+1
-0
TestCornerCases.cs
src/ProtocolBuffers.Test/TestCornerCases.cs
+38
-0
UnitTestExtrasIssuesProtoFile.cs
...lBuffers.Test/TestProtos/UnitTestExtrasIssuesProtoFile.cs
+0
-0
CodedOutputStream.ComputeSize.cs
src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs
+2
-2
CodedOutputStream.cs
src/ProtocolBuffers/CodedOutputStream.cs
+2
-2
No files found.
protos/extest/unittest_issues.proto
View file @
18bf22c2
...
@@ -86,3 +86,17 @@ message NumberField {
...
@@ -86,3 +86,17 @@ message NumberField {
optional
int32
_01
=
1
;
optional
int32
_01
=
1
;
}
}
// issue 19 - negative enum values
enum
NegativeEnum
{
FiveBelow
=
-
5
;
MinusOne
=
-
1
;
Zero
=
0
;
}
message
NegativeEnumMessage
{
optional
NegativeEnum
value
=
1
;
repeated
NegativeEnum
values
=
2
;
repeated
NegativeEnum
packed_values
=
3
[
packed
=
true
];
}
\ No newline at end of file
src/ProtocolBuffers.Test/CodedInputStreamTest.cs
View file @
18bf22c2
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#endregion
#endregion
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
Google.ProtocolBuffers.TestProtos
;
using
Google.ProtocolBuffers.TestProtos
;
using
NUnit.Framework
;
using
NUnit.Framework
;
...
@@ -532,5 +533,77 @@ namespace Google.ProtocolBuffers
...
@@ -532,5 +533,77 @@ namespace Google.ProtocolBuffers
return
base
.
Read
(
buffer
,
offset
,
Math
.
Min
(
count
,
blockSize
));
return
base
.
Read
(
buffer
,
offset
,
Math
.
Min
(
count
,
blockSize
));
}
}
}
}
enum
TestNegEnum
{
None
=
0
,
Value
=
-
2
}
[
Test
]
public
void
TestNegativeEnum
()
{
byte
[]
bytes
=
new
byte
[
10
]
{
0xFE
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0x01
};
CodedInputStream
input
=
CodedInputStream
.
CreateInstance
(
bytes
);
object
unk
;
TestNegEnum
val
=
TestNegEnum
.
None
;
Assert
.
IsTrue
(
input
.
ReadEnum
(
ref
val
,
out
unk
));
Assert
.
IsTrue
(
input
.
IsAtEnd
);
Assert
.
AreEqual
(
TestNegEnum
.
Value
,
val
);
}
[
Test
]
public
void
TestNegativeEnumPackedArray
()
{
int
arraySize
=
1
+
(
10
*
5
);
int
msgSize
=
1
+
1
+
arraySize
;
byte
[]
bytes
=
new
byte
[
msgSize
];
CodedOutputStream
output
=
CodedOutputStream
.
CreateInstance
(
bytes
);
output
.
WritePackedInt32Array
(
8
,
""
,
arraySize
,
new
int
[]
{
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
});
Assert
.
AreEqual
(
0
,
output
.
SpaceLeft
);
CodedInputStream
input
=
CodedInputStream
.
CreateInstance
(
bytes
);
uint
tag
;
string
name
;
Assert
.
IsTrue
(
input
.
ReadTag
(
out
tag
,
out
name
));
List
<
TestNegEnum
>
values
=
new
List
<
TestNegEnum
>();
ICollection
<
object
>
unk
;
input
.
ReadEnumArray
(
tag
,
name
,
values
,
out
unk
);
Assert
.
AreEqual
(
2
,
values
.
Count
);
Assert
.
AreEqual
(
TestNegEnum
.
None
,
values
[
0
]);
Assert
.
AreEqual
(
TestNegEnum
.
Value
,
values
[
1
]);
Assert
.
IsNotNull
(
unk
);
Assert
.
AreEqual
(
4
,
unk
.
Count
);
}
[
Test
]
public
void
TestNegativeEnumArray
()
{
int
arraySize
=
1
+
1
+
(
11
*
5
);
int
msgSize
=
arraySize
;
byte
[]
bytes
=
new
byte
[
msgSize
];
CodedOutputStream
output
=
CodedOutputStream
.
CreateInstance
(
bytes
);
output
.
WriteInt32Array
(
8
,
""
,
new
int
[]
{
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
});
Assert
.
AreEqual
(
0
,
output
.
SpaceLeft
);
CodedInputStream
input
=
CodedInputStream
.
CreateInstance
(
bytes
);
uint
tag
;
string
name
;
Assert
.
IsTrue
(
input
.
ReadTag
(
out
tag
,
out
name
));
List
<
TestNegEnum
>
values
=
new
List
<
TestNegEnum
>();
ICollection
<
object
>
unk
;
input
.
ReadEnumArray
(
tag
,
name
,
values
,
out
unk
);
Assert
.
AreEqual
(
2
,
values
.
Count
);
Assert
.
AreEqual
(
TestNegEnum
.
None
,
values
[
0
]);
Assert
.
AreEqual
(
TestNegEnum
.
Value
,
values
[
1
]);
Assert
.
IsNotNull
(
unk
);
Assert
.
AreEqual
(
4
,
unk
.
Count
);
}
}
}
}
}
\ No newline at end of file
src/ProtocolBuffers.Test/CodedOutputStreamTest.cs
View file @
18bf22c2
...
@@ -34,6 +34,8 @@
...
@@ -34,6 +34,8 @@
#endregion
#endregion
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
Google.ProtocolBuffers.TestProtos
;
using
Google.ProtocolBuffers.TestProtos
;
using
NUnit.Framework
;
using
NUnit.Framework
;
...
@@ -288,5 +290,82 @@ namespace Google.ProtocolBuffers
...
@@ -288,5 +290,82 @@ namespace Google.ProtocolBuffers
Assert
.
AreEqual
(-
75123905439571256L
,
Assert
.
AreEqual
(-
75123905439571256L
,
CodedInputStream
.
DecodeZigZag64
(
CodedOutputStream
.
EncodeZigZag64
(-
75123905439571256L
)));
CodedInputStream
.
DecodeZigZag64
(
CodedOutputStream
.
EncodeZigZag64
(-
75123905439571256L
)));
}
}
[
Test
]
public
void
TestNegativeEnumNoTag
()
{
Assert
.
AreEqual
(
10
,
CodedOutputStream
.
ComputeInt32SizeNoTag
(-
2
));
Assert
.
AreEqual
(
10
,
CodedOutputStream
.
ComputeEnumSizeNoTag
(-
2
));
byte
[]
bytes
=
new
byte
[
10
];
CodedOutputStream
output
=
CodedOutputStream
.
CreateInstance
(
bytes
);
output
.
WriteEnumNoTag
(-
2
);
Assert
.
AreEqual
(
0
,
output
.
SpaceLeft
);
Assert
.
AreEqual
(
"FE-FF-FF-FF-FF-FF-FF-FF-FF-01"
,
BitConverter
.
ToString
(
bytes
));
}
[
Test
]
public
void
TestNegativeEnumWithTag
()
{
Assert
.
AreEqual
(
11
,
CodedOutputStream
.
ComputeInt32Size
(
8
,
-
2
));
Assert
.
AreEqual
(
11
,
CodedOutputStream
.
ComputeEnumSize
(
8
,
-
2
));
byte
[]
bytes
=
new
byte
[
11
];
CodedOutputStream
output
=
CodedOutputStream
.
CreateInstance
(
bytes
);
output
.
WriteEnum
(
8
,
""
,
-
2
,
-
2
);
Assert
.
AreEqual
(
0
,
output
.
SpaceLeft
);
//fyi, 0x40 == 0x08 << 3 + 0, field num + wire format shift
Assert
.
AreEqual
(
"40-FE-FF-FF-FF-FF-FF-FF-FF-FF-01"
,
BitConverter
.
ToString
(
bytes
));
}
[
Test
]
public
void
TestNegativeEnumArrayPacked
()
{
int
arraySize
=
1
+
(
10
*
5
);
int
msgSize
=
1
+
1
+
arraySize
;
byte
[]
bytes
=
new
byte
[
msgSize
];
CodedOutputStream
output
=
CodedOutputStream
.
CreateInstance
(
bytes
);
output
.
WritePackedEnumArray
(
8
,
""
,
arraySize
,
new
int
[]
{
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
});
Assert
.
AreEqual
(
0
,
output
.
SpaceLeft
);
CodedInputStream
input
=
CodedInputStream
.
CreateInstance
(
bytes
);
uint
tag
;
string
name
;
Assert
.
IsTrue
(
input
.
ReadTag
(
out
tag
,
out
name
));
List
<
int
>
values
=
new
List
<
int
>();
input
.
ReadInt32Array
(
tag
,
name
,
values
);
Assert
.
AreEqual
(
6
,
values
.
Count
);
for
(
int
i
=
0
;
i
>
-
6
;
i
--)
Assert
.
AreEqual
(
i
,
values
[
Math
.
Abs
(
i
)]);
}
[
Test
]
public
void
TestNegativeEnumArray
()
{
int
arraySize
=
1
+
1
+
(
11
*
5
);
int
msgSize
=
arraySize
;
byte
[]
bytes
=
new
byte
[
msgSize
];
CodedOutputStream
output
=
CodedOutputStream
.
CreateInstance
(
bytes
);
output
.
WriteEnumArray
(
8
,
""
,
new
int
[]
{
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
});
Assert
.
AreEqual
(
0
,
output
.
SpaceLeft
);
CodedInputStream
input
=
CodedInputStream
.
CreateInstance
(
bytes
);
uint
tag
;
string
name
;
Assert
.
IsTrue
(
input
.
ReadTag
(
out
tag
,
out
name
));
List
<
int
>
values
=
new
List
<
int
>();
input
.
ReadInt32Array
(
tag
,
name
,
values
);
Assert
.
AreEqual
(
6
,
values
.
Count
);
for
(
int
i
=
0
;
i
>
-
6
;
i
--)
Assert
.
AreEqual
(
i
,
values
[
Math
.
Abs
(
i
)]);
}
}
}
}
}
\ No newline at end of file
src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
View file @
18bf22c2
...
@@ -106,6 +106,7 @@
...
@@ -106,6 +106,7 @@
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"ReflectionTester.cs"
/>
<Compile
Include=
"ReflectionTester.cs"
/>
<Compile
Include=
"ServiceTest.cs"
/>
<Compile
Include=
"ServiceTest.cs"
/>
<Compile
Include=
"TestCornerCases.cs"
/>
<Compile
Include=
"TestProtos\UnitTestCSharpOptionsProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestCSharpOptionsProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestCustomOptionsProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestCustomOptionsProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestEmbedOptimizeForProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestEmbedOptimizeForProtoFile.cs"
/>
...
...
src/ProtocolBuffers.Test/TestCornerCases.cs
0 → 100644
View file @
18bf22c2
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
NUnit.Framework
;
using
UnitTest.Issues.TestProtos
;
namespace
Google.ProtocolBuffers
{
[
TestFixture
]
public
class
TestCornerCases
{
[
Test
]
public
void
TestRoundTripNegativeEnums
()
{
NegativeEnumMessage
msg
=
NegativeEnumMessage
.
CreateBuilder
()
.
SetValue
(
NegativeEnum
.
MinusOne
)
//11
.
AddValues
(
NegativeEnum
.
Zero
)
//2
.
AddValues
(
NegativeEnum
.
MinusOne
)
//11
.
AddValues
(
NegativeEnum
.
FiveBelow
)
//11
//2
.
AddPackedValues
(
NegativeEnum
.
Zero
)
//1
.
AddPackedValues
(
NegativeEnum
.
MinusOne
)
//10
.
AddPackedValues
(
NegativeEnum
.
FiveBelow
)
//10
.
Build
();
Assert
.
AreEqual
(
58
,
msg
.
SerializedSize
);
byte
[]
bytes
=
new
byte
[
58
];
CodedOutputStream
output
=
CodedOutputStream
.
CreateInstance
(
bytes
);
msg
.
WriteTo
(
output
);
Assert
.
AreEqual
(
0
,
output
.
SpaceLeft
);
NegativeEnumMessage
copy
=
NegativeEnumMessage
.
ParseFrom
(
bytes
);
Assert
.
AreEqual
(
msg
,
copy
);
}
}
}
src/ProtocolBuffers.Test/TestProtos/UnitTestExtrasIssuesProtoFile.cs
View file @
18bf22c2
This diff is collapsed.
Click to expand it.
src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs
View file @
18bf22c2
...
@@ -202,7 +202,7 @@ namespace Google.ProtocolBuffers
...
@@ -202,7 +202,7 @@ namespace Google.ProtocolBuffers
/// </summary>
/// </summary>
public
static
int
ComputeEnumSize
(
int
fieldNumber
,
int
value
)
public
static
int
ComputeEnumSize
(
int
fieldNumber
,
int
value
)
{
{
return
ComputeTagSize
(
fieldNumber
)
+
Compute
RawVarint32Size
((
uint
)
value
);
return
ComputeTagSize
(
fieldNumber
)
+
Compute
EnumSizeNoTag
(
value
);
}
}
/// <summary>
/// <summary>
...
@@ -391,7 +391,7 @@ namespace Google.ProtocolBuffers
...
@@ -391,7 +391,7 @@ namespace Google.ProtocolBuffers
/// </summary>
/// </summary>
public
static
int
ComputeEnumSizeNoTag
(
int
value
)
public
static
int
ComputeEnumSizeNoTag
(
int
value
)
{
{
return
Compute
RawVarint32Size
((
uint
)
value
);
return
Compute
Int32SizeNoTag
(
value
);
}
}
/// <summary>
/// <summary>
...
...
src/ProtocolBuffers/CodedOutputStream.cs
View file @
18bf22c2
...
@@ -373,7 +373,7 @@ namespace Google.ProtocolBuffers
...
@@ -373,7 +373,7 @@ namespace Google.ProtocolBuffers
public
void
WriteEnum
(
int
fieldNumber
,
string
fieldName
,
int
value
,
object
rawValue
)
public
void
WriteEnum
(
int
fieldNumber
,
string
fieldName
,
int
value
,
object
rawValue
)
{
{
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
Varint
);
WriteTag
(
fieldNumber
,
WireFormat
.
WireType
.
Varint
);
Write
RawVarint32
((
uint
)
value
);
Write
Int32NoTag
(
value
);
}
}
public
void
WriteSFixed32
(
int
fieldNumber
,
string
fieldName
,
int
value
)
public
void
WriteSFixed32
(
int
fieldNumber
,
string
fieldName
,
int
value
)
...
@@ -648,7 +648,7 @@ namespace Google.ProtocolBuffers
...
@@ -648,7 +648,7 @@ namespace Google.ProtocolBuffers
public
void
WriteEnumNoTag
(
int
value
)
public
void
WriteEnumNoTag
(
int
value
)
{
{
Write
RawVarint32
((
uint
)
value
);
Write
Int32NoTag
(
value
);
}
}
public
void
WriteSFixed32NoTag
(
int
value
)
public
void
WriteSFixed32NoTag
(
int
value
)
...
...
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