Skip to content

Commit 53e6601

Browse files
author
Thomas Taschauer
committed
store data for unit test offline
1 parent c1c78f8 commit 53e6601

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

OpenDocumentReader.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
E22EB71A226B65E300053B86 /* DocumentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E22EB719226B65E300053B86 /* DocumentViewController.swift */; };
2626
E22EB71C226B66B300053B86 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E22EB71B226B66B300053B86 /* Main.storyboard */; };
2727
E23795302274844400BA7238 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E237952F2274844400BA7238 /* AdSupport.framework */; };
28+
E24110312586349500800247 /* test.odt in Resources */ = {isa = PBXBuildFile; fileRef = E24110232586349500800247 /* test.odt */; };
2829
E26C39392250DC6E009C484A /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E26C39382250DC6E009C484A /* WebKit.framework */; };
2930
E29E4077225A4672002C06E6 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = E29E4076225A4672002C06E6 /* GoogleService-Info.plist */; };
3031
E2B55504245F13570077ED85 /* libodr_oldms.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E2B55503245F13570077ED85 /* libodr_oldms.a */; };
@@ -309,6 +310,7 @@
309310
E22EB719226B65E300053B86 /* DocumentViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DocumentViewController.swift; sourceTree = "<group>"; };
310311
E22EB71B226B66B300053B86 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
311312
E237952F2274844400BA7238 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
313+
E24110232586349500800247 /* test.odt */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.odt; sourceTree = "<group>"; };
312314
E26C39382250DC6E009C484A /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
313315
E29E4076225A4672002C06E6 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
314316
E2BB4B60220EF3A10056176B /* BridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BridgingHeader.h; sourceTree = "<group>"; };
@@ -406,6 +408,7 @@
406408
E22B252D2557F0E2001D0C52 /* OpenDocumentReaderTests */ = {
407409
isa = PBXGroup;
408410
children = (
411+
E24110232586349500800247 /* test.odt */,
409412
E22B252E2557F0E2001D0C52 /* OpenDocumentReaderTests.swift */,
410413
E22B25302557F0E2001D0C52 /* Info.plist */,
411414
);
@@ -726,6 +729,7 @@
726729
isa = PBXResourcesBuildPhase;
727730
buildActionMask = 2147483647;
728731
files = (
732+
E24110312586349500800247 /* test.odt in Resources */,
729733
);
730734
runOnlyForDeploymentPostprocessing = 0;
731735
};

OpenDocumentReaderTests/OpenDocumentReaderTests.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,39 @@ import XCTest
1212

1313
class OpenDocumentReaderTests: XCTestCase {
1414

15+
// ONLINE fails on GitHub Actions for some reason
16+
private let ONLINE = false
17+
1518
private var saveURL: URL?
1619

1720
override func setUpWithError() throws {
18-
let url = URL(string: "https://api.libreoffice.org/examples/cpp/DocumentLoader/test.odt")
21+
var fileURL: URL?
1922

2023
let documentsURL = try
2124
FileManager.default.url(for: .documentDirectory,
2225
in: .userDomainMask,
2326
appropriateFor: nil,
2427
create: false)
2528

26-
saveURL = documentsURL.appendingPathComponent(url!.lastPathComponent)
29+
saveURL = documentsURL.appendingPathComponent("test.odt")
2730

2831
if (FileManager.default.fileExists(atPath: saveURL!.path)) {
2932
return
3033
}
3134

32-
var fileURL: URL?
33-
34-
let downloadTask = URLSession.shared.downloadTask(with: url!) {
35-
urlOrNil, responseOrNil, errorOrNil in
35+
if (ONLINE) {
36+
let url = URL(string: "https://api.libreoffice.org/examples/cpp/DocumentLoader/test.odt")
3637

37-
fileURL = urlOrNil
38+
let downloadTask = URLSession.shared.downloadTask(with: url!) {
39+
urlOrNil, responseOrNil, errorOrNil in
40+
41+
fileURL = urlOrNil
42+
}
43+
downloadTask.resume()
44+
} else {
45+
let filePath = Bundle(for: type(of: self)).path(forResource: "test", ofType: "odt")
46+
fileURL = URL(string: filePath!)
3847
}
39-
downloadTask.resume()
4048

4149
try FileManager.default.moveItem(at: fileURL!, to: self.saveURL!)
4250
}

OpenDocumentReaderTests/test.odt

10.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)