summaryrefslogtreecommitdiff
path: root/ios/LibreOfficeLight/LibreOfficeLight/LOKit/LibreOfficeKitIOSTests.swift
blob: de9f1ee82c2c6322f9a903df25ca44b2506c079e (plain)
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
//
//  LibreOfficeKitIOSTests.swift
//  LibreOfficeKitIOSTests
//
//  Created by Jon Nermut on 30/12/17.
//  Copyright © 2017 LibreOffice. All rights reserved.
//

import XCTest
@testable import LibreOfficeKitIOS

class LibreOfficeKitIOSTests: XCTestCase {

    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }

    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }



    func testLoadingSimpleDoc() {

        guard let lo = try? LibreOffice() else
        {
            XCTFail("Could not start LibreOffice")
            return
        }

        let b = Bundle.init(for: LibreOfficeKitIOSTests.self)
        guard let url = b.url(forResource: "test-page-format", withExtension: "docx") else
        {
            XCTFail("Failed to get url to test doc")
            return
        }

        var loCallbackCount = 0
        lo.registerCallback()
        {
            typ, payload in
            print(typ)
            print(payload)
            loCallbackCount += 1
        }

        guard let doc = try? lo.documentLoad(url: url.absoluteString) else
        {
            XCTFail("Could not load document")
            return
        }

        var docCallbackCount = 0
        doc.registerCallback()
        {
            typ, payload in
            print(typ)
            print(payload)
            docCallbackCount += 1
        }

        //let typ: LibreOfficeDocumentType = doc.getDocumentType()
        //XCTAssertTrue(typ == LibreOfficeDocumentType.LOK_DOCTYPE_TEXT)

        doc.initializeForRendering()
        let rects = doc.getPartRectanges()
        print(rects) // 284, 284, 12240, 15840; 284, 16408, 12240, 15840
        let tileMode = doc.getTileMode()
        print(tileMode) // 1
        let canvasSize = CGSize(width: 1024,height: 1024)
        let tile = CGRect(x: 284, y: 284, width: 12240, height: 12240)


        guard let image = doc.paintTileToImage(canvasSize: canvasSize, tileRect: tile) else
        {
            XCTFail("No image")
            return
        }
        if let data = UIImagePNGRepresentation(image)
        {
            let filename = getDocumentsDirectory().appendingPathComponent("tile1.png")
            try? data.write(to: filename)
            print("Wrote tile to: \(filename)")
        }
    }

}

func getDocumentsDirectory() -> URL
{
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    return paths[0]
}

public extension Document
{

}