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
fcb92682
Commit
fcb92682
authored
Jun 29, 2017
by
Yilun Chong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change java to uniform message, revert TestValidDataForType's parameters
parent
020a24df
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
147 additions
and
318 deletions
+147
-318
ConformanceJava.java
conformance/ConformanceJava.java
+105
-271
conformance_test.cc
conformance/conformance_test.cc
+41
-45
conformance_test.h
conformance/conformance_test.h
+1
-2
No files found.
conformance/ConformanceJava.java
View file @
fcb92682
import
com.google.protobuf.ByteString
;
import
com.google.protobuf.ByteString
;
import
com.google.protobuf.AbstractMessage
;
import
com.google.protobuf.Parser
;
import
com.google.protobuf.CodedInputStream
;
import
com.google.protobuf.CodedInputStream
;
import
com.google.protobuf.conformance.Conformance
;
import
com.google.protobuf.conformance.Conformance
;
import
com.google.protobuf.InvalidProtocolBufferException
;
import
com.google.protobuf.InvalidProtocolBufferException
;
import
com.google.protobuf_test_messages.proto3.TestMessagesProto3
;
import
com.google.protobuf_test_messages.proto3.TestMessagesProto3
;
import
com.google.protobuf_test_messages.proto3.TestMessagesProto3.TestAllTypes
;
import
com.google.protobuf_test_messages.proto2.TestMessagesProto2
;
import
com.google.protobuf_test_messages.proto2.TestMessagesProto2
;
import
com.google.protobuf_test_messages.proto2.TestMessagesProto2.TestAllTypesProto2
;
import
com.google.protobuf.ExtensionRegistry
;
import
com.google.protobuf.util.JsonFormat
;
import
com.google.protobuf.util.JsonFormat
;
import
com.google.protobuf.util.JsonFormat.TypeRegistry
;
import
com.google.protobuf.util.JsonFormat.TypeRegistry
;
import
java.io.IOException
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.util.ArrayList
;
class
ConformanceJava
{
class
ConformanceJava
{
private
int
testCount
=
0
;
private
int
testCount
=
0
;
...
@@ -51,275 +56,100 @@ class ConformanceJava {
...
@@ -51,275 +56,100 @@ class ConformanceJava {
buf
[
3
]
=
(
byte
)(
val
>>
24
);
buf
[
3
]
=
(
byte
)(
val
>>
24
);
writeToStdout
(
buf
);
writeToStdout
(
buf
);
}
}
private
enum
BinaryDecoder
{
private
enum
BinaryDecoderType
{
BYTE_STRING_DECODER
()
{
BTYE_STRING_DECODER
,
@Override
BYTE_ARRAY_DECODER
,
public
TestMessagesProto3
.
TestAllTypes
parseProto3
(
ByteString
bytes
)
ARRAY_BYTE_BUFFER_DECODER
,
throws
InvalidProtocolBufferException
{
READONLY_ARRAY_BYTE_BUFFER_DECODER
,
return
TestMessagesProto3
.
TestAllTypes
.
parseFrom
(
bytes
);
DIRECT_BYTE_BUFFER_DECODER
,
}
READONLY_DIRECT_BYTE_BUFFER_DECODER
,
@Override
INPUT_STREAM_DECODER
;
public
TestMessagesProto2
.
TestAllTypesProto2
parseProto2
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
return
TestMessagesProto2
.
TestAllTypesProto2
.
parseFrom
(
bytes
);
}
},
BYTE_ARRAY_DECODER
()
{
@Override
public
TestMessagesProto3
.
TestAllTypes
parseProto3
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
return
TestMessagesProto3
.
TestAllTypes
.
parseFrom
(
bytes
.
toByteArray
());
}
@Override
public
TestMessagesProto2
.
TestAllTypesProto2
parseProto2
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
return
TestMessagesProto2
.
TestAllTypesProto2
.
parseFrom
(
bytes
.
toByteArray
());
}
},
ARRAY_BYTE_BUFFER_DECODER
()
{
@Override
public
TestMessagesProto3
.
TestAllTypes
parseProto3
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
bytes
.
size
());
bytes
.
copyTo
(
buffer
);
buffer
.
flip
();
try
{
return
TestMessagesProto3
.
TestAllTypes
.
parseFrom
(
CodedInputStream
.
newInstance
(
buffer
));
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"ByteString based ByteBuffer should not throw IOException."
,
e
);
}
}
@Override
public
TestMessagesProto2
.
TestAllTypesProto2
parseProto2
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
bytes
.
size
());
bytes
.
copyTo
(
buffer
);
buffer
.
flip
();
try
{
return
TestMessagesProto2
.
TestAllTypesProto2
.
parseFrom
(
CodedInputStream
.
newInstance
(
buffer
));
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"ByteString based ByteBuffer should not throw IOException."
,
e
);
}
}
},
READONLY_ARRAY_BYTE_BUFFER_DECODER
()
{
@Override
public
TestMessagesProto3
.
TestAllTypes
parseProto3
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
try
{
return
TestMessagesProto3
.
TestAllTypes
.
parseFrom
(
CodedInputStream
.
newInstance
(
bytes
.
asReadOnlyByteBuffer
()));
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"ByteString based ByteBuffer should not throw IOException."
,
e
);
}
}
@Override
public
TestMessagesProto2
.
TestAllTypesProto2
parseProto2
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
try
{
return
TestMessagesProto2
.
TestAllTypesProto2
.
parseFrom
(
CodedInputStream
.
newInstance
(
bytes
.
asReadOnlyByteBuffer
()));
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"ByteString based ByteBuffer should not throw IOException."
,
e
);
}
}
},
DIRECT_BYTE_BUFFER_DECODER
()
{
@Override
public
TestMessagesProto3
.
TestAllTypes
parseProto3
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
ByteBuffer
buffer
=
ByteBuffer
.
allocateDirect
(
bytes
.
size
());
bytes
.
copyTo
(
buffer
);
buffer
.
flip
();
try
{
return
TestMessagesProto3
.
TestAllTypes
.
parseFrom
(
CodedInputStream
.
newInstance
(
buffer
));
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"ByteString based ByteBuffer should not throw IOException."
,
e
);
}
}
@Override
public
TestMessagesProto2
.
TestAllTypesProto2
parseProto2
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
ByteBuffer
buffer
=
ByteBuffer
.
allocateDirect
(
bytes
.
size
());
bytes
.
copyTo
(
buffer
);
buffer
.
flip
();
try
{
return
TestMessagesProto2
.
TestAllTypesProto2
.
parseFrom
(
CodedInputStream
.
newInstance
(
buffer
));
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"ByteString based ByteBuffer should not throw IOException."
,
e
);
}
}
},
READONLY_DIRECT_BYTE_BUFFER_DECODER
()
{
@Override
public
TestMessagesProto3
.
TestAllTypes
parseProto3
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
ByteBuffer
buffer
=
ByteBuffer
.
allocateDirect
(
bytes
.
size
());
bytes
.
copyTo
(
buffer
);
buffer
.
flip
();
try
{
return
TestMessagesProto3
.
TestAllTypes
.
parseFrom
(
CodedInputStream
.
newInstance
(
buffer
.
asReadOnlyBuffer
()));
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"ByteString based ByteBuffer should not throw IOException."
,
e
);
}
}
@Override
public
TestMessagesProto2
.
TestAllTypesProto2
parseProto2
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
ByteBuffer
buffer
=
ByteBuffer
.
allocateDirect
(
bytes
.
size
());
bytes
.
copyTo
(
buffer
);
buffer
.
flip
();
try
{
return
TestMessagesProto2
.
TestAllTypesProto2
.
parseFrom
(
CodedInputStream
.
newInstance
(
buffer
.
asReadOnlyBuffer
()));
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"ByteString based ByteBuffer should not throw IOException."
,
e
);
}
}
},
INPUT_STREAM_DECODER
()
{
@Override
public
TestMessagesProto3
.
TestAllTypes
parseProto3
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
try
{
return
TestMessagesProto3
.
TestAllTypes
.
parseFrom
(
bytes
.
newInput
());
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"ByteString based InputStream should not throw IOException."
,
e
);
}
}
@Override
public
TestMessagesProto2
.
TestAllTypesProto2
parseProto2
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
try
{
return
TestMessagesProto2
.
TestAllTypesProto2
.
parseFrom
(
bytes
.
newInput
());
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"ByteString based InputStream should not throw IOException."
,
e
);
}
}
};
public
abstract
TestMessagesProto3
.
TestAllTypes
parseProto3
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
;
public
abstract
TestMessagesProto2
.
TestAllTypesProto2
parseProto2
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
;
}
}
private
TestMessagesProto3
.
TestAllTypes
parseBinaryToProto3
(
ByteString
bytes
)
private
static
class
BinaryDecoder
<
MessageType
extends
AbstractMessage
>
{
public
MessageType
decode
(
ByteString
bytes
,
BinaryDecoderType
type
,
Parser
<
MessageType
>
parser
,
ExtensionRegistry
extensions
)
throws
InvalidProtocolBufferException
{
throws
InvalidProtocolBufferException
{
TestMessagesProto3
.
TestAllTypes
[]
messages
=
switch
(
type
)
{
new
TestMessagesProto3
.
TestAllTypes
[
BinaryDecoder
.
values
().
length
];
case
BTYE_STRING_DECODER:
InvalidProtocolBufferException
[]
exceptions
=
return
parser
.
parseFrom
(
bytes
,
extensions
);
new
InvalidProtocolBufferException
[
BinaryDecoder
.
values
().
length
];
case
BYTE_ARRAY_DECODER:
return
parser
.
parseFrom
(
bytes
.
toByteArray
(),
extensions
);
boolean
hasMessage
=
false
;
case
ARRAY_BYTE_BUFFER_DECODER:
{
boolean
hasException
=
false
;
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
bytes
.
size
());
for
(
int
i
=
0
;
i
<
BinaryDecoder
.
values
().
length
;
++
i
)
{
bytes
.
copyTo
(
buffer
);
try
{
buffer
.
flip
();
messages
[
i
]
=
BinaryDecoder
.
values
()[
i
].
parseProto3
(
bytes
);
try
{
hasMessage
=
true
;
return
parser
.
parseFrom
(
CodedInputStream
.
newInstance
(
buffer
),
extensions
);
}
catch
(
InvalidProtocolBufferException
e
)
{
}
catch
(
InvalidProtocolBufferException
e
)
{
exceptions
[
i
]
=
e
;
throw
e
;
hasException
=
true
;
}
}
}
if
(
hasMessage
&&
hasException
)
{
StringBuilder
sb
=
new
StringBuilder
(
"Binary decoders disagreed on whether the payload was valid.\n"
);
for
(
int
i
=
0
;
i
<
BinaryDecoder
.
values
().
length
;
++
i
)
{
sb
.
append
(
BinaryDecoder
.
values
()[
i
].
name
());
if
(
messages
[
i
]
!=
null
)
{
sb
.
append
(
" accepted the payload.\n"
);
}
else
{
sb
.
append
(
" rejected the payload.\n"
);
}
}
}
case
READONLY_ARRAY_BYTE_BUFFER_DECODER:
{
throw
new
RuntimeException
(
sb
.
toString
());
try
{
}
return
parser
.
parseFrom
(
CodedInputStream
.
newInstance
(
bytes
.
asReadOnlyByteBuffer
()),
extensions
);
if
(
hasException
)
{
}
catch
(
InvalidProtocolBufferException
e
)
{
// We do not check if exceptions are equal. Different implementations may return different
throw
e
;
// exception messages. Throw an arbitrary one out instead.
}
throw
exceptions
[
0
];
}
}
case
DIRECT_BYTE_BUFFER_DECODER:
{
ByteBuffer
buffer
=
ByteBuffer
.
allocateDirect
(
bytes
.
size
());
// Fast path comparing all the messages with the first message, assuming equality being
bytes
.
copyTo
(
buffer
);
// symmetric and transitive.
buffer
.
flip
();
boolean
allEqual
=
true
;
try
{
for
(
int
i
=
1
;
i
<
messages
.
length
;
++
i
)
{
return
parser
.
parseFrom
(
CodedInputStream
.
newInstance
(
buffer
),
extensions
);
if
(!
messages
[
0
].
equals
(
messages
[
i
]))
{
}
catch
(
InvalidProtocolBufferException
e
)
{
allEqual
=
false
;
throw
e
;
break
;
}
}
}
}
case
READONLY_DIRECT_BYTE_BUFFER_DECODER:
{
ByteBuffer
buffer
=
ByteBuffer
.
allocateDirect
(
bytes
.
size
());
// Slow path: compare and find out all unequal pairs.
bytes
.
copyTo
(
buffer
);
if
(!
allEqual
)
{
buffer
.
flip
();
StringBuilder
sb
=
new
StringBuilder
();
try
{
for
(
int
i
=
0
;
i
<
messages
.
length
-
1
;
++
i
)
{
return
parser
.
parseFrom
(
for
(
int
j
=
i
+
1
;
j
<
messages
.
length
;
++
j
)
{
CodedInputStream
.
newInstance
(
buffer
.
asReadOnlyBuffer
()),
extensions
);
if
(!
messages
[
i
].
equals
(
messages
[
j
]))
{
}
catch
(
InvalidProtocolBufferException
e
)
{
sb
.
append
(
BinaryDecoder
.
values
()[
i
].
name
())
throw
e
;
.
append
(
" and "
)
}
.
append
(
BinaryDecoder
.
values
()[
j
].
name
())
}
.
append
(
" parsed the payload differently.\n"
);
case
INPUT_STREAM_DECODER:
{
try
{
return
parser
.
parseFrom
(
bytes
.
newInput
(),
extensions
);
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
}
}
}
default
:
return
null
;
}
}
throw
new
RuntimeException
(
sb
.
toString
());
}
}
return
messages
[
0
];
}
}
private
TestMessagesProto2
.
TestAllTypesProto2
parseBinaryToProto2
(
ByteString
bytes
)
private
<
MessageType
extends
AbstractMessage
>
MessageType
parseBinary
(
ByteString
bytes
,
Parser
<
MessageType
>
parser
,
ExtensionRegistry
extensions
)
throws
InvalidProtocolBufferException
{
throws
InvalidProtocolBufferException
{
TestMessagesProto2
.
TestAllTypesProto2
[]
messages
=
ArrayList
<
MessageType
>
messages
=
new
ArrayList
<
MessageType
>
();
new
TestMessagesProto2
.
TestAllTypesProto2
[
BinaryDecoder
.
values
().
length
];
ArrayList
<
InvalidProtocolBufferException
>
exceptions
=
InvalidProtocolBufferException
[]
exceptions
=
new
ArrayList
<
InvalidProtocolBufferException
>();
new
InvalidProtocolBufferException
[
BinaryDecoder
.
values
().
length
];
for
(
int
i
=
0
;
i
<
BinaryDecoderType
.
values
().
length
;
i
++)
{
messages
.
add
(
null
);
exceptions
.
add
(
null
);
}
BinaryDecoder
<
MessageType
>
decoder
=
new
BinaryDecoder
<
MessageType
>
();
boolean
hasMessage
=
false
;
boolean
hasMessage
=
false
;
boolean
hasException
=
false
;
boolean
hasException
=
false
;
for
(
int
i
=
0
;
i
<
BinaryDecoder
.
values
().
length
;
++
i
)
{
for
(
int
i
=
0
;
i
<
BinaryDecoder
Type
.
values
().
length
;
++
i
)
{
try
{
try
{
messages
[
i
]
=
BinaryDecoder
.
values
()[
i
].
parseProto2
(
bytes
);
//= BinaryDecoderType.values()[i].parseProto3(bytes);
messages
.
set
(
i
,
decoder
.
decode
(
bytes
,
BinaryDecoderType
.
values
()[
i
],
parser
,
extensions
));
hasMessage
=
true
;
hasMessage
=
true
;
}
catch
(
InvalidProtocolBufferException
e
)
{
}
catch
(
InvalidProtocolBufferException
e
)
{
exceptions
[
i
]
=
e
;
exceptions
.
set
(
i
,
e
)
;
hasException
=
true
;
hasException
=
true
;
}
}
}
}
...
@@ -327,9 +157,9 @@ class ConformanceJava {
...
@@ -327,9 +157,9 @@ class ConformanceJava {
if
(
hasMessage
&&
hasException
)
{
if
(
hasMessage
&&
hasException
)
{
StringBuilder
sb
=
StringBuilder
sb
=
new
StringBuilder
(
"Binary decoders disagreed on whether the payload was valid.\n"
);
new
StringBuilder
(
"Binary decoders disagreed on whether the payload was valid.\n"
);
for
(
int
i
=
0
;
i
<
BinaryDecoder
.
values
().
length
;
++
i
)
{
for
(
int
i
=
0
;
i
<
BinaryDecoder
Type
.
values
().
length
;
++
i
)
{
sb
.
append
(
BinaryDecoder
.
values
()[
i
].
name
());
sb
.
append
(
BinaryDecoder
Type
.
values
()[
i
].
name
());
if
(
messages
[
i
]
!=
null
)
{
if
(
messages
.
get
(
i
)
!=
null
)
{
sb
.
append
(
" accepted the payload.\n"
);
sb
.
append
(
" accepted the payload.\n"
);
}
else
{
}
else
{
sb
.
append
(
" rejected the payload.\n"
);
sb
.
append
(
" rejected the payload.\n"
);
...
@@ -341,14 +171,14 @@ class ConformanceJava {
...
@@ -341,14 +171,14 @@ class ConformanceJava {
if
(
hasException
)
{
if
(
hasException
)
{
// We do not check if exceptions are equal. Different implementations may return different
// We do not check if exceptions are equal. Different implementations may return different
// exception messages. Throw an arbitrary one out instead.
// exception messages. Throw an arbitrary one out instead.
throw
exceptions
[
0
]
;
throw
exceptions
.
get
(
0
)
;
}
}
// Fast path comparing all the messages with the first message, assuming equality being
// Fast path comparing all the messages with the first message, assuming equality being
// symmetric and transitive.
// symmetric and transitive.
boolean
allEqual
=
true
;
boolean
allEqual
=
true
;
for
(
int
i
=
1
;
i
<
messages
.
length
;
++
i
)
{
for
(
int
i
=
1
;
i
<
messages
.
size
()
;
++
i
)
{
if
(!
messages
[
0
].
equals
(
messages
[
i
]
))
{
if
(!
messages
.
get
(
0
).
equals
(
messages
.
get
(
i
)
))
{
allEqual
=
false
;
allEqual
=
false
;
break
;
break
;
}
}
...
@@ -357,12 +187,12 @@ class ConformanceJava {
...
@@ -357,12 +187,12 @@ class ConformanceJava {
// Slow path: compare and find out all unequal pairs.
// Slow path: compare and find out all unequal pairs.
if
(!
allEqual
)
{
if
(!
allEqual
)
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
messages
.
length
-
1
;
++
i
)
{
for
(
int
i
=
0
;
i
<
messages
.
size
()
-
1
;
++
i
)
{
for
(
int
j
=
i
+
1
;
j
<
messages
.
length
;
++
j
)
{
for
(
int
j
=
i
+
1
;
j
<
messages
.
size
()
;
++
j
)
{
if
(!
messages
[
i
].
equals
(
messages
[
j
]
))
{
if
(!
messages
.
get
(
i
).
equals
(
messages
.
get
(
j
)
))
{
sb
.
append
(
BinaryDecoder
.
values
()[
i
].
name
())
sb
.
append
(
BinaryDecoder
Type
.
values
()[
i
].
name
())
.
append
(
" and "
)
.
append
(
" and "
)
.
append
(
BinaryDecoder
.
values
()[
j
].
name
())
.
append
(
BinaryDecoder
Type
.
values
()[
j
].
name
())
.
append
(
" parsed the payload differently.\n"
);
.
append
(
" parsed the payload differently.\n"
);
}
}
}
}
...
@@ -370,25 +200,29 @@ class ConformanceJava {
...
@@ -370,25 +200,29 @@ class ConformanceJava {
throw
new
RuntimeException
(
sb
.
toString
());
throw
new
RuntimeException
(
sb
.
toString
());
}
}
return
messages
[
0
]
;
return
messages
.
get
(
0
)
;
}
}
private
Conformance
.
ConformanceResponse
doTest
(
Conformance
.
ConformanceRequest
request
)
{
private
Conformance
.
ConformanceResponse
doTest
(
Conformance
.
ConformanceRequest
request
)
{
com
.
google
.
protobuf
.
AbstractMessage
testMessage
;
com
.
google
.
protobuf
.
AbstractMessage
testMessage
;
boolean
isProto3
=
request
.
getMessageType
().
equals
(
"proto3"
);
boolean
isProto3
=
request
.
getMessageType
().
equals
(
"protobuf_test_messages.proto3.TestAllTypes"
);
boolean
isProto2
=
request
.
getMessageType
().
equals
(
"protobuf_test_messages.proto2.TestAllTypesProto2"
);
switch
(
request
.
getPayloadCase
())
{
switch
(
request
.
getPayloadCase
())
{
case
PROTOBUF_PAYLOAD:
{
case
PROTOBUF_PAYLOAD:
{
if
(
isProto3
)
{
if
(
isProto3
)
{
try
{
try
{
testMessage
=
parseBinaryToProto3
(
request
.
getProtobufPayload
());
ExtensionRegistry
extensions
=
ExtensionRegistry
.
newInstance
();
TestMessagesProto3
.
registerAllExtensions
(
extensions
);
testMessage
=
parseBinary
(
request
.
getProtobufPayload
(),
TestAllTypes
.
parser
(),
extensions
);
}
catch
(
InvalidProtocolBufferException
e
)
{
}
catch
(
InvalidProtocolBufferException
e
)
{
return
Conformance
.
ConformanceResponse
.
newBuilder
().
setParseError
(
e
.
getMessage
()).
build
();
return
Conformance
.
ConformanceResponse
.
newBuilder
().
setParseError
(
e
.
getMessage
()).
build
();
}
}
}
else
if
(
request
.
getMessageType
().
equals
(
"proto2"
)
)
{
}
else
if
(
isProto2
)
{
try
{
try
{
testMessage
=
parseBinaryToProto2
(
request
.
getProtobufPayload
());
ExtensionRegistry
extensions
=
ExtensionRegistry
.
newInstance
();
TestMessagesProto2
.
registerAllExtensions
(
extensions
);
testMessage
=
parseBinary
(
request
.
getProtobufPayload
(),
TestAllTypesProto2
.
parser
(),
extensions
);
}
catch
(
InvalidProtocolBufferException
e
)
{
}
catch
(
InvalidProtocolBufferException
e
)
{
return
Conformance
.
ConformanceResponse
.
newBuilder
().
setParseError
(
e
.
getMessage
()).
build
();
return
Conformance
.
ConformanceResponse
.
newBuilder
().
setParseError
(
e
.
getMessage
()).
build
();
}
}
...
...
conformance/conformance_test.cc
View file @
fcb92682
...
@@ -674,35 +674,37 @@ void ConformanceTestSuite::TestPrematureEOFForType(FieldDescriptor::Type type) {
...
@@ -674,35 +674,37 @@ void ConformanceTestSuite::TestPrematureEOFForType(FieldDescriptor::Type type) {
void
ConformanceTestSuite
::
TestValidDataForType
(
void
ConformanceTestSuite
::
TestValidDataForType
(
FieldDescriptor
::
Type
type
,
FieldDescriptor
::
Type
type
,
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
values
,
bool
isProto3
)
{
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
values
)
{
const
string
type_name
=
for
(
int
isProto3
=
0
;
isProto3
<
2
;
isProto3
++
)
{
UpperCase
(
string
(
"."
)
+
FieldDescriptor
::
TypeName
(
type
));
const
string
type_name
=
WireFormatLite
::
WireType
wire_type
=
WireFormatLite
::
WireTypeForFieldType
(
UpperCase
(
string
(
"."
)
+
FieldDescriptor
::
TypeName
(
type
));
static_cast
<
WireFormatLite
::
FieldType
>
(
type
));
WireFormatLite
::
WireType
wire_type
=
WireFormatLite
::
WireTypeForFieldType
(
const
FieldDescriptor
*
field
=
GetFieldForType
(
type
,
false
,
isProto3
);
static_cast
<
WireFormatLite
::
FieldType
>
(
type
));
const
FieldDescriptor
*
rep_field
=
GetFieldForType
(
type
,
true
,
isProto3
);
const
FieldDescriptor
*
field
=
GetFieldForType
(
type
,
false
,
isProto3
);
const
FieldDescriptor
*
rep_field
=
GetFieldForType
(
type
,
true
,
isProto3
);
RunValidProtobufTest
(
"ValidDataScalar"
+
type_name
,
REQUIRED
,
cat
(
tag
(
field
->
number
(),
wire_type
),
values
[
0
].
first
),
RunValidProtobufTest
(
"ValidDataScalar"
+
type_name
,
REQUIRED
,
field
->
name
()
+
": "
+
values
[
0
].
second
,
isProto3
);
cat
(
tag
(
field
->
number
(),
wire_type
),
values
[
0
].
first
),
field
->
name
()
+
": "
+
values
[
0
].
second
,
isProto3
);
string
proto
;
string
text
=
field
->
name
()
+
": "
+
values
.
back
().
second
;
string
proto
;
for
(
size_t
i
=
0
;
i
<
values
.
size
();
i
++
)
{
string
text
=
field
->
name
()
+
": "
+
values
.
back
().
second
;
proto
+=
cat
(
tag
(
field
->
number
(),
wire_type
),
values
[
i
].
first
);
for
(
size_t
i
=
0
;
i
<
values
.
size
();
i
++
)
{
}
proto
+=
cat
(
tag
(
field
->
number
(),
wire_type
),
values
[
i
].
first
);
RunValidProtobufTest
(
"RepeatedScalarSelectsLast"
+
type_name
,
REQUIRED
,
}
proto
,
text
,
isProto3
);
RunValidProtobufTest
(
"RepeatedScalarSelectsLast"
+
type_name
,
REQUIRED
,
proto
,
text
,
isProto3
);
proto
.
clear
();
proto
.
clear
();
text
.
clear
();
text
.
clear
();
for
(
size_t
i
=
0
;
i
<
values
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
values
.
size
();
i
++
)
{
proto
+=
cat
(
tag
(
rep_field
->
number
(),
wire_type
),
values
[
i
].
first
);
proto
+=
cat
(
tag
(
rep_field
->
number
(),
wire_type
),
values
[
i
].
first
);
text
+=
rep_field
->
name
()
+
": "
+
values
[
i
].
second
+
" "
;
text
+=
rep_field
->
name
()
+
": "
+
values
[
i
].
second
+
" "
;
}
RunValidProtobufTest
(
"ValidDataRepeated"
+
type_name
,
REQUIRED
,
proto
,
text
,
isProto3
);
}
}
RunValidProtobufTest
(
"ValidDataRepeated"
+
type_name
,
REQUIRED
,
proto
,
text
,
isProto3
);
}
}
void
ConformanceTestSuite
::
SetFailureList
(
const
string
&
filename
,
void
ConformanceTestSuite
::
SetFailureList
(
const
string
&
filename
,
...
@@ -793,29 +795,23 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
...
@@ -793,29 +795,23 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
{
dbl
(
0.1
),
"0.1"
},
{
dbl
(
0.1
),
"0.1"
},
{
dbl
(
1.7976931348623157e+308
),
"1.7976931348623157e+308"
},
{
dbl
(
1.7976931348623157e+308
),
"1.7976931348623157e+308"
},
{
dbl
(
2.22507385850720138309e-308
),
"2.22507385850720138309e-308"
}
{
dbl
(
2.22507385850720138309e-308
),
"2.22507385850720138309e-308"
}
},
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_DOUBLE
,
{
{
dbl
(
0.1
),
"0.1"
},
{
dbl
(
1.7976931348623157e+308
),
"1.7976931348623157e+308"
},
{
dbl
(
2.22507385850720138309e-308
),
"2.22507385850720138309e-308"
}
},
false
);
TestValidDataForType
(
FieldDescriptor
::
TYPE_FLOAT
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_FLOAT
,
{
{
flt
(
0.1
),
"0.1"
},
{
flt
(
0.1
),
"0.1"
},
{
flt
(
1.00000075e-36
),
"1.00000075e-36"
},
{
flt
(
1.00000075e-36
),
"1.00000075e-36"
},
{
flt
(
3.402823e+38
),
"3.402823e+38"
},
// 3.40282347e+38
{
flt
(
3.402823e+38
),
"3.402823e+38"
},
// 3.40282347e+38
{
flt
(
1.17549435e-38
f
),
"1.17549435e-38"
}
{
flt
(
1.17549435e-38
f
),
"1.17549435e-38"
}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_INT64
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_INT64
,
{
{
varint
(
12345
),
"12345"
},
{
varint
(
12345
),
"12345"
},
{
varint
(
kInt64Max
),
std
::
to_string
(
kInt64Max
)},
{
varint
(
kInt64Max
),
std
::
to_string
(
kInt64Max
)},
{
varint
(
kInt64Min
),
std
::
to_string
(
kInt64Min
)}
{
varint
(
kInt64Min
),
std
::
to_string
(
kInt64Min
)}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_UINT64
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_UINT64
,
{
{
varint
(
12345
),
"12345"
},
{
varint
(
12345
),
"12345"
},
{
varint
(
kUint64Max
),
std
::
to_string
(
kUint64Max
)},
{
varint
(
kUint64Max
),
std
::
to_string
(
kUint64Max
)},
{
varint
(
0
),
"0"
}
{
varint
(
0
),
"0"
}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_INT32
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_INT32
,
{
{
varint
(
12345
),
"12345"
},
{
varint
(
12345
),
"12345"
},
{
longvarint
(
12345
,
2
),
"12345"
},
{
longvarint
(
12345
,
2
),
"12345"
},
...
@@ -825,7 +821,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
...
@@ -825,7 +821,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
{
varint
(
1LL
<<
33
),
std
::
to_string
(
static_cast
<
int32
>
(
1LL
<<
33
))},
{
varint
(
1LL
<<
33
),
std
::
to_string
(
static_cast
<
int32
>
(
1LL
<<
33
))},
{
varint
((
1LL
<<
33
)
-
1
),
{
varint
((
1LL
<<
33
)
-
1
),
std
::
to_string
(
static_cast
<
int32
>
((
1LL
<<
33
)
-
1
))},
std
::
to_string
(
static_cast
<
int32
>
((
1LL
<<
33
)
-
1
))},
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_UINT32
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_UINT32
,
{
{
varint
(
12345
),
"12345"
},
{
varint
(
12345
),
"12345"
},
{
longvarint
(
12345
,
2
),
"12345"
},
{
longvarint
(
12345
,
2
),
"12345"
},
...
@@ -835,42 +831,42 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
...
@@ -835,42 +831,42 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
{
varint
(
1LL
<<
33
),
std
::
to_string
(
static_cast
<
uint32
>
(
1LL
<<
33
))},
{
varint
(
1LL
<<
33
),
std
::
to_string
(
static_cast
<
uint32
>
(
1LL
<<
33
))},
{
varint
((
1LL
<<
33
)
-
1
),
{
varint
((
1LL
<<
33
)
-
1
),
std
::
to_string
(
static_cast
<
uint32
>
((
1LL
<<
33
)
-
1
))},
std
::
to_string
(
static_cast
<
uint32
>
((
1LL
<<
33
)
-
1
))},
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_FIXED64
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_FIXED64
,
{
{
u64
(
12345
),
"12345"
},
{
u64
(
12345
),
"12345"
},
{
u64
(
kUint64Max
),
std
::
to_string
(
kUint64Max
)},
{
u64
(
kUint64Max
),
std
::
to_string
(
kUint64Max
)},
{
u64
(
0
),
"0"
}
{
u64
(
0
),
"0"
}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_FIXED32
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_FIXED32
,
{
{
u32
(
12345
),
"12345"
},
{
u32
(
12345
),
"12345"
},
{
u32
(
kUint32Max
),
std
::
to_string
(
kUint32Max
)},
// UINT32_MAX
{
u32
(
kUint32Max
),
std
::
to_string
(
kUint32Max
)},
// UINT32_MAX
{
u32
(
0
),
"0"
}
{
u32
(
0
),
"0"
}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_SFIXED64
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_SFIXED64
,
{
{
u64
(
12345
),
"12345"
},
{
u64
(
12345
),
"12345"
},
{
u64
(
kInt64Max
),
std
::
to_string
(
kInt64Max
)},
{
u64
(
kInt64Max
),
std
::
to_string
(
kInt64Max
)},
{
u64
(
kInt64Min
),
std
::
to_string
(
kInt64Min
)}
{
u64
(
kInt64Min
),
std
::
to_string
(
kInt64Min
)}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_SFIXED32
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_SFIXED32
,
{
{
u32
(
12345
),
"12345"
},
{
u32
(
12345
),
"12345"
},
{
u32
(
kInt32Max
),
std
::
to_string
(
kInt32Max
)},
{
u32
(
kInt32Max
),
std
::
to_string
(
kInt32Max
)},
{
u32
(
kInt32Min
),
std
::
to_string
(
kInt32Min
)}
{
u32
(
kInt32Min
),
std
::
to_string
(
kInt32Min
)}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_BOOL
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_BOOL
,
{
{
varint
(
1
),
"true"
},
{
varint
(
1
),
"true"
},
{
varint
(
0
),
"false"
},
{
varint
(
0
),
"false"
},
{
varint
(
12345678
),
"true"
}
{
varint
(
12345678
),
"true"
}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_SINT32
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_SINT32
,
{
{
zz32
(
12345
),
"12345"
},
{
zz32
(
12345
),
"12345"
},
{
zz32
(
kInt32Max
),
std
::
to_string
(
kInt32Max
)},
{
zz32
(
kInt32Max
),
std
::
to_string
(
kInt32Max
)},
{
zz32
(
kInt32Min
),
std
::
to_string
(
kInt32Min
)}
{
zz32
(
kInt32Min
),
std
::
to_string
(
kInt32Min
)}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_SINT64
,
{
TestValidDataForType
(
FieldDescriptor
::
TYPE_SINT64
,
{
{
zz64
(
12345
),
"12345"
},
{
zz64
(
12345
),
"12345"
},
{
zz64
(
kInt64Max
),
std
::
to_string
(
kInt64Max
)},
{
zz64
(
kInt64Max
),
std
::
to_string
(
kInt64Max
)},
{
zz64
(
kInt64Min
),
std
::
to_string
(
kInt64Min
)}
{
zz64
(
kInt64Min
),
std
::
to_string
(
kInt64Min
)}
}
,
true
);
});
// TODO(haberman):
// TODO(haberman):
// TestValidDataForType(FieldDescriptor::TYPE_STRING
// TestValidDataForType(FieldDescriptor::TYPE_STRING
...
...
conformance/conformance_test.h
View file @
fcb92682
...
@@ -210,8 +210,7 @@ class ConformanceTestSuite {
...
@@ -210,8 +210,7 @@ class ConformanceTestSuite {
void
TestIllegalTags
();
void
TestIllegalTags
();
void
TestValidDataForType
(
void
TestValidDataForType
(
google
::
protobuf
::
FieldDescriptor
::
Type
,
google
::
protobuf
::
FieldDescriptor
::
Type
,
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
values
,
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
values
);
bool
isProto3
);
bool
CheckSetEmpty
(
const
set
<
string
>&
set_to_check
,
bool
CheckSetEmpty
(
const
set
<
string
>&
set_to_check
,
const
std
::
string
&
write_to_file
,
const
std
::
string
&
msg
);
const
std
::
string
&
write_to_file
,
const
std
::
string
&
msg
);
ConformanceTestRunner
*
runner_
;
ConformanceTestRunner
*
runner_
;
...
...
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