pEpObjCTests/PEPMessageUtilTest.m
author Dirk Zimmermann <dirk@pep-project.org>
Mon, 12 Feb 2018 12:01:06 +0100
changeset 452 b5bf2590069a
parent 404 3db0cf9cf7e1
child 702 98f5190fe89c
permissions -rw-r--r--
IOS-923 verify engine result for encryption to (gray) recipient
andreas@404
     1
//
andreas@404
     2
//  PEPMessageUtilTest.m
andreas@404
     3
//  pEpObjCAdapterTests
andreas@404
     4
//
andreas@404
     5
//  Created by Andreas Buff on 26.01.18.
andreas@404
     6
//  Copyright © 2018 p≡p. All rights reserved.
andreas@404
     7
//
andreas@404
     8
andreas@404
     9
#import <XCTest/XCTest.h>
andreas@404
    10
andreas@404
    11
#import "PEPMessageUtil.h"
andreas@404
    12
#import "PEPIdentity.h"
andreas@404
    13
andreas@404
    14
@interface PEPMessageUtilTest : XCTestCase
andreas@404
    15
@property pEp_identity *pepIdentitySomeOne;
andreas@404
    16
@property NSDictionary *dictSomeOne;
andreas@404
    17
@property pEp_identity *pepIdentityMe;
andreas@404
    18
@property NSDictionary *dictMe;
andreas@404
    19
@end
andreas@404
    20
andreas@404
    21
@implementation PEPMessageUtilTest
andreas@404
    22
andreas@404
    23
- (void)setUp
andreas@404
    24
{
andreas@404
    25
    // Someones (not "Me") identity as struct and dict.
andreas@404
    26
    self.pepIdentitySomeOne = new_identity("some@some.com",
andreas@404
    27
                                           "SOMEONES-FPR_IS_PRETTY_SHORT",
andreas@404
    28
                                           "SOMEONES-USER-ID",
andreas@404
    29
                                           "Bob 12345");
andreas@404
    30
    self.pepIdentitySomeOne->comm_type = PEP_ct_to_be_checked_confirmed;
andreas@404
    31
    self.pepIdentitySomeOne->me = false;
andreas@404
    32
    self.dictSomeOne = @{kPepAddress:@"some@some.com",
andreas@404
    33
                         kPepFingerprint:@"SOMEONES-FPR_IS_PRETTY_SHORT",
andreas@404
    34
                         kPepUserID:@"SOMEONES-USER-ID",
andreas@404
    35
                         kPepUsername:@"Bob 12345",
andreas@404
    36
                         kPepCommType:[NSNumber numberWithInt: PEP_ct_to_be_checked_confirmed],
andreas@404
    37
                         kPepIsOwn:[NSNumber numberWithBool: NO]};
andreas@404
    38
andreas@404
    39
    // "Me" identity as struct and dict.
andreas@404
    40
    self.pepIdentityMe = new_identity("me@me.com",
andreas@404
    41
                                           "MY-FPR_IS_PRETTY_SHORT",
andreas@404
    42
                                           "MY-USER-ID",
andreas@404
    43
                                           "Me 12345");
andreas@404
    44
    self.pepIdentityMe->comm_type = PEP_ct_confirmed;
andreas@404
    45
    self.pepIdentityMe->me = true;
andreas@404
    46
    self.dictMe = @{kPepAddress:@"me@me.com",
andreas@404
    47
                         kPepFingerprint:@"MY-FPR_IS_PRETTY_SHORT",
andreas@404
    48
                         kPepUserID:@"MY-USER-ID",
andreas@404
    49
                         kPepUsername:@ "Me 12345",
andreas@404
    50
                         kPepCommType:[NSNumber numberWithInt: PEP_ct_confirmed],
andreas@404
    51
                         kPepIsOwn:[NSNumber numberWithBool: YES]};
andreas@404
    52
}
andreas@404
    53
andreas@404
    54
#pragma mark - PEP_identityDictToStruct
andreas@404
    55
andreas@404
    56
- (void)testIdentityDictToStruct_someone
andreas@404
    57
{
andreas@404
    58
    pEp_identity *testee = PEP_identityDictToStruct(self.dictSomeOne);
andreas@404
    59
    [self assertEqualIdentityStructs:testee second:self.pepIdentitySomeOne shouldFail:NO];
andreas@404
    60
}
andreas@404
    61
andreas@404
    62
- (void)testIdentityDictToStruct_me
andreas@404
    63
{
andreas@404
    64
    pEp_identity *testee= PEP_identityDictToStruct(self.dictMe);
andreas@404
    65
    [self assertEqualIdentityStructs:testee second:self.pepIdentityMe shouldFail:NO];
andreas@404
    66
}
andreas@404
    67
andreas@404
    68
#pragma mark - PEP_identityDictFromStruct
andreas@404
    69
andreas@404
    70
- (void)testIdentityDictFromStruct_someone
andreas@404
    71
{
andreas@404
    72
    NSDictionary *testee = PEP_identityDictFromStruct(self.pepIdentitySomeOne);
andreas@404
    73
    [self assertEqualIdentityDicts:testee second:self.dictSomeOne shouldFail:NO];
andreas@404
    74
}
andreas@404
    75
