IOS-455 more syntactical control over test data
authorDirk Zimmermann <dirk@pep-project.org>
Mon, 27 Feb 2017 10:15:28 +0100
changeset 17771256fbaf3324
parent 1776 9d7c50e71db6
child 1778 f3d180cadcc2
IOS-455 more syntactical control over test data
.hgignore
README.md
pEpForiOS.xcodeproj/project.pbxproj
pEpForiOSTests/Util/TestData.swift.sample
pEpForiOSTests/Util/TestDataBase.swift
pEpForiOSTests/Util/TestData_sample.swift
     1.1 --- a/.hgignore	Mon Feb 27 10:09:57 2017 +0100
     1.2 +++ b/.hgignore	Mon Feb 27 10:15:28 2017 +0100
     1.3 @@ -3,8 +3,10 @@
     1.4  xcuserdata/.*
     1.5  Pods/.*
     1.6  \.orig$
     1.7 -^.*TestData\.swift$
     1.8 -pEpForiOSTests/Util/TestData.swift
     1.9  \.git/
    1.10  \.gitkeep
    1.11  scripts/config.ini$
    1.12 +
    1.13 +glob
    1.14 +pEpForiOSTests/Util/TestData.swift
    1.15 +pEpForiOSUITests/UITestData.swift
     2.1 --- a/README.md	Mon Feb 27 10:09:57 2017 +0100
     2.2 +++ b/README.md	Mon Feb 27 10:15:28 2017 +0100
     2.3 @@ -84,11 +84,11 @@
     2.4  
     2.5  ### Unit Tests
     2.6  
     2.7 -You need to create a copy of TestData.swift.sample as TestData.swift
     2.8 -and populate it with corresponding (valid) settings to run successful tests.
     2.9 +You need to create a copy of TestDataImpl/sample.swift as TestDataImpl.swift
    2.10 +and populate it with corresponding (valid) settings to run the tests successfully.
    2.11  
    2.12  The tests will not compile without a syntactically correct TestData.swift.
    2.13  
    2.14  ```
    2.15 -cp pEpForiOSTests/Util/TestData.swift.sample pEpForiOSTests/Util/TestData.swift
    2.16 +cp pEpForiOSTests/Util/TestData_sample.swift pEpForiOSTests/Util/TestData.swift
    2.17  ```
     3.1 --- a/pEpForiOS.xcodeproj/project.pbxproj	Mon Feb 27 10:09:57 2017 +0100
     3.2 +++ b/pEpForiOS.xcodeproj/project.pbxproj	Mon Feb 27 10:15:28 2017 +0100
     3.3 @@ -78,8 +78,9 @@
     3.4  		4336229E1DC76B8100133B3D /* MessageModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4336229D1DC76B8100133B3D /* MessageModelTests.swift */; };
     3.5  		4339477B1D5C9D8C005EE7C2 /* HTMLConvertOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4339477A1D5C9D8C005EE7C2 /* HTMLConvertOperation.swift */; };
     3.6  		433BCD951D5388C100DD98EF /* ReplyUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433BCD941D5388C100DD98EF /* ReplyUtil.swift */; };
     3.7 +		433C519A1E64101000272E19 /* TestData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433C51991E64101000272E19 /* TestData.swift */; };
     3.8 +		433C51A01E64236500272E19 /* TestDataBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433C519F1E64236500272E19 /* TestDataBase.swift */; };
     3.9  		43404B481D17D36D00D8B6FF /* EmailHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43404B471D17D36D00D8B6FF /* EmailHeaderView.swift */; };
    3.10 -		43409CE01DD30102008F8F49 /* TestData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439BA8821DC9E3B000D0683E /* TestData.swift */; };
    3.11  		43409CE31DD301CD008F8F49 /* CdMessagePantomimeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43409CE21DD301CD008F8F49 /* CdMessagePantomimeTests.swift */; };
    3.12  		4340F5F91D363BE6006A5C82 /* ContactCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4340F5F81D363BE6006A5C82 /* ContactCell.swift */; };
    3.13  		43463AAE1D8AA54800F3A673 /* CheckAndCreateFolderOfTypeOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43463AAD1D8AA54800F3A673 /* CheckAndCreateFolderOfTypeOperation.swift */; };
    3.14 @@ -376,6 +377,8 @@
    3.15  		433724FC1DA2C2B1005E8DF5 /* pEp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = pEp.entitlements; path = ../pEp.entitlements; sourceTree = "<group>"; };
    3.16  		4339477A1D5C9D8C005EE7C2 /* HTMLConvertOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTMLConvertOperation.swift; sourceTree = "<group>"; };
    3.17  		433BCD941D5388C100DD98EF /* ReplyUtil.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReplyUtil.swift; sourceTree = "<group>"; };
    3.18 +		433C51991E64101000272E19 /* TestData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestData.swift; sourceTree = "<group>"; };
    3.19 +		433C519F1E64236500272E19 /* TestDataBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestDataBase.swift; sourceTree = "<group>"; };
    3.20  		43404B471D17D36D00D8B6FF /* EmailHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmailHeaderView.swift; sourceTree = "<group>"; };
    3.21  		43409CE21DD301CD008F8F49 /* CdMessagePantomimeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CdMessagePantomimeTests.swift; sourceTree = "<group>"; };
    3.22  		4340F5F81D363BE6006A5C82 /* ContactCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactCell.swift; sourceTree = "<group>"; };
    3.23 @@ -433,7 +436,6 @@
    3.24  		439A6C711E535827004CBAA6 /* PrivacyStatusTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrivacyStatusTableViewController.swift; sourceTree = "<group>"; };
    3.25  		439A6C721E535827004CBAA6 /* RoundedButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoundedButton.swift; sourceTree = "<group>"; };
    3.26  		439A6C731E535827004CBAA6 /* TrustwordsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrustwordsTableViewController.swift; sourceTree = "<group>"; };
    3.27 -		439BA8821DC9E3B000D0683E /* TestData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestData.swift; sourceTree = "<group>"; };
    3.28  		439D405C1CC78825009A4E7C /* pEpiOSAdapter.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = pEpiOSAdapter.xcodeproj; path = ../pEpiOSAdapter/pEpiOSAdapter.xcodeproj; sourceTree = "<group>"; };
    3.29  		439D406F1CC78930009A4E7C /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
    3.30  		439D40711CC78958009A4E7C /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; };
    3.31 @@ -693,7 +695,8 @@
    3.32  			children = (
    3.33  				438ACD2B1DE860200016F954 /* ObserverDelegate.swift */,
    3.34  				4352FA1E1DC79E9B0081161A /* ShortCircuitSendLayer.swift */,
    3.35 -				439BA8821DC9E3B000D0683E /* TestData.swift */,
    3.36 +				433C519F1E64236500272E19 /* TestDataBase.swift */,
    3.37 +				433C51991E64101000272E19 /* TestData.swift */,
    3.38  				4374320A1CFC49B1000F8D35 /* TestUtil.swift */,
    3.39  			);
    3.40  			path = Util;
    3.41 @@ -1432,8 +1435,8 @@
    3.42  			buildActionMask = 2147483647;
    3.43  			files = (
    3.44  				4352FA1F1DC79E9B0081161A /* ShortCircuitSendLayer.swift in Sources */,
    3.45 -				43409CE01DD30102008F8F49 /* TestData.swift in Sources */,
    3.46  				438D253C1D4B9E7500BFF7AA /* MimeTests.swift in Sources */,
    3.47 +				433C519A1E64101000272E19 /* TestData.swift in Sources */,
    3.48  				432A24D71DE714A200DAAC5C /* MessagePantomimeTests.swift in Sources */,
    3.49  				438ACD2C1DE860200016F954 /* ObserverDelegate.swift in Sources */,
    3.50  				4336229E1DC76B8100133B3D /* MessageModelTests.swift in Sources */,
    3.51 @@ -1445,6 +1448,7 @@
    3.52  				432F7D611D2102F10094F097 /* PEPSessionTest.swift in Sources */,
    3.53  				43E74C741E38DE2200A2F7A6 /* ImapFlagsTests.swift in Sources */,
    3.54  				43D51E891DD5D902008B77A8 /* SimpleOperationsTest.swift in Sources */,
    3.55 +				433C51A01E64236500272E19 /* TestDataBase.swift in Sources */,
    3.56  				430C80E01D0EADC200CD4582 /* PepAdapterTests.swift in Sources */,
    3.57  				5DEBAA481DE59C3B00FAE12C /* NetworkServiceTests.swift in Sources */,
    3.58  				43409CE31DD301CD008F8F49 /* CdMessagePantomimeTests.swift in Sources */,
     4.1 --- a/pEpForiOSTests/Util/TestData.swift.sample	Mon Feb 27 10:09:57 2017 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,201 +0,0 @@
     4.4 -//
     4.5 -//  TestData.swift
     4.6 -//  pEpForiOS
     4.7 -//
     4.8 -//  Created by Dirk Zimmermann on 02/11/16.
     4.9 -//  Copyright © 2016 p≡p Security S.A. All rights reserved.
    4.10 -//
    4.11 -
    4.12 -import UIKit
    4.13 -
    4.14 -import MessageModel
    4.15 -
    4.16 -fileprivate struct AccountSettings {
    4.17 -    var accountName = "default"
    4.18 -    var idAddress = "email@example.com" // XXX: Used as login name for both, SMTP and IMAP.
    4.19 -    var idUserName = "User Name"
    4.20 -    var smtpServerAddress = "mail.example.com"
    4.21 -    var smtpServerType = Server.ServerType.smtp.rawValue
    4.22 -    var smtpServerTransport = Server.Transport.startTls.rawValue
    4.23 -    var smtpServerPort: UInt16 = 587
    4.24 -    var imapServerAddress = "mail.example.com"
    4.25 -    var imapServerType = Server.ServerType.imap.rawValue
    4.26 -    var imapServerTransport = Server.Transport.tls.rawValue
    4.27 -    var imapServerPort: UInt16 = 993
    4.28 -    var password = "somepassword" // XXX: Same used for both, SMTP and IMAP.
    4.29 -
    4.30 -    init() {}
    4.31 -
    4.32 -    init(accountName: String) {
    4.33 -        self.accountName = accountName
    4.34 -    }
    4.35 -
    4.36 -    init(accountName: String,
    4.37 -         idAddress: String,
    4.38 -         idUserName: String,
    4.39 -         smtpServerAddress: String,
    4.40 -         smtpServerType: Server.ServerType,
    4.41 -         smtpServerTransport: Server.Transport,
    4.42 -         smtpServerPort: UInt16,
    4.43 -         imapServerAddress: String,
    4.44 -         imapServerType: Server.ServerType,
    4.45 -         imapServerTransport: Server.Transport,
    4.46 -         imapServerPort: UInt16,
    4.47 -         password: String) {
    4.48 -        self.accountName = accountName
    4.49 -        self.idAddress = idAddress
    4.50 -        self.idUserName = idUserName
    4.51 -        self.smtpServerAddress = smtpServerAddress
    4.52 -        self.smtpServerType = smtpServerType.rawValue
    4.53 -        self.smtpServerTransport = smtpServerTransport.rawValue
    4.54 -        self.smtpServerPort = smtpServerPort
    4.55 -        self.imapServerAddress = imapServerAddress
    4.56 -        self.imapServerType = imapServerType.rawValue
    4.57 -        self.imapServerTransport = imapServerTransport.rawValue
    4.58 -        self.imapServerPort = imapServerPort
    4.59 -        self.password = password
    4.60 -    }
    4.61 -
    4.62 -    func cdAccount() -> CdAccount {
    4.63 -        let id = CdIdentity.create()
    4.64 -        id.address = idAddress
    4.65 -        id.userName = idUserName
    4.66 -
    4.67 -        let smtp = CdServer.create()
    4.68 -        smtp.serverType = Int16(smtpServerType)
    4.69 -        smtp.port = NSNumber(value: smtpServerPort)
    4.70 -        smtp.address = smtpServerAddress
    4.71 -        smtp.transport = Int16(smtpServerTransport)
    4.72 -
    4.73 -        let imap = CdServer.create()
    4.74 -        imap.serverType = Int16(imapServerType)
    4.75 -        imap.port = NSNumber(value: imapServerPort)
    4.76 -        imap.address = imapServerAddress
    4.77 -        imap.transport = Int16(imapServerTransport)
    4.78 -
    4.79 -        let key = MessageID.generate()
    4.80 -        CdServerCredentials.add(password: password, forKey: key)
    4.81 -
    4.82 -        let cred = CdServerCredentials.create()
    4.83 -        cred.userName = id.address
    4.84 -        cred.key = key
    4.85 -        cred.servers = NSSet(array: [imap, smtp])
    4.86 -
    4.87 -        let acc = CdAccount.create()
    4.88 -        acc.identity = id
    4.89 -        acc.credentials = NSOrderedSet(array: [cred])
    4.90 -
    4.91 -        return acc
    4.92 -    }
    4.93 -
    4.94 -    func account() -> Account {
    4.95 -        let id = Identity.create(address: idAddress,
    4.96 -                                 userName: idUserName)
    4.97 -
    4.98 -        let smtp = Server.create(serverType: .smtp,
    4.99 -                                 port: smtpServerPort,
   4.100 -                                 address: smtpServerAddress,
   4.101 -                                 transport: Server.Transport(rawValue: smtpServerTransport))
   4.102 -
   4.103 -
   4.104 -        let imap = Server.create(serverType: .imap,
   4.105 -                                 port: imapServerPort,
   4.106 -                                 address: imapServerAddress,
   4.107 -                                 transport: Server.Transport(rawValue: imapServerTransport))
   4.108 -
   4.109 -        // Assumes
   4.110 -        let cred = ServerCredentials.create(userName: id.address,
   4.111 -                                            password: password,
   4.112 -                                            servers: [smtp, imap])
   4.113 -
   4.114 -        let acc = Account.create(identity: id, credentials: [cred])
   4.115 -
   4.116 -        return acc
   4.117 -    }
   4.118 -
   4.119 -    func pEpIdentity() -> [String: AnyObject] {
   4.120 -        let theID = [
   4.121 -            kPepAddress: idAddress as AnyObject,
   4.122 -            kPepUsername: accountName as AnyObject
   4.123 -            ] as [String: AnyObject]
   4.124 -        return theID
   4.125 -    }
   4.126 -}
   4.127 -
   4.128 -class TestData {
   4.129 -    fileprivate var testAccounts = [AccountSettings]()
   4.130 -
   4.131 -    /**
   4.132 -     Add more test data (besides the default account) here.
   4.133 -     */
   4.134 -    func populateAccounts() {
   4.135 -        // Default account
   4.136 -        testAccounts.append(AccountSettings())
   4.137 -
   4.138 -        // A second account as example.
   4.139 -        testAccounts.append(AccountSettings(
   4.140 -            accountName: "A second account",
   4.141 -            idAddress: "email2@example.com",
   4.142 -            idUserName: "User Name 2",
   4.143 -            smtpServerAddress: "mail.example.com",
   4.144 -            smtpServerType: Server.ServerType.smtp,
   4.145 -            smtpServerTransport: Server.Transport.tls,
   4.146 -            smtpServerPort: 587,
   4.147 -            imapServerAddress: "mail.example.com",
   4.148 -            imapServerType: Server.ServerType.imap,
   4.149 -            imapServerTransport: Server.Transport.tls,
   4.150 -            imapServerPort: 993,
   4.151 -            password: "someFurtherPassword"))
   4.152 -
   4.153 -        // A third account, just with other account name, but with default data.
   4.154 -        testAccounts.append(AccountSettings(accountName: "A third account"))
   4.155 -    }
   4.156 -
   4.157 -    /**
   4.158 -     - Returns: A valid `CdAccount`.
   4.159 -     */
   4.160 -    func createWorkingCdAccount(number: Int = 0) -> CdAccount {
   4.161 -        populateAccounts()
   4.162 -        return testAccounts[number].cdAccount()
   4.163 -    }
   4.164 -
   4.165 -    /**
   4.166 -     - Returns: A `CdAccount` that should not be able to be verified.
   4.167 -     */
   4.168 -    func createDisfunctionalCdAccount() -> CdAccount {
   4.169 -        populateAccounts()
   4.170 -        var account = testAccounts[0]
   4.171 -        account.smtpServerPort = 2323
   4.172 -        account.imapServerPort = 2323
   4.173 -        return account.cdAccount()
   4.174 -    }
   4.175 -
   4.176 -    /**
   4.177 -     - Returns: A valid `Account`.
   4.178 -     */
   4.179 -    func createWorkingAccount(number: Int = 0) -> Account {
   4.180 -        populateAccounts()
   4.181 -        return testAccounts[number].account()
   4.182 -    }
   4.183 -
   4.184 -    /**
   4.185 -     - Returns: A valid `PEPIdentity`.
   4.186 -     */
   4.187 -    func createWorkingIdentity(number: Int = 0) -> [String: AnyObject] {
   4.188 -        populateAccounts()
   4.189 -        return testAccounts[number].pEpIdentity()
   4.190 -    }
   4.191 -
   4.192 -    /**
   4.193 -     - Returns: A `Account` with servers that should yield a quick timeout.
   4.194 -     */
   4.195 -    func createTimeoutAccount() -> Account {
   4.196 -        populateAccounts()
   4.197 -        var account = testAccounts[0]
   4.198 -        account.imapServerAddress = "localhost"
   4.199 -        account.smtpServerAddress = "localhost"
   4.200 -        account.smtpServerPort = 2323
   4.201 -        account.imapServerPort = 2323
   4.202 -        return account.account()
   4.203 -    }
   4.204 -}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/pEpForiOSTests/Util/TestDataBase.swift	Mon Feb 27 10:15:28 2017 +0100
     5.3 @@ -0,0 +1,204 @@
     5.4 +//
     5.5 +//  TestData.swift
     5.6 +//  pEpForiOS
     5.7 +//
     5.8 +//  Created by Dirk Zimmermann on 02/11/16.
     5.9 +//  Copyright © 2016 p≡p Security S.A. All rights reserved.
    5.10 +//
    5.11 +
    5.12 +import UIKit
    5.13 +import CoreData
    5.14 +
    5.15 +import MessageModel
    5.16 +
    5.17 +class TestDataBase {
    5.18 +    struct AccountSettings {
    5.19 +        var accountName: String?
    5.20 +        var idAddress: String
    5.21 +        var idUserName: String?
    5.22 +        var smtpServerAddress: String?
    5.23 +        var smtpServerType: Server.ServerType = .smtp
    5.24 +        var smtpServerTransport: Server.Transport = .tls
    5.25 +        var smtpServerPort: UInt16 = 587
    5.26 +        var imapServerAddress: String?
    5.27 +        var imapServerType: Server.ServerType = .imap
    5.28 +        var imapServerTransport: Server.Transport = .startTls
    5.29 +        var imapServerPort: UInt16 = 993
    5.30 +        var password: String?
    5.31 +
    5.32 +        init(accountName: String?, address: String) {
    5.33 +            self.accountName = accountName
    5.34 +            self.idAddress = address
    5.35 +        }
    5.36 +
    5.37 +        init(address: String) {
    5.38 +            self.init(accountName: nil, address: address)
    5.39 +        }
    5.40 +
    5.41 +        init(accountName: String,
    5.42 +             idAddress: String,
    5.43 +             idUserName: String,
    5.44 +             imapServerAddress: String,
    5.45 +             imapServerType: Server.ServerType,
    5.46 +             imapServerTransport: Server.Transport,
    5.47 +             imapServerPort: UInt16,
    5.48 +             smtpServerAddress: String,
    5.49 +             smtpServerType: Server.ServerType,
    5.50 +             smtpServerTransport: Server.Transport,
    5.51 +             smtpServerPort: UInt16,
    5.52 +             password: String) {
    5.53 +            self.accountName = accountName
    5.54 +            self.idAddress = idAddress
    5.55 +            self.idUserName = idUserName
    5.56 +            self.smtpServerAddress = smtpServerAddress
    5.57 +            self.smtpServerType = smtpServerType
    5.58 +            self.smtpServerTransport = smtpServerTransport
    5.59 +            self.smtpServerPort = smtpServerPort
    5.60 +            self.imapServerAddress = imapServerAddress
    5.61 +            self.imapServerType = imapServerType
    5.62 +            self.imapServerTransport = imapServerTransport
    5.63 +            self.imapServerPort = imapServerPort
    5.64 +            self.password = password
    5.65 +        }
    5.66 +
    5.67 +        func cdAccount() -> CdAccount {
    5.68 +            let id = CdIdentity.create()
    5.69 +            id.address = idAddress
    5.70 +            id.userName = idUserName
    5.71 +
    5.72 +            let smtp = CdServer.create()
    5.73 +            smtp.serverType = Int16(smtpServerType.rawValue)
    5.74 +            smtp.port = NSNumber(value: smtpServerPort)
    5.75 +            smtp.address = smtpServerAddress
    5.76 +            smtp.transport = Int16(smtpServerTransport.rawValue)
    5.77 +
    5.78 +            let imap = CdServer.create()
    5.79 +            imap.serverType = Int16(imapServerType.rawValue)
    5.80 +            imap.port = NSNumber(value: imapServerPort)
    5.81 +            imap.address = imapServerAddress
    5.82 +            imap.transport = Int16(imapServerTransport.rawValue)
    5.83 +
    5.84 +            let key = MessageID.generate()
    5.85 +            CdServerCredentials.add(password: password, forKey: key)
    5.86 +
    5.87 +            let cred = CdServerCredentials.create()
    5.88 +            cred.userName = id.address
    5.89 +            cred.key = key
    5.90 +            cred.servers = NSSet(array: [imap, smtp])
    5.91 +
    5.92 +            let acc = CdAccount.create()
    5.93 +            acc.identity = id
    5.94 +            acc.credentials = NSOrderedSet(array: [cred])
    5.95 +
    5.96 +            return acc
    5.97 +        }
    5.98 +
    5.99 +        func account() -> Account {
   5.100 +            let id = Identity.create(address: idAddress, userName: idUserName, isMySelf: true)
   5.101 +
   5.102 +            let smtp = Server.create(serverType: .smtp,
   5.103 +                                     port: smtpServerPort,
   5.104 +                                     address: smtpServerAddress ?? "",
   5.105 +                                     transport: smtpServerTransport)
   5.106 +
   5.107 +            let imap = Server.create(serverType: .imap,
   5.108 +                                     port: imapServerPort,
   5.109 +                                     address: imapServerAddress ?? "",
   5.110 +                                     transport: imapServerTransport)
   5.111 +
   5.112 +            // Assumes
   5.113 +            let cred = ServerCredentials.create(userName: id.address,
   5.114 +                                                password: password,
   5.115 +                                                servers: [smtp, imap])
   5.116 +
   5.117 +            let acc = Account.create(identity: id, credentials: [cred])
   5.118 +
   5.119 +            return acc
   5.120 +        }
   5.121 +
   5.122 +        func pEpIdentity() -> [String: AnyObject] {
   5.123 +            let theID = [
   5.124 +                kPepAddress: idAddress as AnyObject,
   5.125 +                kPepUsername: accountName as AnyObject
   5.126 +                ] as [String: AnyObject]
   5.127 +            return theID
   5.128 +        }
   5.129 +    }
   5.130 +
   5.131 +    fileprivate var testAccounts = [AccountSettings]()
   5.132 +
   5.133 +    func append(accountSettings: AccountSettings) {
   5.134 +        testAccounts.append(accountSettings)
   5.135 +    }
   5.136 +
   5.137 +    /**
   5.138 +     Add actual account test data here (override in `TestDataImpl`).
   5.139 +     */
   5.140 +    func populateAccounts() {
   5.141 +        // An example account
   5.142 +        testAccounts.append(AccountSettings(
   5.143 +            accountName: "A second account",
   5.144 +            idAddress: "email2@example.com",
   5.145 +            idUserName: "User Name 2",
   5.146 +
   5.147 +            imapServerAddress: "mail.example.com",
   5.148 +            imapServerType: Server.ServerType.imap,
   5.149 +            imapServerTransport: Server.Transport.tls,
   5.150 +            imapServerPort: 993,
   5.151 +
   5.152 +            smtpServerAddress: "mail.example.com",
   5.153 +            smtpServerType: Server.ServerType.smtp,
   5.154 +            smtpServerTransport: Server.Transport.tls,
   5.155 +            smtpServerPort: 587,
   5.156 +
   5.157 +            password: "someFurtherPassword"))
   5.158 +    }
   5.159 +
   5.160 +    /**
   5.161 +     - Returns: A valid `CdAccount`.
   5.162 +     */
   5.163 +    func createWorkingCdAccount(number: Int = 0) -> CdAccount {
   5.164 +        populateAccounts()
   5.165 +        return testAccounts[number].cdAccount()
   5.166 +    }
   5.167 +
   5.168 +    /**
   5.169 +     - Returns: A `CdAccount` that should not be able to be verified.
   5.170 +     */
   5.171 +    func createDisfunctionalCdAccount() -> CdAccount {
   5.172 +        populateAccounts()
   5.173 +        var account = testAccounts[0]
   5.174 +        account.smtpServerPort = 2323
   5.175 +        account.imapServerPort = 2323
   5.176 +        return account.cdAccount()
   5.177 +    }
   5.178 +
   5.179 +    /**
   5.180 +     - Returns: A valid `Account`.
   5.181 +     */
   5.182 +    func createWorkingAccount(number: Int = 0) -> Account {
   5.183 +        populateAccounts()
   5.184 +        return testAccounts[number].account()
   5.185 +    }
   5.186 +
   5.187 +    /**
   5.188 +     - Returns: A valid `PEPIdentity`.
   5.189 +     */
   5.190 +    func createWorkingIdentity(number: Int = 0) -> [String: AnyObject] {
   5.191 +        populateAccounts()
   5.192 +        return testAccounts[number].pEpIdentity()
   5.193 +    }
   5.194 +
   5.195 +    /**
   5.196 +     - Returns: A `Account` with servers that should yield a quick timeout.
   5.197 +     */
   5.198 +    func createTimeoutAccount() -> Account {
   5.199 +        populateAccounts()
   5.200 +        var account = testAccounts[0]
   5.201 +        account.imapServerAddress = "localhost"
   5.202 +        account.smtpServerAddress = "localhost"
   5.203 +        account.smtpServerPort = 2323
   5.204 +        account.imapServerPort = 2323
   5.205 +        return account.account()
   5.206 +    }
   5.207 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/pEpForiOSTests/Util/TestData_sample.swift	Mon Feb 27 10:15:28 2017 +0100
     6.3 @@ -0,0 +1,33 @@
     6.4 +//
     6.5 +//  TestDataImpl.swift
     6.6 +//  pEpForiOS
     6.7 +//
     6.8 +//  Created by Dirk Zimmermann on 27/02/2017.
     6.9 +//  Copyright © 2017 p≡p Security S.A. All rights reserved.
    6.10 +//
    6.11 +
    6.12 +import UIKit
    6.13 +
    6.14 +import MessageModel
    6.15 +
    6.16 +class TestData: TestDataBase {
    6.17 +    func populateAccounts() {
    6.18 +        // An example account
    6.19 +        testAccounts.append(AccountSettings(
    6.20 +            accountName: "A second account",
    6.21 +            idAddress: "email2@example.com",
    6.22 +            idUserName: "User Name 2",
    6.23 +
    6.24 +            imapServerAddress: "mail.example.com",
    6.25 +            imapServerType: Server.ServerType.imap,
    6.26 +            imapServerTransport: Server.Transport.tls,
    6.27 +            imapServerPort: 993,
    6.28 +
    6.29 +            smtpServerAddress: "mail.example.com",
    6.30 +            smtpServerType: Server.ServerType.smtp,
    6.31 +            smtpServerTransport: Server.Transport.tls,
    6.32 +            smtpServerPort: 587,
    6.33 +
    6.34 +            password: "someFurtherPassword"))
    6.35 +    }
    6.36 +}