OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library reader_test; | 5 library reader_test; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import '../../../pkg/unittest/lib/unittest.dart' | 8 import '../../../pkg/unittest/lib/unittest.dart' |
9 import '../../archive/archive.dart'; | 9 import '../../archive/archive.dart'; |
10 | 10 |
11 final String dataPath = "utils/tests/archive/data"; | 11 final String dataPath = "utils/tests/archive/data"; |
12 | 12 |
13 main() { | 13 main() { |
14 test('reading a .tar.gz file', () { | 14 test('reading a .tar.gz file', () { |
15 var asyncDone = expectAsync0(() {}); | 15 var asyncDone = expectAsync0(() {}); |
16 | 16 |
17 var reader = new ArchiveReader(); | 17 var reader = new ArchiveReader(); |
18 reader.format.tar = true; | 18 reader.format.tar = true; |
19 reader.filter.gzip = true; | 19 reader.filter.gzip = true; |
20 | 20 |
21 var future = reader.openFilename("$dataPath/test-archive.tar.gz") | 21 var future = reader.openFilename("$dataPath/test-archive.tar.gz") |
22 .transform((input) { | 22 .then((input) { |
23 var log = <String>[]; | 23 var log = <String>[]; |
24 input.onEntry = (entry) => guardAsync(() { | 24 input.onEntry = (entry) => guardAsync(() { |
25 log.add("Entry: ${entry.pathname}"); | 25 log.add("Entry: ${entry.pathname}"); |
26 var stream = new StringInputStream(entry.openInputStream()); | 26 var stream = new StringInputStream(entry.openInputStream()); |
27 stream.onData = () => log.add("Contents: ${stream.read().trim()}"); | 27 stream.onData = () => log.add("Contents: ${stream.read().trim()}"); |
28 stream.onClosed = () => log.add("Closed: ${entry.pathname}"); | 28 stream.onClosed = () => log.add("Closed: ${entry.pathname}"); |
29 }); | 29 }); |
30 input.onError = registerException; | 30 input.onError = registerException; |
31 | 31 |
32 input.onClosed = () => guardAsync(() { | 32 input.onClosed = () => guardAsync(() { |
(...skipping 16 matching lines...) Expand all Loading... |
49 expect(future, completes); | 49 expect(future, completes); |
50 }); | 50 }); |
51 | 51 |
52 test('reading a .tar.gz file with readAll', () { | 52 test('reading a .tar.gz file with readAll', () { |
53 var reader = new ArchiveReader(); | 53 var reader = new ArchiveReader(); |
54 reader.format.tar = true; | 54 reader.format.tar = true; |
55 reader.filter.gzip = true; | 55 reader.filter.gzip = true; |
56 | 56 |
57 var future = reader.openFilename("$dataPath/test-archive.tar.gz") | 57 var future = reader.openFilename("$dataPath/test-archive.tar.gz") |
58 .chain((input) => input.readAll()) | 58 .chain((input) => input.readAll()) |
59 .transform((entries) { | 59 .then((entries) { |
60 entries = entries.map((entry) => [entry.pathname, entry.contents.trim()]); | 60 entries = entries |
| 61 .mappedBy((entry) => [entry.pathname, entry.contents.trim()]) |
| 62 .toList(); |
61 expect(entries[0], orderedEquals(["filename1", "contents 1"])); | 63 expect(entries[0], orderedEquals(["filename1", "contents 1"])); |
62 expect(entries[1], orderedEquals(["filename2", "contents 2"])); | 64 expect(entries[1], orderedEquals(["filename2", "contents 2"])); |
63 expect(entries[2], orderedEquals(["filename3", "contents 3"])); | 65 expect(entries[2], orderedEquals(["filename3", "contents 3"])); |
64 }); | 66 }); |
65 | 67 |
66 expect(future, completes); | 68 expect(future, completes); |
67 }); | 69 }); |
68 | 70 |
69 test('reading an in-memory .tar.gz', () { | 71 test('reading an in-memory .tar.gz', () { |
70 var asyncDone = expectAsync0(() {}); | 72 var asyncDone = expectAsync0(() {}); |
71 | 73 |
72 var reader = new ArchiveReader(); | 74 var reader = new ArchiveReader(); |
73 reader.format.tar = true; | 75 reader.format.tar = true; |
74 reader.filter.gzip = true; | 76 reader.filter.gzip = true; |
75 | 77 |
76 var future = new File("$dataPath/test-archive.tar.gz").readAsBytes() | 78 var future = new File("$dataPath/test-archive.tar.gz").readAsBytes() |
77 .chain((bytes) => reader.openData(bytes)) | 79 .chain((bytes) => reader.openData(bytes)) |
78 .transform((input) { | 80 .then((input) { |
79 var log = <String>[]; | 81 var log = <String>[]; |
80 input.onEntry = (entry) => guardAsync(() { | 82 input.onEntry = (entry) => guardAsync(() { |
81 log.add("Entry: ${entry.pathname}"); | 83 log.add("Entry: ${entry.pathname}"); |
82 var stream = new StringInputStream(entry.openInputStream()); | 84 var stream = new StringInputStream(entry.openInputStream()); |
83 stream.onData = () => log.add("Contents: ${stream.read().trim()}"); | 85 stream.onData = () => log.add("Contents: ${stream.read().trim()}"); |
84 stream.onClosed = () => log.add("Closed: ${entry.pathname}"); | 86 stream.onClosed = () => log.add("Closed: ${entry.pathname}"); |
85 }); | 87 }); |
86 input.onError = registerException; | 88 input.onError = registerException; |
87 | 89 |
88 input.onClosed = () => guardAsync(() { | 90 input.onClosed = () => guardAsync(() { |
(...skipping 17 matching lines...) Expand all Loading... |
106 }); | 108 }); |
107 | 109 |
108 test("closing entries before they're read", () { | 110 test("closing entries before they're read", () { |
109 var asyncDone = expectAsync0(() {}); | 111 var asyncDone = expectAsync0(() {}); |
110 | 112 |
111 var reader = new ArchiveReader(); | 113 var reader = new ArchiveReader(); |
112 reader.format.tar = true; | 114 reader.format.tar = true; |
113 reader.filter.gzip = true; | 115 reader.filter.gzip = true; |
114 | 116 |
115 var future = reader.openFilename("$dataPath/test-archive.tar.gz") | 117 var future = reader.openFilename("$dataPath/test-archive.tar.gz") |
116 .transform((input) { | 118 .then((input) { |
117 var log = <String>[]; | 119 var log = <String>[]; |
118 input.onEntry = (entry) => guardAsync(() { | 120 input.onEntry = (entry) => guardAsync(() { |
119 log.add("Entry: ${entry.pathname}"); | 121 log.add("Entry: ${entry.pathname}"); |
120 var underlyingStream = entry.openInputStream(); | 122 var underlyingStream = entry.openInputStream(); |
121 var stream = new StringInputStream(underlyingStream); | 123 var stream = new StringInputStream(underlyingStream); |
122 stream.onData = () => log.add("Contents: ${stream.read().trim()}"); | 124 stream.onData = () => log.add("Contents: ${stream.read().trim()}"); |
123 stream.onClosed = () => log.add("Closed: ${entry.pathname}"); | 125 stream.onClosed = () => log.add("Closed: ${entry.pathname}"); |
124 underlyingStream.close(); | 126 underlyingStream.close(); |
125 }); | 127 }); |
126 input.onError = registerException; | 128 input.onError = registerException; |
(...skipping 16 matching lines...) Expand all Loading... |
143 }); | 145 }); |
144 | 146 |
145 test("closing an archive stream before it's finished", () { | 147 test("closing an archive stream before it's finished", () { |
146 var asyncDone = expectAsync0(() {}); | 148 var asyncDone = expectAsync0(() {}); |
147 | 149 |
148 var reader = new ArchiveReader(); | 150 var reader = new ArchiveReader(); |
149 reader.format.tar = true; | 151 reader.format.tar = true; |
150 reader.filter.gzip = true; | 152 reader.filter.gzip = true; |
151 | 153 |
152 var future = reader.openFilename("$dataPath/test-archive.tar.gz") | 154 var future = reader.openFilename("$dataPath/test-archive.tar.gz") |
153 .transform((input) { | 155 .then((input) { |
154 var count = 0; | 156 var count = 0; |
155 | 157 |
156 var log = <String>[]; | 158 var log = <String>[]; |
157 input.onEntry = (entry) => guardAsync(() { | 159 input.onEntry = (entry) => guardAsync(() { |
158 count += 1; | 160 count += 1; |
159 | 161 |
160 log.add("Entry: ${entry.pathname}"); | 162 log.add("Entry: ${entry.pathname}"); |
161 var underlyingStream = entry.openInputStream(); | 163 var underlyingStream = entry.openInputStream(); |
162 var stream = new StringInputStream(underlyingStream); | 164 var stream = new StringInputStream(underlyingStream); |
163 stream.onData = () => log.add("Contents: ${stream.read().trim()}"); | 165 stream.onData = () => log.add("Contents: ${stream.read().trim()}"); |
(...skipping 25 matching lines...) Expand all Loading... |
189 test("opening a non-existent archive", () { | 191 test("opening a non-existent archive", () { |
190 var reader = new ArchiveReader(); | 192 var reader = new ArchiveReader(); |
191 reader.format.tar = true; | 193 reader.format.tar = true; |
192 reader.filter.gzip = true; | 194 reader.filter.gzip = true; |
193 | 195 |
194 expect(reader.openFilename("$dataPath/non-existent.tar.gz"), | 196 expect(reader.openFilename("$dataPath/non-existent.tar.gz"), |
195 throwsA((e) => e is ArchiveException)); | 197 throwsA((e) => e is ArchiveException)); |
196 }); | 198 }); |
197 } | 199 } |
198 | 200 |
OLD | NEW |