pEpForiOSTests/ImapFlagsTests.swift
author Xavier Algarra <xavier@pep-project.org>
Tue, 06 Jun 2017 07:49:23 +0200
changeset 2248 75013a586bfd
parent 1884 e79206ee642a
child 2616 dfdd77a138cf
permissions -rw-r--r--
IOS-137 add multiple accounts option with the new login
     1 //
     2 //  ImapFlagsTests.swift
     3 //  pEpForiOS
     4 //
     5 //  Created by Dirk Zimmermann on 25/01/2017.
     6 //  Copyright © 2017 p≡p Security S.A. All rights reserved.
     7 //
     8 
     9 import XCTest
    10 
    11 import pEpForiOS
    12 import MessageModel
    13 
    14 class ImapFlagsTests: XCTestCase {
    15 
    16     func loopAllFlags(
    17         cdFlags: CdImapFlags, cwFlags: CWFlags, value: Bool) {
    18         var imapFlags = Message.ImapFlags()
    19 
    20         imapFlags.answered = cdFlags.flagAnswered
    21         imapFlags.draft = cdFlags.flagDraft
    22         imapFlags.flagged = cdFlags.flagFlagged
    23         imapFlags.recent = cdFlags.flagRecent
    24         imapFlags.seen = cdFlags.flagSeen
    25         imapFlags.deleted = cdFlags.flagDeleted
    26 
    27         for pflag in [
    28             PantomimeFlag.answered, PantomimeFlag.draft, PantomimeFlag.flagged,
    29             PantomimeFlag.recent, PantomimeFlag.seen, PantomimeFlag.deleted] {
    30                 switch pflag {
    31                 case .answered:
    32                     cdFlags.flagAnswered = value
    33                     imapFlags.answered = value
    34                 case .draft:
    35                     cdFlags.flagDraft = value
    36                     imapFlags.draft = value
    37                 case .flagged:
    38                     cdFlags.flagFlagged = value
    39                     imapFlags.flagged = value
    40                 case .recent:
    41                     cdFlags.flagRecent = value
    42                     imapFlags.recent = value
    43                 case .seen:
    44                     cdFlags.flagSeen = value
    45                     imapFlags.seen = value
    46                 case .deleted:
    47                     cdFlags.flagDeleted = value
    48                     imapFlags.deleted = value
    49                 }
    50                 if value {
    51                     cwFlags.add(pflag)
    52                 } else {
    53                     cwFlags.remove(pflag)
    54                 }
    55                 XCTAssertEqual(cwFlags.rawFlagsAsShort(), cdFlags.rawFlagsAsShort())
    56                 XCTAssertEqual(cwFlags.rawFlagsAsShort(), imapFlags.rawFlagsAsShort())
    57         }
    58     }
    59     
    60     func testCdImapFields() {
    61         let ps = PersistentSetup()
    62         ps.dummyToAvoidCompilerWarning()
    63 
    64         let cdFlags = CdImapFlags.create()
    65         let cwFlags = CWFlags()
    66 
    67         XCTAssertEqual(cwFlags.rawFlagsAsShort(), cdFlags.rawFlagsAsShort())
    68 
    69         loopAllFlags(cdFlags: cdFlags, cwFlags: cwFlags, value: true)
    70         loopAllFlags(cdFlags: cdFlags, cwFlags: cwFlags, value: false)
    71     }
    72 }