NCGlobalTests.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // NCGlobalTests.swift
  3. // Nextcloud
  4. //
  5. // Created by Henrik Storch on 01.12.21.
  6. // Copyright © 2021 Henrik Storch. All rights reserved.
  7. //
  8. // Author Henrik Storch <henrik.storch@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. @testable import Nextcloud
  24. import XCTest
  25. class NCGlobalTests: XCTestCase {
  26. func testSharedInatance() throws {
  27. XCTAssertNotNil(NCGlobal.shared, "Shared instance should be initialized")
  28. }
  29. func testHashToInt() {
  30. let emptyHash10 = NCGlobal.hashToInt(hash: "", maximum: 10)
  31. let emptyHash2 = NCGlobal.hashToInt(hash: "", maximum: 2)
  32. XCTAssertEqual(emptyHash10, 0, "Empty hash should be zero")
  33. XCTAssertEqual(emptyHash10, emptyHash2, "Empty hashes should be the same")
  34. let emptyHashA = NCGlobal.hashToInt(hash: "a", maximum: 10)
  35. XCTAssertEqual(emptyHashA, 0, "Hash of 'a' mod 10 should be zero")
  36. let emptyHash22 = NCGlobal.hashToInt(hash: "1ab", maximum: 100)
  37. XCTAssertEqual(emptyHash22, 22, "Hash of '1ab' mod 100 should be 22")
  38. let nonHexHash = NCGlobal.hashToInt(hash: "1qw&(*}", maximum: 10)
  39. XCTAssertEqual(nonHexHash, 1, "Non hex characters should be ignored")
  40. }
  41. func testUsernameToColor() {
  42. let color = NCGlobal.shared.usernameToColor("00000000")
  43. let userColor = NCBrandColor.shared.userColors[0]
  44. XCTAssertEqual(color, userColor, "Zero usercolor doesn't match")
  45. let emptyColor = NCGlobal.shared.usernameToColor("")
  46. let emptyUserColor = NCBrandColor.shared.userColors[12]
  47. XCTAssertEqual(emptyColor, emptyUserColor, "Empty usercolor doesn't match")
  48. }
  49. }