IOS-714 NSDictionary.containsPGPCommType
authorDirk Zimmermann <dirk@pep-project.org>
Thu, 14 Sep 2017 10:59:16 +0200
changeset 225591656ce62f0
parent 224 6426331381e6
child 226 aebc0fdcb859
IOS-714 NSDictionary.containsPGPCommType
pEpObjCAdapter/NSDictionary+Extension.h
pEpObjCAdapter/NSDictionary+Extension.m
pEpObjCTests/iOSTests.m
     1.1 --- a/pEpObjCAdapter/NSDictionary+Extension.h	Wed Sep 13 15:31:29 2017 +0200
     1.2 +++ b/pEpObjCAdapter/NSDictionary+Extension.h	Thu Sep 14 10:59:16 2017 +0200
     1.3 @@ -10,6 +10,15 @@
     1.4  
     1.5  @interface NSDictionary (Extension)
     1.6  
     1.7 +/**
     1.8 + Saves itself to the filesystem, under `NSApplicationSupportDirectory`.
     1.9 + */
    1.10  - (void)debugSaveToFilePath:(NSString * _Nonnull)filePath;
    1.11  
    1.12 +/**
    1.13 + If we interpret the self as a dictionary denoting a p≡p Identity,
    1.14 + does the comm type denote a PGP user?
    1.15 + */
    1.16 +- (BOOL)containsPGPCommType;
    1.17 +
    1.18  @end
     2.1 --- a/pEpObjCAdapter/NSDictionary+Extension.m	Wed Sep 13 15:31:29 2017 +0200
     2.2 +++ b/pEpObjCAdapter/NSDictionary+Extension.m	Thu Sep 14 10:59:16 2017 +0200
     2.3 @@ -10,11 +10,10 @@
     2.4  
     2.5  #import "NSDictionary+Extension.h"
     2.6  
     2.7 +#import "PEPMessage.h"
     2.8 +
     2.9  @implementation NSDictionary (Extension)
    2.10  
    2.11 -/**
    2.12 - Saves itself to the filesystem, under `NSApplicationSupportDirectory`.
    2.13 - */
    2.14  - (void)debugSaveToFilePath:(NSString * _Nonnull)filePath
    2.15  {
    2.16      NSFileManager *fileManager = [NSFileManager defaultManager];
    2.17 @@ -32,4 +31,19 @@
    2.18      [self writeToURL:writeURL atomically:YES];
    2.19  }
    2.20  
    2.21 +- (BOOL)containsPGPCommType
    2.22 +{
    2.23 +    NSNumber *ctNum = self[kPepCommType];
    2.24 +    if (!ctNum) {
    2.25 +        return NO;
    2.26 +    }
    2.27 +    NSInteger val = ctNum.integerValue;
    2.28 +
    2.29 +    return
    2.30 +    val == PEP_ct_OpenPGP_weak_unconfirmed ||
    2.31 +    val == PEP_ct_OpenPGP_unconfirmed ||
    2.32 +    val == PEP_ct_OpenPGP_weak ||
    2.33 +    val == PEP_ct_OpenPGP;
    2.34 +}
    2.35 +
    2.36  @end
     3.1 --- a/pEpObjCTests/iOSTests.m	Wed Sep 13 15:31:29 2017 +0200
     3.2 +++ b/pEpObjCTests/iOSTests.m	Thu Sep 14 10:59:16 2017 +0200
     3.3 @@ -11,6 +11,8 @@
     3.4  #import "PEPObjCAdapter.h"
     3.5  #import "PEPSession.h"
     3.6  
     3.7 +#import "NSDictionary+Extension.h"
     3.8 +
     3.9  // MARK: - Helpers
    3.10  
    3.11  PEPDict* _Nonnull mailFromTo(PEPDict * _Nullable fromDict, PEPDict * _Nullable toDict,
    3.12 @@ -74,7 +76,7 @@
    3.13      
    3.14  }
    3.15  
    3.16 -- (bool)waitUntilSent:(time_t)maxSec {
    3.17 +- (BOOL)waitUntilSent:(time_t)maxSec {
    3.18      bool res;
    3.19      [_cond lock];
    3.20      [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow: 2]];
    3.21 @@ -324,17 +326,11 @@
    3.22      
    3.23      [session mySelf:identMe];
    3.24  
    3.25 -    // fingerprint
    3.26      XCTAssertNotNil(identMe[kPepFingerprint]);
    3.27 +    XCTAssertNotNil(identMe[kPepCommType]);
    3.28  
    3.29      // check that the comm type is not a PGP one
    3.30 -    NSNumber *ctNum = identMe[kPepCommType];
    3.31 -    XCTAssertNotNil(ctNum);
    3.32 -    NSInteger ct = ctNum.integerValue;
    3.33 -    XCTAssertNotEqual(ct, PEP_ct_OpenPGP_weak_unconfirmed);
    3.34 -    XCTAssertNotEqual(ct, PEP_ct_OpenPGP_unconfirmed);
    3.35 -    XCTAssertNotEqual(ct, PEP_ct_OpenPGP_weak);
    3.36 -    XCTAssertNotEqual(ct, PEP_ct_OpenPGP);
    3.37 +    XCTAssertFalse([identMe containsPGPCommType]);
    3.38  
    3.39      [self pEpCleanUp];
    3.40