|
| 1 | +/* |
| 2 | + * Copyright 2017 Google |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#import <XCTest/XCTest.h> |
| 18 | + |
| 19 | +#import "FIRUserMetadata_Internal.h" |
| 20 | + |
| 21 | +/** @var kCreationDateInSeconds |
| 22 | + @brief The fake creation date. |
| 23 | + */ |
| 24 | +static NSTimeInterval const kCreationDateTimeIntervalInSeconds = 1505858500; |
| 25 | + |
| 26 | +/** @var kLastSignInDateTimeIntervalInSeconds |
| 27 | + @brief The fake last sign in date date. |
| 28 | + */ |
| 29 | +static NSTimeInterval const kLastSignInDateTimeIntervalInSeconds = 1505858583; |
| 30 | + |
| 31 | +/** @class FIRUserMetadataTests |
| 32 | + @brief Tests for @c FIRUserMetadata. |
| 33 | + */ |
| 34 | +@interface FIRUserMetadataTests : XCTestCase |
| 35 | + |
| 36 | +@end |
| 37 | + |
| 38 | +@implementation FIRUserMetadataTests |
| 39 | + |
| 40 | +/** @fn testUserMetadataCreation |
| 41 | + @brief Tests succuessful creation of a @c FIRUserMetadata object. |
| 42 | + */ |
| 43 | +- (void)testUserMetadataCreation { |
| 44 | + NSDate *creationDate = [NSDate dateWithTimeIntervalSince1970:kCreationDateTimeIntervalInSeconds]; |
| 45 | + NSDate *lastSignInDate = |
| 46 | + [NSDate dateWithTimeIntervalSince1970:kLastSignInDateTimeIntervalInSeconds]; |
| 47 | + FIRUserMetadata *userMetadata = |
| 48 | + [[FIRUserMetadata alloc]initWithCreationDate:creationDate lastSignInDate:lastSignInDate]; |
| 49 | + XCTAssertEqualObjects(userMetadata.creationDate, creationDate); |
| 50 | + XCTAssertEqualObjects(userMetadata.lastSignInDate, lastSignInDate); |
| 51 | +} |
| 52 | + |
| 53 | +/** @fn testUserMetadataCoding |
| 54 | + @brief Tests succuessful archiving and unarchiving of a @c FIRUserMetadata object. |
| 55 | + */ |
| 56 | +- (void)testUserMetadataCoding { |
| 57 | + NSDate *creationDate = [NSDate dateWithTimeIntervalSince1970:kCreationDateTimeIntervalInSeconds]; |
| 58 | + NSDate *lastSignInDate = |
| 59 | + [NSDate dateWithTimeIntervalSince1970:kLastSignInDateTimeIntervalInSeconds]; |
| 60 | + FIRUserMetadata *userMetadata = |
| 61 | + [[FIRUserMetadata alloc]initWithCreationDate:creationDate lastSignInDate:lastSignInDate]; |
| 62 | + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:userMetadata]; |
| 63 | + XCTAssertNotNil(data, @"Should not be nil if archving succeeded."); |
| 64 | + XCTAssertNoThrow([NSKeyedUnarchiver unarchiveObjectWithData:data], |
| 65 | + @"Unarchiving should not throw an exception"); |
| 66 | + FIRUserMetadata *unArchivedUserMetadata = [NSKeyedUnarchiver unarchiveObjectWithData:data]; |
| 67 | + XCTAssertTrue([unArchivedUserMetadata isKindOfClass:[FIRUserMetadata class]]); |
| 68 | + XCTAssertEqualObjects(unArchivedUserMetadata.creationDate, creationDate); |
| 69 | + XCTAssertEqualObjects(unArchivedUserMetadata.lastSignInDate, lastSignInDate); |
| 70 | +} |
| 71 | + |
| 72 | +@end |
0 commit comments