You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

67 lines
2.1 KiB

//
// PEPLanguage+SecureCodingTest.m
// PEPObjCTypesTests_iOS
//
// Created by David Alarcon on 27/1/21.
// Copyright © 2021 p≡p. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "PEPTypesTestUtil.h"
#import "PEPLanguage+SecureCoding.h"
@interface PEPLanguage_SecureCodingTest : XCTestCase
@end
@implementation PEPLanguage_SecureCodingTest
- (void)testConformsSecureCodingProtocol {
PEPLanguage *testee = [PEPLanguage new];
XCTAssertTrue([testee conformsToProtocol:@protocol(NSSecureCoding)]);
}
- (void)testSupportsSecureCodingProtocol {
XCTAssertTrue([PEPLanguage supportsSecureCoding]);
}
- (void)testLanguageCode {
PEPLanguage *testee = [PEPTypesTestUtil pEpLanguageWithAllFieldsFilled];
PEPLanguage *unarchivedTestee = [self archiveAndUnarchiveLanguage:testee];
XCTAssertEqualObjects(testee.code, unarchivedTestee.code);
}
- (void)testLanguageName {
PEPLanguage *testee = [PEPTypesTestUtil pEpLanguageWithAllFieldsFilled];
PEPLanguage *unarchivedTestee = [self archiveAndUnarchiveLanguage:testee];
XCTAssertEqualObjects(testee.name, unarchivedTestee.name);
}
- (void)testLanguageSentence {
PEPLanguage *testee = [PEPTypesTestUtil pEpLanguageWithAllFieldsFilled];
PEPLanguage *unarchivedTestee = [self archiveAndUnarchiveLanguage:testee];
XCTAssertEqualObjects(testee.sentence, unarchivedTestee.sentence);
}
// MARK: - Helper
- (PEPLanguage *)archiveAndUnarchiveLanguage:(PEPLanguage *)language {
NSError *error;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:language
requiringSecureCoding:YES
error:&error];
XCTAssertNotNil(data, "Error archiving pEp language.");
PEPLanguage *unarchivedLanguage = [NSKeyedUnarchiver unarchivedObjectOfClass:[PEPLanguage class]
fromData:data
error:&error];
XCTAssertNotNil(unarchivedLanguage, "Error unarchiving pEp language.");
return unarchivedLanguage;
}
@end