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
cd561ddd
Commit
cd561ddd
authored
Aug 12, 2016
by
Thomas Van Lenten
Committed by
GitHub
Aug 12, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1949 from thomasvl/objc_more_reset_tests
Objc more reset tests
parents
91b6d04e
ff85a173
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
152 additions
and
29 deletions
+152
-29
GPBMessageTests+Runtime.m
objectivec/Tests/GPBMessageTests+Runtime.m
+152
-29
No files found.
objectivec/Tests/GPBMessageTests+Runtime.m
View file @
cd561ddd
...
@@ -326,6 +326,17 @@
...
@@ -326,6 +326,17 @@
//% [msg release];
//% [msg release];
//% }
//% }
//%
//%
//%PDDM-DEFINE PROTO2_TEST_CLEAR_FIELD_WITH_NIL(FIELD, VALUE)
//% { // optional##FIELD
//% Message2 *msg = [[Message2 alloc] init];
//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
//% msg.optional##FIELD = VALUE;
//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
//% msg.optional##FIELD = nil;
//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
//% [msg release];
//% }
//%
//%PDDM-DEFINE PROTO2_TEST_HAS_FIELDS()
//%PDDM-DEFINE PROTO2_TEST_HAS_FIELDS()
//%PROTO2_TEST_HAS_FIELD(Int32, 1, 0)
//%PROTO2_TEST_HAS_FIELD(Int32, 1, 0)
//%PROTO2_TEST_HAS_FIELD(Int64, 1, 0)
//%PROTO2_TEST_HAS_FIELD(Int64, 1, 0)
...
@@ -347,6 +358,14 @@
...
@@ -347,6 +358,14 @@
//% //
//% //
//%
//%
//%PROTO2_TEST_HAS_FIELD(Enum, Message2_Enum_Bar, Message2_Enum_Foo)
//%PROTO2_TEST_HAS_FIELD(Enum, Message2_Enum_Bar, Message2_Enum_Foo)
//% //
//% // Nil can also be used to clear strings, bytes, groups, and messages.
//% //
//%
//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(String, @"foo")
//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding])
//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(Group, [Message2_OptionalGroup message])
//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(Message, [Message2 message])
//%PDDM-EXPAND PROTO2_TEST_HAS_FIELDS()
//%PDDM-EXPAND PROTO2_TEST_HAS_FIELDS()
// This block of code is generated, do not edit it directly.
// This block of code is generated, do not edit it directly.
...
@@ -658,13 +677,57 @@
...
@@ -658,13 +677,57 @@
[
msg
release
];
[
msg
release
];
}
}
//
// Nil can also be used to clear strings, bytes, groups, and messages.
//
{
// optionalString
Message2
*
msg
=
[[
Message2
alloc
]
init
];
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalString
));
msg
.
optionalString
=
@"foo"
;
XCTAssertTrue
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalString
));
msg
.
optionalString
=
nil
;
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalString
));
[
msg
release
];
}
{
// optionalBytes
Message2
*
msg
=
[[
Message2
alloc
]
init
];
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalBytes
));
msg
.
optionalBytes
=
[
@"foo"
dataUsingEncoding
:
NSUTF8StringEncoding
];
XCTAssertTrue
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalBytes
));
msg
.
optionalBytes
=
nil
;
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalBytes
));
[
msg
release
];
}
{
// optionalGroup
Message2
*
msg
=
[[
Message2
alloc
]
init
];
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalGroup
));
msg
.
optionalGroup
=
[
Message2_OptionalGroup
message
];
XCTAssertTrue
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalGroup
));
msg
.
optionalGroup
=
nil
;
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalGroup
));
[
msg
release
];
}
{
// optionalMessage
Message2
*
msg
=
[[
Message2
alloc
]
init
];
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalMessage
));
msg
.
optionalMessage
=
[
Message2
message
];
XCTAssertTrue
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalMessage
));
msg
.
optionalMessage
=
nil
;
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message2_FieldNumber_OptionalMessage
));
[
msg
release
];
}
//%PDDM-EXPAND-END PROTO2_TEST_HAS_FIELDS()
//%PDDM-EXPAND-END PROTO2_TEST_HAS_FIELDS()
}
}
-
(
void
)
testProto3SingleFieldHasBehavior
{
-
(
void
)
testProto3SingleFieldHasBehavior
{
//
//
// Setting to any value
including
the default value (0) should result has*
// Setting to any value
but
the default value (0) should result has*
// being true.
// being true.
When set to the default, shouldn't be true.
//
//
//%PDDM-DEFINE PROTO3_TEST_HAS_FIELD(FIELD, NON_ZERO_VALUE, ZERO_VALUE)
//%PDDM-DEFINE PROTO3_TEST_HAS_FIELD(FIELD, NON_ZERO_VALUE, ZERO_VALUE)
...
@@ -678,6 +741,17 @@
...
@@ -678,6 +741,17 @@
//% [msg release];
//% [msg release];
//% }
//% }
//%
//%
//%PDDM-DEFINE PROTO3_TEST_CLEAR_FIELD_WITH_NIL(FIELD, VALUE)
//% { // optional##FIELD
//% Message3 *msg = [[Message3 alloc] init];
//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
//% msg.optional##FIELD = VALUE;
//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
//% msg.optional##FIELD = nil;
//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
//% [msg release];
//% }
//%
//%PDDM-DEFINE PROTO3_TEST_HAS_FIELDS()
//%PDDM-DEFINE PROTO3_TEST_HAS_FIELDS()
//%PROTO3_TEST_HAS_FIELD(Int32, 1, 0)
//%PROTO3_TEST_HAS_FIELD(Int32, 1, 0)
//%PROTO3_TEST_HAS_FIELD(Int64, 1, 0)
//%PROTO3_TEST_HAS_FIELD(Int64, 1, 0)
...
@@ -695,10 +769,17 @@
...
@@ -695,10 +769,17 @@
//%PROTO3_TEST_HAS_FIELD(String, @"foo", @"")
//%PROTO3_TEST_HAS_FIELD(String, @"foo", @"")
//%PROTO3_TEST_HAS_FIELD(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding], [NSData data])
//%PROTO3_TEST_HAS_FIELD(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding], [NSData data])
//% //
//% //
//% // Test doesn't apply to optional
Group/optionalMessage
.
//% // Test doesn't apply to optional
Message (no groups in proto3)
.
//% //
//% //
//%
//%
//%PROTO3_TEST_HAS_FIELD(Enum, Message3_Enum_Bar, Message3_Enum_Foo)
//%PROTO3_TEST_HAS_FIELD(Enum, Message3_Enum_Bar, Message3_Enum_Foo)
//% //
//% // Nil can also be used to clear strings, bytes, and messages (no groups in proto3).
//% //
//%
//%PROTO3_TEST_CLEAR_FIELD_WITH_NIL(String, @"foo")
//%PROTO3_TEST_CLEAR_FIELD_WITH_NIL(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding])
//%PROTO3_TEST_CLEAR_FIELD_WITH_NIL(Message, [Message3 message])
//%PDDM-EXPAND PROTO3_TEST_HAS_FIELDS()
//%PDDM-EXPAND PROTO3_TEST_HAS_FIELDS()
// This block of code is generated, do not edit it directly.
// This block of code is generated, do not edit it directly.
...
@@ -853,7 +934,7 @@
...
@@ -853,7 +934,7 @@
}
}
//
//
// Test doesn't apply to optional
Group/optionalMessage
.
// Test doesn't apply to optional
Message (no groups in proto3)
.
//
//
{
// optionalEnum
{
// optionalEnum
...
@@ -866,6 +947,40 @@
...
@@ -866,6 +947,40 @@
[
msg
release
];
[
msg
release
];
}
}
//
// Nil can also be used to clear strings, bytes, and messages (no groups in proto3).
//
{
// optionalString
Message3
*
msg
=
[[
Message3
alloc
]
init
];
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message3_FieldNumber_OptionalString
));
msg
.
optionalString
=
@"foo"
;
XCTAssertTrue
(
GPBMessageHasFieldNumberSet
(
msg
,
Message3_FieldNumber_OptionalString
));
msg
.
optionalString
=
nil
;
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message3_FieldNumber_OptionalString
));
[
msg
release
];
}
{
// optionalBytes
Message3
*
msg
=
[[
Message3
alloc
]
init
];
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message3_FieldNumber_OptionalBytes
));
msg
.
optionalBytes
=
[
@"foo"
dataUsingEncoding
:
NSUTF8StringEncoding
];
XCTAssertTrue
(
GPBMessageHasFieldNumberSet
(
msg
,
Message3_FieldNumber_OptionalBytes
));
msg
.
optionalBytes
=
nil
;
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message3_FieldNumber_OptionalBytes
));
[
msg
release
];
}
{
// optionalMessage
Message3
*
msg
=
[[
Message3
alloc
]
init
];
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message3_FieldNumber_OptionalMessage
));
msg
.
optionalMessage
=
[
Message3
message
];
XCTAssertTrue
(
GPBMessageHasFieldNumberSet
(
msg
,
Message3_FieldNumber_OptionalMessage
));
msg
.
optionalMessage
=
nil
;
XCTAssertFalse
(
GPBMessageHasFieldNumberSet
(
msg
,
Message3_FieldNumber_OptionalMessage
));
[
msg
release
];
}
//%PDDM-EXPAND-END PROTO3_TEST_HAS_FIELDS()
//%PDDM-EXPAND-END PROTO3_TEST_HAS_FIELDS()
}
}
...
@@ -2007,52 +2122,52 @@
...
@@ -2007,52 +2122,52 @@
for
(
size_t
i
=
0
;
i
<
GPBARRAYSIZE
(
values
);
++
i
)
{
for
(
size_t
i
=
0
;
i
<
GPBARRAYSIZE
(
values
);
++
i
)
{
switch
(
values
[
i
])
{
switch
(
values
[
i
])
{
case
Message
3
_O_OneOfCase_OneofInt32
:
case
Message
2
_O_OneOfCase_OneofInt32
:
msg
.
oneofInt32
=
100
;
msg
.
oneofInt32
=
100
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofInt64
:
case
Message
2
_O_OneOfCase_OneofInt64
:
msg
.
oneofInt64
=
101
;
msg
.
oneofInt64
=
101
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofUint32
:
case
Message
2
_O_OneOfCase_OneofUint32
:
msg
.
oneofUint32
=
102
;
msg
.
oneofUint32
=
102
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofUint64
:
case
Message
2
_O_OneOfCase_OneofUint64
:
msg
.
oneofUint64
=
103
;
msg
.
oneofUint64
=
103
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofSint32
:
case
Message
2
_O_OneOfCase_OneofSint32
:
msg
.
oneofSint32
=
104
;
msg
.
oneofSint32
=
104
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofSint64
:
case
Message
2
_O_OneOfCase_OneofSint64
:
msg
.
oneofSint64
=
105
;
msg
.
oneofSint64
=
105
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofFixed32
:
case
Message
2
_O_OneOfCase_OneofFixed32
:
msg
.
oneofFixed32
=
106
;
msg
.
oneofFixed32
=
106
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofFixed64
:
case
Message
2
_O_OneOfCase_OneofFixed64
:
msg
.
oneofFixed64
=
107
;
msg
.
oneofFixed64
=
107
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofSfixed32
:
case
Message
2
_O_OneOfCase_OneofSfixed32
:
msg
.
oneofSfixed32
=
108
;
msg
.
oneofSfixed32
=
108
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofSfixed64
:
case
Message
2
_O_OneOfCase_OneofSfixed64
:
msg
.
oneofSfixed64
=
109
;
msg
.
oneofSfixed64
=
109
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofFloat
:
case
Message
2
_O_OneOfCase_OneofFloat
:
msg
.
oneofFloat
=
110
.
0
f
;
msg
.
oneofFloat
=
110
.
0
f
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofDouble
:
case
Message
2
_O_OneOfCase_OneofDouble
:
msg
.
oneofDouble
=
111
.
0
;
msg
.
oneofDouble
=
111
.
0
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofBool
:
case
Message
2
_O_OneOfCase_OneofBool
:
msg
.
oneofBool
=
YES
;
msg
.
oneofBool
=
YES
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofString
:
case
Message
2
_O_OneOfCase_OneofString
:
msg
.
oneofString
=
oneofStringDefault
;
msg
.
oneofString
=
oneofStringDefault
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofBytes
:
case
Message
2
_O_OneOfCase_OneofBytes
:
msg
.
oneofBytes
=
oneofBytesDefault
;
msg
.
oneofBytes
=
oneofBytesDefault
;
break
;
break
;
case
Message
3
_O_OneOfCase_OneofEnum
:
case
Message
2
_O_OneOfCase_OneofEnum
:
msg
.
oneofEnum
=
Message3_Enum_Baz
;
msg
.
oneofEnum
=
Message3_Enum_Baz
;
break
;
break
;
default
:
default
:
...
@@ -2063,7 +2178,7 @@
...
@@ -2063,7 +2178,7 @@
// Should be set to the correct case.
// Should be set to the correct case.
XCTAssertEqual
(
msg
.
oOneOfCase
,
values
[
i
],
"Loop: %zd"
,
i
);
XCTAssertEqual
(
msg
.
oOneOfCase
,
values
[
i
],
"Loop: %zd"
,
i
);
// Confirm everything is
back as
the defaults.
// Confirm everything is the defaults.
XCTAssertEqual
(
msg
.
oneofInt32
,
100
,
"Loop: %zd"
,
i
);
XCTAssertEqual
(
msg
.
oneofInt32
,
100
,
"Loop: %zd"
,
i
);
XCTAssertEqual
(
msg
.
oneofInt64
,
101
,
"Loop: %zd"
,
i
);
XCTAssertEqual
(
msg
.
oneofInt64
,
101
,
"Loop: %zd"
,
i
);
XCTAssertEqual
(
msg
.
oneofUint32
,
102U
,
"Loop: %zd"
,
i
);
XCTAssertEqual
(
msg
.
oneofUint32
,
102U
,
"Loop: %zd"
,
i
);
...
@@ -2079,20 +2194,25 @@
...
@@ -2079,20 +2194,25 @@
XCTAssertEqual
(
msg
.
oneofBool
,
YES
,
"Loop: %zd"
,
i
);
XCTAssertEqual
(
msg
.
oneofBool
,
YES
,
"Loop: %zd"
,
i
);
XCTAssertEqualObjects
(
msg
.
oneofString
,
oneofStringDefault
,
"Loop: %zd"
,
i
);
XCTAssertEqualObjects
(
msg
.
oneofString
,
oneofStringDefault
,
"Loop: %zd"
,
i
);
XCTAssertEqualObjects
(
msg
.
oneofBytes
,
oneofBytesDefault
,
"Loop: %zd"
,
i
);
XCTAssertEqualObjects
(
msg
.
oneofBytes
,
oneofBytesDefault
,
"Loop: %zd"
,
i
);
XCTAssertNotNil
(
msg
.
oneofGroup
,
"Loop: %zd"
,
i
);
// Skip group, no default to consider.
// Skip group
// Skip message, no default to consider.
// Skip message
XCTAssertEqual
(
msg
.
oneofEnum
,
Message2_Enum_Baz
,
"Loop: %zd"
,
i
);
XCTAssertEqual
(
msg
.
oneofEnum
,
Message2_Enum_Baz
,
"Loop: %zd"
,
i
);
}
}
// We special case nil on string, data,
message, ensure they work as expected.
// We special case nil on string, data,
group, and message, ensure they work
// i.e. - it clears the case.
//
as expected.
i.e. - it clears the case.
msg
.
oneofString
=
nil
;
msg
.
oneofString
=
nil
;
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message3_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertEqualObjects
(
msg
.
oneofString
,
oneofStringDefault
);
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message2_O_OneOfCase_GPBUnsetOneOfCase
);
msg
.
oneofBytes
=
nil
;
msg
.
oneofBytes
=
nil
;
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message3_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message2_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertEqualObjects
(
msg
.
oneofBytes
,
oneofBytesDefault
);
msg
.
oneofGroup
=
nil
;
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message2_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertNotNil
(
msg
.
oneofGroup
);
msg
.
oneofMessage
=
nil
;
msg
.
oneofMessage
=
nil
;
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message3_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message2_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertNotNil
(
msg
.
oneofMessage
);
[
msg
release
];
[
msg
release
];
}
}
...
@@ -2212,10 +2332,13 @@
...
@@ -2212,10 +2332,13 @@
// We special case nil on string, data, message, ensure they work as expected.
// We special case nil on string, data, message, ensure they work as expected.
msg
.
oneofString
=
nil
;
msg
.
oneofString
=
nil
;
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message3_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message3_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertEqualObjects
(
msg
.
oneofString
,
oneofStringDefault
);
msg
.
oneofBytes
=
nil
;
msg
.
oneofBytes
=
nil
;
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message3_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message3_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertEqualObjects
(
msg
.
oneofBytes
,
oneofBytesDefault
);
msg
.
oneofMessage
=
nil
;
msg
.
oneofMessage
=
nil
;
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message3_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertEqual
(
msg
.
oOneOfCase
,
Message3_O_OneOfCase_GPBUnsetOneOfCase
);
XCTAssertNotNil
(
msg
.
oneofMessage
);
[
msg
release
];
[
msg
release
];
}
}
...
...
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