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
8c1748f1
Commit
8c1748f1
authored
Oct 02, 2018
by
Thomas Van Lenten
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests to confirm strings/bytes are copied.
parent
09c001e9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
GPBMessageTests+Runtime.m
objectivec/Tests/GPBMessageTests+Runtime.m
+66
-0
No files found.
objectivec/Tests/GPBMessageTests+Runtime.m
View file @
8c1748f1
...
...
@@ -2491,6 +2491,72 @@
XCTAssertEqualObjects
(
@"bar"
,
message
.
mapStringString
[
@"foo"
]);
}
-
(
void
)
test_StringFieldsCopy
{
// ObjC conventions call for NSString properites to be copy, ensure
// that is done correctly and the string isn't simply retained.
Message2
*
msg1
=
[
Message2
message
];
Message2
*
msg2
=
[
Message2
message
];
GPBFieldDescriptor
*
fieldDesc
=
[[
Message2
descriptor
]
fieldWithNumber
:
Message2_FieldNumber_OptionalString
];
NSMutableString
*
mutableStr
=
[
NSMutableString
stringWithString
:
@"foo"
];
msg1
.
optionalString
=
mutableStr
;
GPBSetMessageStringField
(
msg2
,
fieldDesc
,
mutableStr
);
XCTAssertEqualObjects
(
msg1
.
optionalString
,
mutableStr
);
XCTAssertEqualObjects
(
msg1
.
optionalString
,
@"foo"
);
XCTAssertTrue
(
msg1
.
optionalString
!=
mutableStr
);
// Ptr comparision.
XCTAssertEqualObjects
(
msg2
.
optionalString
,
mutableStr
);
XCTAssertEqualObjects
(
msg2
.
optionalString
,
@"foo"
);
XCTAssertTrue
(
msg2
.
optionalString
!=
mutableStr
);
// Ptr comparision.
[
mutableStr
appendString
:
@"bar"
];
XCTAssertNotEqualObjects
(
msg1
.
optionalString
,
mutableStr
);
XCTAssertEqualObjects
(
msg1
.
optionalString
,
@"foo"
);
XCTAssertTrue
(
msg1
.
optionalString
!=
mutableStr
);
// Ptr comparision.
XCTAssertNotEqualObjects
(
msg2
.
optionalString
,
mutableStr
);
XCTAssertEqualObjects
(
msg2
.
optionalString
,
@"foo"
);
XCTAssertTrue
(
msg2
.
optionalString
!=
mutableStr
);
// Ptr comparision.
}
-
(
void
)
test_BytesFieldsCopy
{
// ObjC conventions call for NSData properites to be copy, ensure
// that is done correctly and the data isn't simply retained.
Message2
*
msg1
=
[
Message2
message
];
Message2
*
msg2
=
[
Message2
message
];
GPBFieldDescriptor
*
fieldDesc
=
[[
Message2
descriptor
]
fieldWithNumber
:
Message2_FieldNumber_OptionalBytes
];
NSMutableData
*
mutableData
=
[
NSMutableData
dataWithData
:
DataFromCStr
(
"abc"
)];
msg1
.
optionalBytes
=
mutableData
;
GPBSetMessageBytesField
(
msg2
,
fieldDesc
,
mutableData
);
XCTAssertEqualObjects
(
msg1
.
optionalBytes
,
mutableData
);
XCTAssertEqualObjects
(
msg1
.
optionalBytes
,
DataFromCStr
(
"abc"
));
XCTAssertTrue
(
msg1
.
optionalBytes
!=
mutableData
);
// Ptr comparision.
XCTAssertEqualObjects
(
msg2
.
optionalBytes
,
mutableData
);
XCTAssertEqualObjects
(
msg2
.
optionalBytes
,
DataFromCStr
(
"abc"
));
XCTAssertTrue
(
msg2
.
optionalBytes
!=
mutableData
);
// Ptr comparision.
[
mutableData
appendData
:
DataFromCStr
(
"123"
)];
XCTAssertNotEqualObjects
(
msg1
.
optionalBytes
,
mutableData
);
XCTAssertEqualObjects
(
msg1
.
optionalBytes
,
DataFromCStr
(
"abc"
));
XCTAssertTrue
(
msg1
.
optionalBytes
!=
mutableData
);
// Ptr comparision.
XCTAssertNotEqualObjects
(
msg2
.
optionalBytes
,
mutableData
);
XCTAssertEqualObjects
(
msg2
.
optionalBytes
,
DataFromCStr
(
"abc"
));
XCTAssertTrue
(
msg2
.
optionalBytes
!=
mutableData
);
// Ptr comparision.
}
#pragma mark - Subset from from map_tests.cc
// TEST(GeneratedMapFieldTest, IsInitialized)
...
...
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