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

Side by Side Diff: tests/corelib/data_resource_test.dart

Issue 1276263002: Add resource tests. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 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
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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 const sampleText = "Sample text file";
6
7 main() async {
8 var uriEncoded = sampleText.replaceAll(' ', '%20');
9 await testUri("data:application/dart;charset=utf-8,$uriEncoded");
10 // await testUri("data:text/plain;charset=utf-8,$uriEncoded");
Søren Gjesse 2015/08/07 13:51:16 Open bugs on these contentType and base64 issues.
Lasse Reichstein Nielsen 2015/08/10 10:40:09 Acknowledged.
11 var base64Encoded = "U2FtcGxlIHRleHQgZmlsZQ==";
12 // await testUri("data:application/dart;charset=utf-8;base64,$base64Encoded");
13 // await testUri("data:text/plain;charset=utf-8;base64,$base64Encoded");
Lasse Reichstein Nielsen 2015/08/07 12:21:35 I think we should properly support the data: schem
Ivan Posva 2015/08/10 05:39:56 ACK
Lasse Reichstein Nielsen 2015/08/10 10:40:09 I'm not sure the Uri class is the right place - bu
14 }
15
16 testUri(uriText) async {
17 var resource = new Resource(uriText);
18
19 if (resource.uri != Uri.parse(uriText)) {
20 throw "uriText: Incorrect URI: ${resource.uri}";
21 }
22
23 var text = await resource.readAsString();
24 if (text != sampleText) {
25 throw "uriText: Incorrect reading of text file: $text";
26 }
27
28 var bytes = await resource.readAsBytes();
29 if (!compareBytes(bytes, sampleText.codeUnits)) {
30 throw "uriText: Incorrect reading of bytes: $bytes";
31 }
32
33 var streamBytes = [];
34 await for (var byteSlice in resource.openRead()) {
35 streamBytes.addAll(byteSlice);
36 }
37 if (!compareBytes(streamBytes, sampleText.codeUnits)) {
38 throw "uriText: Incorrect reading of bytes: $bytes";
39 }
40 if (!compareBytes(streamBytes, bytes)) {
Søren Gjesse 2015/08/07 13:51:16 I don't think this check adds anything.
Lasse Reichstein Nielsen 2015/08/07 13:55:52 True, it made sense for the package_resource_test
41 throw "uriText: Inconsistent reading of bytes: $bytes / $streamBytes";
42 }
43 }
44
45 /// Checks that [bytes] and [expectedBytes] have the same contents.
46 bool compareBytes(bytes, expectedBytes) {
47 if (bytes.length != expectedBytes.length) return false;
48 for (int i = 0; i < expectedBytes.length; i++) {
49 if (bytes[i] != expectedBytes[i]) return false;
50 }
51 return true;
52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698