forked from orthros/dart-epub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epub_reader_tests.dart
77 lines (66 loc) · 2.35 KB
/
epub_reader_tests.dart
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
library epubreadertest;
import 'dart:io' as io;
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:epub/epub.dart';
main() async {
String fileName = "hittelOnGoldMines.epub";
String fullPath =
path.join(io.Directory.current.path, "test", "res", fileName);
var targetFile = new io.File(fullPath);
if (!(await targetFile.exists())) {
throw new Exception("Specified epub file not found: ${fullPath}");
}
List<int> bytes = await targetFile.readAsBytes();
test("Test Epub Ref", () async {
EpubBookRef epubRef = await EpubReader.openBook(bytes);
expect(epubRef.Author, equals("John S. Hittell"));
expect(epubRef.Title, equals("Hittel on Gold Mines and Mining"));
});
test("Test Epub Read", () async {
EpubBook epubRef = await EpubReader.readBook(bytes);
expect(epubRef.Author, equals("John S. Hittell"));
expect(epubRef.Title, equals("Hittel on Gold Mines and Mining"));
});
test("Test can read", () async {
String baseName =
path.join(io.Directory.current.path, "test", "res", "std");
io.Directory baseDir = new io.Directory(baseName);
if (!(await baseDir.exists())) {
throw new Exception("Base path does not exist: ${baseName}");
}
await baseDir
.list(recursive: false, followLinks: false)
.forEach((io.FileSystemEntity fe) async {
try {
io.File tf = new io.File(fe.path);
List<int> bytes = await tf.readAsBytes();
EpubBook book = await EpubReader.readBook(bytes);
expect(book, isNotNull);
} catch (e) {
print("File: ${fe.path}, Exception: ${e}");
fail("Caught error...");
}
});
});
test("Test can open", () async {
var baseName = path.join(io.Directory.current.path, "test", "res", "std");
var baseDir = new io.Directory(baseName);
if (!(await baseDir.exists())) {
throw new Exception("Base path does not exist: ${baseName}");
}
await baseDir
.list(recursive: false, followLinks: false)
.forEach((io.FileSystemEntity fe) async {
try {
var tf = new io.File(fe.path);
var bytes = await tf.readAsBytes();
var ref = await EpubReader.openBook(bytes);
expect(ref, isNotNull);
} catch (e) {
print("File: ${fe.path}, Exception: ${e}");
fail("Caught error...");
}
});
});
}