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.AbstractMessage
;
import
com.google.protobuf.Parser
;
import
com.google.protobuf.CodedInputStream
;
import
com.google.protobuf.conformance.Conformance
;
import
com.google.protobuf.InvalidProtocolBufferException
;
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.TestAllTypesProto2
;
import
com.google.protobuf.ExtensionRegistry
;
import
com.google.protobuf.util.JsonFormat
;
import
com.google.protobuf.util.JsonFormat.TypeRegistry
;
import
java.io.IOException
;
import
java.nio.ByteBuffer
;
import
java.util.ArrayList
;
class
ConformanceJava
{
private
int
testCount
=
0
;
...
...
@@ -51,275 +56,100 @@ class ConformanceJava {
buf
[
3
]
=
(
byte
)(
val
>>
24
);
writeToStdout
(
buf
);
}
private
enum
BinaryDecoder
{
BYTE_STRING_DECODER
()
{
@Override
public
TestMessagesProto3
.
TestAllTypes
parseProto3
(
ByteString
bytes
)
throws
InvalidProtocolBufferException
{
return
TestMessagesProto3
.
TestAllTypes
.
parseFrom
(
bytes
);
}
@Override
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
enum
BinaryDecoderType
{
BTYE_STRING_DECODER
,
BYTE_ARRAY_DECODER
,
ARRAY_BYTE_BUFFER_DECODER
,
READONLY_ARRAY_BYTE_BUFFER_DECODER
,
DIRECT_BYTE_BUFFER_DECODER
,
READONLY_DIRECT_BYTE_BUFFER_DECODER
,
INPUT_STREAM_DECODER
;
}
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
{
TestMessagesProto3
.
TestAllTypes
[]
messages
=
new
TestMessagesProto3
.
TestAllTypes
[
BinaryDecoder
.
values
().
length
];
InvalidProtocolBufferException
[]
exceptions
=
new
InvalidProtocolBufferException
[
BinaryDecoder
.
values
().
length
];
boolean
hasMessage
=
false
;
boolean
hasException
=
false
;
for
(
int
i
=
0
;
i
<
BinaryDecoder
.
values
().
length
;
++
i
)
{
try
{
messages
[
i
]
=
BinaryDecoder
.
values
()[
i
].
parseProto3
(
bytes
);
hasMessage
=
true
;
}
catch
(
InvalidProtocolBufferException
e
)
{
exceptions
[
i
]
=
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"
);
switch
(
type
)
{
case
BTYE_STRING_DECODER:
return
parser
.
parseFrom
(
bytes
,
extensions
);
case
BYTE_ARRAY_DECODER:
return
parser
.
parseFrom
(
bytes
.
toByteArray
(),
extensions
);
case
ARRAY_BYTE_BUFFER_DECODER:
{
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
bytes
.
size
());
bytes
.
copyTo
(
buffer
);
buffer
.
flip
();
try
{
return
parser
.
parseFrom
(
CodedInputStream
.
newInstance
(
buffer
),
extensions
);
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
}
}
throw
new
RuntimeException
(
sb
.
toString
());
}
if
(
hasException
)
{
// We do not check if exceptions are equal. Different implementations may return different
// exception messages. Throw an arbitrary one out instead.
throw
exceptions
[
0
];
}
// Fast path comparing all the messages with the first message, assuming equality being
// symmetric and transitive.
boolean
allEqual
=
true
;
for
(
int
i
=
1
;
i
<
messages
.
length
;
++
i
)
{
if
(!
messages
[
0
].
equals
(
messages
[
i
]))
{
allEqual
=
false
;
break
;
}
}
// Slow path: compare and find out all unequal pairs.
if
(!
allEqual
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
messages
.
length
-
1
;
++
i
)
{
for
(
int
j
=
i
+
1
;
j
<
messages
.
length
;
++
j
)
{
if
(!
messages
[
i
].
equals
(
messages
[
j
]))
{
sb
.
append
(
BinaryDecoder
.
values
()[
i
].
name
())
.
append
(
" and "
)
.
append
(
BinaryDecoder
.
values
()[
j
].
name
())
.
append
(
" parsed the payload differently.\n"
);
case
READONLY_ARRAY_BYTE_BUFFER_DECODER:
{
try
{
return
parser
.
parseFrom
(
CodedInputStream
.
newInstance
(
bytes
.
asReadOnlyByteBuffer
()),
extensions
);
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
}
case
DIRECT_BYTE_BUFFER_DECODER:
{
ByteBuffer
buffer
=
ByteBuffer
.
allocateDirect
(
bytes
.
size
());
bytes
.
copyTo
(
buffer
);
buffer
.
flip
();
try
{
return
parser
.
parseFrom
(
CodedInputStream
.
newInstance
(
buffer
),
extensions
);
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
}
case
READONLY_DIRECT_BYTE_BUFFER_DECODER:
{
ByteBuffer
buffer
=
ByteBuffer
.
allocateDirect
(
bytes
.
size
());
bytes
.
copyTo
(
buffer
);
buffer
.
flip
();
try
{
return
parser
.
parseFrom
(
CodedInputStream
.
newInstance
(
buffer
.
asReadOnlyBuffer
()),
extensions
);
}
catch
(
InvalidProtocolBufferException
e
)
{
throw
e
;
}
}
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
{
TestMessagesProto2
.
TestAllTypesProto2
[]
messages
=
new
TestMessagesProto2
.
TestAllTypesProto2
[
BinaryDecoder
.
values
().
length
];
InvalidProtocolBufferException
[]
exceptions
=
new
InvalidProtocolBufferException
[
BinaryDecoder
.
values
().
length
];
ArrayList
<
MessageType
>
messages
=
new
ArrayList
<
MessageType
>
();
ArrayList
<
InvalidProtocolBufferException
>
exceptions
=
new
ArrayList
<
InvalidProtocolBufferException
>();
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
hasException
=
false
;
for
(
int
i
=
0
;
i
<
BinaryDecoder
.
values
().
length
;
++
i
)
{
for
(
int
i
=
0
;
i
<
BinaryDecoder
Type
.
values
().
length
;
++
i
)
{
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
;
}
catch
(
InvalidProtocolBufferException
e
)
{
exceptions
[
i
]
=
e
;
exceptions
.
set
(
i
,
e
)
;
hasException
=
true
;
}
}
...
...
@@ -327,9 +157,9 @@ class ConformanceJava {
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
)
{
for
(
int
i
=
0
;
i
<
BinaryDecoder
Type
.
values
().
length
;
++
i
)
{
sb
.
append
(
BinaryDecoder
Type
.
values
()[
i
].
name
());
if
(
messages
.
get
(
i
)
!=
null
)
{
sb
.
append
(
" accepted the payload.\n"
);
}
else
{
sb
.
append
(
" rejected the payload.\n"
);
...
...
@@ -341,14 +171,14 @@ class ConformanceJava {
if
(
hasException
)
{
// We do not check if exceptions are equal. Different implementations may return different
// 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
// symmetric and transitive.
boolean
allEqual
=
true
;
for
(
int
i
=
1
;
i
<
messages
.
length
;
++
i
)
{
if
(!
messages
[
0
].
equals
(
messages
[
i
]
))
{
for
(
int
i
=
1
;
i
<
messages
.
size
()
;
++
i
)
{
if
(!
messages
.
get
(
0
).
equals
(
messages
.
get
(
i
)
))
{
allEqual
=
false
;
break
;
}
...
...
@@ -357,12 +187,12 @@ class ConformanceJava {
// Slow path: compare and find out all unequal pairs.
if
(!
allEqual
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
messages
.
length
-
1
;
++
i
)
{
for
(
int
j
=
i
+
1
;
j
<
messages
.
length
;
++
j
)
{
if
(!
messages
[
i
].
equals
(
messages
[
j
]
))
{
sb
.
append
(
BinaryDecoder
.
values
()[
i
].
name
())
for
(
int
i
=
0
;
i
<
messages
.
size
()
-
1
;
++
i
)
{
for
(
int
j
=
i
+
1
;
j
<
messages
.
size
()
;
++
j
)
{
if
(!
messages
.
get
(
i
).
equals
(
messages
.
get
(
j
)
))
{
sb
.
append
(
BinaryDecoder
Type
.
values
()[
i
].
name
())
.
append
(
" and "
)
.
append
(
BinaryDecoder
.
values
()[
j
].
name
())
.
append
(
BinaryDecoder
Type
.
values
()[
j
].
name
())
.
append
(
" parsed the payload differently.\n"
);
}
}
...
...
@@ -370,25 +200,29 @@ class ConformanceJava {
throw
new
RuntimeException
(
sb
.
toString
());
}
return
messages
[
0
]
;
return
messages
.
get
(
0
)
;
}
private
Conformance
.
ConformanceResponse
doTest
(
Conformance
.
ConformanceRequest
request
)
{
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
())
{
case
PROTOBUF_PAYLOAD:
{
if
(
isProto3
)
{
try
{
testMessage
=
parseBinaryToProto3
(
request
.
getProtobufPayload
());
ExtensionRegistry
extensions
=
ExtensionRegistry
.
newInstance
();
TestMessagesProto3
.
registerAllExtensions
(
extensions
);
testMessage
=
parseBinary
(
request
.
getProtobufPayload
(),
TestAllTypes
.
parser
(),
extensions
);
}
catch
(
InvalidProtocolBufferException
e
)
{
return
Conformance
.
ConformanceResponse
.
newBuilder
().
setParseError
(
e
.
getMessage
()).
build
();
}
}
else
if
(
request
.
getMessageType
().
equals
(
"proto2"
)
)
{
}
else
if
(
isProto2
)
{
try
{
testMessage
=
parseBinaryToProto2
(
request
.
getProtobufPayload
());
ExtensionRegistry
extensions
=
ExtensionRegistry
.
newInstance
();
TestMessagesProto2
.
registerAllExtensions
(
extensions
);
testMessage
=
parseBinary
(
request
.
getProtobufPayload
(),
TestAllTypesProto2
.
parser
(),
extensions
);
}
catch
(
InvalidProtocolBufferException
e
)
{
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) {
void
ConformanceTestSuite
::
TestValidDataForType
(
FieldDescriptor
::
Type
type
,
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
values
,
bool
isProto3
)
{
const
string
type_name
=
UpperCase
(
string
(
"."
)
+
FieldDescriptor
::
TypeName
(
type
));
WireFormatLite
::
WireType
wire_type
=
WireFormatLite
::
WireTypeForFieldType
(
static_cast
<
WireFormatLite
::
FieldType
>
(
type
));
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
),
field
->
name
()
+
": "
+
values
[
0
].
second
,
isProto3
);
string
proto
;
string
text
=
field
->
name
()
+
": "
+
values
.
back
().
second
;
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
);
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
values
)
{
for
(
int
isProto3
=
0
;
isProto3
<
2
;
isProto3
++
)
{
const
string
type_name
=
UpperCase
(
string
(
"."
)
+
FieldDescriptor
::
TypeName
(
type
));
WireFormatLite
::
WireType
wire_type
=
WireFormatLite
::
WireTypeForFieldType
(
static_cast
<
WireFormatLite
::
FieldType
>
(
type
));
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
),
field
->
name
()
+
": "
+
values
[
0
].
second
,
isProto3
);
string
proto
;
string
text
=
field
->
name
()
+
": "
+
values
.
back
().
second
;
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
);
proto
.
clear
();
text
.
clear
();
proto
.
clear
();
text
.
clear
();
for
(
size_t
i
=
0
;
i
<
values
.
size
();
i
++
)
{
proto
+=
cat
(
tag
(
rep_field
->
number
(),
wire_type
),
values
[
i
].
first
);
text
+=
rep_field
->
name
()
+
": "
+
values
[
i
].
second
+
" "
;
for
(
size_t
i
=
0
;
i
<
values
.
size
();
i
++
)
{
proto
+=
cat
(
tag
(
rep_field
->
number
(),
wire_type
),
values
[
i
].
first
);
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
,
...
...
@@ -793,29 +795,23 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
{
dbl
(
0.1
),
"0.1"
},
{
dbl
(
1.7976931348623157e+308
),
"1.7976931348623157e+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
,
{
{
flt
(
0.1
),
"0.1"
},
{
flt
(
1.00000075e-36
),
"1.00000075e-36"
},
{
flt
(
3.402823e+38
),
"3.402823e+38"
},
// 3.40282347e+38
{
flt
(
1.17549435e-38
f
),
"1.17549435e-38"
}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_INT64
,
{
{
varint
(
12345
),
"12345"
},
{
varint
(
kInt64Max
),
std
::
to_string
(
kInt64Max
)},
{
varint
(
kInt64Min
),
std
::
to_string
(
kInt64Min
)}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_UINT64
,
{
{
varint
(
12345
),
"12345"
},
{
varint
(
kUint64Max
),
std
::
to_string
(
kUint64Max
)},
{
varint
(
0
),
"0"
}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_INT32
,
{
{
varint
(
12345
),
"12345"
},
{
longvarint
(
12345
,
2
),
"12345"
},
...
...
@@ -825,7 +821,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
{
varint
(
1LL
<<
33
),
std
::
to_string
(
static_cast
<
int32
>
(
1LL
<<
33
))},
{
varint
((
1LL
<<
33
)
-
1
),
std
::
to_string
(
static_cast
<
int32
>
((
1LL
<<
33
)
-
1
))},
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_UINT32
,
{
{
varint
(
12345
),
"12345"
},
{
longvarint
(
12345
,
2
),
"12345"
},
...
...
@@ -835,42 +831,42 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
{
varint
(
1LL
<<
33
),
std
::
to_string
(
static_cast
<
uint32
>
(
1LL
<<
33
))},
{
varint
((
1LL
<<
33
)
-
1
),
std
::
to_string
(
static_cast
<
uint32
>
((
1LL
<<
33
)
-
1
))},
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_FIXED64
,
{
{
u64
(
12345
),
"12345"
},
{
u64
(
kUint64Max
),
std
::
to_string
(
kUint64Max
)},
{
u64
(
0
),
"0"
}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_FIXED32
,
{
{
u32
(
12345
),
"12345"
},
{
u32
(
kUint32Max
),
std
::
to_string
(
kUint32Max
)},
// UINT32_MAX
{
u32
(
0
),
"0"
}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_SFIXED64
,
{
{
u64
(
12345
),
"12345"
},
{
u64
(
kInt64Max
),
std
::
to_string
(
kInt64Max
)},
{
u64
(
kInt64Min
),
std
::
to_string
(
kInt64Min
)}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_SFIXED32
,
{
{
u32
(
12345
),
"12345"
},
{
u32
(
kInt32Max
),
std
::
to_string
(
kInt32Max
)},
{
u32
(
kInt32Min
),
std
::
to_string
(
kInt32Min
)}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_BOOL
,
{
{
varint
(
1
),
"true"
},
{
varint
(
0
),
"false"
},
{
varint
(
12345678
),
"true"
}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_SINT32
,
{
{
zz32
(
12345
),
"12345"
},
{
zz32
(
kInt32Max
),
std
::
to_string
(
kInt32Max
)},
{
zz32
(
kInt32Min
),
std
::
to_string
(
kInt32Min
)}
}
,
true
);
});
TestValidDataForType
(
FieldDescriptor
::
TYPE_SINT64
,
{
{
zz64
(
12345
),
"12345"
},
{
zz64
(
kInt64Max
),
std
::
to_string
(
kInt64Max
)},
{
zz64
(
kInt64Min
),
std
::
to_string
(
kInt64Min
)}
}
,
true
);
});
// TODO(haberman):
// TestValidDataForType(FieldDescriptor::TYPE_STRING
...
...
conformance/conformance_test.h
View file @
fcb92682
...
...
@@ -210,8 +210,7 @@ class ConformanceTestSuite {
void
TestIllegalTags
();
void
TestValidDataForType
(
google
::
protobuf
::
FieldDescriptor
::
Type
,
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
values
,
bool
isProto3
);
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
values
);
bool
CheckSetEmpty
(
const
set
<
string
>&
set_to_check
,
const
std
::
string
&
write_to_file
,
const
std
::
string
&
msg
);
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