Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: utils/tests/archive/reader_test.dart

Issue 10842002: Add the beginnings of a Dart wrapper for libarchive. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/archive/utils.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #library('reader_test');
6
7 #import('dart:io');
8 #import('../../../lib/unittest/unittest.dart');
9 #import('../../archive/archive.dart');
10
11 final String dataPath = "utils/tests/archive/data";
12
13 main() {
14 test('reading a .tar.gz file', () {
15 var asyncDone = expectAsync0(() {});
16
17 var reader = new ArchiveReader();
18 reader.format.tar = true;
19 reader.filter.gzip = true;
20
21 var future = reader.openFilename("$dataPath/test-archive.tar.gz")
22 .transform((input) {
23 var log = <String>[];
24 input.onEntry = (entry) => guardAsync(() {
25 log.add("Entry: ${entry.pathname}");
26 var stream = new StringInputStream(entry.openInputStream());
27 stream.onData = () => log.add("Contents: ${stream.read().trim()}");
28 stream.onClosed = () => log.add("Closed: ${entry.pathname}");
29 });
30 input.onError = registerException;
31
32 input.onClosed = () => guardAsync(() {
33 expect(log, orderedEquals([
34 "Entry: filename1",
35 "Contents: contents 1",
36 "Closed: filename1",
37
38 "Entry: filename2",
39 "Contents: contents 2",
40 "Closed: filename2",
41
42 "Entry: filename3",
43 "Contents: contents 3",
44 "Closed: filename3",
45 ]));
46 }, asyncDone);
47 });
48
49 expect(future, completes);
50 });
51
52 test('reading an in-memory .tar.gz', () {
53 var asyncDone = expectAsync0(() {});
54
55 var reader = new ArchiveReader();
56 reader.format.tar = true;
57 reader.filter.gzip = true;
58
59 var future = new File("$dataPath/test-archive.tar.gz").readAsBytes()
60 .chain((bytes) => reader.openData(bytes))
61 .transform((input) {
62 var log = <String>[];
63 input.onEntry = (entry) => guardAsync(() {
64 log.add("Entry: ${entry.pathname}");
65 var stream = new StringInputStream(entry.openInputStream());
66 stream.onData = () => log.add("Contents: ${stream.read().trim()}");
67 stream.onClosed = () => log.add("Closed: ${entry.pathname}");
68 });
69 input.onError = registerException;
70
71 input.onClosed = () => guardAsync(() {
72 expect(log, orderedEquals([
73 "Entry: filename1",
74 "Contents: contents 1",
75 "Closed: filename1",
76
77 "Entry: filename2",
78 "Contents: contents 2",
79 "Closed: filename2",
80
81 "Entry: filename3",
82 "Contents: contents 3",
83 "Closed: filename3",
84 ]));
85 }, asyncDone);
86 });
87
88 expect(future, completes);
89 });
90
91 test("closing entries before they're read", () {
92 var asyncDone = expectAsync0(() {});
93
94 var reader = new ArchiveReader();
95 reader.format.tar = true;
96 reader.filter.gzip = true;
97
98 var future = reader.openFilename("$dataPath/test-archive.tar.gz")
99 .transform((input) {
100 var log = <String>[];
101 input.onEntry = (entry) => guardAsync(() {
102 log.add("Entry: ${entry.pathname}");
103 var underlyingStream = entry.openInputStream();
104 var stream = new StringInputStream(underlyingStream);
105 stream.onData = () => log.add("Contents: ${stream.read().trim()}");
106 stream.onClosed = () => log.add("Closed: ${entry.pathname}");
107 underlyingStream.close();
108 });
109 input.onError = registerException;
110
111 input.onClosed = () => guardAsync(() {
112 expect(log, orderedEquals([
113 "Entry: filename1",
114 "Closed: filename1",
115
116 "Entry: filename2",
117 "Closed: filename2",
118
119 "Entry: filename3",
120 "Closed: filename3",
121 ]));
122 }, asyncDone);
123 });
124
125 expect(future, completes);
126 });
127
128 test("closing an archive stream before it's finished", () {
129 var asyncDone = expectAsync0(() {});
130
131 var reader = new ArchiveReader();
132 reader.format.tar = true;
133 reader.filter.gzip = true;
134
135 var future = reader.openFilename("$dataPath/test-archive.tar.gz")
136 .transform((input) {
137 var count = 0;
138
139 var log = <String>[];
140 input.onEntry = (entry) => guardAsync(() {
141 count += 1;
142
143 log.add("Entry: ${entry.pathname}");
144 var underlyingStream = entry.openInputStream();
145 var stream = new StringInputStream(underlyingStream);
146 stream.onData = () => log.add("Contents: ${stream.read().trim()}");
147 stream.onClosed = () => log.add("Closed: ${entry.pathname}");
148
149 if (count == 2) {
150 input.close();
151 expect(input.closed);
152 }
153 });
154 input.onError = registerException;
155
156 input.onClosed = () {
157 expect(log, orderedEquals([
158 "Entry: filename1",
159 "Contents: contents 1",
160 "Closed: filename1",
161
162 "Entry: filename2",
163 "Closed: filename2",
164 ]));
165 asyncDone();
166 };
167 });
168
169 expect(future, completes);
170 });
171
172 test("opening a non-existent archive", () {
173 var reader = new ArchiveReader();
174 reader.format.tar = true;
175 reader.filter.gzip = true;
176
177 expect(reader.openFilename("$dataPath/non-existent.tar.gz"),
178 throwsA((e) => e is ArchiveException));
179 });
180 }
181
OLDNEW
« no previous file with comments | « utils/archive/utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698