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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/archive/utils.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/tests/archive/reader_test.dart
diff --git a/utils/tests/archive/reader_test.dart b/utils/tests/archive/reader_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..79d15692d725c8dd5af9330d13e8fc1af651f25a
--- /dev/null
+++ b/utils/tests/archive/reader_test.dart
@@ -0,0 +1,181 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#library('reader_test');
+
+#import('dart:io');
+#import('../../../lib/unittest/unittest.dart');
+#import('../../archive/archive.dart');
+
+final String dataPath = "utils/tests/archive/data";
+
+main() {
+ test('reading a .tar.gz file', () {
+ var asyncDone = expectAsync0(() {});
+
+ var reader = new ArchiveReader();
+ reader.format.tar = true;
+ reader.filter.gzip = true;
+
+ var future = reader.openFilename("$dataPath/test-archive.tar.gz")
+ .transform((input) {
+ var log = <String>[];
+ input.onEntry = (entry) => guardAsync(() {
+ log.add("Entry: ${entry.pathname}");
+ var stream = new StringInputStream(entry.openInputStream());
+ stream.onData = () => log.add("Contents: ${stream.read().trim()}");
+ stream.onClosed = () => log.add("Closed: ${entry.pathname}");
+ });
+ input.onError = registerException;
+
+ input.onClosed = () => guardAsync(() {
+ expect(log, orderedEquals([
+ "Entry: filename1",
+ "Contents: contents 1",
+ "Closed: filename1",
+
+ "Entry: filename2",
+ "Contents: contents 2",
+ "Closed: filename2",
+
+ "Entry: filename3",
+ "Contents: contents 3",
+ "Closed: filename3",
+ ]));
+ }, asyncDone);
+ });
+
+ expect(future, completes);
+ });
+
+ test('reading an in-memory .tar.gz', () {
+ var asyncDone = expectAsync0(() {});
+
+ var reader = new ArchiveReader();
+ reader.format.tar = true;
+ reader.filter.gzip = true;
+
+ var future = new File("$dataPath/test-archive.tar.gz").readAsBytes()
+ .chain((bytes) => reader.openData(bytes))
+ .transform((input) {
+ var log = <String>[];
+ input.onEntry = (entry) => guardAsync(() {
+ log.add("Entry: ${entry.pathname}");
+ var stream = new StringInputStream(entry.openInputStream());
+ stream.onData = () => log.add("Contents: ${stream.read().trim()}");
+ stream.onClosed = () => log.add("Closed: ${entry.pathname}");
+ });
+ input.onError = registerException;
+
+ input.onClosed = () => guardAsync(() {
+ expect(log, orderedEquals([
+ "Entry: filename1",
+ "Contents: contents 1",
+ "Closed: filename1",
+
+ "Entry: filename2",
+ "Contents: contents 2",
+ "Closed: filename2",
+
+ "Entry: filename3",
+ "Contents: contents 3",
+ "Closed: filename3",
+ ]));
+ }, asyncDone);
+ });
+
+ expect(future, completes);
+ });
+
+ test("closing entries before they're read", () {
+ var asyncDone = expectAsync0(() {});
+
+ var reader = new ArchiveReader();
+ reader.format.tar = true;
+ reader.filter.gzip = true;
+
+ var future = reader.openFilename("$dataPath/test-archive.tar.gz")
+ .transform((input) {
+ var log = <String>[];
+ input.onEntry = (entry) => guardAsync(() {
+ log.add("Entry: ${entry.pathname}");
+ var underlyingStream = entry.openInputStream();
+ var stream = new StringInputStream(underlyingStream);
+ stream.onData = () => log.add("Contents: ${stream.read().trim()}");
+ stream.onClosed = () => log.add("Closed: ${entry.pathname}");
+ underlyingStream.close();
+ });
+ input.onError = registerException;
+
+ input.onClosed = () => guardAsync(() {
+ expect(log, orderedEquals([
+ "Entry: filename1",
+ "Closed: filename1",
+
+ "Entry: filename2",
+ "Closed: filename2",
+
+ "Entry: filename3",
+ "Closed: filename3",
+ ]));
+ }, asyncDone);
+ });
+
+ expect(future, completes);
+ });
+
+ test("closing an archive stream before it's finished", () {
+ var asyncDone = expectAsync0(() {});
+
+ var reader = new ArchiveReader();
+ reader.format.tar = true;
+ reader.filter.gzip = true;
+
+ var future = reader.openFilename("$dataPath/test-archive.tar.gz")
+ .transform((input) {
+ var count = 0;
+
+ var log = <String>[];
+ input.onEntry = (entry) => guardAsync(() {
+ count += 1;
+
+ log.add("Entry: ${entry.pathname}");
+ var underlyingStream = entry.openInputStream();
+ var stream = new StringInputStream(underlyingStream);
+ stream.onData = () => log.add("Contents: ${stream.read().trim()}");
+ stream.onClosed = () => log.add("Closed: ${entry.pathname}");
+
+ if (count == 2) {
+ input.close();
+ expect(input.closed);
+ }
+ });
+ input.onError = registerException;
+
+ input.onClosed = () {
+ expect(log, orderedEquals([
+ "Entry: filename1",
+ "Contents: contents 1",
+ "Closed: filename1",
+
+ "Entry: filename2",
+ "Closed: filename2",
+ ]));
+ asyncDone();
+ };
+ });
+
+ expect(future, completes);
+ });
+
+ test("opening a non-existent archive", () {
+ var reader = new ArchiveReader();
+ reader.format.tar = true;
+ reader.filter.gzip = true;
+
+ expect(reader.openFilename("$dataPath/non-existent.tar.gz"),
+ throwsA((e) => e is ArchiveException));
+ });
+}
+
« 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