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
b9d1d389
Commit
b9d1d389
authored
Jun 29, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests changed enough to build
parent
f2a27cc2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
15 deletions
+36
-15
CodedInputStreamTest.cs
csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs
+29
-10
CodedOutputStreamTest.cs
csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs
+2
-0
FieldCodecTest.cs
csharp/src/ProtocolBuffers.Test/FieldCodecTest.cs
+5
-5
No files found.
csharp/src/ProtocolBuffers.Test/CodedInputStreamTest.cs
View file @
b9d1d389
...
...
@@ -479,22 +479,34 @@ namespace Google.Protobuf
int
msgSize
=
1
+
1
+
arraySize
;
byte
[]
bytes
=
new
byte
[
msgSize
];
CodedOutputStream
output
=
CodedOutputStream
.
CreateInstance
(
bytes
);
output
.
WriteTag
(
8
,
WireFormat
.
WireType
.
LengthDelimited
);
output
.
WritePackedInt32Array
(
new
RepeatedField
<
int
>
{
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
});
// Length-delimited to show we want the packed representation
uint
tag
=
WireFormat
.
MakeTag
(
8
,
WireFormat
.
WireType
.
LengthDelimited
);
output
.
WriteTag
(
tag
);
int
size
=
0
;
for
(
int
i
=
0
;
i
>=
-
5
;
i
--)
{
size
+=
CodedOutputStream
.
ComputeEnumSize
(
i
);
}
output
.
WriteRawVarint32
((
uint
)
size
);
for
(
int
i
=
0
;
i
>=
-
5
;
i
--)
{
output
.
WriteEnum
(
i
);
}
Assert
.
AreEqual
(
0
,
output
.
SpaceLeft
);
CodedInputStream
input
=
CodedInputStream
.
CreateInstance
(
bytes
);
uint
tag
;
Assert
.
IsTrue
(
input
.
ReadTag
(
out
tag
));
RepeatedField
<
TestNegEnum
>
values
=
new
RepeatedField
<
TestNegEnum
>();
input
.
ReadEnumArray
(
values
);
values
.
AddEntriesFrom
(
input
,
FieldCodec
.
ForEnum
(
tag
,
x
=>
(
int
)
x
,
x
=>
(
TestNegEnum
)
x
)
);
Assert
.
AreEqual
(
6
,
values
.
Count
);
Assert
.
AreEqual
(
TestNegEnum
.
None
,
values
[
0
]);
Assert
.
AreEqual
(((
TestNegEnum
)
(-
1
)),
values
[
1
]);
Assert
.
AreEqual
(
TestNegEnum
.
Value
,
values
[
2
]);
// TODO(jonskeet): Test unknown value preservation
Assert
.
AreEqual
(((
TestNegEnum
)(-
3
)),
values
[
3
]);
Assert
.
AreEqual
(((
TestNegEnum
)(-
4
)),
values
[
4
]);
Assert
.
AreEqual
(((
TestNegEnum
)(-
5
)),
values
[
5
]);
}
[
Test
]
...
...
@@ -504,21 +516,28 @@ namespace Google.Protobuf
int
msgSize
=
arraySize
;
byte
[]
bytes
=
new
byte
[
msgSize
];
CodedOutputStream
output
=
CodedOutputStream
.
CreateInstance
(
bytes
);
output
.
WriteInt32Array
(
8
,
new
RepeatedField
<
int
>
{
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
});
uint
tag
=
WireFormat
.
MakeTag
(
8
,
WireFormat
.
WireType
.
Varint
);
for
(
int
i
=
0
;
i
>=
-
5
;
i
--)
{
output
.
WriteTag
(
tag
);
output
.
WriteEnum
(
i
);
}
Assert
.
AreEqual
(
0
,
output
.
SpaceLeft
);
CodedInputStream
input
=
CodedInputStream
.
CreateInstance
(
bytes
);
uint
tag
;
Assert
.
IsTrue
(
input
.
ReadTag
(
out
tag
));
RepeatedField
<
TestNegEnum
>
values
=
new
RepeatedField
<
TestNegEnum
>();
input
.
ReadEnumArray
(
values
);
values
.
AddEntriesFrom
(
input
,
FieldCodec
.
ForEnum
(
tag
,
x
=>
(
int
)
x
,
x
=>
(
TestNegEnum
)
x
)
);
Assert
.
AreEqual
(
6
,
values
.
Count
);
Assert
.
AreEqual
(
TestNegEnum
.
None
,
values
[
0
]);
Assert
.
AreEqual
(((
TestNegEnum
)(-
1
)),
values
[
1
]);
Assert
.
AreEqual
(
TestNegEnum
.
Value
,
values
[
2
]);
// TODO(jonskeet): Test unknown value preservation
Assert
.
AreEqual
(((
TestNegEnum
)(-
3
)),
values
[
3
]);
Assert
.
AreEqual
(((
TestNegEnum
)(-
4
)),
values
[
4
]);
Assert
.
AreEqual
(((
TestNegEnum
)(-
5
)),
values
[
5
]);
}
//Issue 71: CodedInputStream.ReadBytes go to slow path unnecessarily
...
...
csharp/src/ProtocolBuffers.Test/CodedOutputStreamTest.cs
View file @
b9d1d389
...
...
@@ -308,6 +308,7 @@ namespace Google.Protobuf
enum
TestNegEnum
{
None
=
0
,
Value
=
-
2
}
/*
[Test]
public void TestNegativeEnumArrayPacked()
{
...
...
@@ -355,6 +356,7 @@ namespace Google.Protobuf
for (int i = 0; i > -6; i--)
Assert.AreEqual(i, values[Math.Abs(i)]);
}
*/
[
Test
]
public
void
TestCodedInputOutputPosition
()
...
...
csharp/src/ProtocolBuffers.Test/FieldCodecTest.cs
View file @
b9d1d389
...
...
@@ -104,7 +104,7 @@ namespace Google.Protobuf
{
var
stream
=
new
MemoryStream
();
var
codedOutput
=
CodedOutputStream
.
CreateInstance
(
stream
);
codec
.
Write
(
codedOutput
,
sampleValue
);
codec
.
Write
TagAndValue
(
codedOutput
,
sampleValue
);
codedOutput
.
Flush
();
stream
.
Position
=
0
;
var
codedInput
=
CodedInputStream
.
CreateInstance
(
stream
);
...
...
@@ -119,19 +119,19 @@ namespace Google.Protobuf
{
var
stream
=
new
MemoryStream
();
var
codedOutput
=
CodedOutputStream
.
CreateInstance
(
stream
);
codec
.
Write
(
codedOutput
,
sampleValue
);
codec
.
Write
TagAndValue
(
codedOutput
,
sampleValue
);
codedOutput
.
Flush
();
Assert
.
AreEqual
(
stream
.
Position
,
codec
.
CalculateSize
(
sampleValue
));
Assert
.
AreEqual
(
stream
.
Position
,
codec
.
CalculateSize
WithTag
(
sampleValue
));
}
public
void
TestDefaultValue
()
{
var
stream
=
new
MemoryStream
();
var
codedOutput
=
CodedOutputStream
.
CreateInstance
(
stream
);
codec
.
Write
(
codedOutput
,
codec
.
DefaultValue
);
codec
.
Write
TagAndValue
(
codedOutput
,
codec
.
DefaultValue
);
codedOutput
.
Flush
();
Assert
.
AreEqual
(
0
,
stream
.
Position
);
Assert
.
AreEqual
(
0
,
codec
.
CalculateSize
(
codec
.
DefaultValue
));
Assert
.
AreEqual
(
0
,
codec
.
CalculateSize
WithTag
(
codec
.
DefaultValue
));
if
(
typeof
(
T
).
IsValueType
)
{
Assert
.
AreEqual
(
default
(
T
),
codec
.
DefaultValue
);
...
...
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