Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: third_party/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2015 Google Inc. All rights reserved. 2 // Copyright 2015 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 14 matching lines...) Expand all
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 #import "GPBWellKnownTypes.h" 31 #import "GPBWellKnownTypes.h"
32 32
33 #import <XCTest/XCTest.h> 33 #import <XCTest/XCTest.h>
34 34
35 #import "google/protobuf/AnyTest.pbobjc.h"
36
35 // A basically random interval into the future for testing with. 37 // A basically random interval into the future for testing with.
36 static const NSTimeInterval kFutureOffsetInterval = 15000; 38 static const NSTimeInterval kFutureOffsetInterval = 15000;
37 39
38 // Nanosecond time accuracy 40 // Nanosecond time accuracy
39 static const NSTimeInterval kTimeAccuracy = 1e-9; 41 static const NSTimeInterval kTimeAccuracy = 1e-9;
40 42
41 @interface WellKnownTypesTest : XCTestCase 43 @interface WellKnownTypesTest : XCTestCase
42 @end 44 @end
43 45
44 @implementation WellKnownTypesTest 46 @implementation WellKnownTypesTest
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 GPBDuration *duration2 = 94 GPBDuration *duration2 =
93 [[GPBDuration alloc] initWithTimeIntervalSince1970:time]; 95 [[GPBDuration alloc] initWithTimeIntervalSince1970:time];
94 NSDate *date = [NSDate dateWithTimeIntervalSinceNow:kFutureOffsetInterval]; 96 NSDate *date = [NSDate dateWithTimeIntervalSinceNow:kFutureOffsetInterval];
95 time = date.timeIntervalSince1970; 97 time = date.timeIntervalSince1970;
96 duration2.timeIntervalSince1970 = time; 98 duration2.timeIntervalSince1970 = time;
97 durationTime = duration2.timeIntervalSince1970; 99 durationTime = duration2.timeIntervalSince1970;
98 XCTAssertEqualWithAccuracy(time, durationTime, kTimeAccuracy); 100 XCTAssertEqualWithAccuracy(time, durationTime, kTimeAccuracy);
99 [duration2 release]; 101 [duration2 release];
100 } 102 }
101 103
104 - (void)testAnyHelpers {
105
106 // Set and extract covers most of the code.
107
108 TestAny *subMessage = [TestAny message];
109 subMessage.int32Value = 12345;
110 TestAny *message = [TestAny message];
111 NSError *err = nil;
112 message.anyValue = [GPBAny anyWithMessage:subMessage error:&err];
113 XCTAssertNil(err);
114
115 NSData *data = message.data;
116 XCTAssertNotNil(data);
117
118 TestAny *message2 = [TestAny parseFromData:data error:&err];
119 XCTAssertNil(err);
120 XCTAssertNotNil(message2);
121 XCTAssertTrue(message2.hasAnyValue);
122
123 TestAny *subMessage2 =
124 (TestAny *)[message.anyValue unpackMessageClass:[TestAny class]
125 error:&err];
126 XCTAssertNil(err);
127 XCTAssertNotNil(subMessage2);
128 XCTAssertEqual(subMessage2.int32Value, 12345);
129
130 // NULL errorPtr in the two calls.
131
132 message.anyValue = [GPBAny anyWithMessage:subMessage error:NULL];
133 NSData *data2 = message.data;
134 XCTAssertEqualObjects(data2, data);
135
136 TestAny *subMessage3 =
137 (TestAny *)[message.anyValue unpackMessageClass:[TestAny class]
138 error:NULL];
139 XCTAssertNotNil(subMessage3);
140 XCTAssertEqualObjects(subMessage2, subMessage3);
141
142 // Try to extract wrong type.
143
144 GPBTimestamp *wrongMessage =
145 (GPBTimestamp *)[message.anyValue unpackMessageClass:[GPBTimestamp class]
146 error:&err];
147 XCTAssertNotNil(err);
148 XCTAssertNil(wrongMessage);
149 XCTAssertEqualObjects(err.domain, GPBWellKnownTypesErrorDomain);
150 XCTAssertEqual(err.code, GPBWellKnownTypesErrorCodeTypeURLMismatch);
151
152 wrongMessage =
153 (GPBTimestamp *)[message.anyValue unpackMessageClass:[GPBTimestamp class]
154 error:NULL];
155 XCTAssertNil(wrongMessage);
156 }
157
102 @end 158 @end
OLDNEW
« no previous file with comments | « third_party/protobuf/objectivec/Tests/GPBUtilitiesTests.m ('k') | third_party/protobuf/objectivec/Tests/GPBWireFormatTests.m » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698