andreas@404
    76
- (void)testIdentityDictFromStruct_me
andreas@404
    77
{
andreas@404
    78
    NSDictionary *testee = PEP_identityDictFromStruct(self.pepIdentityMe);
andreas@404
    79
    [self assertEqualIdentityDicts:testee second:self.dictMe shouldFail:NO];
andreas@404
    80
}
andreas@404
    81
andreas@404
    82
andreas@404
    83
andreas@404
    84
#pragma mark - HELPER
andreas@404
    85
andreas@404
    86
- (void)assertEqualIdentityStructs:(pEp_identity *)first
andreas@404
    87
                            second:(pEp_identity *)second
andreas@404
    88
                        shouldFail:(BOOL)shouldFail
andreas@404
    89
{
andreas@404
    90
    XCTAssert(shouldFail
andreas@404
    91
              ? strcmp(first->address, second->address) != 0
andreas@404
    92
              : strcmp(first->address, second->address) == 0);
andreas@404
    93
    XCTAssert(shouldFail
andreas@404
    94
              ? strcmp(first->fpr, second->fpr) != 0
andreas@404
    95
              :  strcmp(first->fpr, second->fpr) == 0);
andreas@404
    96
    XCTAssert(shouldFail
andreas@404
    97
              ? strcmp(first->user_id, second->user_id) != 0
andreas@404
    98
              : strcmp(first->user_id, second->user_id) == 0);
andreas@404
    99
    XCTAssert(shouldFail
andreas@404
   100
              ? strcmp(first->username, second->username) != 0
andreas@404
   101
              :  strcmp(first->username, second->username) == 0);
andreas@404
   102
    XCTAssert(shouldFail
andreas@404
   103
              ? first->comm_type != second->comm_type
andreas@404
   104
              :  first->comm_type == second->comm_type);
andreas@404
   105
    XCTAssert(shouldFail
andreas@404
   106
              ? first->me != second->me
andreas@404
   107
              : first->me == second->me);
andreas@404
   108
}
andreas@404
   109
andreas@404
   110
- (void)assertEqualIdentityDicts:(NSDictionary *)first
andreas@404
   111
                          second:(NSDictionary *)second
andreas@404
   112
                      shouldFail:(BOOL)shouldFail
andreas@404
   113
{
andreas@404
   114
    if (shouldFail) {
andreas@404
   115
        XCTAssertNotEqualObjects(first[kPepAddress], second[kPepAddress]);
andreas@404
   116
        XCTAssertNotEqualObjects(first[kPepFingerprint], second[kPepFingerprint]);
andreas@404
   117
        XCTAssertNotEqualObjects(first[kPepUserID], second[kPepUserID]);
andreas@404
   118
        XCTAssertNotEqualObjects(first[kPepUsername], second[kPepUsername]);
andreas@404
   119
        XCTAssertNotEqualObjects(first[kPepCommType], second[kPepCommType]);
andreas@404
   120
        XCTAssertNotEqualObjects(first[kPepIsOwn], second[kPepIsOwn]);
andreas@404
   121
    } else {
andreas@404
   122
        XCTAssertEqualObjects(first[kPepAddress], second[kPepAddress]);
andreas@404
   123
        XCTAssertEqualObjects(first[kPepFingerprint], second[kPepFingerprint]);
andreas@404
   124
        XCTAssertEqualObjects(first[kPepUserID], second[kPepUserID]);
andreas@404
   125
        XCTAssertEqualObjects(first[kPepUsername], second[kPepUsername]);
andreas@404
   126
        XCTAssertEqualObjects(first[kPepCommType], second[kPepCommType]);
andreas@404
   127
        XCTAssertEqualObjects(first[kPepIsOwn], second[kPepIsOwn]);
andreas@404
   128
    }
andreas@404
   129
}
andreas@404
   130
andreas@404
   131
#pragma mark test the helpers
andreas@404
   132
andreas@404
   133
- (void)testdiffernetIdentityStructsFail
andreas@404
   134
{
andreas@404
   135
    [self assertEqualIdentityStructs:self.pepIdentityMe second:self.pepIdentitySomeOne shouldFail:YES];
andreas@404
   136
}
andreas@404
   137
andreas@404
   138
- (void)testEqualIdentityStructsSucceed
andreas@404
   139
{
andreas@404
   140
    [self assertEqualIdentityStructs:self.pepIdentityMe second:self.pepIdentityMe shouldFail:NO];
andreas@404
   141
}
andreas@404
   142
andreas@404
   143
- (void)testdiffernetIdentityDicsFail
andreas@404
   144
{
andreas@404
   145
    [self assertEqualIdentityDicts:self.dictMe second:self.dictSomeOne shouldFail:YES];
andreas@404
   146
}
andreas@404
   147
andreas@404
   148
- (void)testEqualIdentityDictsSucceed
andreas@404
   149
{
andreas@404
   150
    [self assertEqualIdentityDicts:self.dictMe second:self.dictMe shouldFail:NO];
andreas@404
   151
}
andreas@404
   152
andreas@404
   153
@end