blob: 1e67e60299a846eab86b7a78e6a946d8e26811af [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() {
Thibault Wittemberg14b092a2017-07-04 18:13:26 -040033 self.event = ServiceEvent(withEventType: .accountsChanged)
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050034 }
35
36 /**
37 Tests that the event is properly created and populated.
38 */
39 func testCreateEvent() {
40 XCTAssertNotNil(self.event)
Thibault Wittemberg14b092a2017-07-04 18:13:26 -040041 XCTAssertTrue(self.event?.eventType == ServiceEventType.accountsChanged)
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050042 }
43
44 /**
45 Tests that the event has its String metadata properly created and populated.
46 */
47 func testAddStringMetadata() {
48 let testString = "Identifier"
Thibault Wittemberg14b092a2017-07-04 18:13:26 -040049 self.event?.addEventInput(.id, value: testString)
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050050
Thibault Wittemberg14b092a2017-07-04 18:13:26 -040051 let resultString: String = (self.event?.getEventInput(.id))!
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050052 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 Wittemberg14b092a2017-07-04 18:13:26 -040060 self.event?.addEventInput(.id, value: testInt)
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050061
Thibault Wittemberg14b092a2017-07-04 18:13:26 -040062 let resultInt: Int = (self.event?.getEventInput(.id))!
Romain Bertozzi3b289ad2017-01-04 15:25:02 -050063 XCTAssertEqual(resultInt, testInt)
64 }
65}