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
881db010
Commit
881db010
authored
Sep 04, 2008
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix initialization check when an optional field has required subfields
parent
0dabc77f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
12 deletions
+53
-12
GeneratedMessageTest.cs
csharp/ProtocolBuffers.Test/GeneratedMessageTest.cs
+16
-0
UnitTestOptimizeForProtoFile.cs
...olBuffers.Test/TestProtos/UnitTestOptimizeForProtoFile.cs
+0
-0
GeneratedMessage.cs
csharp/ProtocolBuffers/GeneratedMessage.cs
+1
-1
GeneratedMessage.java
java/src/main/java/com/google/protobuf/GeneratedMessage.java
+1
-1
GeneratedMessageTest.java
...c/test/java/com/google/protobuf/GeneratedMessageTest.java
+27
-10
unittest_optimize_for.proto
src/google/protobuf/unittest_optimize_for.proto
+8
-0
No files found.
csharp/ProtocolBuffers.Test/GeneratedMessageTest.cs
View file @
881db010
...
...
@@ -270,5 +270,21 @@ namespace Google.ProtocolBuffers {
Assert
.
IsFalse
(
TestAllExtensions
.
DefaultInstance
.
HasExtension
(
MultiFileProto
.
ExtensionWithOuter
));
}
[
Test
]
public
void
OptionalFieldWithRequiredSubfieldsOptimizedForSize
()
{
TestOptionalOptimizedForSize
message
=
TestOptionalOptimizedForSize
.
DefaultInstance
;
Assert
.
IsTrue
(
message
.
IsInitialized
);
message
=
TestOptionalOptimizedForSize
.
CreateBuilder
().
SetO
(
TestRequiredOptimizedForSize
.
CreateBuilder
().
BuildPartial
()
).
BuildPartial
();
Assert
.
IsFalse
(
message
.
IsInitialized
);
message
=
TestOptionalOptimizedForSize
.
CreateBuilder
().
SetO
(
TestRequiredOptimizedForSize
.
CreateBuilder
().
SetX
(
5
).
BuildPartial
()
).
BuildPartial
();
Assert
.
IsTrue
(
message
.
IsInitialized
);
}
}
}
csharp/ProtocolBuffers.Test/TestProtos/UnitTestOptimizeForProtoFile.cs
View file @
881db010
This diff is collapsed.
Click to expand it.
csharp/ProtocolBuffers/GeneratedMessage.cs
View file @
881db010
...
...
@@ -92,7 +92,7 @@ namespace Google.ProtocolBuffers {
}
}
}
else
{
if
(!((
IMessage
)
this
[
field
]).
IsInitialized
)
{
if
(
HasField
(
field
)
&&
!((
IMessage
)
this
[
field
]).
IsInitialized
)
{
return
false
;
}
}
...
...
java/src/main/java/com/google/protobuf/GeneratedMessage.java
View file @
881db010
...
...
@@ -94,7 +94,7 @@ public abstract class GeneratedMessage extends AbstractMessage {
}
}
}
else
{
if
(!((
Message
)
getField
(
field
)).
isInitialized
())
{
if
(
hasField
(
field
)
&&
!((
Message
)
getField
(
field
)).
isInitialized
())
{
return
false
;
}
}
...
...
java/src/test/java/com/google/protobuf/GeneratedMessageTest.java
View file @
881db010
...
...
@@ -16,19 +16,21 @@
package
com
.
google
.
protobuf
;
import
java.util.Arrays
;
import
junit.framework.TestCase
;
import
protobuf_unittest.EnumWithNoOuter
;
import
protobuf_unittest.MessageWithNoOuter
;
import
protobuf_unittest.MultipleFilesTestProto
;
import
protobuf_unittest.ServiceWithNoOuter
;
import
protobuf_unittest.UnittestProto
;
import
protobuf_unittest.UnittestProto.ForeignMessage
;
import
protobuf_unittest.UnittestOptimizeFor.TestOptionalOptimizedForSize
;
import
protobuf_unittest.UnittestOptimizeFor.TestRequiredOptimizedForSize
;
import
protobuf_unittest.UnittestProto.ForeignEnum
;
import
protobuf_unittest.UnittestProto.
TestAllTypes
;
import
protobuf_unittest.UnittestProto.
ForeignMessage
;
import
protobuf_unittest.UnittestProto.TestAllExtensions
;
import
protobuf_unittest.UnittestProto.TestAllTypes
;
import
protobuf_unittest.UnittestProto.TestExtremeDefaultValues
;
import
protobuf_unittest.MultipleFilesTestProto
;
import
protobuf_unittest.MessageWithNoOuter
;
import
protobuf_unittest.EnumWithNoOuter
;
import
protobuf_unittest.ServiceWithNoOuter
;
import
junit.framework.TestCase
;
import
java.util.Arrays
;
/**
* Unit test for generated messages and generated code. See also
...
...
@@ -93,7 +95,7 @@ public class GeneratedMessageTest extends TestCase {
// TODO(ngd): Upgrade to using real #equals method once implemented
assertEquals
(
expectedMessage
.
toString
(),
message
.
toString
());
}
public
void
testSettingRepeatedForeignMessageUsingBuilder
()
throws
Exception
{
TestAllTypes
message
=
TestAllTypes
.
newBuilder
()
// Pass builder for foreign message instance.
...
...
@@ -243,4 +245,19 @@ public class GeneratedMessageTest extends TestCase {
TestAllExtensions
.
getDefaultInstance
().
hasExtension
(
MultipleFilesTestProto
.
extensionWithOuter
));
}
public
void
testOptionalFieldWithRequiredSubfieldsOptimizedForSize
()
throws
Exception
{
TestOptionalOptimizedForSize
message
=
TestOptionalOptimizedForSize
.
getDefaultInstance
();
assertTrue
(
message
.
isInitialized
());
message
=
TestOptionalOptimizedForSize
.
newBuilder
().
setO
(
TestRequiredOptimizedForSize
.
newBuilder
().
buildPartial
()
).
buildPartial
();
assertFalse
(
message
.
isInitialized
());
message
=
TestOptionalOptimizedForSize
.
newBuilder
().
setO
(
TestRequiredOptimizedForSize
.
newBuilder
().
setX
(
5
).
buildPartial
()
).
buildPartial
();
assertTrue
(
message
.
isInitialized
());
}
}
src/google/protobuf/unittest_optimize_for.proto
View file @
881db010
...
...
@@ -39,3 +39,11 @@ message TestOptimizedForSize {
optional
int32
test_extension
=
1234
;
}
}
message
TestRequiredOptimizedForSize
{
required
int32
x
=
1
;
}
message
TestOptionalOptimizedForSize
{
optional
TestRequiredOptimizedForSize
o
=
1
;
}
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