| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- //
- // DiagnosticLogTests.swift
- // LoopKitTests
- //
- // Created by Darin Krauss on 8/23/19.
- // Copyright © 2019 LoopKit Authors. All rights reserved.
- //
- import XCTest
- import os.log
- @testable import LoopKit
- class DiagnosticLogTests: XCTestCase {
-
- fileprivate var testLogging: TestLogging!
-
- override func setUp() {
- testLogging = TestLogging()
- SharedLogging.instance = testLogging
- }
-
- override func tearDown() {
- SharedLogging.instance = nil
- testLogging = nil
- }
-
- func testInitializer() {
- XCTAssertNotNil(DiagnosticLog(subsystem: "subsystem", category: "category"))
- }
-
- func testDebugWithoutArguments() {
- let diagnosticLog = DiagnosticLog(subsystem: "debug subsystem", category: "debug category")
-
- diagnosticLog.debug("debug message without arguments")
-
- XCTAssertEqual(testLogging.message.description, "debug message without arguments")
- XCTAssertEqual(testLogging.subsystem, "debug subsystem")
- XCTAssertEqual(testLogging.category, "debug category")
- XCTAssertEqual(testLogging.type, .debug)
- XCTAssertEqual(testLogging.args.count, 0)
- }
-
- func testDebugWithArguments() {
- let diagnosticLog = DiagnosticLog(subsystem: "debug subsystem", category: "debug category")
-
- diagnosticLog.debug("debug message with arguments", "a")
-
- XCTAssertEqual(testLogging.message.description, "debug message with arguments")
- XCTAssertEqual(testLogging.subsystem, "debug subsystem")
- XCTAssertEqual(testLogging.category, "debug category")
- XCTAssertEqual(testLogging.type, .debug)
- XCTAssertEqual(testLogging.args.count, 1)
- }
-
- func testInfoWithoutArguments() {
- let diagnosticLog = DiagnosticLog(subsystem: "info subsystem", category: "info category")
-
- diagnosticLog.info("info message without arguments")
-
- XCTAssertEqual(testLogging.message.description, "info message without arguments")
- XCTAssertEqual(testLogging.subsystem, "info subsystem")
- XCTAssertEqual(testLogging.category, "info category")
- XCTAssertEqual(testLogging.type, .info)
- XCTAssertEqual(testLogging.args.count, 0)
- }
-
- func testInfoWithArguments() {
- let diagnosticLog = DiagnosticLog(subsystem: "info subsystem", category: "info category")
-
- diagnosticLog.info("info message with arguments", "a", "b")
-
- XCTAssertEqual(testLogging.message.description, "info message with arguments")
- XCTAssertEqual(testLogging.subsystem, "info subsystem")
- XCTAssertEqual(testLogging.category, "info category")
- XCTAssertEqual(testLogging.type, .info)
- XCTAssertEqual(testLogging.args.count, 2)
- }
-
- func testDefaultWithoutArguments() {
- let diagnosticLog = DiagnosticLog(subsystem: "default subsystem", category: "default category")
-
- diagnosticLog.default("default message without arguments")
-
- XCTAssertEqual(testLogging.message.description, "default message without arguments")
- XCTAssertEqual(testLogging.subsystem, "default subsystem")
- XCTAssertEqual(testLogging.category, "default category")
- XCTAssertEqual(testLogging.type, .default)
- XCTAssertEqual(testLogging.args.count, 0)
- }
-
- func testDefaultWithArguments() {
- let diagnosticLog = DiagnosticLog(subsystem: "default subsystem", category: "default category")
-
- diagnosticLog.default("default message with arguments", "a", "b", "c")
-
- XCTAssertEqual(testLogging.message.description, "default message with arguments")
- XCTAssertEqual(testLogging.subsystem, "default subsystem")
- XCTAssertEqual(testLogging.category, "default category")
- XCTAssertEqual(testLogging.type, .default)
- XCTAssertEqual(testLogging.args.count, 3)
- }
-
- func testErrorWithoutArguments() {
- let diagnosticLog = DiagnosticLog(subsystem: "error subsystem", category: "error category")
-
- diagnosticLog.error("error message without arguments")
-
- XCTAssertEqual(testLogging.message.description, "error message without arguments")
- XCTAssertEqual(testLogging.subsystem, "error subsystem")
- XCTAssertEqual(testLogging.category, "error category")
- XCTAssertEqual(testLogging.type, .error)
- XCTAssertEqual(testLogging.args.count, 0)
- }
-
- func testErrorWithArguments() {
- let diagnosticLog = DiagnosticLog(subsystem: "error subsystem", category: "error category")
-
- diagnosticLog.error("error message with arguments", "a", "b", "c", "d")
-
- XCTAssertEqual(testLogging.message.description, "error message with arguments")
- XCTAssertEqual(testLogging.subsystem, "error subsystem")
- XCTAssertEqual(testLogging.category, "error category")
- XCTAssertEqual(testLogging.type, .error)
- XCTAssertEqual(testLogging.args.count, 4)
- }
-
- }
- fileprivate class TestLogging: Logging {
- var message: StaticString!
-
- var subsystem: String!
-
- var category: String!
-
- var type: OSLogType!
-
- var args: [CVarArg]!
-
- init() {}
-
- func log (_ message: StaticString, subsystem: String, category: String, type: OSLogType, _ args: [CVarArg]) {
- self.message = message
- self.subsystem = subsystem
- self.category = category
- self.type = type
- self.args = args
- }
- }
|