blob: a97557548ac5a18d56dc054e989c9ce9ce8a13e0 [file] [log] [blame]
Romain Bertozzi3b289ad2017-01-04 15:25:02 -05001/*
Sébastien Blin77c737a2019-01-02 17:34:46 -05002 * Copyright (C) 2017-2019 Savoir-faire Linux Inc.
Romain Bertozzi3b289ad2017-01-04 15:25:02 -05003 *
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
21import XCTest
Thibault Wittemberg67e34612017-07-04 15:36:03 -040022@testable import Ring
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050023
24/**
25 A test class designed to validate that the ServiceEvent class is reacting properly.
26 */
27class ServiceEventTests: XCTestCase {
28
29 /// The ServiceEvent that will be used during the tests.
Raphaël Brulé41f84982020-08-14 15:34:57 -040030 private var event: ServiceEvent?
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050031
32 override func setUp() {
Raphaël Bruléa9265502020-08-19 09:24:05 -040033 super.setUp()
Thibault Wittemberg14b092a2017-07-04 18:13:26 -040034 self.event = ServiceEvent(withEventType: .accountsChanged)
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050035 }
36
37 /**
38 Tests that the event is properly created and populated.
39 */
40 func testCreateEvent() {
41 XCTAssertNotNil(self.event)
Thibault Wittemberg14b092a2017-07-04 18:13:26 -040042 XCTAssertTrue(self.event?.eventType == ServiceEventType.accountsChanged)
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050043 }
44
45 /**
46 Tests that the event has its String metadata properly created and populated.
47 */
48 func testAddStringMetadata() {
49 let testString = "Identifier"
Thibault Wittemberg14b092a2017-07-04 18:13:26 -040050 self.event?.addEventInput(.id, value: testString)
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050051
Thibault Wittemberg14b092a2017-07-04 18:13:26 -040052 let resultString: String = (self.event?.getEventInput(.id))!
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050053 XCTAssertEqual(resultString, testString)
54 }
55
56 /**
57 Tests that the event has its Int metadata properly created and populated.
58 */
59 func testAddIntMetadata() {
60 let testInt = 1
Thibault Wittemberg14b092a2017-07-04 18:13:26 -040061 self.event?.addEventInput(.id, value: testInt)
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050062
Thibault Wittemberg14b092a2017-07-04 18:13:26 -040063 let resultInt: Int = (self.event?.getEventInput(.id))!
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050064 XCTAssertEqual(resultInt, testInt)
65 }
66}