Browse Source

remove NextcloudTests

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 year ago
parent
commit
a35c10091c

+ 0 - 54
NextcloudTests/NCGlobalTests.swift

@@ -1,54 +0,0 @@
-//
-//  NCGlobalTests.swift
-//  Nextcloud
-//
-//  Created by Henrik Storch on 01.12.21.
-//  Copyright © 2021 Henrik Storch. All rights reserved.
-//
-//  Author Henrik Storch <henrik.storch@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-@testable import Nextcloud
-import XCTest
-
-class NCGlobalTests: XCTestCase {
-
-    func testSharedInatance() throws {
-        XCTAssertNotNil(NCGlobal.shared, "Shared instance should be initialized")
-    }
-
-    func testHashToInt() {
-        let emptyHash10 = NCGlobal.hashToInt(hash: "", maximum: 10)
-        let emptyHash2 = NCGlobal.hashToInt(hash: "", maximum: 2)
-        XCTAssertEqual(emptyHash10, 0, "Empty hash should be zero")
-        XCTAssertEqual(emptyHash10, emptyHash2, "Empty hashes should be the same")
-        let emptyHashA = NCGlobal.hashToInt(hash: "a", maximum: 10)
-        XCTAssertEqual(emptyHashA, 0, "Hash of 'a' mod 10 should be zero")
-        let emptyHash22 = NCGlobal.hashToInt(hash: "1ab", maximum: 100)
-        XCTAssertEqual(emptyHash22, 22, "Hash of '1ab' mod 100 should be 22")
-        let nonHexHash = NCGlobal.hashToInt(hash: "1qw&(*}", maximum: 10)
-        XCTAssertEqual(nonHexHash, 1, "Non hex characters should be ignored")
-    }
-
-    func testUsernameToColor() {
-        let color = NCGlobal.shared.usernameToColor("00000000")
-        let userColor = NCBrandColor.shared.userColors[0]
-        XCTAssertEqual(color, userColor, "Zero usercolor doesn't match")
-        let emptyColor = NCGlobal.shared.usernameToColor("")
-        let emptyUserColor = NCBrandColor.shared.userColors[12]
-        XCTAssertEqual(emptyColor, emptyUserColor, "Empty usercolor doesn't match")
-    }
-}

+ 0 - 85
NextcloudTests/ParallelWorkerTest.swift

@@ -1,85 +0,0 @@
-//
-//  ParallelWorkerTest.swift
-//  Nextcloud
-//
-//  Created by Henrik Storch on 18.02.22.
-//  Copyright © 2021 Henrik Storch. All rights reserved.
-//
-//  Author Henrik Storch <henrik.storch@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-@testable import Nextcloud
-import XCTest
-
-class ParallelWorkerTest: XCTestCase {
-
-    func testWorkerComplete() throws {
-        let expectation = XCTestExpectation(description: "Worker executes all tasks")
-        let taskCount = 20
-        var tasksComplete = 0
-        let worker = ParallelWorker(n: 5, titleKey: nil, totalTasks: nil, hudView: nil)
-        for _ in 0..<taskCount {
-            worker.execute { completion in
-                tasksComplete += 1
-                completion()
-            }
-        }
-        worker.completeWork {
-            XCTAssertEqual(tasksComplete, taskCount)
-            if tasksComplete == taskCount {
-                expectation.fulfill()
-            }
-        }
-
-        let result = XCTWaiter.wait(for: [expectation], timeout: 5)
-        XCTAssertEqual(result, .completed)
-    }
-
-    func testWorkerOrder() throws {
-        let expectation = XCTestExpectation(description: "Worker executes work in sequence for n = 1")
-        let sortedArray = Array(0..<20)
-        var array: [Int] = []
-        let worker = ParallelWorker(n: 1, titleKey: nil, totalTasks: nil, hudView: nil)
-        for i in sortedArray {
-            worker.execute { completion in
-                DispatchQueue.main.asyncAfter(deadline: .now() + Double.random(in: 0...0.2)) {
-                    array.append(i)
-                    completion()
-                }
-            }
-        }
-        worker.completeWork {
-            XCTAssertEqual(sortedArray, array)
-            if sortedArray == array {
-                expectation.fulfill()
-            }
-        }
-        let result = XCTWaiter.wait(for: [expectation], timeout: 5)
-        XCTAssertEqual(result, .completed)
-    }
-
-    func testWorkerFailsWithoutCompletion() throws {
-        let expectation = XCTestExpectation(description: "Worker fails if completion isn't called")
-        expectation.isInverted = true
-        let worker = ParallelWorker(n: 5, titleKey: nil, totalTasks: nil, hudView: nil)
-        for _ in 0..<20 {
-            worker.execute { _ in }
-        }
-        worker.completeWork { expectation.fulfill() }
-        let result = XCTWaiter.wait(for: [expectation], timeout: 5)
-        XCTAssertEqual(result, .completed)
-    }
-}

