Add an explicit test using secure coding for added safety.

This commit is contained in:
Thomas Van Lenten 2019-08-29 17:09:02 -04:00
parent 829bb1d791
commit 6ec27f0d08

View File

@ -338,14 +338,38 @@
}
- (void)testCoding {
GPBMessage *original = [self mergeResult];
NSData *data =
[NSKeyedArchiver archivedDataWithRootObject:[self mergeResult]];
[NSKeyedArchiver archivedDataWithRootObject:original];
id unarchivedObject = [NSKeyedUnarchiver unarchiveObjectWithData:data];
XCTAssertEqualObjects(unarchivedObject, [self mergeResult]);
XCTAssertEqualObjects(unarchivedObject, original);
// Intentionally doing a pointer comparison.
XCTAssertNotEqual(unarchivedObject, [self mergeResult]);
XCTAssertNotEqual(unarchivedObject, original);
}
- (void)testSecureCoding {
GPBMessage *original = [self mergeResult];
NSString *key = @"testing123";
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver setRequiresSecureCoding:YES];
[archiver encodeObject:obj forKey:key];
[archiver finishEncoding];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
[unarchiver setRequiresSecureCoding:YES];
id unarchivedObject = [unarchiver decodeObjectOfClass:[GPBMessage class]
forKey:key];
[unarchiver finishDecoding];
XCTAssertEqualObjects(unarchivedObject, original);
// Intentionally doing a pointer comparison.
XCTAssertNotEqual(unarchivedObject, original);
}
- (void)testObjectReset {