-
Notifications
You must be signed in to change notification settings - Fork 2
/
DocumentProtectionTests.swift
110 lines (92 loc) · 5.86 KB
/
DocumentProtectionTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* --------------------------------------------------------------------------------
* <copyright company="Aspose" file="DocumentProtectionTests.swift">
* Copyright (c) 2024 Aspose.Words for Cloud
* </copyright>
* <summary>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* </summary>
* --------------------------------------------------------------------------------
*/
import XCTest
@testable import AsposeWordsCloud
// Example of how to set document protection.
@available(macOS 10.12, iOS 10.3, watchOS 3.3, tvOS 12.0, *)
class DocumentProtectionTests: BaseTestContext {
static var allTests = [
("testProtectDocument", testProtectDocument),
("testProtectDocumentOnline", testProtectDocumentOnline),
("testGetDocumentProtection", testGetDocumentProtection),
("testGetDocumentProtectionOnline", testGetDocumentProtectionOnline),
("testDeleteUnprotectDocument", testDeleteUnprotectDocument),
("testDeleteUnprotectDocumentOnline", testDeleteUnprotectDocumentOnline)
];
let remoteDataFolder = BaseTestContext.getRemoteTestDataFolder() + "/DocumentElements/DocumentProtection";
let localFile = "Common/test_multi_pages.docx";
// Test for setting document protection.
func testProtectDocument() throws {
let remoteFileName = "TestProtectDocument.docx";
try super.uploadFile(fileContent: getLocalTestDataFolder().appendingPathComponent(localFile, isDirectory: false), path: remoteDataFolder + "/" + remoteFileName);
let requestProtectionRequest = ProtectionRequestV2()
.setProtectionPassword(protectionPassword: "123")
.setProtectionType(protectionType: ProtectionRequestV2.ProtectionType.readOnly);
let request = ProtectDocumentRequest(name: remoteFileName, protectionRequest: requestProtectionRequest, folder: remoteDataFolder, destFileName: BaseTestContext.getRemoteTestOut() + "/" + remoteFileName);
let actual = try super.getApi().protectDocument(request: request);
if (!(actual.getProtectionData() != nil)) { XCTFail("actual.getProtectionData() != nil"); return; }
}
// Test for setting document protection.
func testProtectDocumentOnline() throws {
let requestDocument = InputStream(url: self.getLocalTestDataFolder().appendingPathComponent(localFile, isDirectory: false))!;
let requestProtectionRequest = ProtectionRequestV2()
.setProtectionPassword(protectionPassword: "123")
.setProtectionType(protectionType: ProtectionRequestV2.ProtectionType.readOnly);
let request = ProtectDocumentOnlineRequest(document: requestDocument, protectionRequest: requestProtectionRequest);
_ = try super.getApi().protectDocumentOnline(request: request);
}
// Test for getting document protection.
func testGetDocumentProtection() throws {
let localFilePath = "DocumentActions/DocumentProtection/SampleProtectedBlankWordDocument.docx";
let remoteFileName = "TestGetDocumentProtection.docx";
try super.uploadFile(fileContent: getLocalTestDataFolder().appendingPathComponent(localFilePath, isDirectory: false), path: remoteDataFolder + "/" + remoteFileName);
let request = GetDocumentProtectionRequest(name: remoteFileName, folder: remoteDataFolder);
_ = try super.getApi().getDocumentProtection(request: request);
}
// Test for getting document protection.
func testGetDocumentProtectionOnline() throws {
let requestDocument = InputStream(url: self.getLocalTestDataFolder().appendingPathComponent(localFile, isDirectory: false))!;
let request = GetDocumentProtectionOnlineRequest(document: requestDocument);
_ = try super.getApi().getDocumentProtectionOnline(request: request);
}
// Test for deleting unprotect document.
func testDeleteUnprotectDocument() throws {
let localFilePath = "DocumentActions/DocumentProtection/SampleProtectedBlankWordDocument.docx";
let remoteFileName = "TestDeleteUnprotectDocument.docx";
try super.uploadFile(fileContent: getLocalTestDataFolder().appendingPathComponent(localFilePath, isDirectory: false), path: remoteDataFolder + "/" + remoteFileName);
let request = UnprotectDocumentRequest(name: remoteFileName, folder: remoteDataFolder);
let actual = try super.getApi().unprotectDocument(request: request);
if (!(actual.getProtectionData() != nil)) { XCTFail("actual.getProtectionData() != nil"); return; }
}
// Test for deleting unprotect document.
func testDeleteUnprotectDocumentOnline() throws {
let localFilePath = "DocumentActions/DocumentProtection/SampleProtectedBlankWordDocument.docx";
let requestDocument = InputStream(url: self.getLocalTestDataFolder().appendingPathComponent(localFilePath, isDirectory: false))!;
let request = UnprotectDocumentOnlineRequest(document: requestDocument);
_ = try super.getApi().unprotectDocumentOnline(request: request);
}
}