Romain Bertozzi | 3b289ad | 2017-01-04 15:25:02 -0500 | [diff] [blame] | 1 | /* |
Sébastien Blin | 77c737a | 2019-01-02 17:34:46 -0500 | [diff] [blame] | 2 | * Copyright (C) 2017-2019 Savoir-faire Linux Inc. |
Romain Bertozzi | 3b289ad | 2017-01-04 15:25:02 -0500 | [diff] [blame] | 3 | * |
| 4 | * Author: Romain Bertozzi <romain.bertozzi@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | import XCTest |
Thibault Wittemberg | 67e3461 | 2017-07-04 15:36:03 -0400 | [diff] [blame] | 22 | @testable import Ring |
Romain Bertozzi | 3b289ad | 2017-01-04 15:25:02 -0500 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | A test class designed to validate that the ServiceEvent class is reacting properly. |
| 26 | */ |
| 27 | class ServiceEventTests: XCTestCase { |
| 28 | |
| 29 | /// The ServiceEvent that will be used during the tests. |
| 30 | fileprivate var event: ServiceEvent? |
| 31 | |
| 32 | override func setUp() { |
Thibault Wittemberg | 14b092a | 2017-07-04 18:13:26 -0400 | [diff] [blame] | 33 | self.event = ServiceEvent(withEventType: .accountsChanged) |
Romain Bertozzi | 3b289ad | 2017-01-04 15:25:02 -0500 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /** |
| 37 | Tests that the event is properly created and populated. |
| 38 | */ |
| 39 | func testCreateEvent() { |
| 40 | XCTAssertNotNil(self.event) |
Thibault Wittemberg | 14b092a | 2017-07-04 18:13:26 -0400 | [diff] [blame] | 41 | XCTAssertTrue(self.event?.eventType == ServiceEventType.accountsChanged) |
Romain Bertozzi | 3b289ad | 2017-01-04 15:25:02 -0500 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /** |
| 45 | Tests that the event has its String metadata properly created and populated. |
| 46 | */ |
| 47 | func testAddStringMetadata() { |
| 48 | let testString = "Identifier" |
Thibault Wittemberg | 14b092a | 2017-07-04 18:13:26 -0400 | [diff] [blame] | 49 | self.event?.addEventInput(.id, value: testString) |
Romain Bertozzi | 3b289ad | 2017-01-04 15:25:02 -0500 | [diff] [blame] | 50 | |
Thibault Wittemberg | 14b092a | 2017-07-04 18:13:26 -0400 | [diff] [blame] | 51 | let resultString: String = (self.event?.getEventInput(.id))! |
Romain Bertozzi | 3b289ad | 2017-01-04 15:25:02 -0500 | [diff] [blame] | 52 | XCTAssertEqual(resultString, testString) |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | Tests that the event has its Int metadata properly created and populated. |
| 57 | */ |
| 58 | func testAddIntMetadata() { |
| 59 | let testInt = 1 |
Thibault Wittemberg | 14b092a | 2017-07-04 18:13:26 -0400 | [diff] [blame] | 60 | self.event?.addEventInput(.id, value: testInt) |
Romain Bertozzi | 3b289ad | 2017-01-04 15:25:02 -0500 | [diff] [blame] | 61 | |
Thibault Wittemberg | 14b092a | 2017-07-04 18:13:26 -0400 | [diff] [blame] | 62 | let resultInt: Int = (self.event?.getEventInput(.id))! |
Romain Bertozzi | 3b289ad | 2017-01-04 15:25:02 -0500 | [diff] [blame] | 63 | XCTAssertEqual(resultInt, testInt) |
| 64 | } |
| 65 | } |