+ 0 - 136
NextcloudTests/SharePermissionTest.swift

@@ -1,136 +0,0 @@
-//
-//  SharePermissionTest.swift
-//  Nextcloud
-//
-//  Created by Henrik Storch on 29.03.22.
-//  Copyright © 2021 Henrik Storch. All rights reserved.
-//
-//  Author Henrik Storch <henrik.storch@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-@testable import Nextcloud
-import XCTest
-import NextcloudKit
-
-class SharePermissionTest: XCTestCase {
-    override func setUp() {
-        let json =
-        """
-        {"ocs":{"data":{"capabilities":{"files_sharing":{"default_permissions":31}}}}}
-        """.data(using: .utf8)!
-        NCManageDatabase.shared.addCapabilitiesJSon(json, account: "")
-    }
-
-    func testShareCellPermissionCell() throws {
-        let share = NCTableShareOptions(sharee: NKSharee(), metadata: tableMetadata(), password: nil)
-        let shareConfig = NCShareConfig(parentMetadata: tableMetadata(), share: share)
-
-        for row in 0..<shareConfig.permissions.count {
-            guard let cell = shareConfig.config(for: IndexPath(row: row, section: 0)) as? NCToggleCellConfig else {
-                XCTFail("Invalid share permission cell")
-                continue
-            }
-            XCTAssertFalse(cell.isOn(for: share))
-        }
-
-        let meta = tableMetadata()
-        meta.sharePermissionsCollaborationServices = 31
-        let fullShare = NCTableShareOptions(sharee: NKSharee(), metadata: meta, password: nil)
-        let shareFullConfig = NCShareConfig(parentMetadata: meta, share: fullShare)
-
-        for row in 0..<shareFullConfig.permissions.count {
-            guard let cell = shareConfig.config(for: IndexPath(row: row, section: 0)) as? NCToggleCellConfig else {
-                XCTFail("Invalid share permission cell")
-                continue
-            }
-            XCTAssertTrue(cell.isOn(for: fullShare))
-        }
-    }
-
-    func testSharePermission() throws {
-        XCTAssertTrue(NCLinkPermission.allowEdit.hasResharePermission(for: 15))
-        XCTAssertTrue(NCLinkPermission.allowEdit.hasResharePermission(for: 11))
-        XCTAssertTrue(NCLinkPermission.allowEdit.hasResharePermission(for: 7))
-        XCTAssertFalse(NCLinkPermission.allowEdit.hasResharePermission(for: 13))
-        XCTAssertFalse(NCLinkPermission.allowEdit.hasResharePermission(for: 1))
-
-        XCTAssertTrue(NCLinkPermission.viewOnly.hasResharePermission(for: 25))
-        XCTAssertTrue(NCLinkPermission.viewOnly.hasResharePermission(for: 17))
-        XCTAssertFalse(NCLinkPermission.viewOnly.hasResharePermission(for: 12))
-        XCTAssertFalse(NCLinkPermission.viewOnly.hasResharePermission(for: 2))
-
-        XCTAssertTrue(NCLinkPermission.fileDrop.hasResharePermission(for: 4))
-        XCTAssertFalse(NCLinkPermission.fileDrop.hasResharePermission(for: 27))
-
-        XCTAssertTrue(NCUserPermission.create.hasResharePermission(for: 4))
-        XCTAssertFalse(NCUserPermission.create.hasResharePermission(for: 27))
-
-        XCTAssertTrue(NCUserPermission.edit.hasResharePermission(for: 2))
-        XCTAssertFalse(NCUserPermission.edit.hasResharePermission(for: 29))
-
-        XCTAssertTrue(NCUserPermission.reshare.hasResharePermission(for: 16))
-        XCTAssertFalse(NCUserPermission.reshare.hasResharePermission(for: 15))
-    }
-
-    func testFileShare() throws {
-        let meta = tableMetadata()
-        meta.directory = false
-        let share = NCTableShareOptions.shareLink(metadata: meta, password: nil)
-        let fileConfig = NCShareConfig(parentMetadata: meta, share: share)
-        XCTAssertEqual(fileConfig.advanced, NCShareDetails.forLink)
-        XCTAssertEqual(fileConfig.permissions as? [NCLinkPermission], NCLinkPermission.forFile)
-
-        meta.directory = true
-        let folderConfig = NCShareConfig(parentMetadata: meta, share: share)
-        XCTAssertEqual(folderConfig.advanced, NCShareDetails.forLink)
-        XCTAssertEqual(folderConfig.permissions as? [NCLinkPermission], NCLinkPermission.forDirectory)
-    }
-
-    func testUserShare() throws {
-        let meta = tableMetadata()
-        meta.directory = false
-        let sharee = NKSharee()
-        let share = NCTableShareOptions(sharee: sharee, metadata: meta, password: nil)
-        let fileConfig = NCShareConfig(parentMetadata: meta, share: share)
-        XCTAssertEqual(fileConfig.advanced, NCShareDetails.forUser)
-        XCTAssertEqual(fileConfig.permissions as? [NCUserPermission], NCUserPermission.forFile)
-
-        meta.directory = true
-        let folderConfig = NCShareConfig(parentMetadata: meta, share: share)
-        XCTAssertEqual(folderConfig.advanced, NCShareDetails.forUser)
-        XCTAssertEqual(folderConfig.permissions as? [NCUserPermission], NCUserPermission.forDirectory)
-    }
-
-    func testResharePermission() throws {
-        let meta = tableMetadata()
-        let permissionReadShare = NCGlobal.shared.permissionShareShare + NCGlobal.shared.permissionReadShare
-        meta.sharePermissionsCollaborationServices = permissionReadShare
-        meta.directory = false
-        let share = NCTableShareOptions.shareLink(metadata: meta, password: nil)
-        let fileConfig = NCShareConfig(parentMetadata: meta, share: share)
-        XCTAssertEqual(fileConfig.resharePermission, meta.sharePermissionsCollaborationServices)
-        XCTAssertEqual(fileConfig.advanced, NCShareDetails.forLink)
-        XCTAssertEqual(fileConfig.permissions as? [NCLinkPermission], NCLinkPermission.forFile)
-
-        meta.directory = true
-        let sharee = NKSharee()
-        let folderShare = NCTableShareOptions(sharee: sharee, metadata: meta, password: nil)
-        let folderConfig = NCShareConfig(parentMetadata: meta, share: folderShare)
-        XCTAssertEqual(folderConfig.resharePermission, meta.sharePermissionsCollaborationServices)
-        XCTAssertEqual(folderConfig.advanced, NCShareDetails.forUser)
-        XCTAssertEqual(folderConfig.permissions as? [NCUserPermission], NCUserPermission.forDirectory)
-    }
-}

+ 0 - 64
NextcloudTests/UserAgentTests.swift

@@ -1,64 +0,0 @@
-//
-//  UserAgentTests.swift
-//  Nextcloud
-//
-//  Created by Henrik Storch on 03.05.22.
-//  Copyright © 2022 Henrik Storch. All rights reserved.
-//
-//  Author Henrik Storch <henrik.storch@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-@testable import Nextcloud
-import XCTest
-
-class UserAgentTests: XCTestCase {
-    // https://github.com/nextcloud/server/blob/fc826e98115b510313ddacbf6fef4ce8d041e373/lib/public/IRequest.php#L83
-    let ncServerUARegex = "^Mozilla\\/5\\.0 \\(iOS\\) (ownCloud|Nextcloud)\\-iOS.*$"
-
-    // https://github.com/ProseMirror/prosemirror-view/blob/427d278aaaacde422ed1f2b8c84bb53337162775/src/browser.js#L18-L22
-    let proseMirrorWebKitUARegex = "\\bAppleWebKit\\/(\\d+)"
-    let proseMirroriOSUARegex = "Mobile\\/\\w+"
-
-    func testDefaultUserAgent() throws {
-        let userAgent: String = CCUtility.getUserAgent()
-        let match = try matches(for: ncServerUARegex, in: userAgent).first
-        XCTAssertNotNil(match)
-    }
-
-    func testTextUserAgent() throws {
-        let userAgent: String = NCUtility.shared.getCustomUserAgentNCText()
-        let match = try matches(for: ncServerUARegex, in: userAgent).first
-        XCTAssertNotNil(match)
-
-        let iOSMatch = try matches(for: proseMirroriOSUARegex, in: userAgent).first
-        XCTAssertNotNil(iOSMatch)
-
-        // https://github.com/ProseMirror/prosemirror-view/blob/8f246f320801f8e3cac92c97f71ac91e3e327f2f/src/input.js#L521-L522
-        let webKitMatch = try matches(for: proseMirrorWebKitUARegex, in: userAgent).first
-        XCTAssertNotNil(webKitMatch)
-        XCTAssertEqual(webKitMatch!.numberOfRanges, 2)
-        let versionRange = webKitMatch!.range(at: 1)
-        let versionString = userAgent[Range(versionRange, in: userAgent)!]
-        let webkitVersion = Int(versionString) ?? 0
-        XCTAssertGreaterThanOrEqual(webkitVersion, 604)
-    }
-
-    func matches(for regex: String, in text: String) throws -> [NSTextCheckingResult] {
-        let range = NSRange(location: 0, length: text.utf16.count)
-        let regex = try NSRegularExpression(pattern: regex)
-        return regex.matches(in: text, range: range)
-    }
-}