mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 12:57:42 +00:00
[nnbd] Migrate standalone/io to NNBD.
The tests are also now dartfmt. Bug: https://github.com/dart-lang/sdk/issues/40040 Change-Id: I8dece8097b37b70d47a5374dae2f3fadb0fc4b90 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134338 Commit-Queue: Jonas Termansen <sortie@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
parent
02ced42875
commit
3433d8cfc3
221
tests/standalone/io/addlatexhash_test.dart
Executable file
221
tests/standalone/io/addlatexhash_test.dart
Executable file
|
@ -0,0 +1,221 @@
|
|||
#!/usr/bin/env dart
|
||||
// Copyright (c) 2014, 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.
|
||||
|
||||
// testing ../../../tools/addlatexhash.dart
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:path/path.dart' as path;
|
||||
import '../../../tools/addlatexhash.dart';
|
||||
|
||||
final execDir = path.dirname(Platform.resolvedExecutable);
|
||||
final dartRootDir = path.dirname(path.dirname(execDir));
|
||||
final dartRootPath = dartRootDir.toString();
|
||||
|
||||
List<String> packageOptions() {
|
||||
if (Platform.packageRoot != null) {
|
||||
return <String>['--package-root=${Platform.packageRoot}'];
|
||||
} else if (Platform.packageConfig != null) {
|
||||
return <String>['--packages=${Platform.packageConfig}'];
|
||||
} else {
|
||||
return <String>[];
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the given ProcessResult indicates success; if so
|
||||
// return the standard output, otherwise report the failure
|
||||
checkAction(result, errorMessage) {
|
||||
if (result.exitCode != 0) {
|
||||
print(result.stdout);
|
||||
print(result.stderr);
|
||||
throw errorMessage;
|
||||
}
|
||||
return result.stdout;
|
||||
}
|
||||
|
||||
oneTestCutMatch(line, re, expected) {
|
||||
var result = cutMatch(line, new RegExp(re).firstMatch(line));
|
||||
if (result != expected) {
|
||||
throw "cutMatch '$re' from '$line' yields '$result' != '$expected'";
|
||||
}
|
||||
}
|
||||
|
||||
void testCutMatch() {
|
||||
oneTestCutMatch("test", "", "test");
|
||||
oneTestCutMatch("test", "e", "tst");
|
||||
oneTestCutMatch("test", "te", "st");
|
||||
oneTestCutMatch("test", "st", "te");
|
||||
oneTestCutMatch("test", "test", "");
|
||||
}
|
||||
|
||||
oneTestSisp(sispFun, nameSuffix, line, expected) {
|
||||
var result = sispFun(line);
|
||||
if (result != expected) {
|
||||
throw "sispIsDart$nameSuffix '$line' yields $result";
|
||||
}
|
||||
}
|
||||
|
||||
testSisp() {
|
||||
oneTestSisp(sispIsDartBegin, "Begin", "\\begin{dartCode}\n", true);
|
||||
oneTestSisp(sispIsDartBegin, "Begin", " \\begin{dartCode}\n", true);
|
||||
oneTestSisp(sispIsDartBegin, "Begin", "whatever else ..", false);
|
||||
oneTestSisp(sispIsDartEnd, "End", "\\end{dartCode}", true);
|
||||
oneTestSisp(sispIsDartEnd, "End", " \\end{dartCode}\t \n", true);
|
||||
oneTestSisp(sispIsDartEnd, "End", "whatever else ..", false);
|
||||
}
|
||||
|
||||
// Check that the hash values of paragraphs in the specially prepared
|
||||
// LaTeX source 'addlatexhash_test_src.tex' are identical in groups
|
||||
// of eight (so we get 8 identical hash values, then another hash
|
||||
// value 8 times, etc.)
|
||||
testSameHash(String tmpDirPath) {
|
||||
// file names/paths for file containing groups of 8 variants of a paragraph
|
||||
const par8timesName = "addlatexhash_test_src";
|
||||
const par8timesFileName = "$par8timesName.tex";
|
||||
final par8timesDirPath =
|
||||
path.join(dartRootDir, "tests", "standalone_2", "io");
|
||||
final par8timesPath = path.join(par8timesDirPath, par8timesFileName);
|
||||
final tmpPar8timesPath = path.join(tmpDirPath, par8timesFileName);
|
||||
|
||||
// file names paths for output
|
||||
final hashName = par8timesName + "-hash";
|
||||
final hashFileName = "$hashName.tex";
|
||||
final hashPath = path.join(tmpDirPath, hashFileName);
|
||||
final listName = par8timesName + "-list";
|
||||
final listFileName = "$listName.txt";
|
||||
final listPath = path.join(tmpDirPath, listFileName);
|
||||
|
||||
// dart executable
|
||||
final dartExecutable = Platform.executable;
|
||||
if (dartExecutable == "") throw "dart executable not available";
|
||||
|
||||
// actions to take
|
||||
runAddHash() {
|
||||
var args = <String>[]..addAll(Platform.executableArguments);
|
||||
args.addAll([
|
||||
path.join(dartRootPath, "tools", "addlatexhash.dart"),
|
||||
tmpPar8timesPath,
|
||||
hashPath,
|
||||
listPath
|
||||
]);
|
||||
return Process.runSync(dartExecutable, args);
|
||||
}
|
||||
|
||||
// perform test
|
||||
new File(par8timesPath).copySync(tmpPar8timesPath);
|
||||
checkAction(runAddHash(), "addlatexhash.dart failed");
|
||||
var listFile = new File(listPath);
|
||||
var listLines = listFile.readAsLinesSync();
|
||||
var latestLine = null;
|
||||
var sameCount = 0;
|
||||
for (var line in listLines) {
|
||||
if (!line.startsWith(" ")) continue; // section marker
|
||||
if (line.startsWith(" %")) continue; // transformed text "comment"
|
||||
if (line != latestLine) {
|
||||
// new hash, check for number of equal hashes, then reset
|
||||
if (sameCount % 8 == 0) {
|
||||
// saw zero or more blocks of 8 identical hash values: OK
|
||||
latestLine = line;
|
||||
sameCount = 1;
|
||||
} else {
|
||||
throw "normalization failed to produce same result";
|
||||
}
|
||||
} else {
|
||||
sameCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the LaTeX source transformation done by addlatexhash.dart
|
||||
// does not affect the generated output, as seen via dvi2tty and diff.
|
||||
// NB: Not part of normal testing (only local): latex and dvi2tty are
|
||||
// not installed in the standard test environment.
|
||||
testSameDVI(String tmpDirPath) {
|
||||
// file names/paths for original spec
|
||||
const specName = "dartLangSpec";
|
||||
const specFileName = "$specName.tex";
|
||||
final specDirPath = path.join(dartRootDir, "docs", "language");
|
||||
final specPath = path.join(specDirPath, specFileName);
|
||||
final tmpSpecPath = path.join(tmpDirPath, specFileName);
|
||||
const specDviFileName = "$specName.dvi";
|
||||
final specDviPath = path.join(tmpDirPath, specDviFileName);
|
||||
|
||||
// file names/paths for associated sty
|
||||
const styFileName = "dart.sty";
|
||||
final styPath = path.join(specDirPath, styFileName);
|
||||
final tmpStyPath = path.join(tmpDirPath, styFileName);
|
||||
|
||||
// file names paths for output
|
||||
const hashName = "dartLangSpec-hash";
|
||||
const hashFileName = "$hashName.tex";
|
||||
final hashPath = path.join(tmpDirPath, hashFileName);
|
||||
final hashDviPath = path.join(tmpDirPath, "$hashName.dvi");
|
||||
|
||||
final listName = "$specName-list";
|
||||
final listFileName = "$listName.txt";
|
||||
final listPath = path.join(tmpDirPath, listFileName);
|
||||
|
||||
// dart executable
|
||||
final dartExecutable = Platform.executable;
|
||||
if (dartExecutable == "") throw "dart executable not available";
|
||||
|
||||
// actions to take; rely on having latex and dvi2tty in PATH
|
||||
runLatex(fileName, workingDirectory) =>
|
||||
Process.runSync("latex", [fileName], workingDirectory: workingDirectory);
|
||||
|
||||
runAddHash() {
|
||||
var args = packageOptions();
|
||||
args.addAll([
|
||||
path.join(dartRootPath, "tools", "addlatexhash.dart"),
|
||||
tmpSpecPath,
|
||||
hashPath,
|
||||
listPath
|
||||
]);
|
||||
return Process.runSync(dartExecutable, args);
|
||||
}
|
||||
|
||||
runDvi2tty(dviFile) =>
|
||||
Process.runSync("dvi2tty", [dviFile], workingDirectory: tmpDirPath);
|
||||
|
||||
chkDvi2tty(file, subject) =>
|
||||
checkAction(runDvi2tty(file), "dvitty on $subject failed");
|
||||
|
||||
// perform test
|
||||
var renewLMHashCmd = r"\renewcommand{\LMHash}[1]{\OriginalLMHash{xxxx}}";
|
||||
new File(styPath)
|
||||
.copySync(tmpStyPath)
|
||||
.writeAsStringSync(renewLMHashCmd, mode: FileMode.append);
|
||||
new File(specPath).copySync(tmpSpecPath);
|
||||
|
||||
checkAction(runAddHash(), "addlatexhash.dart failed");
|
||||
for (var i = 0; i < 5; i++) {
|
||||
checkAction(runLatex(specName, tmpDirPath), "LaTeX on spec failed");
|
||||
}
|
||||
for (var i = 0; i < 5; i++) {
|
||||
checkAction(runLatex(hashFileName, tmpDirPath), "LaTeX on output failed");
|
||||
}
|
||||
if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(hashDviPath, "output")) {
|
||||
throw "dvi2tty spec != dvitty output";
|
||||
}
|
||||
}
|
||||
|
||||
runWithTempDir(void test(String tempDir)) {
|
||||
final tempDir = Directory.systemTemp.createTempSync("addlatexhash_test");
|
||||
try {
|
||||
test(tempDir.path);
|
||||
} finally {
|
||||
tempDir.delete(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
main([args]) {
|
||||
testCutMatch();
|
||||
testSisp();
|
||||
|
||||
runWithTempDir(testSameHash);
|
||||
// latex and dvi2tty are not installed in the standard test environment
|
||||
if (args.length > 0 && args[0] == "local") {
|
||||
runWithTempDir(testSameDVI);
|
||||
}
|
||||
}
|
825
tests/standalone/io/addlatexhash_test_src.tex
Normal file
825
tests/standalone/io/addlatexhash_test_src.tex
Normal file
|
@ -0,0 +1,825 @@
|
|||
\documentclass{article}
|
||||
\usepackage{epsfig}
|
||||
\usepackage{color}
|
||||
\usepackage{dart}
|
||||
\usepackage{bnf}
|
||||
\usepackage{hyperref}
|
||||
\usepackage{lmodern}
|
||||
\newcommand{\code}[1]{{\sf #1}}
|
||||
\title{Test File used by addlatexhash}
|
||||
|
||||
\begin{document}
|
||||
\maketitle
|
||||
\tableofcontents
|
||||
\newpage
|
||||
|
||||
\pagestyle{myheadings}
|
||||
\markright{Test file used by addlatexhash}
|
||||
|
||||
% begin Ecma boilerplate
|
||||
\section{Scope}
|
||||
\LMLabel{ecmaScope}
|
||||
|
||||
% Selected certain paragraphs from the spec, created exactly eight
|
||||
% copies of each of them, modifying the copies in ways that should
|
||||
% not affect the hash values; to verify correct behavior, grep for
|
||||
% '^ *\\LMHash' in the output LaTeX source or take every 2nd line
|
||||
% from the list file, and check that the sequence of hashes consists
|
||||
% of subsequences of identical values, all with length eight.
|
||||
|
||||
% Test a "normal" paragraph -------------------------------------------
|
||||
|
||||
%0 original
|
||||
\LMHash{}
|
||||
This Ecma standard specifies the syntax and semantics of the Dart programming language. It does not specify the APIs of the Dart libraries except where those library elements are essential to the correct functioning of the language itself (e.g., the existence of class \cd{Object} with methods such as \cd{noSuchMethod}, \cd{runtimeType}).
|
||||
|
||||
%1 enlarge white space; NB: cannot add new white space, just enlarge
|
||||
\LMHash{}
|
||||
This Ecma standard specifies the syntax and semantics of the Dart programming language. It does not specify the APIs of the Dart libraries except where those library elements are essential to the correct functioning of the language itself (e.g., the existence of class \cd{Object} with methods such as \cd{noSuchMethod}, \cd{runtimeType}).
|
||||
|
||||
%2 insert extra newlines
|
||||
\LMHash{}
|
||||
This Ecma standard specifies the syntax and semantics of the Dart
|
||||
programming language. It does not specify the APIs of the Dart
|
||||
libraries except where those library elements are essential to the
|
||||
correct functioning of the language itself (e.g., the existence of
|
||||
class \cd{Object} with methods such as \cd{noSuchMethod},
|
||||
\cd{runtimeType}).
|
||||
|
||||
%3 insert comments
|
||||
\LMHash{}
|
||||
This Ecma standard specifies the syntax and semantics of the Dart % blah
|
||||
programming language. It does not specify the APIs of the Dart%blah
|
||||
libraries except where those library elements are essential to the% blah
|
||||
correct functioning of the language itself (e.g., the existence of
|
||||
class \cd{Object} with methods such as \cd{noSuchMethod},
|
||||
\cd{runtimeType}). % blah blah
|
||||
|
||||
%4 insert commentary
|
||||
\LMHash{}
|
||||
This Ecma standard specifies the syntax and semantics of the Dart programming language. It does not specify the APIs of the Dart libraries except where those library elements are \commentary{whatever} essential to the correct functioning of the language itself (e.g., the existence of class \cd{Object} with methods such as \cd{noSuchMethod}, \cd{runtimeType}).
|
||||
|
||||
%5 insert rationale
|
||||
\LMHash{}
|
||||
This Ecma standard specifies the syntax and semantics of the Dart programming language. It does not specify the APIs of the \rationale{whatever} Dart libraries except where those library elements are essential to the correct functioning of the language itself (e.g., the existence of class \cd{Object} with methods such as \cd{noSuchMethod}, \cd{runtimeType}).
|
||||
|
||||
%6 insert nested rationale/commentary
|
||||
\LMHash{}
|
||||
This Ecma standard specifies \rationale{whatever \commentary{whatever}} the syntax and semantics of the Dart programming language. It does not specify the APIs of the Dart libraries except where those library elements are essential to the correct functioning of the language itself (e.g., the existence of class \cd{Object} with methods such as \cd{noSuchMethod}, \cd{runtimeType}).
|
||||
|
||||
%7 insert all; note that this block ends with more blank lines, too
|
||||
\LMHash{}
|
||||
This Ecma standard specifies the syntax \rationale{whatever \commentary{whatever}} and semantics of the Dart programming language. It does not specify the APIs of the
|
||||
Dart libraries except where those library elements are
|
||||
essential to the correct functioning of
|
||||
the language itself (e.g., the existence of class
|
||||
\cd{Object} with methods such as \cd{noSuchMethod}, \cd{runtimeType}).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
\section{Conformance}
|
||||
\LMLabel{ecmaConformance}
|
||||
|
||||
% Test a paragraph including math mode --------------------------------
|
||||
|
||||
%0 original
|
||||
\LMHash{}
|
||||
A list $x_1, \ldots, x_n$ denotes any list of $n$ elements of the form $x_i, 1 \le i \le n$. Note that $n$ may be zero, in which case the list is empty. We use such lists extensively throughout this specification.
|
||||
|
||||
%1 enlarge white space in math mode; NB: cannot add new ws, even in math mode
|
||||
\LMHash{}
|
||||
A list $x_1, \ldots, x_n$ denotes any list of $n$ elements of the form $x_i, 1 \le i \le n$. Note that $n$ may be zero, in which case the list is empty. We use such lists extensively throughout this specification.
|
||||
|
||||
%2 enlarge other white space
|
||||
\LMHash{}
|
||||
A list $x_1, \ldots, x_n$ denotes any list of $n$ elements
|
||||
of the form $x_i, 1 \le i \le n$.
|
||||
Note that $n$ may be zero, in
|
||||
which case the list is empty. We use such lists
|
||||
extensively throughout this
|
||||
specification.
|
||||
|
||||
%3 add comments, also in math mode
|
||||
\LMHash{}
|
||||
A list $x_1, \ldots, x_n$ denotes any list of $n$ elements% blah % blah
|
||||
of the form $x_i, 1% blah
|
||||
\le i % blah
|
||||
\le n$. Note that $n$ may be zero, in which
|
||||
% blah blah %
|
||||
case the list is empty. We use such lists extensively throughout this
|
||||
specification.
|
||||
|
||||
%4 even multiple newlines do not count when before '$'
|
||||
\LMHash{}
|
||||
A list $x_1, \ldots, x_n$ denotes any list of $n$ elements of the form
|
||||
|
||||
|
||||
$x_i, 1 \le i \le n$. Note that $n$ may be zero, in which case the list is empty. We use such lists extensively throughout this specification.
|
||||
|
||||
%5 multiple new lines and leading ws before '$', and comments
|
||||
\LMHash{}
|
||||
A list $x_1, \ldots, x_n$ denotes any list of $n$ elements of the form $x_i, 1 \le i \le n$. Note that
|
||||
|
||||
% blah blah blah blah blah blah blah blah
|
||||
% blah blah blah blah blah blah blah blah
|
||||
% blah blah blah blah blah blah blah blah
|
||||
% blah blah blah blah blah blah blah blah
|
||||
|
||||
$n$ may be zero, in which case the list is empty. We use such lists extensively throughout this specification.
|
||||
|
||||
%6 precede paragraph with comments
|
||||
\LMHash{}
|
||||
% blah
|
||||
% blah
|
||||
%
|
||||
A list $x_1, \ldots, x_n$ denotes any list of $n$ elements of the form $x_i, 1 \le i \le n$. Note that $n$ may be zero, in which case the list is empty. We use such lists extensively throughout this specification.
|
||||
|
||||
%7 insert comment lines in the middle of the paragraph
|
||||
\LMHash{}
|
||||
A list $x_1, \ldots, x_n$ denotes any list of $n$ elements of the form $x_i, 1 \le i \le n$. Note that $n$ may be zero,
|
||||
%
|
||||
% blah
|
||||
%
|
||||
in which case the list is empty. We use such lists extensively throughout this specification.
|
||||
|
||||
|
||||
% Test paragraph plus dartCode, with commentary -----------------------
|
||||
|
||||
%0 original
|
||||
\LMHash{}
|
||||
If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically enclosing scope of $S$.
|
||||
|
||||
\commentary {
|
||||
A consequence of these rules is that it is possible to hide a type with a method or variable.
|
||||
Naming conventions usually prevent such abuses. Nevertheless,the following program is legal:
|
||||
}
|
||||
|
||||
\begin{dartCode}
|
||||
\CLASS{} HighlyStrung \{
|
||||
String() $=>$ "?";
|
||||
\}
|
||||
\end{dartCode}
|
||||
|
||||
%1 delete/insert in the commentary, altering number of paragraphs in there
|
||||
\LMHash{}
|
||||
If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically enclosing scope of $S$.
|
||||
|
||||
\commentary {% NB: this space before brace begin is ignored by LaTeX
|
||||
New paragraph.
|
||||
|
||||
New paragraph new paragraph new paragraph new paragraph new paragraph new paragraph new paragraph new paragraph new paragraph new paragraph new paragraph new paragraph new paragraph new paragraph new paragraph new paragraph new paragraph.
|
||||
|
||||
New paragraph,
|
||||
new paragraph, and
|
||||
new paragraph. % blah \commentary{ with unbalanced '{'
|
||||
|
||||
\rationale{nested rationale}
|
||||
|
||||
Naming conventions usually prevent such abuses. Nevertheless,the following program is legal:
|
||||
}
|
||||
|
||||
\begin{dartCode}
|
||||
\CLASS{} HighlyStrung \{
|
||||
String() $=>$ "?";
|
||||
\}
|
||||
\end{dartCode}
|
||||
|
||||
%2 remove commentary entirely, including newlines
|
||||
\LMHash{}
|
||||
If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically enclosing scope of $S$.
|
||||
|
||||
\begin{dartCode}
|
||||
\CLASS{} HighlyStrung \{
|
||||
String() $=>$ "?";
|
||||
\}
|
||||
\end{dartCode}
|
||||
|
||||
%3 change the amount of indentation in dartCode
|
||||
\LMHash{}
|
||||
If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically enclosing scope of $S$.
|
||||
|
||||
\commentary {
|
||||
A consequence of these rules is that it is possible to hide a type with a method or variable.
|
||||
Naming conventions usually prevent such abuses. Nevertheless,the following program is legal:
|
||||
}
|
||||
|
||||
\begin{dartCode}
|
||||
\CLASS{} HighlyStrung \{
|
||||
String() $=>$ "?";
|
||||
\}
|
||||
\end{dartCode}
|
||||
|
||||
%4 change other white space in dartCode
|
||||
\LMHash{}
|
||||
If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically enclosing scope of $S$.
|
||||
|
||||
\commentary {
|
||||
A consequence of these rules is that it is possible to hide a type with a method or variable.
|
||||
Naming conventions usually prevent such abuses. Nevertheless,the following program is legal:
|
||||
}
|
||||
|
||||
\begin{dartCode}
|
||||
|
||||
\CLASS{} HighlyStrung \{
|
||||
String() $=>$ "?";
|
||||
|
||||
|
||||
\}
|
||||
\end{dartCode}
|
||||
|
||||
%5 add comments in dartCode
|
||||
\LMHash{}
|
||||
If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically enclosing scope of $S$.
|
||||
|
||||
\commentary {
|
||||
A consequence of these rules is that it is possible to hide a type with a method or variable.
|
||||
Naming conventions usually prevent such abuses. Nevertheless,the following program is legal:
|
||||
}
|
||||
|
||||
\begin{dartCode}
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
\CLASS{} HighlyStrung \{
|
||||
String() $=>$ "?";% blah % blah
|
||||
\} % blah
|
||||
%blah
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
\end{dartCode}
|
||||
|
||||
%6 remove commentary
|
||||
\LMHash{}
|
||||
If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically enclosing scope of $S$.
|
||||
|
||||
\begin{dartCode}
|
||||
\CLASS{} HighlyStrung \{
|
||||
String() $=>$ "?";
|
||||
\}
|
||||
\end{dartCode}
|
||||
|
||||
%7 add comment lines after the block
|
||||
\LMHash{}
|
||||
If a declaration $d$ named $n$ is in the namespace induced by a scope $S$, then $d$ {\em hides} any declaration named $n$ that is available in the lexically enclosing scope of $S$.
|
||||
|
||||
\commentary {
|
||||
A consequence of these rules is that it is possible to hide a type with a method or variable.
|
||||
Naming conventions usually prevent such abuses. Nevertheless,the following program is legal:
|
||||
}
|
||||
|
||||
\begin{dartCode}
|
||||
\CLASS{} HighlyStrung \{
|
||||
String() $=>$ "?";
|
||||
\}
|
||||
\end{dartCode}
|
||||
|
||||
% blah blah blah blah blah blah blah blah blah
|
||||
% blah blah blah blah blah blah blah blah blah
|
||||
% blah blah blah blah blah blah blah blah blah
|
||||
% no blank lines before \section this time
|
||||
\section{Variables}
|
||||
\LMLabel{variables}
|
||||
|
||||
% Test paragraph followed by grammar ----------------------------------
|
||||
|
||||
%0 original
|
||||
\LMHash{}
|
||||
Variables are storage locations in memory.
|
||||
|
||||
\begin{grammar}
|
||||
{\bf variableDeclaration:}
|
||||
declaredIdentifier (`,' identifier)*
|
||||
.
|
||||
|
||||
{\bf declaredIdentifier:}
|
||||
metadata finalConstVarOrType identifier
|
||||
.
|
||||
|
||||
{\bf finalConstVarOrType:}\FINAL{} type?;
|
||||
\CONST{} type?;
|
||||
varOrType
|
||||
.
|
||||
|
||||
{\bf varOrType:}\VAR{};
|
||||
type
|
||||
.
|
||||
|
||||
{\bf initializedVariableDeclaration:}
|
||||
declaredIdentifier (`=' expression)? (`,' initializedIdentifier)* % could do top level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifier:}
|
||||
identifier (`=' expression)? % could do top-level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifierList:}
|
||||
initializedIdentifier (`,' initializedIdentifier)*
|
||||
.
|
||||
|
||||
|
||||
|
||||
|
||||
\end{grammar}
|
||||
|
||||
%1 collecting grammar rules on single lines
|
||||
\LMHash{}
|
||||
Variables are storage locations in memory.
|
||||
|
||||
\begin{grammar}
|
||||
{\bf variableDeclaration:} declaredIdentifier (`,' identifier)* .
|
||||
|
||||
{\bf declaredIdentifier:} metadata finalConstVarOrType identifier .
|
||||
|
||||
{\bf finalConstVarOrType:}\FINAL{} type?; \CONST{} type?; varOrType .
|
||||
|
||||
{\bf varOrType:}\VAR{}; type .
|
||||
|
||||
{\bf initializedVariableDeclaration:} declaredIdentifier (`=' expression)? (`,' initializedIdentifier)* .
|
||||
|
||||
{\bf initializedIdentifier:} identifier (`=' expression)? .
|
||||
|
||||
{\bf initializedIdentifierList:} initializedIdentifier (`,' initializedIdentifier)* .
|
||||
\end{grammar}
|
||||
|
||||
%2 adding comments to grammar
|
||||
\LMHash{}
|
||||
Variables are storage locations in memory.
|
||||
|
||||
\begin{grammar}% blah
|
||||
%blah
|
||||
{\bf variableDeclaration:}%blah
|
||||
declaredIdentifier (`,' identifier)*%blah
|
||||
.%blah
|
||||
%blah
|
||||
{\bf declaredIdentifier:}
|
||||
metadata finalConstVarOrType identifier
|
||||
.
|
||||
|
||||
{\bf finalConstVarOrType:}\FINAL{} type?;
|
||||
\CONST{} type?;
|
||||
varOrType
|
||||
.
|
||||
|
||||
{\bf varOrType:}\VAR{};
|
||||
type
|
||||
.
|
||||
|
||||
{\bf initializedVariableDeclaration:}
|
||||
declaredIdentifier (`=' expression)? (`,' initializedIdentifier)* % could do top level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifier:}
|
||||
identifier (`=' expression)? % could do top-level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifierList:}
|
||||
initializedIdentifier (`,' initializedIdentifier)*
|
||||
.% blah
|
||||
|
||||
|
||||
|
||||
%blah
|
||||
\end{grammar}%blah
|
||||
|
||||
%3 removing empty lines from grammar
|
||||
\LMHash{}
|
||||
Variables are storage locations in memory.
|
||||
|
||||
\begin{grammar}
|
||||
{\bf variableDeclaration:}
|
||||
declaredIdentifier (`,' identifier)*
|
||||
.
|
||||
{\bf declaredIdentifier:}
|
||||
metadata finalConstVarOrType identifier
|
||||
.
|
||||
{\bf finalConstVarOrType:}\FINAL{} type?;
|
||||
\CONST{} type?;
|
||||
varOrType
|
||||
.
|
||||
{\bf varOrType:}\VAR{};
|
||||
type
|
||||
.
|
||||
{\bf initializedVariableDeclaration:}
|
||||
declaredIdentifier (`=' expression)? (`,' initializedIdentifier)* % could do top level here
|
||||
.
|
||||
{\bf initializedIdentifier:}
|
||||
identifier (`=' expression)? % could do top-level here
|
||||
.
|
||||
{\bf initializedIdentifierList:}
|
||||
initializedIdentifier (`,' initializedIdentifier)*
|
||||
.
|
||||
\end{grammar}
|
||||
|
||||
%4 inserting comment block in grammar
|
||||
\LMHash{}
|
||||
Variables are storage locations in memory.
|
||||
|
||||
\begin{grammar}
|
||||
{\bf variableDeclaration:}
|
||||
declaredIdentifier (`,' identifier)*
|
||||
.
|
||||
|
||||
{\bf declaredIdentifier:}
|
||||
metadata finalConstVarOrType identifier
|
||||
.
|
||||
|
||||
{\bf finalConstVarOrType:}\FINAL{} type?;
|
||||
\CONST{} type?;
|
||||
varOrType
|
||||
.
|
||||
|
||||
{\bf varOrType:}\VAR{};
|
||||
type
|
||||
.
|
||||
%% {\bf finalConstVarOrType:}\FINAL{} type?;
|
||||
%% \CONST{} type?;
|
||||
%% varOrType
|
||||
%% .
|
||||
|
||||
%% {\bf varOrType:}\VAR{};
|
||||
%% type
|
||||
%% .
|
||||
|
||||
|
||||
{\bf initializedVariableDeclaration:}
|
||||
declaredIdentifier (`=' expression)? (`,' initializedIdentifier)* % could do top level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifier:}
|
||||
identifier (`=' expression)? % could do top-level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifierList:}
|
||||
initializedIdentifier (`,' initializedIdentifier)*
|
||||
.
|
||||
|
||||
|
||||
|
||||
|
||||
\end{grammar}
|
||||
|
||||
%5 adding commentary/rationale in grammar (may not happen, is OK anyway)
|
||||
\LMHash{}
|
||||
Variables are storage locations in memory.
|
||||
|
||||
\begin{grammar}
|
||||
{\bf variableDeclaration:}
|
||||
declaredIdentifier (`,' identifier)*
|
||||
.
|
||||
|
||||
{\bf declaredIdentifier:}
|
||||
metadata finalConstVarOrType identifier
|
||||
.
|
||||
|
||||
\rationale{blah \commentary{blah}}
|
||||
{\bf finalConstVarOrType:}\FINAL{} type?;
|
||||
\CONST{} type?;
|
||||
varOrType
|
||||
.
|
||||
|
||||
{\bf varOrType:}\VAR{};
|
||||
type
|
||||
.
|
||||
|
||||
{\bf initializedVariableDeclaration:}
|
||||
declaredIdentifier (`=' expression)? (`,' initializedIdentifier)* % could do top level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifier:}
|
||||
identifier (`=' expression)? % could do top-level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifierList:}
|
||||
initializedIdentifier (`,' initializedIdentifier)*
|
||||
.
|
||||
|
||||
|
||||
|
||||
|
||||
\end{grammar}
|
||||
|
||||
%6 inserting newlines in grammar (not new paragraph, only at existing ws)
|
||||
\LMHash{}
|
||||
Variables are storage locations in memory.
|
||||
|
||||
\begin{grammar}
|
||||
{\bf variableDeclaration:}
|
||||
declaredIdentifier
|
||||
(`,'
|
||||
identifier)*
|
||||
.
|
||||
|
||||
{\bf declaredIdentifier:}
|
||||
metadata finalConstVarOrType
|
||||
identifier
|
||||
.
|
||||
|
||||
{\bf
|
||||
finalConstVarOrType:}\FINAL{}
|
||||
type?;
|
||||
\CONST{} type?;
|
||||
varOrType
|
||||
.
|
||||
|
||||
{\bf varOrType:}\VAR{};
|
||||
type
|
||||
.
|
||||
|
||||
{\bf initializedVariableDeclaration:}
|
||||
declaredIdentifier (`=' expression)?
|
||||
(`,' initializedIdentifier)*
|
||||
% could do top level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifier:}
|
||||
identifier (`=' expression)? % could do top-level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifierList:}
|
||||
initializedIdentifier (`,' initializedIdentifier)*
|
||||
.
|
||||
|
||||
|
||||
|
||||
|
||||
\end{grammar}
|
||||
|
||||
%7
|
||||
\LMHash{}
|
||||
Variables are storage locations in memory.
|
||||
|
||||
\begin{grammar}
|
||||
{\bf variableDeclaration:}
|
||||
declaredIdentifier (`,' identifier)*
|
||||
.
|
||||
|
||||
{\bf declaredIdentifier:}
|
||||
metadata finalConstVarOrType identifier
|
||||
.
|
||||
|
||||
{\bf finalConstVarOrType:}\FINAL{} type?;
|
||||
\CONST{} type?;
|
||||
varOrType
|
||||
.
|
||||
|
||||
{\bf varOrType:}\VAR{};
|
||||
type
|
||||
.
|
||||
|
||||
{\bf initializedVariableDeclaration:}
|
||||
declaredIdentifier (`=' expression)? (`,' initializedIdentifier)* % could do top level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifier:}
|
||||
identifier (`=' expression)? % could do top-level here
|
||||
.
|
||||
|
||||
{\bf initializedIdentifierList:}
|
||||
initializedIdentifier (`,' initializedIdentifier)*
|
||||
.
|
||||
|
||||
|
||||
|
||||
|
||||
\end{grammar}
|
||||
|
||||
\subsection{Evaluation of Implicit Variable Getters}
|
||||
\LMLabel{evaluationOfImplicitVariableGetters}
|
||||
|
||||
% Test itemized list, right after paragraph ---------------------------
|
||||
|
||||
%0 original
|
||||
\LMHash{}
|
||||
Let $d$ be the declaration of a static or instance variable $v$. If $d$ is an instance variable, then the invocation of the implicit getter of $v$ evaluates to the value stored in $v$.
|
||||
If $d$ is a static or library variable then the implicit getter method of $v$ executes as follows:
|
||||
\begin{itemize}
|
||||
\item {\bf Non-constant variable declaration with initializer}. If $d$ is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} , \code{\FINAL{} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;}, \code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ then the initializer expression $e$ is evaluated. If, during the evaluation of $e$, the getter for $v$ is invoked, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the getter is $r$.
|
||||
\item {\bf Constant variable declaration}. If $d$ is of one of the forms \code{\CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; }, \code{\STATIC{} \CONST{} $v$ = $e$; } or \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. \commentary{Note that a compile time constant cannot depend on itself, so no cyclic references can occur.}
|
||||
Otherwise
|
||||
\item {\bf Variable declaration without initializer}. The result of executing the getter method is the value stored in $v$.
|
||||
\end{itemize}
|
||||
|
||||
%1 insert blank lines and comments between paragraph and list ---------
|
||||
\LMHash{}
|
||||
Let $d$ be the declaration of a static or instance variable $v$. If $d$ is an instance variable, then the invocation of the implicit getter of $v$ evaluates to the value stored in $v$.
|
||||
If $d$ is a static or library variable then the implicit getter method of $v$ executes as follows:
|
||||
|
||||
%blah
|
||||
%blah
|
||||
|
||||
\begin{itemize}
|
||||
\item {\bf Non-constant variable declaration with initializer}. If $d$ is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} , \code{\FINAL{} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;}, \code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ then the initializer expression $e$ is evaluated. If, during the evaluation of $e$, the getter for $v$ is invoked, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the getter is $r$.
|
||||
\item {\bf Constant variable declaration}. If $d$ is of one of the forms \code{\CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; }, \code{\STATIC{} \CONST{} $v$ = $e$; } or \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. \commentary{Note that a compile time constant cannot depend on itself, so no cyclic references can occur.}
|
||||
Otherwise
|
||||
\item {\bf Variable declaration without initializer}. The result of executing the getter method is the value stored in $v$.
|
||||
\end{itemize}
|
||||
|
||||
%2 insert line break before each item
|
||||
\LMHash{}
|
||||
Let $d$ be the declaration of a static or instance variable $v$. If $d$ is an instance variable, then the invocation of the implicit getter of $v$ evaluates to the value stored in $v$.
|
||||
If $d$ is a static or library variable then the implicit getter method of $v$ executes as follows:
|
||||
\begin{itemize}
|
||||
\item
|
||||
{\bf Non-constant variable declaration with initializer}. If $d$ is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} , \code{\FINAL{} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;}, \code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ then the initializer expression $e$ is evaluated. If, during the evaluation of $e$, the getter for $v$ is invoked, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the getter is $r$.
|
||||
\item
|
||||
{\bf Constant variable declaration}. If $d$ is of one of the forms \code{\CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; }, \code{\STATIC{} \CONST{} $v$ = $e$; } or \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. \commentary{Note that a compile time constant cannot depend on itself, so no cyclic references can occur.}
|
||||
Otherwise
|
||||
\item
|
||||
{\bf Variable declaration without initializer}. The result of executing the getter method is the value stored in $v$.
|
||||
\end{itemize}
|
||||
|
||||
%3 insert blank/comment lines between,before,after items, and on begin/end
|
||||
\LMHash{}
|
||||
Let $d$ be the declaration of a static or instance variable $v$. If $d$ is an instance variable, then the invocation of the implicit getter of $v$ evaluates to the value stored in $v$.
|
||||
If $d$ is a static or library variable then the implicit getter method of $v$ executes as follows:
|
||||
\begin{itemize}%blah
|
||||
|
||||
% blah
|
||||
|
||||
\item {\bf Non-constant variable declaration with initializer}. If $d$ is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} , \code{\FINAL{} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;}, \code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ then the initializer expression $e$ is evaluated. If, during the evaluation of $e$, the getter for $v$ is invoked, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the getter is $r$.
|
||||
|
||||
\item {\bf Constant variable declaration}. If $d$ is of one of the forms \code{\CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; }, \code{\STATIC{} \CONST{} $v$ = $e$; } or \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. \commentary{Note that a compile time constant cannot depend on itself, so no cyclic references can occur.}
|
||||
Otherwise
|
||||
|
||||
%blah
|
||||
%blah
|
||||
%blah
|
||||
|
||||
|
||||
\item {\bf Variable declaration without initializer}. The result of executing the getter method is the value stored in $v$.
|
||||
|
||||
% blah
|
||||
\end{itemize}%blah
|
||||
|
||||
%4 insert commentary/rationale inside itemized list
|
||||
\LMHash{}
|
||||
Let $d$ be the declaration of a static or instance variable $v$. If $d$ is an instance variable, then the invocation of the implicit getter of $v$ evaluates to the value stored in $v$.
|
||||
If $d$ is a static or library variable then the implicit getter method of $v$ executes as follows:
|
||||
\begin{itemize}
|
||||
\commentary{maybe this will not happen, but it is ok}
|
||||
\item {\bf Non-constant variable declaration with initializer}. If $d$ is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} , \code{\FINAL{} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;}, \code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ then the initializer expression $e$ is evaluated. If, during the evaluation of $e$, the getter for $v$ is invoked, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the getter is $r$.
|
||||
\rationale{but rationale at the end of an item seems to make sense}
|
||||
\item {\bf Constant variable declaration}. If $d$ is of one of the forms \code{\CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; }, \code{\STATIC{} \CONST{} $v$ = $e$; } or \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. \commentary{Note that a compile time constant cannot depend on itself, so no cyclic references can occur.}
|
||||
Otherwise
|
||||
\item {\bf Variable declaration without initializer}. The result of executing the getter method is the value stored in $v$.
|
||||
\end{itemize}
|
||||
\rationale{and we can of course have it immediately after the list}
|
||||
|
||||
%5 add line breaks in items, with/without indentation
|
||||
\LMHash{}
|
||||
Let $d$ be the declaration of a static or instance variable $v$. If $d$ is an instance variable, then the invocation of the implicit getter of $v$ evaluates to the value stored in $v$.
|
||||
If $d$ is a static or library variable then the implicit getter method of $v$ executes as follows:
|
||||
\begin{itemize}
|
||||
\item {\bf Non-constant variable declaration with initializer}. If $d$
|
||||
is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} ,
|
||||
\code{\FINAL{} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;},
|
||||
\code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; },
|
||||
\code{\STATIC{} \FINAL{} $v$ = $e$; } or
|
||||
\code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored
|
||||
into $v$ then the initializer expression $e$ is evaluated. If, during
|
||||
the evaluation of $e$, the getter for $v$ is invoked, a
|
||||
\code{CyclicInitializationError} is thrown. If the evaluation succeeded
|
||||
yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In
|
||||
any case, $r$ is stored into $v$. The result of executing the getter
|
||||
is $r$.
|
||||
\item {\bf Constant variable declaration}. If $d$ is of one of the
|
||||
forms \code{\CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; },
|
||||
\code{\STATIC{} \CONST{} $v$ = $e$; } or
|
||||
\code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the
|
||||
value of the compile time constant $e$.
|
||||
\commentary{Note that a compile time constant cannot depend on
|
||||
itself, so no cyclic references can occur.}
|
||||
Otherwise
|
||||
\item {\bf Variable declaration without initializer}. The result of
|
||||
executing the getter method is the value stored in $v$.
|
||||
\end{itemize}
|
||||
|
||||
%6 add line breaks, then "eliminate" them with comments
|
||||
\LMHash{}
|
||||
Let $d$ be the declaration of a static or instance%
|
||||
variable $v$. If $d$ is an instance variable, then the %
|
||||
invocation of the implicit getter of $v$ evaluates to%
|
||||
the value stored in $v$.
|
||||
If $d$ is a static or library variable then the implicit %
|
||||
getter method of $v$ executes as follows: %
|
||||
|
||||
\begin{itemize}
|
||||
\item {\bf Non-constant variable declaration with initializer}. If $d$ is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} , \code{\FINAL{} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;}, \code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ then the initializer expression $e$ is evaluated. If, during the evaluation of $e$, the getter for $v$ is invoked, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the getter is $r$. %
|
||||
|
||||
\item {\bf Constant variable declaration}. If $d$ is of one of the%
|
||||
forms \code{\CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; }, %
|
||||
\code{\STATIC{} \CONST{} $v$ = $e$; } or%
|
||||
\code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. \commentary{Note that a compile time constant cannot depend on itself, so no cyclic references can occur.}
|
||||
Otherwise
|
||||
\item {\bf Variable declaration without initializer}. The result of executing the getter method is the value stored in $v$.
|
||||
\end{itemize}
|
||||
|
||||
%7 eliminate line break before environment and before \item
|
||||
\LMHash{}
|
||||
Let $d$ be the declaration of a static or instance variable $v$. If $d$ is an instance variable, then the invocation of the implicit getter of $v$ evaluates to the value stored in $v$.
|
||||
If $d$ is a static or library variable then the implicit getter method of $v$ executes as follows: \begin{itemize}
|
||||
\item {\bf Non-constant variable declaration with initializer}. If $d$ is of one of the forms \code{\VAR{} $v$ = $e$;} , \code{$T$ $v$ = $e$;} , \code{\FINAL{} $v$ = $e$;} , \code{\FINAL{} $T$ $v$ = $e$;}, \code{\STATIC{} $v$ = $e$; }, \code{\STATIC{} $T$ $v$ = $e$; }, \code{\STATIC{} \FINAL{} $v$ = $e$; } or \code{\STATIC{} \FINAL{} $T$ $v$ = $e$;} and no value has yet been stored into $v$ then the initializer expression $e$ is evaluated. If, during the evaluation of $e$, the getter for $v$ is invoked, a \code{CyclicInitializationError} is thrown. If the evaluation succeeded yielding an object $o$, let $r = o$, otherwise let $r = \NULL{}$. In any case, $r$ is stored into $v$. The result of executing the getter is $r$. \item {\bf Constant variable declaration}. If $d$ is of one of the forms \code{\CONST{} $v$ = $e$; } , \code{\CONST{} $T$ $v$ = $e$; }, \code{\STATIC{} \CONST{} $v$ = $e$; } or \code{\STATIC{} \CONST{} $T$ $v$ = $e$;} the result of the getter is the value of the compile time constant $e$. \commentary{Note that a compile time constant cannot depend on itself, so no cyclic references can occur.}
|
||||
Otherwise%
|
||||
\item {\bf Variable declaration without initializer}. The result of executing the getter method is the value stored in $v$.
|
||||
\end{itemize}
|
||||
|
||||
% Test multiple commentary/rationale blocks in succession -------------
|
||||
|
||||
%0 original
|
||||
\LMHash{}
|
||||
The run time type of a function object always implements the class \cd{Function}.
|
||||
|
||||
\commentary{
|
||||
One cannot assume, based on the above, that given a function \cd{f}, \cd{f.runtimeType} will actually be \cd{Function}, or that any two distinct function objects necessarily have the same runtime type.
|
||||
}
|
||||
|
||||
\rationale{
|
||||
It is up to the implementation to choose an appropriate representation for functions.
|
||||
For example, consider that a closure produced via property extraction treats equality different from ordinary closures, and is therefore likely a different class. Implementations may also use different classes for functions based on arity and or type. Arity may be implicitly affected by whether a function is an instance method (with an implicit receiver parameter) or not. The variations are manifold, and so this specification only guarantees that function objects are instances of some class that is considered to implement \cd{Function}.
|
||||
|
||||
}
|
||||
|
||||
%1 remove commentary/first
|
||||
\LMHash{}
|
||||
The run time type of a function object always implements the class \cd{Function}.
|
||||
|
||||
\rationale{
|
||||
It is up to the implementation to choose an appropriate representation for functions.
|
||||
For example, consider that a closure produced via property extraction treats equality different from ordinary closures, and is therefore likely a different class. Implementations may also use different classes for functions based on arity and or type. Arity may be implicitly affected by whether a function is an instance method (with an implicit receiver parameter) or not. The variations are manifold, and so this specification only guarantees that function objects are instances of some class that is considered to implement \cd{Function}.
|
||||
|
||||
}
|
||||
|
||||
%2 remove rationale second
|
||||
\LMHash{}
|
||||
The run time type of a function object always implements the class \cd{Function}.
|
||||
|
||||
\commentary{
|
||||
One cannot assume, based on the above, that given a function \cd{f}, \cd{f.runtimeType} will actually be \cd{Function}, or that any two distinct function objects necessarily have the same runtime type.
|
||||
}
|
||||
|
||||
%3 remove both
|
||||
\LMHash{}
|
||||
The run time type of a function object always implements the class \cd{Function}.
|
||||
|
||||
%4 make first in paragraph, even with \par (double newline)
|
||||
\LMHash{}
|
||||
\commentary{
|
||||
One cannot assume, based on the above, that given a function \cd{f}, \cd{f.runtimeType} will actually be \cd{Function}, or that any two distinct function objects necessarily have the same runtime type.
|
||||
}
|
||||
|
||||
\rationale{
|
||||
It is up to the implementation to choose an appropriate representation for functions.
|
||||
For example, consider that a closure produced via property extraction treats equality different from ordinary closures, and is therefore likely a different class. Implementations may also use different classes for functions based on arity and or type. Arity may be implicitly affected by whether a function is an instance method (with an implicit receiver parameter) or not. The variations are manifold, and so this specification only guarantees that function objects are instances of some class that is considered to implement \cd{Function}.
|
||||
|
||||
}
|
||||
|
||||
The run time type of a function object always implements the class \cd{Function}.
|
||||
|
||||
%5 insert misleading 'dartCode' comments
|
||||
\LMHash{}
|
||||
The run time type of a function object always implements the class \cd{Function}.
|
||||
|
||||
\commentary{
|
||||
One cannot assume, based on the above, that given a function \cd{f}, \cd{f.runt
|
||||
imeType} will actually be \cd{Function}, or that any two distinct function objec
|
||||
%\begin{dartCode}
|
||||
ts necessarily have the same runtime type.
|
||||
}
|
||||
|
||||
\rationale{
|
||||
It is up to the implementation to choose an appropriate representation for functions.
|
||||
%\end{dartCode}
|
||||
For example, consider that a closure produced via property extraction treats equality different from ordinary closures, and is therefore likely a different class. Implementations may also use different classes for functions based on arity and or type. Arity may be implicitly affected by whether a function is an instance method (with an implicit receiver parameter) or not. The variations are manifold, and so this specification only guarantees that function objects are instances of some class that is considered to implement \cd{Function}.
|
||||
|
||||
}
|
||||
|
||||
%6 remove empty lines between normative and non-normative text
|
||||
\LMHash{}
|
||||
The run time type of a function object always implements the class \cd{Function}.
|
||||
\commentary{
|
||||
One cannot assume, based on the above, that given a function \cd{f}, \cd{f.runtimeType} will actually be \cd{Function}, or that any two distinct function objects necessarily have the same runtime type.
|
||||
}
|
||||
\rationale{
|
||||
It is up to the implementation to choose an appropriate representation for functions.
|
||||
For example, consider that a closure produced via property extraction treats equality different from ordinary closures, and is therefore likely a different class. Implementations may also use different classes for functions based on arity and or type. Arity may be implicitly affected by whether a function is an instance method (with an implicit receiver parameter) or not. The variations are manifold, and so this specification only guarantees that function objects are instances of some class that is considered to implement \cd{Function}.
|
||||
|
||||
}
|
||||
|
||||
%7 remove white space between normative and non-normative text
|
||||
\LMHash{}
|
||||
The run time type of a function object always implements the class \cd{Function}.\commentary{
|
||||
One cannot assume, based on the above, that given a function \cd{f}, \cd{f.runtimeType} will actually be \cd{Function}, or that any two distinct function objects necessarily have the same runtime type.
|
||||
}\rationale{
|
||||
It is up to the implementation to choose an appropriate representation for functions.
|
||||
For example, consider that a closure produced via property extraction treats equality different from ordinary closures, and is therefore likely a different class. Implementations may also use different classes for functions based on arity and or type. Arity may be implicitly affected by whether a function is an instance method (with an implicit receiver parameter) or not. The variations are manifold, and so this specification only guarantees that function objects are instances of some class that is considered to implement \cd{Function}.}
|
||||
|
||||
% Test structure command (\section) with leading white space ----------
|
||||
|
||||
\subsection{ Equality}
|
||||
\LMLabel{equality}
|
||||
|
||||
The subsection should end the hashing block, so these words should
|
||||
not affect the previous hash value.
|
||||
|
||||
% ---------------------------------------------------------------------
|
||||
|
||||
\end{document}
|
35
tests/standalone/io/ansi_supported_test.dart
Normal file
35
tests/standalone/io/ansi_supported_test.dart
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) 2017, 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.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
testStdout(Stdout s) {
|
||||
try {
|
||||
s.supportsAnsiEscapes;
|
||||
} catch (e, st) {
|
||||
Expect.fail("$s.supportsAnsiEscapes threw: $e\n$st\n");
|
||||
}
|
||||
Expect.isNotNull(s.supportsAnsiEscapes);
|
||||
Expect.isTrue(s.supportsAnsiEscapes is bool);
|
||||
if (s.supportsAnsiEscapes) {
|
||||
s.writeln('\x1b[31mThis text has a red foreground using SGR.31.');
|
||||
s.writeln('\x1b[39mThis text has restored the foreground color.');
|
||||
} else {
|
||||
s.writeln('ANSI escape codes are not supported on this platform');
|
||||
}
|
||||
}
|
||||
|
||||
main() {
|
||||
testStdout(stdout);
|
||||
testStdout(stderr);
|
||||
try {
|
||||
stdin.supportsAnsiEscapes;
|
||||
} catch (e, st) {
|
||||
Expect.fail("stdin.supportsAnsiEscapes threw: $e\n$st\n");
|
||||
}
|
||||
Expect.isNotNull(stdin.supportsAnsiEscapes);
|
||||
Expect.isTrue(stdin.supportsAnsiEscapes is bool);
|
||||
}
|
17
tests/standalone/io/arguments_test.dart
Normal file
17
tests/standalone/io/arguments_test.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// DartOptions=10 arguments_test 20
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
main(List<String> args) {
|
||||
// Basic test for functionality.
|
||||
Expect.equals(3, args.length);
|
||||
Expect.equals(10, int.parse(args[0]));
|
||||
Expect.equals("arguments_test", args[1]);
|
||||
Expect.equals(20, int.parse(args[2]));
|
||||
// Cannot add an additional argument.
|
||||
Expect.throwsUnsupportedError(() => args.add("Fourth"));
|
||||
}
|
47
tests/standalone/io/async_catch_errors_test.dart
Normal file
47
tests/standalone/io/async_catch_errors_test.dart
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
var events = [];
|
||||
|
||||
Future testSocketException() {
|
||||
var completer = new Completer();
|
||||
runZoned(() {
|
||||
Socket.connect("4", 1).then((Socket s) {
|
||||
Expect.fail("Socket should not be able to connect");
|
||||
});
|
||||
}, onError: (err) {
|
||||
if (err is! SocketException) Expect.fail("Not expected error: $err");
|
||||
completer.complete("socket test, ok.");
|
||||
events.add("SocketException");
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future testFileSystemException() {
|
||||
var completer = new Completer();
|
||||
runZoned(() {
|
||||
new File("lol it's not a file\n").openRead().listen(null);
|
||||
}, onError: (err) {
|
||||
if (err is! FileSystemException) Expect.fail("Not expected error: $err");
|
||||
completer.complete("file test, ok.");
|
||||
events.add("FileSystemException");
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
main() {
|
||||
// We keep a ReceivePort open until all tests are done. This way the VM will
|
||||
// hang if the callbacks are not invoked and the test will time out.
|
||||
asyncStart();
|
||||
testSocketException().then((_) => testFileSystemException()).then((_) {
|
||||
asyncEnd();
|
||||
Expect.listEquals(["SocketException", "FileSystemException"], events);
|
||||
});
|
||||
}
|
64
tests/standalone/io/bytes_builder_test.dart
Normal file
64
tests/standalone/io/bytes_builder_test.dart
Normal file
|
@ -0,0 +1,64 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
|
||||
import "dart:io";
|
||||
import "dart:typed_data";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
main() {
|
||||
for (var copying in [true, false]) {
|
||||
var b;
|
||||
testLength(n) {
|
||||
Expect.equals(n, b.length);
|
||||
if (n == 0) {
|
||||
Expect.isTrue(b.isEmpty, "isEmpty: #${b.length}");
|
||||
Expect.isFalse(b.isNotEmpty, "isNotEmpty: #${b.length}");
|
||||
} else {
|
||||
Expect.isTrue(b.isNotEmpty, "isNotEmpty: #${b.length}");
|
||||
Expect.isFalse(b.isEmpty, "isEmpty: #${b.length}");
|
||||
}
|
||||
}
|
||||
|
||||
b = new BytesBuilder(copy: copying);
|
||||
testLength(0);
|
||||
|
||||
b.addByte(0);
|
||||
testLength(1);
|
||||
|
||||
b.add([1, 2, 3]);
|
||||
testLength(4);
|
||||
|
||||
b.add(<int>[4, 5, 6]);
|
||||
testLength(7);
|
||||
|
||||
b.add(new Uint8List.fromList([7, 8, 9]));
|
||||
testLength(10);
|
||||
|
||||
b.add(new Uint16List.fromList([10, 11, 12]));
|
||||
testLength(13);
|
||||
|
||||
var bytes = b.toBytes();
|
||||
Expect.isTrue(bytes is Uint8List);
|
||||
Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], bytes);
|
||||
testLength(13);
|
||||
|
||||
b.add("\x0d\x0e\x0f".codeUnits);
|
||||
testLength(16);
|
||||
|
||||
bytes = b.takeBytes();
|
||||
testLength(0);
|
||||
Expect.isTrue(bytes is Uint8List);
|
||||
Expect.listEquals(
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], bytes);
|
||||
|
||||
b.addByte(0);
|
||||
testLength(1);
|
||||
|
||||
b.clear();
|
||||
testLength(0);
|
||||
|
||||
b.addByte(0);
|
||||
testLength(1);
|
||||
}
|
||||
}
|
70
tests/standalone/io/certificates/README
Normal file
70
tests/standalone/io/certificates/README
Normal file
|
@ -0,0 +1,70 @@
|
|||
This directory, tests/standalone/io/certificates, contains the
|
||||
X509 TLS certificates and private keys needed to run tests of Dart's
|
||||
secure networking code. The SecureSocket and SecureServer classes
|
||||
are tested by making TLS (formerly called SSL) connections, secured
|
||||
by certificates from a self-signed test root authority.
|
||||
|
||||
The certificates are created by running ../create_sample_certificates.sh
|
||||
in a bash or sh shell, with the openssl tools installed. Run the script
|
||||
twice to create the untrusted_* files.
|
||||
|
||||
PEM files:
|
||||
|
||||
server_chain.pem:
|
||||
Contains the chain of certificates, from the self-signed
|
||||
test certificate authority, through the intermediate CA, to the server
|
||||
certificate, used on the server side of a test connection.
|
||||
|
||||
server_key.pem:
|
||||
Contains the private key for the server certificate
|
||||
|
||||
trusted_certs.pem:
|
||||
Contains the self-signed certificate of the test certificate authority.
|
||||
This certificate is set as "trusted" by the client side of the connection
|
||||
in its SecurityContext object, so that a verified TLS connection to the
|
||||
server can be made.
|
||||
|
||||
untrusted_server_chain.pem:
|
||||
Contains a chain of certificates, from a different self-signed
|
||||
test certificate authority, through an intermediate CA, to a server
|
||||
certificate, used on the server side of a test connection that is intended
|
||||
to fail because the client does not accept this certificate authority
|
||||
|
||||
untrusted_server_key.pem:
|
||||
Contains the private key for the untrusted server certificate
|
||||
in untrusted_server_chain.pem
|
||||
|
||||
*_malformed.pem:
|
||||
Truncated PEM formatted certificates used to test error handling.
|
||||
|
||||
PKCS12 files:
|
||||
|
||||
server_key.12:
|
||||
Created with:
|
||||
$ openssl pkcs12 -export -inkey server_key.pem -out server_key.p12 -nocerts
|
||||
with password 'dartdart'
|
||||
|
||||
server_chain.p12:
|
||||
Created with:
|
||||
$ openssl pkcs12 -export -in server_chain.pem -out server_chain.p12 -nokeys
|
||||
with password 'dartdart'
|
||||
|
||||
client1_key.p12:
|
||||
Created with:
|
||||
$ openssl pkcs12 -export -inkey client1_key.pem -out client1_key.p12 -nocerts
|
||||
with password 'dartdart'
|
||||
|
||||
client1.p12:
|
||||
Created with:
|
||||
$ openssl pkcs12 -export -in client1.pem -out client1.p12 -nokeys
|
||||
with password 'dartdart'
|
||||
|
||||
trusted_certs.p12:
|
||||
Created with:
|
||||
$ openssl pkcs12 -export -in trusted_certs.pem -out trusted_certs.p12 -nokeys
|
||||
with password 'dartdart'
|
||||
|
||||
client_authority.p12:
|
||||
Created with:
|
||||
$ openssl pkcs12 -export -in client_authority.pem -out client_authority.p12 -nokeys
|
||||
with password 'dartdart'
|
58
tests/standalone/io/certificates/bad_server_chain.pem
Normal file
58
tests/standalone/io/certificates/bad_server_chain.pem
Normal file
|
@ -0,0 +1,58 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDJzCCAg+gAwIBAgIBATANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVpbnRl
|
||||
cm1lZGlhdGVhdXRob3JpdHkwHhcNMTgwNDIzMjAxNjM0WhcNMjgwNDIwMjAxNjM0
|
||||
WjAXMRUwEwYDVQQDDAxiYWRsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IB
|
||||
DwAwggEKAoIBAQC6gVBNsFLEkomxJ1VRe5rZ1ELduRLHJKio9zTrh+o/6EaCZ4X6
|
||||
EIr3CwVx7UiBDRyCApGZXbqvtNbP/ihbjRvxmlvCSL9ztF9tNrLqsaEq4w5KvQDT
|
||||
5u27+pAzdLjjoFTK6VZfw+AhEZHxiokEDDYB3t6gWkfabOstDouLyEYL25RLKaGQ
|
||||
v/Qb7XU6K4f20OnuXVoQ4FxNdqtvm7TgmXBT0kp+f62q6BvLUIzewpblBlgT5h3h
|
||||
KAZF7RDpGBxRgYxA6ZH4n3mv4kh84YtTODRGfb8ugdaQjrgTWOhQ4nddcdR5TVww
|
||||
A8Jp+G000RQ97Go0zgd29CicKF96zbGdKFkZAgMBAAGjdTBzMAwGA1UdEwEB/wQC
|
||||
MAAwHQYDVR0OBBYEFG8s5yvy1kAoNjJ5PYrx9RNSPFJXMB8GA1UdIwQYMBaAFCpT
|
||||
tHybjDJ/Jz25uI9Bxikc1muYMA4GA1UdDwEB/wQEAwIDqDATBgNVHSUEDDAKBggr
|
||||
BgEFBQcDATANBgkqhkiG9w0BAQsFAAOCAQEAgom55wfxp9ywWKZOzaGCa+uXZjPK
|
||||
rmdUcnJLduRdnchuIsQUZa3Ijpzn7Dw+UZV8ggxvU0L07PbT0QlZUoKhDj6BlZ4W
|
||||
TAseBh5QyBUeEdMU+Tr2fXGM6+mmVURBLTX5I2Chmnw2ymqqUK8MtbUhPXbfZayV
|
||||
eUV35iloOhm3q/5rKBtfdNq31zrg+Naam6/UyRgBhinweFFXiYeZRpctD3w3cA3g
|
||||
RGjuNNNRASZZzAXGiE4IOv9drd0/wGajwBT1DJDQOAxZPfADC3wEcDRG4ve1SYHY
|
||||
5N3AlidXe8dPDePhlxH3JH9s2WPi6lgiHQSmtzyeehbzqpJ9JCBM5BerdQ==
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDLjCCAhagAwIBAgIBAjANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1yb290
|
||||
YXV0aG9yaXR5MB4XDTE4MDQyMzIwMTYzM1oXDTI4MDQyMDIwMTYzM1owIDEeMBwG
|
||||
A1UEAwwVaW50ZXJtZWRpYXRlYXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOC
|
||||
AQ8AMIIBCgKCAQEAsSFr3/sYhGFF7gEZSn7Am8ATtPhTo5ypQqSAv/4Uy+k4zvT3
|
||||
b3OZyYpzr5Wsa6NXcEKwNipyR1GBpYwaYI/W4DSi+COdH4DQSZDQFr+hvmXRazzj
|
||||
VSsOxF6veGLcza53meLPRb4o4yVoZARd6xR5i3OUD4kezvOjpmlFT3OKNU0Di+Vq
|
||||
qeS14/at6Vt6G0rS8CluafD7Z0/5zp6vrImKwC6OWzlmmcAqBGsE/BTzrAxLdt4K
|
||||
uw3Xs3uvS3YZIAC536C1Mop1n4FBUGxeUMWH+I/llzK9ol1pmQHJrxfOD5WdFuuE
|
||||
iFfpiOmBdUfDBbEPllmIvzUBFOo5VhxVmq8EHQIDAQABo3sweTASBgNVHRMBAf8E
|
||||
CDAGAQH/AgEAMB0GA1UdDgQWBBQqU7R8m4wyfyc9ubiPQcYpHNZrmDAfBgNVHSME
|
||||
GDAWgBT0rD9lRUhqJvAg7hfBEz/ZqHCzHjAOBgNVHQ8BAf8EBAMCAgQwEwYDVR0l
|
||||
BAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQELBQADggEBAGjRSFvVeIrRF3iuA5vr
|
||||
SgufTCNzAyEz7+pDKflzHSQXF1fdItiOdPGv1i57gIr7HaYuxvBiEklhmnWreYye
|
||||
Tn6ghfhEHhdZHBpihDXuIvLizhtR/lg9CDZrHjuY6nukyx4JnWwUBR3TulPK5gJu
|
||||
jB9YISY8tjXrvVNqdi0a+G0T4HHnVs3v6Nd/Qdsxfp4maAB1U3HFmR3DXKTxDtBK
|
||||
mNNMqf9PpX4lw4o6UieiEwOMd+4REhmwLNTwhWrhVg5q6GKQl873Ge/7J2nXvgkH
|
||||
nUbEsncLsArqqrz201f2m32A6pinwY/j85vEeRkHwlsU0jOvVnHzAlggP0u/kFAF
|
||||
EjE=
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIC/jCCAeagAwIBAgIBATANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1yb290
|
||||
YXV0aG9yaXR5MB4XDTE4MDQyMzIwMTYzM1oXDTI4MDQyMDIwMTYzM1owGDEWMBQG
|
||||
A1UEAwwNcm9vdGF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
||||
ggEBALkvRWdbx9GwxePkh0nnpht4MrPW5NkZBORqfhFi7PFbQ7Rwgl39hm9iAmci
|
||||
pOWZGSJi7AaqLuSID0UEeRdG/fNFawI5XIoxP+TmdKdrk/SaTJQKKJiZ9B8+EG0z
|
||||
hV8/v6jrlwj0gq9eBBAmOInnmQiEYE4gKFNvh9xdP//gi+otBf30gmtJ4AxXOTu/
|
||||
M+XEigXelmIvy57b+B+qnonTFcGkXhSr+JfCA1l6ta7OtknQtItpV0FDr/d8hA+6
|
||||
Bn25ZSisd00GC3CUMX1tM5V8cQE6GO/W2mnpUFVvWycYx9wDyU7rlyNUf8nWeoIW
|
||||
3d3s/6KAppa07KrkLiTantIrqMUCAwEAAaNTMFEwHQYDVR0OBBYEFPSsP2VFSGom
|
||||
8CDuF8ETP9mocLMeMB8GA1UdIwQYMBaAFPSsP2VFSGom8CDuF8ETP9mocLMeMA8G
|
||||
A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAJ1VynTevPnNtwevQpUa
|
||||
zlur64N+Dx/yF4gvd4byjO+JouMJLaJqV2dwnqgAahg6YKasVtv4xX9MVJR2IjIb
|
||||
Tfa0nYQxM5clwk3J78nh82Ncb2RNeYJyNmSdocnOkmTSoOGUFOxtRz1vmKUcrfwl
|
||||
yENO/qGe/sYmOv0IWJjeGQ2OZPblRumV4dJy3qTHFmOLpYwA0BGiIV5uj5Ou7QU1
|
||||
R5PY2pnJg4RXeaq95Pr50lkO9vpRyFUJHjR+P+J05M9FbjLPOQIFkpMYx/GyBg5n
|
||||
P+omyagOGW8bXfBTtUYu+rP/k+BC5AxI3Kdv/AD5vyHKi/JXhP3ycb8AYx5ENHoK
|
||||
qjA=
|
||||
-----END CERTIFICATE-----
|
29
tests/standalone/io/certificates/bad_server_key.pem
Normal file
29
tests/standalone/io/certificates/bad_server_key.pem
Normal file
|
@ -0,0 +1,29 @@
|
|||
-----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
MIIE4zAcBgoqhkiG9w0BDAEBMA4ECPLRqWLveTDuAgIIAASCBMGjMwpu3Hy4cuO7
|
||||
i3p2EyH+UJGm9J/KcRN2ys6E5rwCdLHtURLmdWsmtNkDNTvmgdllXfdVhO9XavRJ
|
||||
ShBSvTzvOokpl/nxRaFmhEhMWskdGpP1WSp+GtQiVHM2gczDR2jNZDZKWEnZfU5B
|
||||
CUt0VJkokJZxmdeSpFIrTTJxcOQZEsbb1ujrAMpWqEvIGq+U2Is7A5RxWJl1XKmY
|
||||
5QB9nfw5Olj0J499kMKJx8WjRhmfQHu+qMpN2HglBVK44fnk/I5ilNdhuScuaKPZ
|
||||
csOv5D5Ojlgc6hQG1zCPh8lRNH1MXLd2BMwEJqPSKNbvfrUWvr7BnJMoOdnlZwaH
|
||||
73/zJrMwuUpZzAm2sgHZlJhELoYyK0A40IhAz4u9XF1iv35yK2D6/O2qJO6VUzqD
|
||||
TsdSnUYaUTZkZdgfucR+EbmPSw7r+QYEsHFzErPTUR64hwIeC3bCv0Q4hrPskxKj
|
||||
135iDQDbuCykeNe8s51qgEt8oawdig/Anaguksuj/eKGTWZXPrhA3LTYqBkaX8ao
|
||||
XFWkj3ALvjRHCeLfQ5AlXyd3mJiHl93pxH9GIaTiL66ptYvfcN5tERcD6GL/sUXh
|
||||
vJ0kr8HsBS9WTFvVg4dzQ9NAqtRoDB1IUqEq2dLys/gjrhE26tmUnuaXiOuokSWx
|
||||
HXEK/2pWAqZ/ZA7vbQ/DyV25TDeEP3SRKeTDLdlWBjTNUKyBv3nfsoZBK1K2wOUh
|
||||
UDmB3TMBEdXI6L2FvjxMuDRJxruhn7HhRz7ifsizRHPyaPDbUFF9IK/x9qPAzufK
|
||||
lk6NqqcgJdNg8wxv/dVYAHeJmMOhTau9CL6N7AYo2VDWphlZSjBgtTZw7sY739c2
|
||||
35ziR9yBoJyveFcQko01ycJrjhivn3cqbFXZfsIbecDKz+8qZhWjKw/yysv0X6tI
|
||||
tB1btpWtlVB8h7WlXWgUGJWKCUFXRC1fCJA5W7LoTnvZ9VvYMBRKUbDsMiSWNcTZ
|
||||
mLmJj0yIhve9uCHsFXBidTCT751CYucaZYvOqNr3pKf4eTQQNCYB5Pt6jx4V7Xks
|
||||
ZDjr5ljVy6Ux6NweQT2Zs/hOnuS3q1XoLbRVsW9d9YttahnNyjP8il3HphSzBHOF
|
||||
SUReTlgAHEbSUZTZ1z2GXFblUJPb2syfJOIXP5qHQtSrGN3CkQ//JvysxlOck41h
|
||||
fLO6TZUadorgEHqb+en6h6gVvDvI3i0T66yWwurhlEvWZepAWetzSv64VsVGXEjc
|
||||
lrT8yj6AAZYISoYZU0vtM0tP+FDqvyA597DZMiDDBU6chmGxWhcnaqIIDTP2KQIJ
|
||||
Z0NAYp924NHAgnTq1FbXxllej6vxcCwymsnXGyCMhsOt1RTAVHeY0uZ5qPCToJ30
|
||||
xS/WTrVH5z0xtp2Qz+INFleNnseYKBJvEDfk+gK0sLm533fehnFeB+GgNqqV9hKc
|
||||
bLpU+C3VrsxX0JLWYgfweVDT+jT78FXzUIkWykvBGv+iv+ztFUFiopDzJzfLriH8
|
||||
K4kG2o/K3MQWrygjnt+iTjpBe08auX9Ot8X65ygArOa0zOy0nUwSQGyPXL/7L3dQ
|
||||
LqS6ZBpreqXClTeegKH8SwEYnXLFNDuU1GuD+pRyQJVWYfqiiWeenaKpCi73VWaK
|
||||
J+9e86VqcQ==
|
||||
-----END ENCRYPTED PRIVATE KEY-----
|
BIN
tests/standalone/io/certificates/client1.p12
Normal file
BIN
tests/standalone/io/certificates/client1.p12
Normal file
Binary file not shown.
19
tests/standalone/io/certificates/client1.pem
Normal file
19
tests/standalone/io/certificates/client1.pem
Normal file
|
@ -0,0 +1,19 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDBzCCAe+gAwIBAgIBAjANBgkqhkiG9w0BAQsFADAaMRgwFgYDVQQDDA9jbGll
|
||||
bnRhdXRob3JpdHkwHhcNMTgwNDIzMjAxNjM0WhcNMjgwNDIwMjAxNjM0WjAQMQ4w
|
||||
DAYDVQQDDAV1c2VyMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJ0k
|
||||
FC9D1LDt0as0Kk3EbMKR9IXBtKazVOXq1y3VYmSM+r8l70HViKZOQ13vWHBt+iYI
|
||||
2ATt+lFfKrAo2xO74d7bJD6ag12Ar60mpfVWO1lrmbSzGGsfJZl1kI7Z9SJ4RQCp
|
||||
xqAKu+ZtIY40fO7YqRFT+yPjjdcsNOYHedATa4coq1ZHnFbU4HZgerFIeMCHr2Mb
|
||||
MPuqraJuk4G7yJgPWMwNawKKfWWiH4aRNGgmVqInVTh6hLLFC2po0koF8h4fyVz9
|
||||
BmptVyn7+/V5OOWteiaaNanRlSc9ozljSxVnqSUD9JuaIINd4+0Lf5Yp2hcPj54l
|
||||
Mt8q51euv2JGzk5NLOcCAwEAAaNiMGAwCQYDVR0TBAIwADAdBgNVHQ4EFgQUZOyE
|
||||
+fTDi2XHfAg9q9Ci4B3/PKIwHwYDVR0jBBgwFoAU+TlPoMTEPn2GHUDuD49Nm+iq
|
||||
vwwwEwYDVR0lBAwwCgYIKwYBBQUHAwIwDQYJKoZIhvcNAQELBQADggEBAADdlG1z
|
||||
kHKAI4HQojtx8yWM/D5q48/5wQjmsx6oBfaWPobL1mkc0iPQ6GNARY1Mv8OPbGkk
|
||||
8M00qVikaUyA3K14mZBzNY1Pprr06JRlDuYZABU7Jcfd6pe1LAfM0GMlng5KbHlK
|
||||
NqsECNQNIihEECdJ9UxEl191aAf4hnfvnL+RRaalCCeM9LZY+CTCuG1RH61H8Dxl
|
||||
Fq615+4DP7bKHUf2FiYVcqu9MqLCw6YasrCNFcBQuZuzO/3HUyBWHOQ2jb5w5uID
|
||||
cDsV5rGtQjc0DNc7v34lHYsfP8BWRF+z/VE865wgupQ3f5OTTHPBeMy1bO0t5rU6
|
||||
iDdImoz2KZ3ZwDc=
|
||||
-----END CERTIFICATE-----
|
BIN
tests/standalone/io/certificates/client1_key.p12
Normal file
BIN
tests/standalone/io/certificates/client1_key.p12
Normal file
Binary file not shown.
29
tests/standalone/io/certificates/client1_key.pem
Normal file
29
tests/standalone/io/certificates/client1_key.pem
Normal file
|
@ -0,0 +1,29 @@
|
|||
-----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
MIIE5DAcBgoqhkiG9w0BDAEBMA4ECDBZgjf6kratAgIIAASCBML/IWUC3eylBatQ
|
||||
SawxuYM81Ak+LnjidlC+/3APnYNFdppoUbZu8WK9Nj/SPQBXnpuGpVuUWWaIkjzI
|
||||
d3tivlboh17M6TBSBiI6wopmi4uO7k+BKTCH0chdqKM8OjJajpeGOfejW7Jojnr8
|
||||
Yx8G3IYO5DWWXSU7kp4w5WwN93vvRZh4pmLwOIFLwdGVNooBu1FRBaguPFQoWgO+
|
||||
JFbT3qDYvpttdsgtOalqpudHcQteapgQkUfKwk+unB+dgxS3sTTY+Zy9ClnArd0d
|
||||
1wlgOm34jgDxxWIdfaa/l/hcz82F45HeA/jwvP7/EXTni3hkDT92vTMHJQPKguhL
|
||||
V+be+XNnGihNT3k6fXpHAr6Y+HXN+4nqd/ndKRkfzVeZkNMzjFgeWy/LQ1bruMSP
|
||||
Cz/RdpatxH/fRvazCXe160YIB25cwFMUvt4saiN3SvHETxC02SsA6hY1TZB2UOmO
|
||||
/PjyXiXB6nyHchwEbTkzwnHKJSDX5FlAvweOkJ9PhKZIgfXRG/5orqXWqczUV+Vk
|
||||
FyC4338kCtY8sGYlbBvusNqugkbOEMaKUtJd4R2vvXUUbcybrAmjHg10To1uHAxw
|
||||
2xE/gewcvrPTdo4upV4JzyGszJte3MWspv/tyXY/s8F1/ENwatPOZWqMDAa3WSaz
|
||||
dzi8cfQFVo2Pq2b2TtrBE0KPKt1Zw7zIHYcyWnGJaLTzXhFdaw+8jY1+tudnBtzE
|
||||
l84fqwBX/9sAjOdCz1TkIskdpDhWQm33MvTbWluj1FvEQMYgLpLpLIOs1kw8DMNE
|
||||
TH6rrVnMDpdr9bGOPwmxBa/SC6n0EHGczSJ0IyGt5GrjOLGhPgYvETUDCH00GUY7
|
||||
cH+v6S4Lh4Z19aBcDEcW+drU/I+HfoC1qhnqksvNJFeYbEDqTcXD3De2zd6MzMiL
|
||||
qoxaNWshoAYqMbNdZNeCjlJTFq4mU2v+CxLKxUmnoLzkPsrfdniEfTwCg+LoERCk
|
||||
t588o6N8g3JfPDjpTWiH17KEuiKvDYPfheKr3Zu2Zzgd3Rm63l80vINtYffTfKB+
|
||||
U/nuGRzX0bRqWLZlEEnUJxnSYurG7DH7uozCgozbkVqYRE75/wxBDNSeOWSy5HDq
|
||||
0UeRafBOJmGU/7jhNLnKP8YZ5o+XBI3oQMfLb2q3uNbLTc73vqWoFCC7hCUJnKq9
|
||||
z8yD7mETNYTyS1g7uGt2yWmuYinyn+VQkg/f2ExQ36HCjzkoaJyobpNgdzoTF0+q
|
||||
dhzCAfb3C04p/iUIXFQCD1YdZVgwXCmAgxRKbfJaW6B1FFHe3PYzac5RQtvLJQ0q
|
||||
u8sUFlkhr/ax5wUXhILXnvH0S7QtEcGTRJawna7TBZWk4kvTlU0N0DcLU+LKUmws
|
||||
3seuvYROHZ6VSrGikL5IMVZl+h47Ub4HMTvdWAiaSMchl3fxVFW5kGJcAMvoI9ZO
|
||||
ENIWeZVgXrz7FPfnfYnLLNXeHC1LM0hYHztkaXuBC4ujupPmy4/oHNmQXx/yufDK
|
||||
wmQEWsFPf/JrwraW6PAX+/FvZ2G97LIDoxB4TjaIdBXKr17YRAOD9PCcqWBtFrHu
|
||||
4HXwSF4tALbDlMryhjMNOOs0jWjl+jx1LtZ+I+USOjX+3G1ZBWgl5Ps29YMJYF5e
|
||||
NRqyXPpLaco=
|
||||
-----END ENCRYPTED PRIVATE KEY-----
|
17
tests/standalone/io/certificates/client1_key_malformed.pem
Normal file
17
tests/standalone/io/certificates/client1_key_malformed.pem
Normal file
|
@ -0,0 +1,17 @@
|
|||
MIIE4jAcBgoqhkiG9w0BDAEBMA4ECF4ZB27y60SWAgIIAASCBMCEL3ZCzfC0q+m+
|
||||
B8gM9jQe1JFRD5reAuwK6+3speBS4KE+wjbcyQq09/5UoQu3Dci1WG1nKLB1u0Bk
|
||||
w9NuRahWCpvVLzz/GQ6Psesixq3V69zD3N6iMl/XQKymQBwGK51xIkeJO+6Skh2d
|
||||
+qoyBHINTlKY9+548Zgqu+Z3mI3pGmdhd7hCiamiffDwCLEqRxbXdZdLpC9GpAP5
|
||||
HOqXHzN2aZbAGHb1GkHVxskSNzAwlEEZhh4Ibe6o7U65hoL9borewT+gj6sQohI5
|
||||
/LHL0P2bVvtRZiwBVPUX8HZWuVYIFb6GEGTTqOofNhNHvHaKUlD8Uxi5/h/Xi8fq
|
||||
xpdkjIn7VXj9e+I3TkfiphDtk0+Q+f+UkuPyuzU1PafinPfRK1J6gk+ZqAQHW/sp
|
||||
g6GVr2r4PkOrBPsA6jmCnQhs2C4MlZyR2p65qjVutdkKU5NgftW+giK9shgglcza
|
||||
38RF8i01THOnD3j+2teM/t/Ziqb2PGWv/bmvhcYqt1aG186Pe3bBCxhh/L7bqNKD
|
||||
q7sxDmaDE2pTkfyvh07udarmBQc5gvfXYqwghbqP/n7wizqjeEJgAwwHyi8LLsFV
|
||||
XreBQ/8Z2gQwXurrh5WD+7KSgvgopW/oVC8a3++8Hmf5Nkj27lACzoDWTG2/Swah
|
||||
O1MmdtPyy/KCbf5ujt2BlXM9D206Rsr6hoO9UZ1s1ohRdJReVGc4NZ4XrVWc4TKT
|
||||
gUAFTaHIKgFe/DgLaQn8L8Pqb8B/JfoSgQ74r69S434Kc+EDKui8wnkgso5bqrr1
|
||||
M07H9Xo+OtG1D6rma2EUlpoU06CAIcyqNx5fHJ3xfk9GHScQi4U6vEDCAQTNTS65
|
||||
I5AOHthZ2kZzfXvP6TF39S5D37NrV7/WJu7ZFaJx3bUGwnS2HYTwjFPABHpVLMwJ
|
||||
nBylVJs+h7bCZdBNCWgTytcn1mYMCvXVmrW8VTwBRjUQsy4rgE2wjpZuIM9rx+gZ
|
||||
HtNvy5t2RlOSqVKapyvV0ll7qbT1lwGIePxjttiWmNbgbwRBQzjv6FZ1Yo331Fl4
|
19
tests/standalone/io/certificates/client2.pem
Normal file
19
tests/standalone/io/certificates/client2.pem
Normal file
|
@ -0,0 +1,19 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDBzCCAe+gAwIBAgIBAzANBgkqhkiG9w0BAQsFADAaMRgwFgYDVQQDDA9jbGll
|
||||
bnRhdXRob3JpdHkwHhcNMTgwNDIzMjAxNjM0WhcNMjgwNDIwMjAxNjM0WjAQMQ4w
|
||||
DAYDVQQDDAV1c2VyMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMBX
|
||||
SxFoCWZxTjBXABqf9ygEicJDLcBEnStDbo+XE7CGDNkf6AmYy9cFpNK3brxfmU3x
|
||||
ZKizie8fLeTMpaEAAR73epPn9Ui3JzP4e12HacLXVIZkDdoOjCcksf1n6CTXSTeC
|
||||
K2h8aO5oqC7ouwUcWbCbdLu+OxohAMg/vmDXvRhJC9uoJyW8hYJwpAuErh/W/DuX
|
||||
LUgAAGNnztth5UWmrD4b9vdhU6yR2t5Gj2DP44Ow5rlurqC0vY87pe+rMal26mF0
|
||||
GLYCzrJOdEwy4WGCuTxXtbqvud9NIV++61cPtOu+GQKwI6/KJ5TEKsLGEbqQViM4
|
||||
rUguOwndm/7HK00nbPECAwEAAaNiMGAwCQYDVR0TBAIwADAdBgNVHQ4EFgQUKpNM
|
||||
YZQHavaPs/m1k7d3a9QbbTQwHwYDVR0jBBgwFoAU+TlPoMTEPn2GHUDuD49Nm+iq
|
||||
vwwwEwYDVR0lBAwwCgYIKwYBBQUHAwIwDQYJKoZIhvcNAQELBQADggEBAJSyKalJ
|
||||
wh1wQvmZ6sa7imzsWwQ70Kr8NgDZFm8Ds1dkfzxsP6lBey8HVY6nDQD2LzJth9ny
|
||||
2AXcHvT9DKRto1cJI5z8/H+E7oKzPAlJjnmhL2dIk6als2KYfBHu5eLyaoWOCvNx
|
||||
wd4wk+JrMIQuVeIQwrG2PPDSUffScb5y5OeW1PvmnAJNTI9bHSIA4/GN45/l3FEW
|
||||
IZuOBfv5DjubYoWT+OJMfSXoqIU/wciyx+SsSPHQ8F8Q6eLgxhF74eqIrIWstZIf
|
||||
bwo83QHOpqXxEkzny4Pbdcis6rGWagH6JXHoiIHcHlsRveMEUGLUJaV0nxN2DgUa
|
||||
Umod67RaTcbdses=
|
||||
-----END CERTIFICATE-----
|
29
tests/standalone/io/certificates/client2_key.pem
Normal file
29
tests/standalone/io/certificates/client2_key.pem
Normal file
|
@ -0,0 +1,29 @@
|
|||
-----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
MIIE5DAcBgoqhkiG9w0BDAEBMA4ECOesX1fugaR0AgIIAASCBMIl6TrcBn0oHRHl
|
||||
X3MSXdAyEMLYBaSVgyRUt1gu0WhyT9uu1xlB1VGu14QHY3uqvTMZpJabSYsafV+P
|
||||
3dbFmk9YHg3Ss0GPaRcx4Q74NR/3BzMIB3q429JSK+GYKHNkRtdMNiQ9OcFVavhD
|
||||
BDApEkavka/A9U5YOB4+/20BPYpfSZT9Z+hLffH6vl6PSsuRzYHdqbbTi44Rff+R
|
||||
m62xzgSxG2+n9J68XPaVxVOLAoNQAlPVfq+lxYF04PdZGz8euJMw2C281Ddpo+sU
|
||||
Jtvbp0JuAa24GNLM5DnmHvRbfQVxlm6dKJi40Gi0g4ellSs0roqUY+RXUC6VqL/R
|
||||
qPWiJhtnvue8zOA6F0C2nFF+Qdtm0UiwEp4TR5jhC5y1+uWzy190mM2fuo0m/7/0
|
||||
6FRv2Oc3tnYXTYg0m8h8QjPGCp3A1TwDlTOoeG81GD4sYvu/kPQH0cKmytwAqMJw
|
||||
LP6OCgOjEFwWxKkYaBVSnr7aP7f/26F8Rf8eGJO0VH2P67F8usweof30bP9eQ9MR
|
||||
rrA9uA0+odpufNMaVbA9Vnj4ipCWR0xqU0Uq+UODVwvI3Vnf1c8gWm9rFCi3hZb5
|
||||
kuxtDpXWlR7SgiRejt1cZmWTWijToF81HkFZf9XoS8jdN26XLlhqy45h9G2N3mVQ
|
||||
jS0uSAjZVk4A1k/HbicOcj92eL1nXK0QFY7OPL9XBSms+KlwAVN15M2tnfQ5mlxC
|
||||
mVAFqho5KQmYipViO/VI5aS/CxVnABSqLxhhj/ge9SQFONjsNDKkaIz7tYtz5KJ+
|
||||
dvJAg2IMcOtV4jZIBrNdfslw0TP17GZwrCUibLzEdPQ02awpemyi1sHquR/B9uoi
|
||||
3CDsPoDABzVp79wsiYz2sEwY23AaKZtMuQRSbR8BtvmMIArgJ273/vfx92skMdjn
|
||||
dpJbxTlNZ/xPo3NSXVTQYxlfeNrGelXvJYT0LxZ4uapMa91gRXRvJsjC3JGu4o+T
|
||||
CeMtclG9uYrSOlbyg4WzVKpwIHTjSCp/CkWCBJIkdxKkScwhDoG3mAcglwMikUEt
|
||||
Eg60+jPBHH3dTOvuaRXvYDVdPG8SPa3txrR1tetKGB6g7eMjYgbmYDOxQESS0j1H
|
||||
cUCIfK+NwKMBRJFy1wjWqZLKhCWrtevAMhpPFa3HWv2fLY0Vf2s6n9W9mr/hA3Tt
|
||||
tPo+c5r7M/I2jzxiHSo1bJD/0yeZDegWrB+8+8PzHoFY05458ei1rc9iNTziogl1
|
||||
DYOOcBlROOitO3VZYjbab0iwX0zqEuSYQy41zVJHbMQFp+rbIpuPWQpNAC3FxZuW
|
||||
iTVchbpHiCHZ+I1Lud3aqN2z3CBC6GLONUoyCvLfmCKoLIbjusZ/xFH9Q7INPOkH
|
||||
g2Sr/bw+8oC+FCujORB2iUmFo5fcgrF1FLxFEbYaB629ed8vE+2aII2OA4amsiD5
|
||||
1RkylPMD4Tv6FOvp4G37ph98vfdQvZeX9OdkqS3rGdbwSCf6+AngomJEJ7uVA/c7
|
||||
Won/1j0eF6JtcRPBo+jFKfdzr6ynu2AoAyKg0Rn/S7HC0YLEB1iPDWpOC39yQp+A
|
||||
x4NNJm1NJjR3oby6LdVp2J8GlKuhztxqkJ6aV9BZDM0rEpP4EdA0QClhXnIJ9H6e
|
||||
7bQ8uhT8sW8=
|
||||
-----END ENCRYPTED PRIVATE KEY-----
|
BIN
tests/standalone/io/certificates/client_authority.p12
Normal file
BIN
tests/standalone/io/certificates/client_authority.p12
Normal file
Binary file not shown.
19
tests/standalone/io/certificates/client_authority.pem
Normal file
19
tests/standalone/io/certificates/client_authority.pem
Normal file
|
@ -0,0 +1,19 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDKjCCAhKgAwIBAgIBATANBgkqhkiG9w0BAQsFADAaMRgwFgYDVQQDDA9jbGll
|
||||
bnRhdXRob3JpdHkwHhcNMTgwNDIzMjAxNjM0WhcNMjgwNDIwMjAxNjM0WjAaMRgw
|
||||
FgYDVQQDDA9jbGllbnRhdXRob3JpdHkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
||||
ggEKAoIBAQDckwmIcOYIRbH1jcuBCC/y1a4aiqXhvUCty59Cdqzlx0gbrhkVGmf0
|
||||
B0Tmo/PW4p9rcl0hwwxGvGoCvsxVpodHQmIxYwwn1sRl2C7Yo2ZHPMYbv9uq+D0d
|
||||
kS8SxHb5l4HvpcT7WoqUq8ZWEm0Losbp8cOcrvLiBQgo8xIOKQzKbwrXydnviQKL
|
||||
E5iBmUswzHwb7ZK84u6dS3iHbl9iPy+QTfiboT6BNMsO/dm6Nqmdj35fOPQgFUN/
|
||||
QR3NsPWL9GtzB9iZc3D7c30FqqqQO/THjaLJIyzdFdF3Fsp+omSuZw/q1d4/R8M3
|
||||
FRCcqzbWLA9Dy12kK/9asmlpf/fdHByVAgMBAAGjezB5MBIGA1UdEwEB/wQIMAYB
|
||||
Af8CAQAwHQYDVR0OBBYEFPk5T6DExD59hh1A7g+PTZvoqr8MMB8GA1UdIwQYMBaA
|
||||
FPk5T6DExD59hh1A7g+PTZvoqr8MMA4GA1UdDwEB/wQEAwICBDATBgNVHSUEDDAK
|
||||
BggrBgEFBQcDAjANBgkqhkiG9w0BAQsFAAOCAQEAh4f1I0kXK88S3yC8k0zRAp4n
|
||||
RyyjnPW9Sr2nIuC27RgfH0lxWGOlAVVrFUlgifECD/RSoMuQk5yYgAJiALbnfdlP
|
||||
AutjtwClWZ6u1BXnwdUxS+ypWtq4Fb4+vz/VRSK24ZNcrI9NF3wkqKHxnjccxROA
|
||||
BratiMbHi5VxU63iec2XqAEhqi+ArWks8XJyTvv/tBYOqmmP4Fi0i/wbpzxmFJ61
|
||||
ZGUiHFifkYHKBI/HhjDazdeAhAwcFHSbVInea10+V0dkW7sOGnJFW5PyW1F/TBBe
|
||||
3dsp8Tz88+oHbSGwV7qF/Qf6U6kRxeVVctmSSCAohUbPH26xhPhk+t1TVdb3EA==
|
||||
-----END CERTIFICATE-----
|
|
@ -0,0 +1,8 @@
|
|||
MIIDKjCCAhKgAwIBAgIBATANBgkqhkiG9w0BAQsFADAaMRgwFgYDVQQDEw9jbGll
|
||||
bnRhdXRob3JpdHkwHhcNMTUxMDI3MTAyNjM1WhcNMjUxMDI0MTAyNjM1WjAaMRgw
|
||||
FgYDVQQDEw9jbGllbnRhdXRob3JpdHkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
||||
ggEKAoIBAQCi6wJAs6nppNmTZ3e/wE9l0pAmkMtDONwB9o115XXTG3rmSKfZOxa8
|
||||
TFjSn818Pr1OYb9fPdI1Y6x4WY9PELUtQyEBlNcKjwg96vhrP4p2DhqbWsI5nASH
|
||||
DSjJsM75bQ7D7qHYzriuAl0Fk1C4LcodRj+5wmErMtvGJG0x06qFbxCCMAJ2kC+h
|
||||
SneTN955/YHSXADgxjFlt3s1T0QPnqrr+G7Ro6PrVKLPBulglq7wAeTwrGkPRUt0
|
||||
3lDGOSi6i97NbpiXwrGp5XiLUtVCiID6Ro0xKWH4sjJ4JnVjIUG8CQWERc6sFDJM
|
BIN
tests/standalone/io/certificates/server_chain.p12
Normal file
BIN
tests/standalone/io/certificates/server_chain.p12
Normal file
Binary file not shown.
60
tests/standalone/io/certificates/server_chain.pem
Normal file
60
tests/standalone/io/certificates/server_chain.pem
Normal file
|
@ -0,0 +1,60 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDZDCCAkygAwIBAgIBATANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVpbnRl
|
||||
cm1lZGlhdGVhdXRob3JpdHkwHhcNMTgwNDIzMjAxNjM0WhcNMjgwNDIwMjAxNjM0
|
||||
WjAUMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
||||
ggEKAoIBAQDZE0gF3bAFxBaxAZUFGkeFkF5B8nJD//+14rcz/Kr/Rau38g38jNyp
|
||||
K3bsyWIBq/4A/cPykwncG6Z04WD2FrLR1xDdAbO2zD3cQKbOoFOYXeYMmP4FZcbq
|
||||
nSngCzfUfJkwXXHfCC6v3XZkmR0ojWp9tGHJ6G4f9QI8wwT/Y9pvAVQVR9+S43C0
|
||||
ZAPkuNiMBN3lAH4QF2WTC5GTQo4hR+IAWN28lnqAbVoRMNvFoDenDZxURq2kT/6j
|
||||
ot6UB9f6AOugCUlEpVovTX3evPKrIZz68BM4DttA/r2wo6dw3fouZk/REJ38fi7x
|
||||
lg5n5ccCmguE2fF5PoAMH7WCc7EupYKNAgMBAAGjgbQwgbEwPAYDVR0RBDUwM4IJ
|
||||
bG9jYWxob3N0ggkxMjcuMC4wLjGCAzo6MYcEfwAAAYcQAAAAAAAAAAAAAAAAAAAA
|
||||
ATAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBSFtW0d7VGk7g7ywHgrf+bbg/BhQTAf
|
||||
BgNVHSMEGDAWgBQqU7R8m4wyfyc9ubiPQcYpHNZrmDAOBgNVHQ8BAf8EBAMCA6gw
|
||||
EwYDVR0lBAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQELBQADggEBAKL0FaPO+YM+
|
||||
JJgQryvkf2/WqdnnTGg/7A/HCOk1rkT9q0282Bj1OT4GiyOIOTyHkxrF72dSiN4Q
|
||||
0hg1YoUITR1uR5odQsnK3YKSfmGfn+IRNuHf/Oy1XfRrjuIgo3syeqquIJM4W1MO
|
||||
uZBkqwdXQIYqBGj4E+y32bxGVhI53rb9MyKfugajRxImTO7UnUydHsIgqNG6MfuH
|
||||
LXBNUAw6uPLyW6srfWiiDVlkUzSmXYFoScCXTj7u12Ar/hffGKrXqHojSE0XtcRz
|
||||
WuncYKJE/pflgClA5Qe64erD3q2w2SfOZDFwizP7aZU9uAMin8NbiE8Nd6h8hoRc
|
||||
ztJfeC+1gro=
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDLjCCAhagAwIBAgIBAjANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1yb290
|
||||
YXV0aG9yaXR5MB4XDTE4MDQyMzIwMTYzM1oXDTI4MDQyMDIwMTYzM1owIDEeMBwG
|
||||
A1UEAwwVaW50ZXJtZWRpYXRlYXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOC
|
||||
AQ8AMIIBCgKCAQEAsSFr3/sYhGFF7gEZSn7Am8ATtPhTo5ypQqSAv/4Uy+k4zvT3
|
||||
b3OZyYpzr5Wsa6NXcEKwNipyR1GBpYwaYI/W4DSi+COdH4DQSZDQFr+hvmXRazzj
|
||||
VSsOxF6veGLcza53meLPRb4o4yVoZARd6xR5i3OUD4kezvOjpmlFT3OKNU0Di+Vq
|
||||
qeS14/at6Vt6G0rS8CluafD7Z0/5zp6vrImKwC6OWzlmmcAqBGsE/BTzrAxLdt4K
|
||||
uw3Xs3uvS3YZIAC536C1Mop1n4FBUGxeUMWH+I/llzK9ol1pmQHJrxfOD5WdFuuE
|
||||
iFfpiOmBdUfDBbEPllmIvzUBFOo5VhxVmq8EHQIDAQABo3sweTASBgNVHRMBAf8E
|
||||
CDAGAQH/AgEAMB0GA1UdDgQWBBQqU7R8m4wyfyc9ubiPQcYpHNZrmDAfBgNVHSME
|
||||
GDAWgBT0rD9lRUhqJvAg7hfBEz/ZqHCzHjAOBgNVHQ8BAf8EBAMCAgQwEwYDVR0l
|
||||
BAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQELBQADggEBAGjRSFvVeIrRF3iuA5vr
|
||||
SgufTCNzAyEz7+pDKflzHSQXF1fdItiOdPGv1i57gIr7HaYuxvBiEklhmnWreYye
|
||||
Tn6ghfhEHhdZHBpihDXuIvLizhtR/lg9CDZrHjuY6nukyx4JnWwUBR3TulPK5gJu
|
||||
jB9YISY8tjXrvVNqdi0a+G0T4HHnVs3v6Nd/Qdsxfp4maAB1U3HFmR3DXKTxDtBK
|
||||
mNNMqf9PpX4lw4o6UieiEwOMd+4REhmwLNTwhWrhVg5q6GKQl873Ge/7J2nXvgkH
|
||||
nUbEsncLsArqqrz201f2m32A6pinwY/j85vEeRkHwlsU0jOvVnHzAlggP0u/kFAF
|
||||
EjE=
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIC/jCCAeagAwIBAgIBATANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1yb290
|
||||
YXV0aG9yaXR5MB4XDTE4MDQyMzIwMTYzM1oXDTI4MDQyMDIwMTYzM1owGDEWMBQG
|
||||
A1UEAwwNcm9vdGF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
||||
ggEBALkvRWdbx9GwxePkh0nnpht4MrPW5NkZBORqfhFi7PFbQ7Rwgl39hm9iAmci
|
||||
pOWZGSJi7AaqLuSID0UEeRdG/fNFawI5XIoxP+TmdKdrk/SaTJQKKJiZ9B8+EG0z
|
||||
hV8/v6jrlwj0gq9eBBAmOInnmQiEYE4gKFNvh9xdP//gi+otBf30gmtJ4AxXOTu/
|
||||
M+XEigXelmIvy57b+B+qnonTFcGkXhSr+JfCA1l6ta7OtknQtItpV0FDr/d8hA+6
|
||||
Bn25ZSisd00GC3CUMX1tM5V8cQE6GO/W2mnpUFVvWycYx9wDyU7rlyNUf8nWeoIW
|
||||
3d3s/6KAppa07KrkLiTantIrqMUCAwEAAaNTMFEwHQYDVR0OBBYEFPSsP2VFSGom
|
||||
8CDuF8ETP9mocLMeMB8GA1UdIwQYMBaAFPSsP2VFSGom8CDuF8ETP9mocLMeMA8G
|
||||
A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAJ1VynTevPnNtwevQpUa
|
||||
zlur64N+Dx/yF4gvd4byjO+JouMJLaJqV2dwnqgAahg6YKasVtv4xX9MVJR2IjIb
|
||||
Tfa0nYQxM5clwk3J78nh82Ncb2RNeYJyNmSdocnOkmTSoOGUFOxtRz1vmKUcrfwl
|
||||
yENO/qGe/sYmOv0IWJjeGQ2OZPblRumV4dJy3qTHFmOLpYwA0BGiIV5uj5Ou7QU1
|
||||
R5PY2pnJg4RXeaq95Pr50lkO9vpRyFUJHjR+P+J05M9FbjLPOQIFkpMYx/GyBg5n
|
||||
P+omyagOGW8bXfBTtUYu+rP/k+BC5AxI3Kdv/AD5vyHKi/JXhP3ycb8AYx5ENHoK
|
||||
qjA=
|
||||
-----END CERTIFICATE-----
|
|
@ -0,0 +1,6 @@
|
|||
MIIDZDCCAkygAwIBAgIBATANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVpbnRl
|
||||
cm1lZGlhdGVhdXRob3JpdHkwHhcNMTUxMDI3MTAyNjM1WhcNMjUxMDI0MTAyNjM1
|
||||
WjAUMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
||||
ggEKAoIBAQCkg/Qr8RQeLTOSgCkyiEX2ztgkgscX8hKGHEHdvlkmVK3JVEIIwkvu
|
||||
/Y9LtHZUia3nPAgqEEbexzTENZjSCcC0V6I2XW/e5tIE3rO0KLZyhtZhN/2SfJ6p
|
||||
KbOh0HLr1VtkKJGp1tzUmHW/aZI32pK60ZJ/N917NLPCJpCaL8+wHo3+w3oNqln6
|
41
tests/standalone/io/certificates/server_chain_malformed2.pem
Normal file
41
tests/standalone/io/certificates/server_chain_malformed2.pem
Normal file
|
@ -0,0 +1,41 @@
|
|||
MIIDZDCCAkygAwIBAgIBATANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVpbnRl
|
||||
cm1lZGlhdGVhdXRob3JpdHkwHhcNMTUxMDI3MTAyNjM1WhcNMjUxMDI0MTAyNjM1
|
||||
WjAUMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
||||
ggEKAoIBAQCkg/Qr8RQeLTOSgCkyiEX2ztgkgscX8hKGHEHdvlkmVK3JVEIIwkvu
|
||||
/Y9LtHZUia3nPAgqEEbexzTENZjSCcC0V6I2XW/e5tIE3rO0KLZyhtZhN/2SfJ6p
|
||||
KbOh0HLr1VtkKJGp1tzUmHW/aZI32pK60ZJ/N917NLPCJpCaL8+wHo3+w3oNqln6
|
||||
oJsfgxy9SUM8Bsc9WMYKMUdqLO1QKs1A5YwqZuO7Mwj+4LY2QDixC7Ua7V9YAPo2
|
||||
1SBeLvMCHbYxSPCuxcZ/kDkgax/DF9u7aZnGhMImkwBka0OQFvpfjKtTIuoobTpe
|
||||
PAG7MQYXk4RjnjdyEX/9XAQzvNo1CDObAgMBAAGjgbQwgbEwPAYDVR0RBDUwM4IJ
|
||||
bG9jYWxob3N0ggkxMjcuMC4wLjGCAzo6MYcEfwAAAYcQAAAAAAAAAAAAAAAAAAAA
|
||||
ATAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBSvhJo6taTggJQBukEvMo/PDk8tKTAf
|
||||
BgNVHSMEGDAWgBS98L4T5RaIToE3DkBRsoeWPil0eDAOBgNVHQ8BAf8EBAMCA6gw
|
||||
EwYDVR0lBAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQELBQADggEBAHLOt0mL2S4A
|
||||
B7vN7KsfQeGlVgZUVlEjem6kqBh4fIzl4CsQuOO8oJ0FlO1z5JAIo98hZinymJx1
|
||||
phBVpyGIKakT/etMH0op5evLe9dD36VA3IM/FEv5ibk35iGnPokiJXIAcdHd1zam
|
||||
YaTHRAnZET5S03+7BgRTKoRuszhbvuFz/vKXaIAnVNOF4Gf2NUJ/Ax7ssJtRkN+5
|
||||
UVxe8TZVxzgiRv1uF6NTr+J8PDepkHCbJ6zEQNudcFKAuC56DN1vUe06gRDrNbVq
|
||||
2JHEh4pRfMpdsPCrS5YHBjVq/XHtFHgwDR6g0WTwSUJvDeM4OPQY5f61FB0JbFza
|
||||
PkLkXmoIod8=
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDLjCCAhagAwIBAgIBAjANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1yb290
|
||||
YXV0aG9yaXR5MB4XDTE1MTAyNzEwMjYzNVoXDTI1MTAyNDEwMjYzNVowIDEeMBwG
|
||||
A1UEAwwVaW50ZXJtZWRpYXRlYXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOC
|
||||
AQ8AMIIBCgKCAQEA6GndRFiXk+2q+Ig7ZOWKKGta+is8137qyXz+eVFs5sA0ajMN
|
||||
ZBAMWS0TIXw/Yks+y6fEcV/tfv91k1eUN4YXPcoxTdDF97d2hO9wxumeYOMnQeDy
|
||||
VZVDKQBZ+jFMeI+VkNpMEdmsLErpZDGob/1dC8tLEuR6RuRR8X6IDGMPOCMw1jLK
|
||||
V1bQjPtzqKadTscfjLuKxuLgspJdTrzsu6hdcl1mm8K6CjTY2HNXWxs1yYmwfuQ2
|
||||
Z4/8sOMNqFqLjN+ChD7pksTMq7IosqGiJzi2bpd5f44ek/k822Y0ATncJHk4h1Z+
|
||||
kZBnW6kgcLna1gDri9heRwSZ+M8T8nlHgIMZIQIDAQABo3sweTASBgNVHRMBAf8E
|
||||
CDAGAQH/AgEAMB0GA1UdDgQWBBS98L4T5RaIToE3DkBRsoeWPil0eDAfBgNVHSME
|
||||
GDAWgBRxD5DQHTmtpDFKDOiMf5FAi6vfbzAOBgNVHQ8BAf8EBAMCAgQwEwYDVR0l
|
||||
BAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQELBQADggEBAD+4KpUeV5mUPw5IG/7w
|
||||
eOXnUpeS96XFGuS1JuFo/TbgntPWSPyo+rD4GrPIkUXyoHaMCDd2UBEjyGbBIKlB
|
||||
NZA3RJOAEp7DTkLNK4RFn/OEcLwG0J5brL7kaLRO4vwvItVIdZ2XIqzypRQTc0MG
|
||||
MmF08zycnSlaN01ryM67AsMhwdHqVa+uXQPo8R8sdFGnZ33yywTYD73FeImXilQ2
|
||||
rDnFUVqmrW1fjl0Fi4rV5XI0EQiPrzKvRtmF8ZqjGATPOsRd64cwQX6V+P5hNeIR
|
||||
9pba6td7AbNGausHfacRYMyoGJWWWkFPd+7jWOCPqW7Fk1tmBgdB8GzXa3inWIRM
|
||||
RUE=
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
BIN
tests/standalone/io/certificates/server_key.p12
Normal file
BIN
tests/standalone/io/certificates/server_key.p12
Normal file
Binary file not shown.
29
tests/standalone/io/certificates/server_key.pem
Normal file
29
tests/standalone/io/certificates/server_key.pem
Normal file
|
@ -0,0 +1,29 @@
|
|||
-----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
MIIE4zAcBgoqhkiG9w0BDAEBMA4ECDmmTgwIo/3yAgIIAASCBMHPUDfzHGi72H4W
|
||||
nKLepeD31Upra9tvQx6UrRQaBmf0frh5Coo4Yw3Z+IOZQ4ZwxoIv0/kty7FvXVDU
|
||||
BMdFqFeVvKKlsMm7Ub0hC5ks7A0mTVqcc9nW/aBL87W4nZsJ3LSLiPYXptBWOGRh
|
||||
kVghEsySowsK8OmYDwauLi5ZoZC/3cwy2YIaOC9/J8sbnzAq3EVEpJwI0GIQgYET
|
||||
aGGELjpariWrcPUa16dRU5vrBlFL2Sn3BVJU24DFq/8RJwsL2rpWXxg9x5QxoraW
|
||||
WPvxIGvanBphthRABjZ4A8mtQwvkKfdqMuJ7bWAA2YqcZnk7N5zh4XmARKvjlM5K
|
||||
ujpjRFu4+NjyQ65vqTfAwQptxj9l/nzaSZqV5K8ROlpa+UODNzLsL/gf4l/22zZ+
|
||||
/rnyko97NQ0Jhy/m0xPhXd620IWjmsjNZk+txYWx4K0srBTptRTqKWkQuY7DV/N0
|
||||
4xEA0y3T1kLXZmGmvoidB8VwWD7ZC4/fhuFKAKQmEccMsR9AUsI0h4bAjJ419AK2
|
||||
G1jsirQS5P1vBweddwbzCtztUNuCCFy9LHmJCLE/yJ2JMmnePi7eOiyvsjU4es6b
|
||||
yj9/ekbWQwZO5L15UkY9T/pP8kSR+gAvn/92DB+e2U4R+ZK886unDyLCCp0rGsPK
|
||||
ijdcwMkAJampirw3iO5FkXbGO4GoVggNUxTTCDnYenY8jcKePlP0YM7A9XZ+kmmS
|
||||
1gcNuNikKmfzusvUuvOX4Dt24gCOGa5dDEOeYHsC7SZT40IFogshZyVdKNzlyIxj
|
||||
yqIlr9LOGo7vL84aUYUUF2mRJ9n2+ivqRadQ9s59iH96uYjvZ12KztCjHEPVSVHk
|
||||
+rwd4WJ5ByBV7MeB8370JtwN/ZfzAIB7ONfXP9rrfcP19VC+MpsIuOCYPJERlhBT
|
||||
9w/UuThPhM/cXp9YiDJepa0T2vmCRKHSz932WKGe3dZn+0saKa5ShdMSepp9CroE
|
||||
ot2aF+uU9rMh+DIeNVLmHFwa5+3UC18G6rIB9wpZCHmg6LyMDf/OwW2/yao/GKXN
|
||||
WayHbex+Z4yXrVUo+5m9rFwFgo2Hl8fVdSJhKmvp9HQKQjEgxUhUC9B46ErS5efM
|
||||
SPlMOYfWST5eOG55vr04dWI5t2AXAKWAxxowO1OBhj3J0FjCS/vtUkUiFohc91oV
|
||||
b11afVtizPQJOJ9D1xNEADemnJq6KNT1pRaeKOA94JKODwBMi4K3KmEN51l1uJZ8
|
||||
U5h1CjweXZjmq81Da2LMLtGgJuTUuAT6LWIXLSck7EX35D1mY4lGHcuMqVCQ1St1
|
||||
UvRjRFx3rd6aBEgj7M/FNsUAIlq4X6+58wdh3mx31608CYGyQ8p5kPhj26ZxziJj
|
||||
WSFW+YiVrLPBXhIn6Q9DIqvMPdTbLM/fDy9G0ZinhHZH+a41t7v+UZh2FtiT+p52
|
||||
n+hiHTbkGQgQ8SYZT0WAjiaS+1pVVvv+MRqpsYpnNPYxI5bp6orSFOudF3pdAbqQ
|
||||
f4WDOY0kGg2tPmaNpZSz+FPuuiWC7Y0J1+o3fMnrUMvY4XrUwkstFfROdnM0W9YG
|
||||
I1MsVM4NhcKPHcVxKWgsmL5yAVl92mz88rhgbsArhcpO5K4lxE1LB/giUZRdTkRP
|
||||
bKFBVqrcpg==
|
||||
-----END ENCRYPTED PRIVATE KEY-----
|
58
tests/standalone/io/certificates/server_trusted.pem
Normal file
58
tests/standalone/io/certificates/server_trusted.pem
Normal file
|
@ -0,0 +1,58 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDLjCCAhagAwIBAgIBAjANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1yb290
|
||||
YXV0aG9yaXR5MB4XDTE4MDQyMzIwMTYzM1oXDTI4MDQyMDIwMTYzM1owIDEeMBwG
|
||||
A1UEAwwVaW50ZXJtZWRpYXRlYXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOC
|
||||
AQ8AMIIBCgKCAQEAsSFr3/sYhGFF7gEZSn7Am8ATtPhTo5ypQqSAv/4Uy+k4zvT3
|
||||
b3OZyYpzr5Wsa6NXcEKwNipyR1GBpYwaYI/W4DSi+COdH4DQSZDQFr+hvmXRazzj
|
||||
VSsOxF6veGLcza53meLPRb4o4yVoZARd6xR5i3OUD4kezvOjpmlFT3OKNU0Di+Vq
|
||||
qeS14/at6Vt6G0rS8CluafD7Z0/5zp6vrImKwC6OWzlmmcAqBGsE/BTzrAxLdt4K
|
||||
uw3Xs3uvS3YZIAC536C1Mop1n4FBUGxeUMWH+I/llzK9ol1pmQHJrxfOD5WdFuuE
|
||||
iFfpiOmBdUfDBbEPllmIvzUBFOo5VhxVmq8EHQIDAQABo3sweTASBgNVHRMBAf8E
|
||||
CDAGAQH/AgEAMB0GA1UdDgQWBBQqU7R8m4wyfyc9ubiPQcYpHNZrmDAfBgNVHSME
|
||||
GDAWgBT0rD9lRUhqJvAg7hfBEz/ZqHCzHjAOBgNVHQ8BAf8EBAMCAgQwEwYDVR0l
|
||||
BAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQELBQADggEBAGjRSFvVeIrRF3iuA5vr
|
||||
SgufTCNzAyEz7+pDKflzHSQXF1fdItiOdPGv1i57gIr7HaYuxvBiEklhmnWreYye
|
||||
Tn6ghfhEHhdZHBpihDXuIvLizhtR/lg9CDZrHjuY6nukyx4JnWwUBR3TulPK5gJu
|
||||
jB9YISY8tjXrvVNqdi0a+G0T4HHnVs3v6Nd/Qdsxfp4maAB1U3HFmR3DXKTxDtBK
|
||||
mNNMqf9PpX4lw4o6UieiEwOMd+4REhmwLNTwhWrhVg5q6GKQl873Ge/7J2nXvgkH
|
||||
nUbEsncLsArqqrz201f2m32A6pinwY/j85vEeRkHwlsU0jOvVnHzAlggP0u/kFAF
|
||||
EjE=
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIC/jCCAeagAwIBAgIBATANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1yb290
|
||||
YXV0aG9yaXR5MB4XDTE4MDQyMzIwMTYzM1oXDTI4MDQyMDIwMTYzM1owGDEWMBQG
|
||||
A1UEAwwNcm9vdGF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
||||
ggEBALkvRWdbx9GwxePkh0nnpht4MrPW5NkZBORqfhFi7PFbQ7Rwgl39hm9iAmci
|
||||
pOWZGSJi7AaqLuSID0UEeRdG/fNFawI5XIoxP+TmdKdrk/SaTJQKKJiZ9B8+EG0z
|
||||
hV8/v6jrlwj0gq9eBBAmOInnmQiEYE4gKFNvh9xdP//gi+otBf30gmtJ4AxXOTu/
|
||||
M+XEigXelmIvy57b+B+qnonTFcGkXhSr+JfCA1l6ta7OtknQtItpV0FDr/d8hA+6
|
||||
Bn25ZSisd00GC3CUMX1tM5V8cQE6GO/W2mnpUFVvWycYx9wDyU7rlyNUf8nWeoIW
|
||||
3d3s/6KAppa07KrkLiTantIrqMUCAwEAAaNTMFEwHQYDVR0OBBYEFPSsP2VFSGom
|
||||
8CDuF8ETP9mocLMeMB8GA1UdIwQYMBaAFPSsP2VFSGom8CDuF8ETP9mocLMeMA8G
|
||||
A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAJ1VynTevPnNtwevQpUa
|
||||
zlur64N+Dx/yF4gvd4byjO+JouMJLaJqV2dwnqgAahg6YKasVtv4xX9MVJR2IjIb
|
||||
Tfa0nYQxM5clwk3J78nh82Ncb2RNeYJyNmSdocnOkmTSoOGUFOxtRz1vmKUcrfwl
|
||||
yENO/qGe/sYmOv0IWJjeGQ2OZPblRumV4dJy3qTHFmOLpYwA0BGiIV5uj5Ou7QU1
|
||||
R5PY2pnJg4RXeaq95Pr50lkO9vpRyFUJHjR+P+J05M9FbjLPOQIFkpMYx/GyBg5n
|
||||
P+omyagOGW8bXfBTtUYu+rP/k+BC5AxI3Kdv/AD5vyHKi/JXhP3ycb8AYx5ENHoK
|
||||
qjA=
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDKjCCAhKgAwIBAgIBATANBgkqhkiG9w0BAQsFADAaMRgwFgYDVQQDDA9jbGll
|
||||
bnRhdXRob3JpdHkwHhcNMTgwNDIzMjAxNjM0WhcNMjgwNDIwMjAxNjM0WjAaMRgw
|
||||
FgYDVQQDDA9jbGllbnRhdXRob3JpdHkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
||||
ggEKAoIBAQDckwmIcOYIRbH1jcuBCC/y1a4aiqXhvUCty59Cdqzlx0gbrhkVGmf0
|
||||
B0Tmo/PW4p9rcl0hwwxGvGoCvsxVpodHQmIxYwwn1sRl2C7Yo2ZHPMYbv9uq+D0d
|
||||
kS8SxHb5l4HvpcT7WoqUq8ZWEm0Losbp8cOcrvLiBQgo8xIOKQzKbwrXydnviQKL
|
||||
E5iBmUswzHwb7ZK84u6dS3iHbl9iPy+QTfiboT6BNMsO/dm6Nqmdj35fOPQgFUN/
|
||||
QR3NsPWL9GtzB9iZc3D7c30FqqqQO/THjaLJIyzdFdF3Fsp+omSuZw/q1d4/R8M3
|
||||
FRCcqzbWLA9Dy12kK/9asmlpf/fdHByVAgMBAAGjezB5MBIGA1UdEwEB/wQIMAYB
|
||||
Af8CAQAwHQYDVR0OBBYEFPk5T6DExD59hh1A7g+PTZvoqr8MMB8GA1UdIwQYMBaA
|
||||
FPk5T6DExD59hh1A7g+PTZvoqr8MMA4GA1UdDwEB/wQEAwICBDATBgNVHSUEDDAK
|
||||
BggrBgEFBQcDAjANBgkqhkiG9w0BAQsFAAOCAQEAh4f1I0kXK88S3yC8k0zRAp4n
|
||||
RyyjnPW9Sr2nIuC27RgfH0lxWGOlAVVrFUlgifECD/RSoMuQk5yYgAJiALbnfdlP
|
||||
AutjtwClWZ6u1BXnwdUxS+ypWtq4Fb4+vz/VRSK24ZNcrI9NF3wkqKHxnjccxROA
|
||||
BratiMbHi5VxU63iec2XqAEhqi+ArWks8XJyTvv/tBYOqmmP4Fi0i/wbpzxmFJ61
|
||||
ZGUiHFifkYHKBI/HhjDazdeAhAwcFHSbVInea10+V0dkW7sOGnJFW5PyW1F/TBBe
|
||||
3dsp8Tz88+oHbSGwV7qF/Qf6U6kRxeVVctmSSCAohUbPH26xhPhk+t1TVdb3EA==
|
||||
-----END CERTIFICATE-----
|
BIN
tests/standalone/io/certificates/trusted_certs.p12
Normal file
BIN
tests/standalone/io/certificates/trusted_certs.p12
Normal file
Binary file not shown.
19
tests/standalone/io/certificates/trusted_certs.pem
Normal file
19
tests/standalone/io/certificates/trusted_certs.pem
Normal file
|
@ -0,0 +1,19 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIC/jCCAeagAwIBAgIBATANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1yb290
|
||||
YXV0aG9yaXR5MB4XDTE4MDQyMzIwMTYzM1oXDTI4MDQyMDIwMTYzM1owGDEWMBQG
|
||||
A1UEAwwNcm9vdGF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
||||
ggEBALkvRWdbx9GwxePkh0nnpht4MrPW5NkZBORqfhFi7PFbQ7Rwgl39hm9iAmci
|
||||
pOWZGSJi7AaqLuSID0UEeRdG/fNFawI5XIoxP+TmdKdrk/SaTJQKKJiZ9B8+EG0z
|
||||
hV8/v6jrlwj0gq9eBBAmOInnmQiEYE4gKFNvh9xdP//gi+otBf30gmtJ4AxXOTu/
|
||||
M+XEigXelmIvy57b+B+qnonTFcGkXhSr+JfCA1l6ta7OtknQtItpV0FDr/d8hA+6
|
||||
Bn25ZSisd00GC3CUMX1tM5V8cQE6GO/W2mnpUFVvWycYx9wDyU7rlyNUf8nWeoIW
|
||||
3d3s/6KAppa07KrkLiTantIrqMUCAwEAAaNTMFEwHQYDVR0OBBYEFPSsP2VFSGom
|
||||
8CDuF8ETP9mocLMeMB8GA1UdIwQYMBaAFPSsP2VFSGom8CDuF8ETP9mocLMeMA8G
|
||||
A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAJ1VynTevPnNtwevQpUa
|
||||
zlur64N+Dx/yF4gvd4byjO+JouMJLaJqV2dwnqgAahg6YKasVtv4xX9MVJR2IjIb
|
||||
Tfa0nYQxM5clwk3J78nh82Ncb2RNeYJyNmSdocnOkmTSoOGUFOxtRz1vmKUcrfwl
|
||||
yENO/qGe/sYmOv0IWJjeGQ2OZPblRumV4dJy3qTHFmOLpYwA0BGiIV5uj5Ou7QU1
|
||||
R5PY2pnJg4RXeaq95Pr50lkO9vpRyFUJHjR+P+J05M9FbjLPOQIFkpMYx/GyBg5n
|
||||
P+omyagOGW8bXfBTtUYu+rP/k+BC5AxI3Kdv/AD5vyHKi/JXhP3ycb8AYx5ENHoK
|
||||
qjA=
|
||||
-----END CERTIFICATE-----
|
|
@ -0,0 +1,8 @@
|
|||
MIIC+zCCAeOgAwIBAgIBATANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1yb290
|
||||
YXV0aG9yaXR5MB4XDTE1MTAyNzEwMjYzNFoXDTI1MTAyNDEwMjYzNFowGDEWMBQG
|
||||
A1UEAwwNcm9vdGF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
||||
ggEBAMl+dcraUM/E7E6zl7+7hK9oUJYXJLnfiMtP/TRFVbH4+2aEN8vXzPbzKdR3
|
||||
FfaHczXQTwnTCaYA4u4uSDvSOsFFEfxEwYORsdKmQEM8nGpVX2NVvKsMcGIhh8kh
|
||||
ZwJfkMIOcAxmGIHGdMhF8VghonJ8uGiuqktxdfpARq0g3fqIjDHsF9/LpfshUfk9
|
||||
wsRyTF0yr90U/dsfnE+u8l7GvVl8j2Zegp0sagAGtLaNv7tP17AibqEGg2yDBrBN
|
||||
a
|
60
tests/standalone/io/certificates/untrusted_server_chain.pem
Normal file
60
tests/standalone/io/certificates/untrusted_server_chain.pem
Normal file
|
@ -0,0 +1,60 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDZDCCAkygAwIBAgIBATANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVpbnRl
|
||||
cm1lZGlhdGVhdXRob3JpdHkwHhcNMTgwNDIzMTcxNTEzWhcNMjgwNDIwMTcxNTEz
|
||||
WjAUMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
||||
ggEKAoIBAQDO+XxT1pAvzkIWvAZJFGEjuIuXz1kNoCDxBHAilptAOCX5sKyLaWTc
|
||||
YvzYpDf0LOwU3T/ZtlSinkX2xCY7EXgsGJEFc1RDmhmPmSsY9Az/ewS1TNrTOkD5
|
||||
VGUwnRKpl3o+140A/aNYGQfHJRz0+BCLftv7b95HinLDq26d01eTHLOozfGqkcfA
|
||||
LfUauiwXRV817ceLiliGUtgW8DDNTVqtHA2aeKVisZZtyeEMc3BsnJDGmU6kcQ4B
|
||||
KeLHaaxCufy4bMlObwSLcdlp7R6MTudzKVEjXVz/WRLz7yZYaYDrcacUvsI8v+jX
|
||||
B7quGGkLGJH+GxDGMObFWKsAB229c9ZlAgMBAAGjgbQwgbEwPAYDVR0RBDUwM4IJ
|
||||
bG9jYWxob3N0ggkxMjcuMC4wLjGCAzo6MYcEfwAAAYcQAAAAAAAAAAAAAAAAAAAA
|
||||
ATAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBR6zQbX0GnDCsjksKYXlzovO2yplDAf
|
||||
BgNVHSMEGDAWgBSkX16pB/ZB0hzdYIUgMhWO89CxZzAOBgNVHQ8BAf8EBAMCA6gw
|
||||
EwYDVR0lBAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQELBQADggEBAIDPqZllHvJa
|
||||
XSpqOFaT7oFzKbBnV8lLMvYnbDWHL8N+23q+y803GGNRMkDJG98OalqqKMskk4/v
|
||||
ek6dhkTHKnB7hunhogIICXCcHOJGaHN67vvkxkP5mTx6AMaPT+q6NXzu2y9YBTkr
|
||||
BIw6ZUyPxqIcH4/GezVe+pokvNZHghDePBChALXEmQLBuJy+gM55w4nB5eq8pNnP
|
||||
1r9vVhlr4jqiVNd95MglwB4xLQV5SeG8gGwGvad0vvIpHljOwT9TmlofeqqGpPLf
|
||||
3LtqrBK5qdxWcn0jDxG/Qe2EfsdmzsCQ+imu5rTc1YMCGZD52mnnq4tZj0hroWLn
|
||||
Wys+JpPMdKo=
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDLjCCAhagAwIBAgIBAjANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1yb290
|
||||
YXV0aG9yaXR5MB4XDTE4MDQyMzE3MTUxMloXDTI4MDQyMDE3MTUxMlowIDEeMBwG
|
||||
A1UEAwwVaW50ZXJtZWRpYXRlYXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOC
|
||||
AQ8AMIIBCgKCAQEAvpFatw9XMWQDbKzWtsA5NfjQsddw5wlDpFeRYghyqo/mgWru
|
||||
Rapcz6tEpEodc3SZ/4PCwE1PmYZuxhcYnaDCM3YdmJAMPUhqi+YO+Gc7WNTbrOR0
|
||||
aJGzS2HEPxjbC4OsFG7TVuKMH1uI4rWOZxBn4rODkTmiH7epuyu65nzUJemct8GV
|
||||
OcPChjPVKvXzbHVtk8UVreD/DVyuYwsBMSAuYWiq2pgAAQV/7TKVDAQ8yRVW28J7
|
||||
+QrNXqV+I6MZeMho45xgLNQmi5os9vqTuEu3oGyLFWxXz6uJ2MOFOFTjxMhHGcGn
|
||||
aICAA9BIcCeaWWRN9nZkvQuS2nysvJwBu/LROQIDAQABo3sweTASBgNVHRMBAf8E
|
||||
CDAGAQH/AgEAMB0GA1UdDgQWBBSkX16pB/ZB0hzdYIUgMhWO89CxZzAfBgNVHSME
|
||||
GDAWgBR9W+i1d5oZtiZAEjI9RDLd9SnUnDAOBgNVHQ8BAf8EBAMCAgQwEwYDVR0l
|
||||
BAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQELBQADggEBAIdIh5sIk9Qi2KZfzJUQ
|
||||
/DmMTv6NZzAGROJGA+o6jfrMh/plzBre7QM2vzw6iHxFokepLnsXtgrqdtr1lluO
|
||||
R6apN2QLp5AJeT8gZfn0V35Wz2iYn+fJR77Map3u57IOj08gvk/BZmJxxqMT/qH/
|
||||
1H5qpd934aFLSgqsmpGOVIzrdwHVmwOKU9SDNxOILVpvgtjQ/KWEUxftKtU7Z/dd
|
||||
WGN56Vu3Ul0gzgCFifj8mnHnHpug/wEHLl0l2hk3BD1AUrCyCK4yalvsDV7vFex7
|
||||
8+Whuh4OijTP/yomn8VGPN5lMmGT4XN8Z3h97PUHF9yF4FYGJJ/lilIhxctashk+
|
||||
HuE=
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIC/jCCAeagAwIBAgIBATANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1yb290
|
||||
YXV0aG9yaXR5MB4XDTE4MDQyMzE3MTUxMloXDTI4MDQyMDE3MTUxMlowGDEWMBQG
|
||||
A1UEAwwNcm9vdGF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
||||
ggEBAMuTL5lztughNg/G/9Ge8c6EmROymW0zGTN6hRp3rG2SkpJdag08ntKAmny3
|
||||
ilpnlEoxGOk1L9jq/lJsCsiqsSETCadkLsXFNeKOG+S48nc8ThOrmJe5WV6NDNmn
|
||||
qaQeek5rjvuRSdukhyZVLzmIyTYNErwkMuo+Jk1V7IS1X2pFyTfF+SLlYrOuDQIW
|
||||
qXYfWqdMSYpI8s3onIwR/qVapGu55D0CECzNyX6ZBnqYK0cGzmRaZToT84VPsJwB
|
||||
DmALQw9WNNn1CHAIt17CwsdSSasgaKz/XDDjwgKL7CI6bFttDIWVLBt8ikrsrjZN
|
||||
6L5b8PZx/dHwJJ7QjYOMKKSUjyECAwEAAaNTMFEwHQYDVR0OBBYEFH1b6LV3mhm2
|
||||
JkASMj1EMt31KdScMB8GA1UdIwQYMBaAFH1b6LV3mhm2JkASMj1EMt31KdScMA8G
|
||||
A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAJTJx9nh+fTJ6a0aIzPY
|
||||
FUX5tg+MdUxsAG5QA2jrwZIKCSrHa/ka0vjwLO+94EWcWgKdNDu8lt2FPnJh0nzN
|
||||
Ad/CaQNSMesihlmGOgxvLgd3ndYDVYjsCrXx3ESoRavgAWXY+/p69KR1ibVLpKF/
|
||||
yr/YURqT9SLKAlgrZt5I/syzxhWdAND62oxqiDCMzPoVR2cLswIUDNRvq5nRiCIt
|
||||
1TLPDINjG1EdmwzV2jyPxphL8esopopVm/d9wgD0xQ2Ocb2Nj6Jduuli0sm+dVBL
|
||||
3t2pldRq0hXZt/9qhu38tF41TlKSpCz2oFyx2D6ObLSX0MeFp6zXM0c1lGqSCDIM
|
||||
ubk=
|
||||
-----END CERTIFICATE-----
|
29
tests/standalone/io/certificates/untrusted_server_key.pem
Normal file
29
tests/standalone/io/certificates/untrusted_server_key.pem
Normal file
|
@ -0,0 +1,29 @@
|
|||
-----BEGIN ENCRYPTED PRIVATE KEY-----
|
||||
MIIE5TAcBgoqhkiG9w0BDAEBMA4ECI8YmURjepD4AgIIAASCBMMwp7gfo4FvSVuR
|
||||
5w7+OcjkXNQmvrwTRFDaMWV3ORgVFMQx02Q325SnoQsmulB+dk19uj2Piel5j/+j
|
||||
xHLvC0rBQC8BjHg/uLmN/f9yW6qolDthmeJEad/L8slB7rziilOGmlPh7H1voJgr
|
||||
94uoTn6L2tE9GfoPDsksedRtGIlgSOM3UmLvCkCMcZBqrDi4uqzbhrW3bIbqdoeo
|
||||
1lbNsvFuNzF+P3cBHyUUZpPGwCZ8M/XCsCAB+9eH7TM2FJnbuffA6BfkanpQR0ul
|
||||
PLo5KDjcS5lQ4YUkI2+lYMSZMiIf50Y8eHP0QnDAuYunA2cPLd90rPpdBCgNtQqk
|
||||
aUI7FHvtLFZsTJ1s8EPnZhZOZq1LYUTFQuimMWz+nvC0oQy925brwyjfnrm44KS7
|
||||
xpJqsYMBHYflDCwE4LbxjFSeneOy4wwNMurupSdcLCm02Sm1wUMrzRrNsAy3jxP6
|
||||
TfJjHRBSt3XEDwDG3olQoK/Ewa1qP0JhAZOd7SrKw9eLQltH+djy0iDUblf5uIHj
|
||||
pDC+T1pY9tTwSVxhsJI5a0qxXYNgdaxhr0Fv8BbdScd8Tzdw7g4AByjvgCKArlNJ
|
||||
alR1ZaJP/JYuzb3VH8uXEO4b6Tjqw9O4tkZGrc8He5HTAOnSZKbclDxyRH8hkDy+
|
||||
apIJUjbE3Gc1mCbyo2nc6WDrGfQNrXDWAVIz4/lb8e8P5k1Rex4rVNhb/VA0Vh4m
|
||||
T2BSQ3pvZtKTFedvWgIFIk85rVaYyuB7Icb0YLs2cPppMCfbv+6bOMkJ4hVk5tbX
|
||||
AGk6FOjgqsQSY/gzDo9ReCJooETP2AmvHEi2b7LKs+M0Pw+CfvKD/dOkQp62WMpt
|
||||
vZJVSXIQ2bHarbhxmUxcT//G+i3QBgkM2xTRvARfRMBiCoBh0Ta3gd4/GJDwv8pr
|
||||
pkJi3Q6u88NfGG0eyYyHz+kqTtptqJj1hbAFPdt6d6sFL/wpwhK/L5MOECQ3m100
|
||||
N3/aGT7yizM0w/m6PSycSbXycRafRF3XNMBXsUWeFpSWxpJV9GH+T3z8k46GrsM6
|
||||
c3YrLG6nvmersDI2AuS9KuhIQQvp+sgwjt3HeURsDv3X4edgCILRTjv3nVuU+DGD
|
||||
Xd8CuPYmRei4eJ4nkzxY6fM7ticuArnyE+INVtA0T8yL4UbRxQV/f9jOZWJ1LXLr
|
||||
caxCOZP9YcDVG9JUK4WGUC3LVWfhJW+i51cLJk9iGZ8qDLSvgJhj+/7Ajsg6/4xO
|
||||
IPon0DVMD9jgMSWLdfpCPawyY+VLVH2CXB2z83c2818gAs85QGUlsW+xLkELSTIU
|
||||
6p+mtTF5B2IhsjEdMDAWOpAp/Gj/U9OKapTyE1sGxn66jG/UvxcgYqZo3JGjNaDE
|
||||
rMnBhOH4VQQ+FxCA6lXKYCcU1UEze5BuCzJCA7gmCceMlMe+1Car2F+nJCuLNtzB
|
||||
uJhlXDbIVhMb5cZBBd3LSjmuRZ/gWbMvV3UqoCROBXqLzVGTufpcn/MgYQKYYHkp
|
||||
I+vKDypj0a4IPovDdxg8aMKNn59mtvmMDyrt0716H9DP4SCU/nuxVSeT/HywRBo/
|
||||
53fxqtdH3hTAUXqcOLzHnvLUENiABKMeJOtGTV9MFCxgGsnzgYNXnB9hDhm84+IX
|
||||
JQdMjj+BNFE6
|
||||
-----END ENCRYPTED PRIVATE KEY-----
|
51
tests/standalone/io/client_socket_add_close_error_test.dart
Normal file
51
tests/standalone/io/client_socket_add_close_error_test.dart
Normal file
|
@ -0,0 +1,51 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Tests socket exceptions.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void clientSocketAddCloseErrorTest() {
|
||||
asyncStart();
|
||||
ServerSocket.bind("127.0.0.1", 0).then((server) {
|
||||
var completer = new Completer();
|
||||
server.listen((socket) {
|
||||
completer.future.then((_) => socket.destroy());
|
||||
});
|
||||
Socket.connect("127.0.0.1", server.port).then((client) {
|
||||
const int SIZE = 1024 * 1024;
|
||||
int errors = 0;
|
||||
client.listen((data) => Expect.fail("Unexpected data"), onError: (error) {
|
||||
Expect.isTrue(error is SocketException);
|
||||
errors++;
|
||||
}, onDone: () {
|
||||
// We get either a close or an error followed by a close
|
||||
// on the socket. Whether we get both depends on
|
||||
// whether the system notices the error for the read
|
||||
// event or only for the write event.
|
||||
Expect.isTrue(errors <= 1);
|
||||
server.close();
|
||||
});
|
||||
client.add(new List.filled(SIZE, 0));
|
||||
// Destroy other socket now.
|
||||
completer.complete(null);
|
||||
client.done.then((_) {
|
||||
Expect.fail("Expected error");
|
||||
}, onError: (error) {
|
||||
Expect.isTrue(error is SocketException);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncStart();
|
||||
clientSocketAddCloseErrorTest();
|
||||
asyncEnd();
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Tests socket exceptions.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void clientSocketAddCloseNoErrorTest() {
|
||||
ServerSocket.bind("127.0.0.1", 0).then((server) {
|
||||
var completer = new Completer();
|
||||
server.listen((socket) {
|
||||
// The socket is 'paused' until the future completes.
|
||||
completer.future.then((_) => socket.cast<List<int>>().pipe(socket));
|
||||
});
|
||||
Socket.connect("127.0.0.1", server.port).then((client) {
|
||||
const int SIZE = 1024 * 1024;
|
||||
int count = 0;
|
||||
client.listen((data) => count += data.length, onDone: () {
|
||||
Expect.equals(SIZE, count);
|
||||
server.close();
|
||||
});
|
||||
client.add(new List.filled(SIZE, 0));
|
||||
client.close();
|
||||
// Start piping now.
|
||||
completer.complete(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncStart();
|
||||
clientSocketAddCloseNoErrorTest();
|
||||
asyncEnd();
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Tests socket exceptions.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void clientSocketAddCloseResultErrorTest() {
|
||||
ServerSocket.bind("127.0.0.1", 0).then((server) {
|
||||
var completer = new Completer();
|
||||
server.listen((socket) {
|
||||
completer.future.then((_) => socket.destroy());
|
||||
});
|
||||
Socket.connect("127.0.0.1", server.port).then((client) {
|
||||
const int SIZE = 1024 * 1024;
|
||||
int errors = 0;
|
||||
client.add(new List.filled(SIZE, 0));
|
||||
client.close();
|
||||
client.done.catchError((_) {}).whenComplete(() {
|
||||
server.close();
|
||||
});
|
||||
// Destroy other socket now.
|
||||
completer.complete(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncStart();
|
||||
clientSocketAddCloseResultErrorTest();
|
||||
asyncEnd();
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Tests socket exceptions.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void clientSocketAddDestroyNoErrorTest() {
|
||||
ServerSocket.bind("127.0.0.1", 0).then((server) {
|
||||
server.listen((socket) {
|
||||
// Passive block data by not subscribing to socket.
|
||||
});
|
||||
Socket.connect("127.0.0.1", server.port).then((client) {
|
||||
client.listen((data) {}, onDone: server.close);
|
||||
client.add(new List.filled(1024 * 1024, 0));
|
||||
client.destroy();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncStart();
|
||||
clientSocketAddDestroyNoErrorTest();
|
||||
asyncEnd();
|
||||
}
|
29
tests/standalone/io/client_socket_destory_no_error_test.dart
Normal file
29
tests/standalone/io/client_socket_destory_no_error_test.dart
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Tests socket exceptions.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void clientSocketDestroyNoErrorTest() {
|
||||
ServerSocket.bind("127.0.0.1", 0).then((server) {
|
||||
server.listen((socket) {
|
||||
socket.cast<List<int>>().pipe(socket);
|
||||
});
|
||||
Socket.connect("127.0.0.1", server.port).then((client) {
|
||||
client.listen((data) {}, onDone: server.close);
|
||||
client.destroy();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncStart();
|
||||
clientSocketDestroyNoErrorTest();
|
||||
asyncEnd();
|
||||
}
|
104
tests/standalone/io/client_socket_exception_test.dart
Normal file
104
tests/standalone/io/client_socket_exception_test.dart
Normal file
|
@ -0,0 +1,104 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Tests socket exceptions.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void clientSocketExceptionTest() {
|
||||
bool exceptionCaught = false;
|
||||
bool wrongExceptionCaught = false;
|
||||
|
||||
ServerSocket.bind("127.0.0.1", 0).then((server) {
|
||||
Expect.isNotNull(server);
|
||||
int port = server.port;
|
||||
Socket.connect("127.0.0.1", port).then((client) {
|
||||
Expect.isNotNull(client);
|
||||
client.close();
|
||||
// First calls for which exceptions are note expected.
|
||||
try {
|
||||
client.close();
|
||||
} on SocketException catch (ex) {
|
||||
exceptionCaught = true;
|
||||
} catch (ex) {
|
||||
wrongExceptionCaught = true;
|
||||
}
|
||||
Expect.isFalse(exceptionCaught);
|
||||
Expect.isFalse(wrongExceptionCaught);
|
||||
try {
|
||||
client.destroy();
|
||||
} on SocketException catch (ex) {
|
||||
exceptionCaught = true;
|
||||
} catch (ex) {
|
||||
wrongExceptionCaught = true;
|
||||
}
|
||||
Expect.isFalse(exceptionCaught);
|
||||
Expect.isFalse(wrongExceptionCaught);
|
||||
try {
|
||||
List<int> buffer = new List<int>.filled(10, 0);
|
||||
client.add(buffer);
|
||||
} on StateError catch (ex) {
|
||||
exceptionCaught = true;
|
||||
} catch (ex) {
|
||||
wrongExceptionCaught = true;
|
||||
}
|
||||
Expect.isTrue(exceptionCaught);
|
||||
Expect.isFalse(wrongExceptionCaught);
|
||||
|
||||
// From here exceptions are expected.
|
||||
exceptionCaught = false;
|
||||
try {
|
||||
client.port;
|
||||
} on SocketException catch (ex) {
|
||||
exceptionCaught = true;
|
||||
} catch (ex) {
|
||||
wrongExceptionCaught = true;
|
||||
}
|
||||
Expect.isTrue(exceptionCaught);
|
||||
Expect.isFalse(wrongExceptionCaught);
|
||||
exceptionCaught = false;
|
||||
try {
|
||||
client.remotePort;
|
||||
} on SocketException catch (ex) {
|
||||
exceptionCaught = true;
|
||||
} catch (ex) {
|
||||
wrongExceptionCaught = true;
|
||||
}
|
||||
Expect.isTrue(exceptionCaught);
|
||||
Expect.isFalse(wrongExceptionCaught);
|
||||
exceptionCaught = false;
|
||||
try {
|
||||
client.address;
|
||||
} on SocketException catch (ex) {
|
||||
exceptionCaught = true;
|
||||
} catch (ex) {
|
||||
wrongExceptionCaught = true;
|
||||
}
|
||||
Expect.isTrue(exceptionCaught);
|
||||
Expect.isFalse(wrongExceptionCaught);
|
||||
exceptionCaught = false;
|
||||
try {
|
||||
client.remoteAddress;
|
||||
} on SocketException catch (ex) {
|
||||
exceptionCaught = true;
|
||||
} catch (ex) {
|
||||
wrongExceptionCaught = true;
|
||||
}
|
||||
Expect.isTrue(exceptionCaught);
|
||||
Expect.isFalse(wrongExceptionCaught);
|
||||
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncStart();
|
||||
clientSocketExceptionTest();
|
||||
asyncEnd();
|
||||
}
|
12
tests/standalone/io/compile_all_test.dart
Normal file
12
tests/standalone/io/compile_all_test.dart
Normal file
|
@ -0,0 +1,12 @@
|
|||
// 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.
|
||||
//
|
||||
// Test that ensures that the VM can compile all the code in the dart:io
|
||||
// library.
|
||||
//
|
||||
// VMOptions=--compile_all
|
||||
|
||||
import "dart:io";
|
||||
|
||||
main() => null;
|
34
tests/standalone/io/console_unicode_test.dart
Normal file
34
tests/standalone/io/console_unicode_test.dart
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2017, 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.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
// This test ensures that the VM will support string literals that have non
|
||||
// ascii characters. An unhandeld exception will be thrown if the VM fails
|
||||
// to support non ascii characters.
|
||||
|
||||
main() {
|
||||
String canary = "Canary";
|
||||
String spades = "These are three black spades: ♠♠♠";
|
||||
String german = "German characters: aäbcdefghijklmnoöpqrsßtuüvwxyz";
|
||||
|
||||
stdout.writeln(canary);
|
||||
stdout.writeln(spades);
|
||||
stdout.writeln(german);
|
||||
print(spades);
|
||||
print(german);
|
||||
|
||||
stdout.add(canary.runes.toList());
|
||||
stdout.writeln();
|
||||
|
||||
stdout.writeln(canary);
|
||||
stdout.writeln(spades);
|
||||
stdout.writeln(german);
|
||||
print(spades);
|
||||
print(german);
|
||||
|
||||
stdout.add(canary.codeUnits);
|
||||
stdout.writeln();
|
||||
}
|
140
tests/standalone/io/create_recursive_test.dart
Normal file
140
tests/standalone/io/create_recursive_test.dart
Normal file
|
@ -0,0 +1,140 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
import "package:path/path.dart";
|
||||
|
||||
main() {
|
||||
testCreateDirectoryRecursiveSync();
|
||||
testCreateLinkRecursiveSync();
|
||||
testCreateFileRecursiveSync();
|
||||
testCreateDirectoryRecursive();
|
||||
testCreateLinkRecursive();
|
||||
testCreateFileRecursive();
|
||||
}
|
||||
|
||||
testCreateDirectoryRecursiveSync() {
|
||||
var temp = Directory.systemTemp.createTempSync('directory_test');
|
||||
try {
|
||||
var dir = new Directory(join(temp.path, 'a', 'b', 'c'));
|
||||
Expect.throws(() => dir.createSync());
|
||||
dir.createSync(recursive: true);
|
||||
Expect.isTrue(dir.existsSync());
|
||||
// Test cases where the directory or parent directory already exists.
|
||||
dir.deleteSync();
|
||||
dir.createSync(recursive: true);
|
||||
Expect.isTrue(dir.existsSync());
|
||||
dir.createSync(recursive: true);
|
||||
Expect.isTrue(dir.existsSync());
|
||||
} finally {
|
||||
temp.deleteSync(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
testCreateFileRecursiveSync() {
|
||||
var temp = Directory.systemTemp.createTempSync('directory_test');
|
||||
try {
|
||||
var file = new File(join(temp.path, 'a', 'b', 'c'));
|
||||
Expect.throws(() => file.createSync());
|
||||
file.createSync(recursive: true);
|
||||
Expect.isTrue(file.existsSync());
|
||||
// Test cases where the file or parent directory already exists.
|
||||
file.deleteSync();
|
||||
file.createSync(recursive: true);
|
||||
Expect.isTrue(file.existsSync());
|
||||
file.createSync(recursive: true);
|
||||
Expect.isTrue(file.existsSync());
|
||||
} finally {
|
||||
temp.deleteSync(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
testCreateLinkRecursiveSync() {
|
||||
var temp = Directory.systemTemp.createTempSync('directory_test');
|
||||
try {
|
||||
var link = new Link(join(temp.path, 'a', 'b', 'c'));
|
||||
Expect.throws(() => link.createSync(temp.path));
|
||||
link.createSync(temp.path, recursive: true);
|
||||
Expect.isTrue(link.existsSync());
|
||||
Expect.isTrue(new Directory(link.targetSync()).existsSync());
|
||||
// Test cases where the link or parent directory already exists.
|
||||
link.deleteSync();
|
||||
link.createSync(temp.path, recursive: true);
|
||||
Expect.isTrue(link.existsSync());
|
||||
Expect.throws(() => link.createSync(temp.path, recursive: true));
|
||||
Expect.isTrue(link.existsSync());
|
||||
} finally {
|
||||
temp.deleteSync(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
Future expectFutureIsTrue(Future future) =>
|
||||
future.then((value) => Expect.isTrue(value));
|
||||
|
||||
Future expectFileSystemException(Function f, String message) {
|
||||
return f().then(
|
||||
(_) => Expect.fail('Expected a FileSystemException: $message'),
|
||||
onError: (e) => Expect.isTrue(e is FileSystemException));
|
||||
}
|
||||
|
||||
testCreateDirectoryRecursive() {
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_directory').then((temp) {
|
||||
var dir = new Directory(join(temp.path, 'a', 'b', 'c'));
|
||||
return expectFileSystemException(() => dir.create(), 'dir.create')
|
||||
.then((_) => dir.create(recursive: true))
|
||||
.then((_) => expectFutureIsTrue(dir.exists()))
|
||||
// Test cases where the directory or parent directory already exists.
|
||||
.then((_) => dir.delete())
|
||||
.then((_) => dir.create(recursive: true))
|
||||
.then((_) => expectFutureIsTrue(dir.exists()))
|
||||
.then((_) => dir.create(recursive: true))
|
||||
.then((_) => expectFutureIsTrue(dir.exists()))
|
||||
.then((_) => asyncEnd())
|
||||
.whenComplete(() => temp.delete(recursive: true));
|
||||
});
|
||||
}
|
||||
|
||||
testCreateFileRecursive() {
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_directory').then((temp) {
|
||||
var file = new File(join(temp.path, 'a', 'b', 'c'));
|
||||
return expectFileSystemException(() => file.create(), 'file.create')
|
||||
.then((_) => file.create(recursive: true))
|
||||
.then((_) => expectFutureIsTrue(file.exists()))
|
||||
// Test cases where the file or parent directory already exists.
|
||||
.then((_) => file.delete())
|
||||
.then((_) => file.create(recursive: true))
|
||||
.then((_) => expectFutureIsTrue(file.exists()))
|
||||
.then((_) => file.create(recursive: true))
|
||||
.then((_) => expectFutureIsTrue(file.exists()))
|
||||
.then((_) => asyncEnd())
|
||||
.whenComplete(() => temp.delete(recursive: true));
|
||||
});
|
||||
}
|
||||
|
||||
testCreateLinkRecursive() {
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_directory').then((temp) {
|
||||
var link = new Link(join(temp.path, 'a', 'b', 'c'));
|
||||
return expectFileSystemException(
|
||||
() => link.create(temp.path), 'link.create')
|
||||
.then((_) => link.create(temp.path, recursive: true))
|
||||
.then((_) => expectFutureIsTrue(link.exists()))
|
||||
// Test cases where the link or parent directory already exists.
|
||||
.then((_) => link.delete())
|
||||
.then((_) => link.create(temp.path, recursive: true))
|
||||
.then((_) => expectFutureIsTrue(link.exists()))
|
||||
.then((_) => expectFileSystemException(
|
||||
() => link.create(temp.path, recursive: true),
|
||||
'existing link.create'))
|
||||
.then((_) => expectFutureIsTrue(link.exists()))
|
||||
.then((_) => asyncEnd())
|
||||
.whenComplete(() => temp.delete(recursive: true));
|
||||
});
|
||||
}
|
117
tests/standalone/io/create_sample_certificates.sh
Executable file
117
tests/standalone/io/create_sample_certificates.sh
Executable file
|
@ -0,0 +1,117 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2015, 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.
|
||||
|
||||
# Script to create sample certificates for the dart:io SecureSocket tests.
|
||||
# Creates a root certificate authority, an intermediate authority,
|
||||
# and a server certificate,
|
||||
|
||||
password=pass:dartdart
|
||||
|
||||
# We need a server certificate chain where we don't trust the root. Take the
|
||||
# server certificate from the previous run of this script, for that purpose.
|
||||
if [ -d "certificates" ]; then
|
||||
mv certificates/server_key.pem certificates/untrusted_server_key.pem
|
||||
mv certificates/server_chain.pem certificates/untrusted_server_chain.pem
|
||||
else
|
||||
mkdir certificates
|
||||
fi
|
||||
|
||||
mkdir -p certificate_authority
|
||||
cd certificate_authority
|
||||
|
||||
# Create a self-signed certificate authority.
|
||||
openssl req -subj /CN=rootauthority -set_serial 1 -batch -verbose \
|
||||
-passout $password -new -x509 -keyout root_authority_key.pem \
|
||||
-out root_authority.pem -days 3650
|
||||
|
||||
# Create a certificate request for the intermediate authority.
|
||||
openssl req -subj /CN=intermediateauthority -batch -verbose \
|
||||
-passout $password -new -keyout intermediate_authority_key.pem \
|
||||
-out intermediate_authority_request.pem
|
||||
|
||||
# Sign the certificate of the intermediate authority with the root authority.
|
||||
# Add the certificate extensions marking it as a certificate authority.
|
||||
openssl x509 -req -in intermediate_authority_request.pem \
|
||||
-out intermediate_authority.pem -set_serial 2 \
|
||||
-CA root_authority.pem -CAkey root_authority_key.pem \
|
||||
-passin $password -extfile ../sample_certificate_v3_extensions \
|
||||
-extensions intermediate_authority -days 3650
|
||||
|
||||
# Create a certificate request for the server certificate
|
||||
openssl req -subj /CN=localhost -batch -verbose -passout $password -new \
|
||||
-keyout localhost_key.pem -out localhost_request.pem
|
||||
|
||||
openssl req -subj /CN=badlocalhost -batch -verbose -passout $password -new \
|
||||
-keyout badlocalhost_key.pem -out badlocalhost_request.pem
|
||||
|
||||
# Sign the server certificate with the intermediate authority. Add the
|
||||
# certificate extensions for SubjectAltName and that it is not a CA itself.
|
||||
openssl x509 -req -in localhost_request.pem -out localhost.pem -set_serial 1 \
|
||||
-CA intermediate_authority.pem -CAkey intermediate_authority_key.pem \
|
||||
-passin $password -extfile ../sample_certificate_v3_extensions \
|
||||
-extensions localhost -days 3650
|
||||
|
||||
openssl x509 -req -in badlocalhost_request.pem -out badlocalhost.pem -set_serial 1 \
|
||||
-CA intermediate_authority.pem -CAkey intermediate_authority_key.pem \
|
||||
-passin $password -extfile ../sample_certificate_v3_extensions \
|
||||
-extensions badlocalhost -days 3650
|
||||
|
||||
# Create a self-signed client certificate authority.
|
||||
openssl req -subj /CN=clientauthority -set_serial 1 -batch -verbose \
|
||||
-passout $password -new -x509 -keyout client_authority_key.pem \
|
||||
-out client_authority.pem -config ../sample_certificate_v3_extensions \
|
||||
-extensions client_authority -days 3650
|
||||
|
||||
# Create certificate requests for the client certificates
|
||||
openssl req -subj /CN=user1 -batch -verbose -passout $password -new \
|
||||
-keyout client1_key.pem -out client1_request.pem
|
||||
openssl req -subj /CN=user2 -batch -verbose -passout $password -new \
|
||||
-keyout client2_key.pem -out client2_request.pem
|
||||
|
||||
# Sign the certificate requests with the client authority
|
||||
openssl x509 -req -in client1_request.pem -out client1.pem -set_serial 2 \
|
||||
-CA client_authority.pem -CAkey client_authority_key.pem \
|
||||
-passin $password -extfile ../sample_certificate_v3_extensions \
|
||||
-extensions client_certificate -days 3650
|
||||
openssl x509 -req -in client2_request.pem -out client2.pem -set_serial 3 \
|
||||
-CA client_authority.pem -CAkey client_authority_key.pem \
|
||||
-passin $password -extfile ../sample_certificate_v3_extensions \
|
||||
-extensions client_certificate -days 3650
|
||||
|
||||
# Copy the certificates we will use to the 'certificates' directory.
|
||||
CERTS=../certificates
|
||||
cat localhost.pem intermediate_authority.pem root_authority.pem \
|
||||
> $CERTS/server_chain.pem
|
||||
|
||||
cat badlocalhost.pem intermediate_authority.pem root_authority.pem \
|
||||
> $CERTS/bad_server_chain.pem
|
||||
|
||||
cat intermediate_authority.pem root_authority.pem client_authority.pem \
|
||||
> $CERTS/server_trusted.pem
|
||||
|
||||
# BoringSSL only accepts private keys signed with the PBE-SHA1-RC4-128 cipher.
|
||||
openssl pkcs8 -in localhost_key.pem -out $CERTS/server_key.pem \
|
||||
-topk8 -v1 PBE-SHA1-RC4-128 -passin $password -passout $password
|
||||
openssl pkcs8 -in badlocalhost_key.pem -out $CERTS/bad_server_key.pem \
|
||||
-topk8 -v1 PBE-SHA1-RC4-128 -passin $password -passout $password
|
||||
openssl pkcs8 -in client1_key.pem -out $CERTS/client1_key.pem \
|
||||
-topk8 -v1 PBE-SHA1-RC4-128 -passin $password -passout $password
|
||||
openssl pkcs8 -in client2_key.pem -out $CERTS/client2_key.pem \
|
||||
-topk8 -v1 PBE-SHA1-RC4-128 -passin $password -passout $password
|
||||
|
||||
# Delete all the signing keys for the authorities, so testers that add
|
||||
# them as trusted are less vulnerable: only the sample server certificate
|
||||
# and client certificates will be signed by them. No more certificates
|
||||
# will ever be signed.
|
||||
rm root_authority_key.pem
|
||||
rm intermediate_authority.pem
|
||||
rm client_authority_key.pem
|
||||
|
||||
cp root_authority.pem $CERTS/trusted_certs.pem
|
||||
cp client_authority.pem $CERTS
|
||||
cp client1.pem $CERTS
|
||||
cp client2.pem $CERTS
|
||||
|
||||
cd ..
|
34
tests/standalone/io/dart_std_io_pipe_script.dart
Normal file
34
tests/standalone/io/dart_std_io_pipe_script.dart
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Utility script to echo stdin to stdout or stderr or both.
|
||||
|
||||
import "dart:io";
|
||||
|
||||
main(List<String> arguments) {
|
||||
if (stdioType(stdin) is! StdioType) exit(1);
|
||||
if (stdioType(stdout) is! StdioType) exit(1);
|
||||
if (stdioType(stderr) is! StdioType) exit(1);
|
||||
if (stdioType(stdin).name != arguments[1]) {
|
||||
throw stdioType(stdin).name;
|
||||
}
|
||||
if (stdioType(stdout).name != arguments[2]) {
|
||||
throw stdioType(stdout).name;
|
||||
}
|
||||
if (stdioType(stderr).name != arguments[3]) {
|
||||
throw stdioType(stderr).name;
|
||||
}
|
||||
if (arguments.length > 0) {
|
||||
if (arguments[0] == "0") {
|
||||
stdin.pipe(stdout);
|
||||
} else if (arguments[0] == "1") {
|
||||
stdin.pipe(stderr);
|
||||
} else if (arguments[0] == "2") {
|
||||
stdin.listen((data) {
|
||||
stdout.add(data);
|
||||
stderr.add(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
127
tests/standalone/io/dart_std_io_pipe_test.dart
Normal file
127
tests/standalone/io/dart_std_io_pipe_test.dart
Normal file
|
@ -0,0 +1,127 @@
|
|||
// 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.
|
||||
//
|
||||
// Test a dart sub-process handling stdio with different types of
|
||||
// redirection.
|
||||
//
|
||||
// VMOptions=
|
||||
// VMOptions=--short_socket_read
|
||||
// VMOptions=--short_socket_write
|
||||
// VMOptions=--short_socket_read --short_socket_write
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "dart:io";
|
||||
import "process_test_util.dart";
|
||||
|
||||
void checkFileEmpty(String fileName) {
|
||||
RandomAccessFile pipeOut = new File(fileName).openSync();
|
||||
Expect.equals(0, pipeOut.lengthSync());
|
||||
pipeOut.closeSync();
|
||||
}
|
||||
|
||||
void checkFileContent(String fileName, String content) {
|
||||
RandomAccessFile pipeOut = new File(fileName).openSync();
|
||||
int length = pipeOut.lengthSync();
|
||||
var data = new List<int>.filled(length, 0);
|
||||
pipeOut.readIntoSync(data, 0, length);
|
||||
Expect.equals(content, new String.fromCharCodes(data));
|
||||
pipeOut.closeSync();
|
||||
}
|
||||
|
||||
void test(String shellScript, String dartScript, String type, bool devNull) {
|
||||
Directory dir = Directory.systemTemp.createTempSync('dart_dart_std_io_pipe');
|
||||
|
||||
// The shell script will run the dart executable passed with a
|
||||
// number of different redirections of stdio.
|
||||
String pipeOutFile = "${dir.path}/pipe";
|
||||
if (devNull) pipeOutFile = "/dev/null";
|
||||
String redirectOutFile = "${dir.path}/redirect";
|
||||
String executable = Platform.executable;
|
||||
List<String> args = [
|
||||
([executable]..addAll(Platform.executableArguments)).join(' '),
|
||||
dartScript,
|
||||
type,
|
||||
pipeOutFile,
|
||||
redirectOutFile,
|
||||
devNull ? "terminal" : "file"
|
||||
];
|
||||
var future = Process.start(shellScript, args);
|
||||
future.then((process) {
|
||||
process.exitCode.then((exitCode) {
|
||||
Expect.equals(0, exitCode);
|
||||
|
||||
// Check the expected file contents.
|
||||
if (type == "0") {
|
||||
if (devNull) {
|
||||
checkFileEmpty("${redirectOutFile}.stdout");
|
||||
} else {
|
||||
checkFileContent("${pipeOutFile}", "Hello\n");
|
||||
checkFileContent("${redirectOutFile}.stdout", "Hello\nHello\n");
|
||||
}
|
||||
checkFileEmpty("${redirectOutFile}.stderr");
|
||||
}
|
||||
if (type == "1") {
|
||||
if (devNull) {
|
||||
checkFileEmpty("${redirectOutFile}.stderr");
|
||||
} else {
|
||||
checkFileContent("${pipeOutFile}", "Hello\n");
|
||||
checkFileContent("${redirectOutFile}.stderr", "Hello\nHello\n");
|
||||
}
|
||||
checkFileEmpty("${redirectOutFile}.stdout");
|
||||
}
|
||||
if (type == "2") {
|
||||
if (devNull) {
|
||||
checkFileEmpty("${redirectOutFile}.stdout");
|
||||
checkFileEmpty("${redirectOutFile}.stderr");
|
||||
} else {
|
||||
checkFileContent("${pipeOutFile}", "Hello\nHello\n");
|
||||
checkFileContent(
|
||||
"${redirectOutFile}.stdout", "Hello\nHello\nHello\nHello\n");
|
||||
checkFileContent(
|
||||
"${redirectOutFile}.stderr", "Hello\nHello\nHello\nHello\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup test directory.
|
||||
dir.deleteSync(recursive: true);
|
||||
});
|
||||
// Drain out and err streams so they close.
|
||||
process.stdout.listen((_) {});
|
||||
process.stderr.listen((_) {});
|
||||
});
|
||||
future.catchError((error) {
|
||||
dir.deleteSync(recursive: true);
|
||||
Expect.fail(error.toString());
|
||||
});
|
||||
}
|
||||
|
||||
// This tests that the Dart standalone VM can handle piping to stdin
|
||||
// and can pipe to stdout.
|
||||
main() {
|
||||
// Don't try to run shell scripts on Windows.
|
||||
var os = Platform.operatingSystem;
|
||||
if (os == 'windows') return;
|
||||
|
||||
// Get the shell script for testing the Standalone Dart VM with
|
||||
// piping and redirections of stdio.
|
||||
var shellScript = new File("tests/standalone_2/io/dart_std_io_pipe_test.sh");
|
||||
if (!shellScript.existsSync()) {
|
||||
shellScript = new File("../tests/standalone_2/io/dart_std_io_pipe_test.sh");
|
||||
}
|
||||
// Get the Dart script file which echoes stdin to stdout or stderr or both.
|
||||
var scriptFile =
|
||||
new File("tests/standalone_2/io/dart_std_io_pipe_script.dart");
|
||||
if (!scriptFile.existsSync()) {
|
||||
scriptFile =
|
||||
new File("../tests/standalone_2/io/dart_std_io_pipe_script.dart");
|
||||
}
|
||||
|
||||
// Run the shell script.
|
||||
test(shellScript.path, scriptFile.path, "0", false); //# 01: ok
|
||||
test(shellScript.path, scriptFile.path, "0", true); //# 02: ok
|
||||
test(shellScript.path, scriptFile.path, "1", false); //# 03: ok
|
||||
test(shellScript.path, scriptFile.path, "1", true); //# 04: ok
|
||||
test(shellScript.path, scriptFile.path, "2", false); //# 05: ok
|
||||
test(shellScript.path, scriptFile.path, "2", true); //# 06: ok
|
||||
}
|
17
tests/standalone/io/dart_std_io_pipe_test.sh
Executable file
17
tests/standalone/io/dart_std_io_pipe_test.sh
Executable file
|
@ -0,0 +1,17 @@
|
|||
#! /bin/bash
|
||||
|
||||
# This script expects the following arguments
|
||||
# $1: Path to dart executable
|
||||
# $2: Path to dart echoing script
|
||||
# $3: Argument to dart echoing script (0, 1 or 2)
|
||||
# $4: File for output from piping stdout and stderr
|
||||
# $5: File prefix for output from redirecting stdout and stderr to a file.
|
||||
# $6: Stdio type of stdin
|
||||
|
||||
# Test piping and stdio file redirection.
|
||||
echo "Hello" | $1 $2 $3 pipe pipe pipe 2>&1 | cat - > $4
|
||||
$1 $2 $3 $6 file file < $4 > $5.stdout 2> $5.stderr
|
||||
$1 $2 $3 $6 file file < $4 >> $5.stdout 2>> $5.stderr
|
||||
$1 $2 $3 $6 terminal terminal < $4 > /dev/null 2> /dev/null
|
||||
$1 $2 $3 $6 terminal pipe < $4 2>&1 > /dev/null
|
||||
$1 $2 $3 $6 terminal terminal < $4 > /dev/null 2>&1
|
52
tests/standalone/io/delete_symlink_test.dart
Normal file
52
tests/standalone/io/delete_symlink_test.dart
Normal file
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void main() {
|
||||
// temp/
|
||||
// a/
|
||||
// file.txt
|
||||
// b/
|
||||
// a_link -> a
|
||||
var d = Directory.systemTemp.createTempSync('dart_delete_symlink');
|
||||
var a = new Directory("${d.path}/a");
|
||||
a.createSync();
|
||||
|
||||
var b = new Directory("${d.path}/b");
|
||||
b.createSync();
|
||||
|
||||
var f = new File("${d.path}/a/file.txt");
|
||||
f.createSync();
|
||||
Expect.isTrue(f.existsSync());
|
||||
|
||||
// Create a symlink (or junction on Windows) from
|
||||
// temp/b/a_link to temp/a.
|
||||
var cmd = "ln";
|
||||
var args = ['-s', "${d.path}/b/a_link", "${d.path}/a"];
|
||||
|
||||
if (Platform.operatingSystem == "windows") {
|
||||
cmd = "cmd";
|
||||
args = ["/c", "mklink", "/j", "${d.path}\\b\\a_link", "${d.path}\\a"];
|
||||
}
|
||||
|
||||
asyncStart();
|
||||
|
||||
Process.run(cmd, args).then((_) {
|
||||
// Delete the directory containing the junction.
|
||||
b.deleteSync(recursive: true);
|
||||
|
||||
// We should not have recursed through a_link into a.
|
||||
Expect.isTrue(f.existsSync());
|
||||
|
||||
// Clean up after ourselves.
|
||||
d.deleteSync(recursive: true);
|
||||
|
||||
// Terminate now that we are done with everything.
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
52
tests/standalone/io/directory_chdir_test.dart
Normal file
52
tests/standalone/io/directory_chdir_test.dart
Normal file
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Directory listing test.
|
||||
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
testChangeDirectory() {
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_directory_chdir').then((temp) {
|
||||
var initialCurrent = Directory.current;
|
||||
Directory.current = temp;
|
||||
var newCurrent = Directory.current;
|
||||
new File("111").createSync();
|
||||
var dir = new Directory(newCurrent.path + Platform.pathSeparator + "222");
|
||||
dir.createSync();
|
||||
Directory.current = dir;
|
||||
new File("333").createSync();
|
||||
Expect.isTrue(new File("333").existsSync());
|
||||
Expect.isTrue(new File("../111").existsSync());
|
||||
Directory.current = "..";
|
||||
Expect.isTrue(new File("111").existsSync());
|
||||
Expect.isTrue(new File("222/333").existsSync());
|
||||
// Deleting the current working directory causes an error.
|
||||
// On Windows, the deletion fails, and on non-Windows, the getter fails.
|
||||
Expect.throws(() {
|
||||
temp.deleteSync(recursive: true);
|
||||
Directory.current;
|
||||
}, (e) => e is FileSystemException);
|
||||
Directory.current = initialCurrent;
|
||||
Directory.current;
|
||||
if (temp.existsSync()) temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
testChangeDirectoryIllegalArguments() {
|
||||
Expect.throwsArgumentError(() => Directory.current = 1);
|
||||
Expect.throwsArgumentError(() => Directory.current = 9223372036854775807);
|
||||
Expect.throwsArgumentError(() => Directory.current = true);
|
||||
Expect.throwsArgumentError(() => Directory.current = []);
|
||||
Expect.throwsArgumentError(() => Directory.current = new File("xxx"));
|
||||
}
|
||||
|
||||
main() {
|
||||
testChangeDirectory();
|
||||
testChangeDirectoryIllegalArguments();
|
||||
}
|
46
tests/standalone/io/directory_create_race_test.dart
Normal file
46
tests/standalone/io/directory_create_race_test.dart
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Test for a race condition that can occur when recursively creating
|
||||
// a directory multiple times simultaneously. This consistently reproduces
|
||||
// issue https://code.google.com/p/dart/issues/detail?id=7679 in revisions
|
||||
// without the fix for this issue.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void testCreateRecursiveRace() {
|
||||
asyncStart();
|
||||
var temp = Directory.systemTemp.createTempSync('dart_directory_create_race');
|
||||
var d = new Directory('${temp.path}/a/b/c/d/e');
|
||||
Future.wait([
|
||||
d.create(recursive: true),
|
||||
d.create(recursive: true),
|
||||
d.create(recursive: true),
|
||||
d.create(recursive: true),
|
||||
d.create(recursive: true),
|
||||
d.create(recursive: true),
|
||||
d.create(recursive: true),
|
||||
d.create(recursive: true),
|
||||
d.create(recursive: true),
|
||||
d.create(recursive: true)
|
||||
]).then((_) {
|
||||
Expect.isTrue(new Directory('${temp.path}/a').existsSync());
|
||||
Expect.isTrue(new Directory('${temp.path}/a/b').existsSync());
|
||||
Expect.isTrue(new Directory('${temp.path}/a/b/c').existsSync());
|
||||
Expect.isTrue(new Directory('${temp.path}/a/b/c/d').existsSync());
|
||||
Expect.isTrue(new Directory('${temp.path}/a/b/c/d/e').existsSync());
|
||||
temp.delete(recursive: true).then((_) {
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
testCreateRecursiveRace();
|
||||
testCreateRecursiveRace();
|
||||
}
|
206
tests/standalone/io/directory_error_test.dart
Normal file
206
tests/standalone/io/directory_error_test.dart
Normal file
|
@ -0,0 +1,206 @@
|
|||
// 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.
|
||||
//
|
||||
// Dart test program for testing error handling in directory I/O.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
Directory tempDir() {
|
||||
return Directory.systemTemp.createTempSync('dart_directory_error');
|
||||
}
|
||||
|
||||
bool checkCreateInNonExistentFileSystemException(e) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
Expect.isTrue(e.osError != null);
|
||||
Expect.isTrue(e.toString().indexOf("Creation failed") != -1);
|
||||
if (Platform.operatingSystem == "linux") {
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
} else if (Platform.operatingSystem == "macos") {
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
} else if (Platform.operatingSystem == "windows") {
|
||||
Expect.equals(3, e.osError.errorCode);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void testCreateInNonExistent(Directory temp, Function done) {
|
||||
Directory inNonExistent = new Directory("${temp.path}/nonExistent/xxx");
|
||||
Expect.throws(() => inNonExistent.createSync(),
|
||||
(e) => checkCreateInNonExistentFileSystemException(e));
|
||||
|
||||
inNonExistent.create().catchError((error) {
|
||||
checkCreateInNonExistentFileSystemException(error);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
bool checkCreateTempInNonExistentFileSystemException(e) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
Expect.isTrue(e.osError != null);
|
||||
if (Platform.operatingSystem == "linux") {
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
} else if (Platform.operatingSystem == "macos") {
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
} else if (Platform.operatingSystem == "windows") {
|
||||
Expect.equals(3, e.osError.errorCode);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void testCreateTempInNonExistent(Directory temp, Function done) {
|
||||
Directory nonExistent = new Directory("${temp.path}/nonExistent/xxx");
|
||||
Expect.throws(() => nonExistent.createTempSync('tempdir'),
|
||||
(e) => checkCreateTempInNonExistentFileSystemException(e));
|
||||
|
||||
nonExistent.createTemp('tempdir').catchError((error) {
|
||||
checkCreateTempInNonExistentFileSystemException(error);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
bool checkDeleteNonExistentFileSystemException(e) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
Expect.isTrue(e.osError != null);
|
||||
// File not not found has error code 2 on all supported platforms.
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void testDeleteNonExistent(Directory temp, Function done) {
|
||||
Directory nonExistent = new Directory("${temp.path}/nonExistent");
|
||||
Expect.throws(() => nonExistent.deleteSync(),
|
||||
(e) => checkDeleteNonExistentFileSystemException(e));
|
||||
|
||||
nonExistent.delete().catchError((error) {
|
||||
checkDeleteNonExistentFileSystemException(error);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
bool checkDeleteRecursivelyNonExistentFileSystemException(e) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
Expect.isTrue(e.osError != null);
|
||||
Expect.isTrue(e.toString().indexOf("Deletion failed") != -1);
|
||||
// File not not found has error code 2 on all supported platforms.
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void testDeleteRecursivelyNonExistent(Directory temp, Function done) {
|
||||
Directory nonExistent = new Directory("${temp.path}/nonExistent");
|
||||
Expect.throws(() => nonExistent.deleteSync(recursive: true),
|
||||
(e) => checkDeleteRecursivelyNonExistentFileSystemException(e));
|
||||
|
||||
nonExistent.delete(recursive: true).catchError((error) {
|
||||
checkDeleteRecursivelyNonExistentFileSystemException(error);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
bool checkListNonExistentFileSystemException(e) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
Expect.isTrue(e.osError != null);
|
||||
Expect.isTrue(e.toString().indexOf("Directory listing failed") != -1);
|
||||
if (Platform.operatingSystem == "linux") {
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
} else if (Platform.operatingSystem == "macos") {
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
} else if (Platform.operatingSystem == "windows") {
|
||||
Expect.equals(3, e.osError.errorCode);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkAsyncListNonExistentFileSystemException(error) {
|
||||
return checkListNonExistentFileSystemException(error);
|
||||
}
|
||||
|
||||
void testListNonExistent(Directory temp, Function done) {
|
||||
Directory nonExistent = new Directory("${temp.path}/nonExistent");
|
||||
Expect.throws(() => nonExistent.listSync(), (e) => e is FileSystemException);
|
||||
nonExistent.list().listen((_) => Expect.fail("listing should not succeed"),
|
||||
onError: (e) {
|
||||
checkAsyncListNonExistentFileSystemException(e);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
void testRenameNonExistent(Directory temp, Function done) {
|
||||
Directory nonExistent = new Directory("${temp.path}/nonExistent");
|
||||
var newPath = "${temp.path}/nonExistent2";
|
||||
Expect.throws(
|
||||
() => nonExistent.renameSync(newPath), (e) => e is FileSystemException);
|
||||
var renameDone = nonExistent.rename(newPath);
|
||||
renameDone
|
||||
.then((ignore) => Expect.fail('rename non existent'))
|
||||
.catchError((error) {
|
||||
Expect.isTrue(error is FileSystemException);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
void testRenameFileAsDirectory(Directory temp, Function done) {
|
||||
File f = new File("${temp.path}/file");
|
||||
var newPath = "${temp.path}/file2";
|
||||
f.createSync();
|
||||
var d = new Directory(f.path);
|
||||
Expect.throws(() => d.renameSync(newPath), (e) => e is FileSystemException);
|
||||
var renameDone = d.rename(newPath);
|
||||
renameDone
|
||||
.then((ignore) => Expect.fail('rename file as directory'))
|
||||
.catchError((error) {
|
||||
Expect.isTrue(error is FileSystemException);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
testRenameOverwriteFile(Directory temp, Function done) {
|
||||
var temp1 = Directory.systemTemp.createTempSync('dart_directory_error');
|
||||
var fileName = '${temp.path}/x';
|
||||
new File(fileName).createSync();
|
||||
Expect.throws(
|
||||
() => temp1.renameSync(fileName), (e) => e is FileSystemException);
|
||||
var renameDone = temp1.rename(fileName);
|
||||
renameDone
|
||||
.then((ignore) => Expect.fail('rename dir overwrite file'))
|
||||
.catchError((error) {
|
||||
Expect.isTrue(error is FileSystemException);
|
||||
temp1.deleteSync(recursive: true);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
void runTest(Function test) {
|
||||
// Create a temporary directory for the test.
|
||||
var temp = Directory.systemTemp.createTempSync('dart_directory_error');
|
||||
|
||||
// Wait for the test to finish and delete the temporary directory.
|
||||
asyncStart();
|
||||
|
||||
// Run the test.
|
||||
test(temp, () {
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
runTest(testCreateInNonExistent);
|
||||
runTest(testCreateTempInNonExistent);
|
||||
runTest(testDeleteNonExistent);
|
||||
runTest(testDeleteRecursivelyNonExistent);
|
||||
runTest(testListNonExistent);
|
||||
runTest(testRenameNonExistent);
|
||||
runTest(testRenameFileAsDirectory);
|
||||
runTest(testRenameOverwriteFile);
|
||||
}
|
81
tests/standalone/io/directory_fuzz_test.dart
Normal file
81
tests/standalone/io/directory_fuzz_test.dart
Normal file
|
@ -0,0 +1,81 @@
|
|||
// 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.
|
||||
|
||||
// 'fuzz' test the directory APIs by providing unexpected type
|
||||
// arguments. The test passes if the VM does not crash.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
import 'fuzz_support.dart';
|
||||
|
||||
fuzzSyncMethods() {
|
||||
typeMapping.forEach((k, v) {
|
||||
doItSync(() {
|
||||
Directory.systemTemp.createTempSync(v as String?).deleteSync();
|
||||
});
|
||||
late Directory d;
|
||||
doItSync(() => d = new Directory(v as String));
|
||||
if (d == null) return;
|
||||
doItSync(d.existsSync);
|
||||
doItSync(d.createSync);
|
||||
doItSync(d.deleteSync);
|
||||
doItSync(d.listSync);
|
||||
doItSync(() {
|
||||
d.createTempSync('tempdir').deleteSync();
|
||||
});
|
||||
doItSync(() {
|
||||
// Let's be a little careful. If the directory exists we don't
|
||||
// want to delete it and all its contents.
|
||||
if (!d.existsSync()) d.deleteSync(recursive: true);
|
||||
});
|
||||
typeMapping.forEach((k2, v2) {
|
||||
doItSync(() => d.renameSync(v2 as String));
|
||||
doItSync(() => d.listSync(recursive: v2 as bool));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fuzzAsyncMethods() {
|
||||
asyncStart();
|
||||
var futures = <Future>[];
|
||||
typeMapping.forEach((k, v) {
|
||||
futures.add(doItAsync(() {
|
||||
Directory.systemTemp.createTempSync(v as String?).deleteSync();
|
||||
}));
|
||||
if (v is! String) {
|
||||
return;
|
||||
}
|
||||
var d = new Directory(v);
|
||||
futures.add(doItAsync(d.exists));
|
||||
futures.add(doItAsync(d.create));
|
||||
futures.add(doItAsync(d.delete));
|
||||
futures.add(doItAsync(() {
|
||||
return d.createTemp('tempdir').then((temp) {
|
||||
return temp.delete();
|
||||
});
|
||||
}));
|
||||
futures.add(doItAsync(() {
|
||||
return d.exists().then((res) {
|
||||
if (!res) return d.delete(recursive: true);
|
||||
return new Future.value(true);
|
||||
});
|
||||
}));
|
||||
typeMapping.forEach((k2, v2) {
|
||||
futures.add(doItAsync(() => d.rename(v2 as String)));
|
||||
futures.add(doItAsync(() {
|
||||
d.list(recursive: v2 as bool).listen((_) {}, onError: (e) => null);
|
||||
}));
|
||||
});
|
||||
});
|
||||
Future.wait(futures).then((_) => asyncEnd());
|
||||
}
|
||||
|
||||
main() {
|
||||
fuzzSyncMethods();
|
||||
fuzzAsyncMethods();
|
||||
}
|
53
tests/standalone/io/directory_list_nonexistent_test.dart
Normal file
53
tests/standalone/io/directory_list_nonexistent_test.dart
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Directory listing test that tests listSync on a missing directory.
|
||||
//
|
||||
// TODO(7157): Merge this test into directory_test.dart testListNonExistent()
|
||||
// when it no longer crashes on Windows, when issue 7157 is resolved.
|
||||
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void testListNonExistent() {
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_directory_list_nonexistent').then((d) {
|
||||
d.delete().then((ignore) {
|
||||
Expect.throws(() => d.listSync(), (e) => e is FileSystemException);
|
||||
Expect.throws(
|
||||
() => d.listSync(recursive: true), (e) => e is FileSystemException);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testListTooLongName() {
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_directory_list_nonexistent').then((d) {
|
||||
var subDirName = 'subdir';
|
||||
var subDir = new Directory("${d.path}/$subDirName");
|
||||
subDir.create().then((ignore) {
|
||||
// Construct a long string of the form
|
||||
// 'tempdir/subdir/../subdir/../subdir'.
|
||||
var buffer = new StringBuffer();
|
||||
buffer.write(subDir.path);
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
buffer.write("/../${subDirName}");
|
||||
}
|
||||
var long = new Directory("${buffer.toString()}");
|
||||
Expect.throws(() => long.listSync(), (e) => e is FileSystemException);
|
||||
Expect.throws(() => long.listSync(recursive: true),
|
||||
(e) => e is FileSystemException);
|
||||
d.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
testListNonExistent();
|
||||
testListTooLongName();
|
||||
}
|
97
tests/standalone/io/directory_list_pause_test.dart
Normal file
97
tests/standalone/io/directory_list_pause_test.dart
Normal file
|
@ -0,0 +1,97 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void testPauseList() {
|
||||
asyncStart();
|
||||
// TOTAL should be bigger the our directory listing buffer.
|
||||
const int TOTAL = 128;
|
||||
Directory.systemTemp.createTemp('dart_directory_list_pause').then((d) {
|
||||
for (int i = 0; i < TOTAL; i++) {
|
||||
new Directory("${d.path}/$i").createSync();
|
||||
new File("${d.path}/$i/file").createSync();
|
||||
}
|
||||
bool first = true;
|
||||
var subscription;
|
||||
int count = 0;
|
||||
subscription = d.list(recursive: true).listen((file) {
|
||||
if (file is File) {
|
||||
if (first) {
|
||||
first = false;
|
||||
subscription.pause();
|
||||
Timer.run(() {
|
||||
for (int i = 0; i < TOTAL; i++) {
|
||||
new File("${d.path}/$i/file").deleteSync();
|
||||
}
|
||||
subscription.resume();
|
||||
});
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}, onDone: () {
|
||||
Expect.notEquals(TOTAL, count);
|
||||
Expect.isTrue(count > 0);
|
||||
d.delete(recursive: true).then((ignore) => asyncEnd());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testPauseResumeCancelList() {
|
||||
asyncStart();
|
||||
// TOTAL should be bigger the our directory listing buffer.
|
||||
const int TOTAL = 128;
|
||||
Directory.systemTemp.createTemp('dart_directory_list_pause').then((d) {
|
||||
for (int i = 0; i < TOTAL; i++) {
|
||||
new Directory("${d.path}/$i").createSync();
|
||||
new File("${d.path}/$i/file").createSync();
|
||||
}
|
||||
var subscription;
|
||||
subscription = d.list(recursive: true).listen((entity) {
|
||||
subscription.pause();
|
||||
subscription.resume();
|
||||
void close() {
|
||||
d.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
}
|
||||
|
||||
var future = subscription.cancel();
|
||||
if (future != null) {
|
||||
future.whenComplete(close);
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
}, onDone: () {
|
||||
Expect.fail('the stream was canceled, onDone should not happen');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testListIsEmpty() {
|
||||
asyncStart();
|
||||
// TOTAL should be bigger the our directory listing buffer.
|
||||
const int TOTAL = 128;
|
||||
Directory.systemTemp.createTemp('dart_directory_list_pause').then((d) {
|
||||
for (int i = 0; i < TOTAL; i++) {
|
||||
new Directory("${d.path}/$i").createSync();
|
||||
new File("${d.path}/$i/file").createSync();
|
||||
}
|
||||
// isEmpty will cancel the stream after first data event.
|
||||
d.list(recursive: true).isEmpty.then((empty) {
|
||||
Expect.isFalse(empty);
|
||||
d.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
testPauseList();
|
||||
testPauseResumeCancelList();
|
||||
testListIsEmpty();
|
||||
}
|
15
tests/standalone/io/directory_list_sync_test.dart
Normal file
15
tests/standalone/io/directory_list_sync_test.dart
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright (c) 2014, 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.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
void main() {
|
||||
File script = new File.fromUri(Platform.script);
|
||||
// tests/standalone/io/../..
|
||||
Directory startingDir = script.parent.parent.parent;
|
||||
print("Recursively listing entries in directory ${startingDir.path} ...");
|
||||
List<FileSystemEntity> each =
|
||||
startingDir.listSync(recursive: true, followLinks: false);
|
||||
print("Found: ${each.length} entities");
|
||||
}
|
30
tests/standalone/io/directory_non_ascii_sync_test.dart
Normal file
30
tests/standalone/io/directory_non_ascii_sync_test.dart
Normal file
|
@ -0,0 +1,30 @@
|
|||
// 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:io';
|
||||
|
||||
main() {
|
||||
Directory tempDir =
|
||||
Directory.systemTemp.createTempSync('dart_directory_non_ascii_sync');
|
||||
var nonAsciiDir = new Directory("${tempDir.path}/æøå");
|
||||
// On MacOS you get the decomposed utf8 form of file and directory
|
||||
// names from the system. Therefore, we have to check for both here.
|
||||
var precomposed = 'æøå';
|
||||
var decomposed = new String.fromCharCodes([47, 230, 248, 97, 778]);
|
||||
Expect.isFalse(nonAsciiDir.existsSync());
|
||||
nonAsciiDir.createSync();
|
||||
Expect.isTrue(nonAsciiDir.existsSync());
|
||||
var temp = new Directory("${tempDir.path}/æøå").createTempSync('tempdir');
|
||||
Expect.isTrue(
|
||||
temp.path.contains(precomposed) || temp.path.contains(decomposed));
|
||||
temp.deleteSync();
|
||||
temp = tempDir.createTempSync('æøå');
|
||||
Expect.isTrue(
|
||||
temp.path.contains(precomposed) || temp.path.contains(decomposed));
|
||||
temp.deleteSync();
|
||||
tempDir.deleteSync(recursive: true);
|
||||
Expect.isFalse(nonAsciiDir.existsSync());
|
||||
Expect.isFalse(temp.existsSync());
|
||||
}
|
45
tests/standalone/io/directory_non_ascii_test.dart
Normal file
45
tests/standalone/io/directory_non_ascii_test.dart
Normal file
|
@ -0,0 +1,45 @@
|
|||
// 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.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
main() {
|
||||
asyncStart();
|
||||
|
||||
// On MacOS you get the decomposed utf8 form of file and directory
|
||||
// names from the system. Therefore, we have to check for both here.
|
||||
var precomposed = 'æøå';
|
||||
var decomposed = new String.fromCharCodes([47, 230, 248, 97, 778]);
|
||||
|
||||
Directory.systemTemp.createTemp('dart_directory_non_ascii').then((tempDir) {
|
||||
var nonAsciiDir = new Directory("${tempDir.path}/æøå");
|
||||
nonAsciiDir
|
||||
.exists()
|
||||
.then((e) => Expect.isFalse(e))
|
||||
.then((_) => nonAsciiDir.create())
|
||||
.then((_) => nonAsciiDir.exists())
|
||||
.then((e) => Expect.isTrue(e))
|
||||
.then((_) => new Directory("${tempDir.path}/æøå").createTemp('temp'))
|
||||
.then((temp) {
|
||||
Expect.isTrue(temp.path.contains(precomposed) ||
|
||||
temp.path.contains(decomposed));
|
||||
return temp.delete();
|
||||
})
|
||||
.then((_) => tempDir.createTemp('æøå'))
|
||||
.then((temp) {
|
||||
Expect.isTrue(temp.path.contains(precomposed) ||
|
||||
temp.path.contains(decomposed));
|
||||
return temp.delete();
|
||||
})
|
||||
.then((temp) => Expect.isFalse(temp.existsSync()))
|
||||
.then((_) => tempDir.delete(recursive: true))
|
||||
.then((_) {
|
||||
Expect.isFalse(nonAsciiDir.existsSync());
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
626
tests/standalone/io/directory_test.dart
Normal file
626
tests/standalone/io/directory_test.dart
Normal file
|
@ -0,0 +1,626 @@
|
|||
// 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.
|
||||
//
|
||||
// Directory listing test.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class DirectoryTest {
|
||||
static void testListing() {
|
||||
bool listedDir = false;
|
||||
bool listedFile = false;
|
||||
|
||||
Directory directory =
|
||||
Directory.systemTemp.createTempSync('dart_directory_test');
|
||||
Directory subDirectory = new Directory("${directory.path}/subdir");
|
||||
Expect.isTrue('$directory'.contains(directory.path));
|
||||
Expect.isFalse(subDirectory.existsSync());
|
||||
subDirectory.createSync();
|
||||
Expect.isTrue(subDirectory.existsSync());
|
||||
File f = new File('${subDirectory.path}/file.txt');
|
||||
File fLong = new File('${directory.path}/subdir/../subdir/file.txt');
|
||||
Expect.isFalse(f.existsSync());
|
||||
f.createSync();
|
||||
|
||||
void testSyncListing(bool recursive) {
|
||||
for (var entry in directory.listSync(recursive: recursive)) {
|
||||
if (entry is File) {
|
||||
Expect.isTrue(entry.path.contains(directory.path));
|
||||
Expect.isTrue(entry.path.contains('subdir'));
|
||||
Expect.isTrue(entry.path.contains('file.txt'));
|
||||
Expect.isFalse(listedFile);
|
||||
listedFile = true;
|
||||
} else {
|
||||
Expect.isTrue(entry is Directory);
|
||||
Expect.isTrue(entry.path.contains(directory.path));
|
||||
Expect.isTrue(entry.path.contains('subdir'));
|
||||
Expect.isFalse(listedDir);
|
||||
listedDir = true;
|
||||
}
|
||||
}
|
||||
Expect.equals(listedFile, recursive);
|
||||
Expect.isTrue(listedDir);
|
||||
listedFile = false;
|
||||
listedDir = false;
|
||||
}
|
||||
|
||||
testSyncListing(true);
|
||||
testSyncListing(false);
|
||||
Expect.equals(
|
||||
f.resolveSymbolicLinksSync(), fLong.resolveSymbolicLinksSync());
|
||||
|
||||
asyncStart();
|
||||
directory.list(recursive: true).listen((FileSystemEntity entity) {
|
||||
if (entity is File) {
|
||||
var path = entity.path;
|
||||
listedFile = true;
|
||||
Expect.isTrue(path.contains(directory.path));
|
||||
Expect.isTrue(path.contains('subdir'));
|
||||
Expect.isTrue(path.contains('file.txt'));
|
||||
} else {
|
||||
var path = entity.path;
|
||||
Expect.isTrue(entity is Directory);
|
||||
listedDir = true;
|
||||
Expect.isTrue(path.contains(directory.path));
|
||||
Expect.isTrue(path.contains('subdir'));
|
||||
}
|
||||
}, onDone: () {
|
||||
Expect.isTrue(listedDir, "directory not found");
|
||||
Expect.isTrue(listedFile, "file not found");
|
||||
directory.delete(recursive: true).then((ignore) {
|
||||
f.exists().then((exists) => Expect.isFalse(exists));
|
||||
directory.exists().then((exists) => Expect.isFalse(exists));
|
||||
subDirectory.exists().then((exists) => Expect.isFalse(exists));
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
|
||||
// Listing is asynchronous, so nothing should be listed at this
|
||||
// point.
|
||||
Expect.isFalse(listedDir);
|
||||
Expect.isFalse(listedFile);
|
||||
}
|
||||
|
||||
static void testListingTailingPaths() {
|
||||
Directory directory =
|
||||
Directory.systemTemp.createTempSync('dart_directory_test');
|
||||
Directory subDirectory = new Directory("${directory.path}/subdir/");
|
||||
subDirectory.createSync();
|
||||
File f = new File('${subDirectory.path}/file.txt');
|
||||
f.createSync();
|
||||
|
||||
void test(entry) {
|
||||
Expect.isFalse(entry.path.contains(new RegExp('[\\/][\\/]')));
|
||||
}
|
||||
|
||||
subDirectory.listSync().forEach(test);
|
||||
|
||||
subDirectory.list().listen(test, onDone: () {
|
||||
directory.deleteSync(recursive: true);
|
||||
});
|
||||
}
|
||||
|
||||
static void testListNonExistent() {
|
||||
setupListerHandlers(Stream<FileSystemEntity> stream) {
|
||||
stream.listen(
|
||||
(_) => Expect.fail("Listing of non-existing directory should fail"),
|
||||
onError: (error) {
|
||||
Expect.isTrue(error is FileSystemException);
|
||||
});
|
||||
}
|
||||
|
||||
Directory.systemTemp.createTemp('dart_directory').then((d) {
|
||||
d.delete().then((ignore) {
|
||||
setupListerHandlers(d.list());
|
||||
setupListerHandlers(d.list(recursive: true));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static void testListTooLongName() {
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_directory').then((d) {
|
||||
var errors = 0;
|
||||
setupListHandlers(Stream<FileSystemEntity> stream) {
|
||||
stream.listen(
|
||||
(_) => Expect.fail("Listing of non-existing directory should fail"),
|
||||
onError: (error) {
|
||||
Expect.isTrue(error is FileSystemException);
|
||||
if (++errors == 2) {
|
||||
d.delete(recursive: true).then((_) {
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var subDirName = 'subdir';
|
||||
var subDir = new Directory("${d.path}/$subDirName");
|
||||
subDir.create().then((ignore) {
|
||||
// Construct a long string of the form
|
||||
// 'tempdir/subdir/../subdir/../subdir'.
|
||||
var buffer = new StringBuffer();
|
||||
buffer.write(subDir.path);
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
buffer.write("/../${subDirName}");
|
||||
}
|
||||
var long = new Directory("${buffer.toString()}");
|
||||
setupListHandlers(long.list());
|
||||
setupListHandlers(long.list(recursive: true));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static void testDeleteNonExistent() {
|
||||
// Test that deleting a non-existing directory fails.
|
||||
setupFutureHandlers(future) {
|
||||
future.then((ignore) {
|
||||
Expect.fail("Deletion of non-existing directory should fail");
|
||||
}).catchError((error) {
|
||||
Expect.isTrue(error is FileSystemException);
|
||||
});
|
||||
}
|
||||
|
||||
Directory.systemTemp.createTemp('dart_directory').then((d) {
|
||||
d.delete().then((ignore) {
|
||||
setupFutureHandlers(d.delete());
|
||||
setupFutureHandlers(d.delete(recursive: true));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static void testDeleteTooLongName() {
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_directory').then((d) {
|
||||
var subDirName = 'subdir';
|
||||
var subDir = new Directory("${d.path}/$subDirName");
|
||||
subDir.create().then((ignore) {
|
||||
// Construct a long string of the form
|
||||
// 'tempdir/subdir/../subdir/../subdir'.
|
||||
var buffer = new StringBuffer();
|
||||
buffer.write(subDir.path);
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
buffer.write("/../${subDirName}");
|
||||
}
|
||||
var long = new Directory("${buffer.toString()}");
|
||||
var errors = 0;
|
||||
onError(error) {
|
||||
Expect.isTrue(error is FileSystemException);
|
||||
if (++errors == 2) {
|
||||
d.delete(recursive: true).then((_) => asyncEnd());
|
||||
}
|
||||
}
|
||||
|
||||
long.delete().catchError(onError);
|
||||
long.delete(recursive: true).catchError(onError);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static void testDeleteNonExistentSync() {
|
||||
Directory d = Directory.systemTemp.createTempSync('dart_directory_test');
|
||||
d.deleteSync();
|
||||
Expect.throws(d.deleteSync);
|
||||
Expect.throws(() => d.deleteSync(recursive: true));
|
||||
}
|
||||
|
||||
static void testDeleteTooLongNameSync() {
|
||||
Directory d = Directory.systemTemp.createTempSync('dart_directory_test');
|
||||
var subDirName = 'subdir';
|
||||
var subDir = new Directory("${d.path}/$subDirName");
|
||||
subDir.createSync();
|
||||
// Construct a long string of the form
|
||||
// 'tempdir/subdir/../subdir/../subdir'.
|
||||
var buffer = new StringBuffer();
|
||||
buffer.write(subDir.path);
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
buffer.write("/../${subDirName}");
|
||||
}
|
||||
var long = new Directory("${buffer.toString()}");
|
||||
Expect.throws(long.deleteSync);
|
||||
Expect.throws(() => long.deleteSync(recursive: true));
|
||||
d.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
static void testExistsCreateDelete() {
|
||||
Directory.systemTemp.createTemp('dart_directory').then((d) {
|
||||
d.exists().then((bool exists) {
|
||||
Expect.isTrue(exists);
|
||||
Directory created = new Directory("${d.path}/subdir");
|
||||
created.create().then((ignore) {
|
||||
created.exists().then((bool exists) {
|
||||
Expect.isTrue(exists);
|
||||
created.delete().then((ignore) {
|
||||
created.exists().then((bool exists) {
|
||||
Expect.isFalse(exists);
|
||||
d.delete().then((ignore) {
|
||||
d.exists().then((bool exists) {
|
||||
Expect.isFalse(exists);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static void testExistsCreateDeleteSync() {
|
||||
Directory d = Directory.systemTemp.createTempSync('dart_directory_test');
|
||||
Directory d2 = new Directory('${d.path}/');
|
||||
Expect.isTrue(d.existsSync());
|
||||
Expect.isTrue(d2.existsSync());
|
||||
Directory created = new Directory("${d.path}/subdir");
|
||||
created.createSync();
|
||||
Expect.isTrue(created.existsSync());
|
||||
created.deleteSync();
|
||||
Expect.isFalse(created.existsSync());
|
||||
d.deleteSync();
|
||||
Expect.isFalse(d.existsSync());
|
||||
}
|
||||
|
||||
static void testDeleteLinkSync() {
|
||||
Directory tmp = Directory.systemTemp.createTempSync('dart_directory_test');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
Directory d = new Directory("${path}target");
|
||||
d.createSync();
|
||||
Link l = new Link("${path}symlink");
|
||||
l.createSync("${path}target");
|
||||
Expect.isTrue(d.existsSync());
|
||||
Expect.isTrue(l.existsSync());
|
||||
new Directory(l.path).deleteSync(recursive: true);
|
||||
Expect.isTrue(d.existsSync());
|
||||
Expect.isFalse(l.existsSync());
|
||||
d.deleteSync();
|
||||
Expect.isFalse(d.existsSync());
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
static void testDeleteLinkAsFileSync() {
|
||||
Directory tmp = Directory.systemTemp.createTempSync('dart_directory_test');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
Directory d = new Directory("${path}target");
|
||||
d.createSync();
|
||||
Link l = new Link("${path}symlink");
|
||||
l.createSync("${path}target");
|
||||
Expect.isTrue(d.existsSync());
|
||||
Expect.isTrue(l.existsSync());
|
||||
new Link(l.path).deleteSync();
|
||||
Expect.isTrue(d.existsSync());
|
||||
Expect.isFalse(l.existsSync());
|
||||
d.deleteSync();
|
||||
Expect.isFalse(d.existsSync());
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
static void testDeleteBrokenLinkAsFileSync() {
|
||||
Directory tmp = Directory.systemTemp.createTempSync('dart_directory_test');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
Directory d = new Directory("${path}target");
|
||||
d.createSync();
|
||||
Link l = new Link("${path}symlink");
|
||||
l.createSync("${path}target");
|
||||
d.deleteSync();
|
||||
Expect.isFalse(d.existsSync());
|
||||
Expect.isTrue(l.existsSync());
|
||||
new Link(l.path).deleteSync();
|
||||
Expect.isFalse(l.existsSync());
|
||||
Expect.isFalse(d.existsSync());
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
static void testListBrokenLinkSync() {
|
||||
Directory tmp = Directory.systemTemp.createTempSync('dart_directory_test');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
Directory d = new Directory("${path}target");
|
||||
d.createSync();
|
||||
Link l = new Link("${path}symlink");
|
||||
l.createSync("${path}target");
|
||||
d.deleteSync();
|
||||
int count = 0;
|
||||
tmp.list(followLinks: true).listen((file) {
|
||||
count++;
|
||||
Expect.isTrue(file is Link);
|
||||
}, onDone: () {
|
||||
Expect.equals(1, count);
|
||||
l.deleteSync();
|
||||
tmp.deleteSync();
|
||||
});
|
||||
}
|
||||
|
||||
static void testListLinkSync() {
|
||||
Directory tmp = Directory.systemTemp.createTempSync('dart_directory_test');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
Directory d = new Directory("${path}target");
|
||||
d.createSync();
|
||||
Link l = new Link("${path}symlink");
|
||||
l.createSync("${path}target");
|
||||
int count = 0;
|
||||
tmp.list(followLinks: true).listen((file) {
|
||||
count++;
|
||||
Expect.isTrue(file is Directory);
|
||||
}, onDone: () {
|
||||
Expect.equals(2, count);
|
||||
l.deleteSync();
|
||||
d.deleteSync();
|
||||
tmp.deleteSync();
|
||||
});
|
||||
}
|
||||
|
||||
static void testCreateTemp() {
|
||||
Directory base = new Directory('/tmp');
|
||||
String template = 'dart_temp_dir';
|
||||
if (base.existsSync()) {
|
||||
asyncStart();
|
||||
Future.wait([base.createTemp(template), base.createTemp(template)])
|
||||
.then((tempDirs) {
|
||||
Expect.notEquals(tempDirs[0].path, tempDirs[1].path);
|
||||
for (Directory t in tempDirs) {
|
||||
Expect.isTrue(t.existsSync());
|
||||
t.deleteSync();
|
||||
Expect.isFalse(t.existsSync());
|
||||
}
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void testCreateSystemTemp() {
|
||||
String template = 'dart_system_temp_dir';
|
||||
asyncStart();
|
||||
Future.wait([
|
||||
Directory.systemTemp.createTemp(template),
|
||||
Directory.systemTemp.createTemp(template)
|
||||
]).then((tempDirs) {
|
||||
Expect.notEquals(tempDirs[0].path, tempDirs[1].path);
|
||||
for (Directory t in tempDirs) {
|
||||
Expect.isTrue(t.existsSync());
|
||||
t.deleteSync();
|
||||
Expect.isFalse(t.existsSync());
|
||||
}
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
static void testCreateDeleteTemp() {
|
||||
Directory.systemTemp.createTemp('dart_directory').then((tempDirectory) {
|
||||
String filename =
|
||||
"${tempDirectory.path}${Platform.pathSeparator}dart_testfile";
|
||||
File file = new File(filename);
|
||||
Expect.isFalse(file.existsSync());
|
||||
file.create().then((ignore) {
|
||||
file.exists().then((exists) {
|
||||
Expect.isTrue(exists);
|
||||
// Try to delete the directory containing the file - should throw.
|
||||
Expect.throws(tempDirectory.deleteSync);
|
||||
Expect.isTrue(tempDirectory.existsSync());
|
||||
|
||||
// Delete the file, and then delete the directory.
|
||||
file.delete().then((ignore) {
|
||||
tempDirectory.deleteSync();
|
||||
Expect.isFalse(tempDirectory.existsSync());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static void testCurrent() {
|
||||
Directory current = Directory.current;
|
||||
if (Platform.operatingSystem != "windows") {
|
||||
Expect.equals("/", current.path.substring(0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
static void testEquals() {
|
||||
var name = new File('.').resolveSymbolicLinksSync();
|
||||
Directory current1 = new Directory(name);
|
||||
Directory current2 = new Directory(name);
|
||||
Expect.equals(current1.path, current2.path);
|
||||
Expect.isTrue(current1.existsSync());
|
||||
}
|
||||
|
||||
static void testMain() {
|
||||
testListing();
|
||||
testListingTailingPaths();
|
||||
testListNonExistent();
|
||||
testListTooLongName();
|
||||
testDeleteNonExistent();
|
||||
testDeleteTooLongName();
|
||||
testDeleteNonExistentSync();
|
||||
testDeleteTooLongNameSync();
|
||||
testExistsCreateDelete();
|
||||
testExistsCreateDeleteSync();
|
||||
testDeleteLinkSync();
|
||||
testDeleteLinkAsFileSync();
|
||||
testDeleteBrokenLinkAsFileSync();
|
||||
testListBrokenLinkSync();
|
||||
testListLinkSync();
|
||||
testCreateTemp();
|
||||
testCreateSystemTemp();
|
||||
testCreateDeleteTemp();
|
||||
testCurrent();
|
||||
testEquals();
|
||||
}
|
||||
}
|
||||
|
||||
class NestedTempDirectoryTest {
|
||||
List<Directory> createdDirectories;
|
||||
|
||||
NestedTempDirectoryTest.run() : createdDirectories = new List<Directory>() {
|
||||
Directory.systemTemp.createTemp('dart_directory').then(createPhaseCallback);
|
||||
}
|
||||
|
||||
void createPhaseCallback(temp) {
|
||||
createdDirectories.add(temp);
|
||||
int nestingDepth = 6;
|
||||
var os = Platform.operatingSystem;
|
||||
if (os == "windows") nestingDepth = 2;
|
||||
if (createdDirectories.length < nestingDepth) {
|
||||
temp
|
||||
.createTemp('nested_temp_dir_${createdDirectories.length}_')
|
||||
.then(createPhaseCallback);
|
||||
} else {
|
||||
deletePhaseCallback();
|
||||
}
|
||||
}
|
||||
|
||||
void deletePhaseCallback() {
|
||||
if (!createdDirectories.isEmpty) {
|
||||
final current = createdDirectories.removeLast();
|
||||
current.deleteSync();
|
||||
deletePhaseCallback();
|
||||
}
|
||||
}
|
||||
|
||||
static void testMain() {
|
||||
new NestedTempDirectoryTest.run();
|
||||
new NestedTempDirectoryTest.run();
|
||||
}
|
||||
}
|
||||
|
||||
String? illegalTempDirectoryLocation() {
|
||||
// Determine a platform specific illegal location for a temporary directory.
|
||||
var os = Platform.operatingSystem;
|
||||
if (os == "linux" || os == "macos") {
|
||||
return "/dev/zero/";
|
||||
}
|
||||
if (os == "windows") {
|
||||
return "*";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
testCreateTempErrorSync() {
|
||||
var location = illegalTempDirectoryLocation();
|
||||
if (location != null) {
|
||||
Expect.throws(() => new Directory(location).createTempSync('dart_tempdir'),
|
||||
(e) => e is FileSystemException);
|
||||
}
|
||||
}
|
||||
|
||||
testCreateTempError() {
|
||||
var location = illegalTempDirectoryLocation();
|
||||
if (location == null) return;
|
||||
|
||||
asyncStart();
|
||||
var future = new Directory(location).createTemp('dart_tempdir');
|
||||
future.catchError((_) => asyncEnd());
|
||||
}
|
||||
|
||||
testCreateExistingSync() {
|
||||
// Test that creating an existing directory succeeds.
|
||||
var temp = Directory.systemTemp.createTempSync('directory_test');
|
||||
var subDir = new Directory('${temp.path}/flaf');
|
||||
Expect.isFalse(subDir.existsSync());
|
||||
subDir.createSync();
|
||||
Expect.isTrue(subDir.existsSync());
|
||||
subDir.createSync();
|
||||
Expect.isTrue(subDir.existsSync());
|
||||
temp.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
testCreateExisting() {
|
||||
// Test that creating an existing directory succeeds.
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_directory').then((temp) {
|
||||
var subDir = new Directory('${temp.path}/flaf');
|
||||
subDir.exists().then((dirExists) {
|
||||
Expect.isFalse(dirExists);
|
||||
subDir.create().then((_) {
|
||||
subDir.exists().then((dirExists) {
|
||||
Expect.isTrue(dirExists);
|
||||
subDir.create().then((_) {
|
||||
subDir.exists().then((dirExists) {
|
||||
Expect.isTrue(dirExists);
|
||||
temp.delete(recursive: true).then((_) {
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
testCreateDirExistingFileSync() {
|
||||
// Test that creating an existing directory succeeds.
|
||||
var temp = Directory.systemTemp.createTempSync('directory_test');
|
||||
var path = '${temp.path}/flaf';
|
||||
var file = new File(path);
|
||||
file.createSync();
|
||||
Expect.isTrue(file.existsSync());
|
||||
Expect.throws(
|
||||
new Directory(path).createSync, (e) => e is FileSystemException);
|
||||
temp.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
testCreateDirExistingFile() {
|
||||
// Test that creating an existing directory succeeds.
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_directory').then((temp) {
|
||||
var path = '${temp.path}/flaf';
|
||||
var file = new File(path);
|
||||
var subDir = new Directory(path);
|
||||
file.create().then((_) {
|
||||
subDir.create().then((_) {
|
||||
Expect.fail("dir create should fail on existing file");
|
||||
}).catchError((error) {
|
||||
Expect.isTrue(error is FileSystemException);
|
||||
temp.delete(recursive: true).then((_) {
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
testRename() {
|
||||
var temp1 = Directory.systemTemp.createTempSync('directory_test');
|
||||
var temp2 = Directory.systemTemp.createTempSync('directory_test');
|
||||
var temp3 = temp1.renameSync(temp2.path);
|
||||
Expect.isFalse(temp1.existsSync());
|
||||
Expect.isTrue(temp2.existsSync());
|
||||
Expect.equals(temp3.path, temp2.path);
|
||||
|
||||
var temp4 = temp2.renameSync(temp1.path);
|
||||
Expect.isFalse(temp3.existsSync());
|
||||
Expect.isFalse(temp2.existsSync());
|
||||
Expect.isTrue(temp1.existsSync());
|
||||
Expect.isTrue(temp4.existsSync());
|
||||
Expect.equals(temp1.path, temp4.path);
|
||||
|
||||
String foo = '${temp4.path}/foo';
|
||||
String bar = '${temp4.path}/bar';
|
||||
new File(foo).createSync();
|
||||
try {
|
||||
new Directory(foo).renameSync(bar);
|
||||
Expect.fail('Directory.rename should fail to rename a non-directory');
|
||||
} catch (e) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
if (Platform.isLinux || Platform.isMacOS) {
|
||||
Expect.isTrue(e.osError.message.contains('Not a directory'));
|
||||
}
|
||||
}
|
||||
|
||||
temp1.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
main() {
|
||||
DirectoryTest.testMain();
|
||||
NestedTempDirectoryTest.testMain();
|
||||
testCreateTempErrorSync();
|
||||
testCreateTempError();
|
||||
testCreateExistingSync();
|
||||
testCreateExisting();
|
||||
testCreateDirExistingFileSync();
|
||||
testCreateDirExistingFile();
|
||||
testRename();
|
||||
}
|
46
tests/standalone/io/directory_uri_test.dart
Normal file
46
tests/standalone/io/directory_uri_test.dart
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void testFromUri() {
|
||||
asyncStart();
|
||||
Directory originalWorkingDirectory = Directory.current;
|
||||
Directory.systemTemp.createTemp('directory_uri').then((temp) {
|
||||
String dirname = temp.path + '/from_uri';
|
||||
Uri dirUri = new Uri.file(dirname);
|
||||
Directory dir = new Directory.fromUri(dirUri);
|
||||
Expect.isTrue(dirUri.isAbsolute);
|
||||
Expect.isTrue(dirUri.path.startsWith('/'));
|
||||
dir.createSync();
|
||||
Expect.isTrue(new Directory.fromUri(dirUri).existsSync());
|
||||
Expect.isTrue(
|
||||
new Directory.fromUri(Uri.base.resolveUri(dirUri)).existsSync());
|
||||
Directory.current = temp.path;
|
||||
Expect.isTrue(new Directory.fromUri(Uri.parse('from_uri')).existsSync());
|
||||
Expect.isTrue(
|
||||
new Directory.fromUri(Uri.base.resolve('from_uri')).existsSync());
|
||||
Directory.current = originalWorkingDirectory;
|
||||
dir.deleteSync();
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testFromUriUnsupported() {
|
||||
Expect.throwsUnsupportedError(() =>
|
||||
new Directory.fromUri(Uri.parse('http://localhost:8080/index.html')));
|
||||
Expect.throwsUnsupportedError(
|
||||
() => new Directory.fromUri(Uri.parse('ftp://localhost/tmp/xxx')));
|
||||
Expect.throwsUnsupportedError(
|
||||
() => new Directory.fromUri(Uri.parse('name#fragment')));
|
||||
}
|
||||
|
||||
void main() {
|
||||
testFromUri();
|
||||
testFromUriUnsupported();
|
||||
}
|
14
tests/standalone/io/disable_exit_test.dart
Normal file
14
tests/standalone/io/disable_exit_test.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) 2017, 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.
|
||||
// VMOptions=--disable-exit
|
||||
|
||||
import "dart:io" as io;
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void main() {
|
||||
Expect.throws(() {
|
||||
io.exit(-1);
|
||||
}, (e) => (e is UnsupportedError));
|
||||
}
|
143
tests/standalone/io/echo_server_stream_test.dart
Normal file
143
tests/standalone/io/echo_server_stream_test.dart
Normal file
|
@ -0,0 +1,143 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
// VMOptions=--enable-isolate-groups
|
||||
// VMOptions=--no-enable-isolate-groups
|
||||
//
|
||||
// Echo server test program to test socket streams.
|
||||
//
|
||||
// VMOptions=
|
||||
// VMOptions=--short_socket_read
|
||||
// VMOptions=--short_socket_write
|
||||
// VMOptions=--short_socket_read --short_socket_write
|
||||
|
||||
library ServerTest;
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
import "dart:isolate";
|
||||
part "testing_server.dart";
|
||||
|
||||
class EchoServerGame {
|
||||
static const MSGSIZE = 10;
|
||||
static const MESSAGES = 100;
|
||||
static const FIRSTCHAR = 65;
|
||||
|
||||
EchoServerGame.start() {
|
||||
for (int i = 0; i < MSGSIZE; i++) {
|
||||
_buffer[i] = FIRSTCHAR + i;
|
||||
}
|
||||
initialize();
|
||||
}
|
||||
|
||||
void sendData() {
|
||||
int offset = 0;
|
||||
List<int> data;
|
||||
|
||||
void onData(List<int> data) {
|
||||
int bytesRead = data.length;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
Expect.equals(FIRSTCHAR + i + offset, data[i]);
|
||||
}
|
||||
offset += bytesRead;
|
||||
}
|
||||
|
||||
void onClosed() {
|
||||
Expect.equals(MSGSIZE, offset);
|
||||
_messages++;
|
||||
if (_messages < MESSAGES) {
|
||||
sendData();
|
||||
} else {
|
||||
shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
void errorHandler(e, trace) {
|
||||
String msg = "Socket error $e";
|
||||
if (trace != null) msg += "\nStackTrace: $trace";
|
||||
Expect.fail(msg);
|
||||
}
|
||||
|
||||
void connectHandler() {
|
||||
_socket.listen(onData, onError: errorHandler, onDone: onClosed);
|
||||
_socket.add(_buffer);
|
||||
_socket.close();
|
||||
data = new List<int>.filled(MSGSIZE, 0);
|
||||
}
|
||||
|
||||
Socket.connect(TestingServer.HOST, _port).then((s) {
|
||||
_socket = s;
|
||||
connectHandler();
|
||||
});
|
||||
}
|
||||
|
||||
void initialize() {
|
||||
var receivePort = new ReceivePort();
|
||||
var remote = Isolate.spawn(startEchoServer, receivePort.sendPort);
|
||||
receivePort.first.then((msg) {
|
||||
this._port = msg[0];
|
||||
this._closeSendPort = msg[1];
|
||||
sendData();
|
||||
});
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
_closeSendPort.send(null);
|
||||
asyncEnd();
|
||||
}
|
||||
|
||||
late int _port;
|
||||
late SendPort _closeSendPort;
|
||||
late Socket _socket;
|
||||
final _buffer = new List<int>.filled(MSGSIZE, 0);
|
||||
int _messages = 0;
|
||||
}
|
||||
|
||||
void startEchoServer(Object replyPortObj) {
|
||||
SendPort replyPort = replyPortObj as SendPort;
|
||||
var server = new EchoServer();
|
||||
server.init().then((port) {
|
||||
replyPort.send([port, server.closeSendPort]);
|
||||
});
|
||||
}
|
||||
|
||||
class EchoServer extends TestingServer {
|
||||
static const int MSGSIZE = EchoServerGame.MSGSIZE;
|
||||
|
||||
void onConnection(Socket connection) {
|
||||
List<int> buffer = new List<int>.filled(MSGSIZE, 0);
|
||||
int offset = 0;
|
||||
|
||||
void dataReceived(List<int> data) {
|
||||
int bytesRead;
|
||||
bytesRead = data.length;
|
||||
if (bytesRead > 0) {
|
||||
buffer.setRange(offset, offset + data.length, data);
|
||||
offset += bytesRead;
|
||||
for (int i = 0; i < offset; i++) {
|
||||
Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]);
|
||||
}
|
||||
if (offset == MSGSIZE) {
|
||||
connection.add(buffer);
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void errorHandler(e, trace) {
|
||||
String msg = "Socket error $e";
|
||||
if (trace != null) msg += "\nStackTrace: $trace";
|
||||
Expect.fail(msg);
|
||||
}
|
||||
|
||||
connection.listen(dataReceived, onError: errorHandler);
|
||||
}
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncStart();
|
||||
EchoServerGame echoServerGame = new EchoServerGame.start();
|
||||
}
|
0
tests/standalone/io/empty_file
Normal file
0
tests/standalone/io/empty_file
Normal file
68
tests/standalone/io/file_absolute_path_test.dart
Normal file
68
tests/standalone/io/file_absolute_path_test.dart
Normal file
|
@ -0,0 +1,68 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Dart test program for testing FileSystemEntity.absolute
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:io';
|
||||
|
||||
main() {
|
||||
if (Platform.isWindows) {
|
||||
testWindows();
|
||||
try {
|
||||
Directory.current = 'C:\\';
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
testWindows();
|
||||
} else {
|
||||
testPosix();
|
||||
Directory.current = '.';
|
||||
testPosix();
|
||||
Directory.current = '/';
|
||||
testPosix();
|
||||
}
|
||||
}
|
||||
|
||||
testWindows() {
|
||||
String current = Directory.current.path;
|
||||
for (String relative in ['abd', '..', '.', 'efg/hij', 'abc/']) {
|
||||
if (current.endsWith('\\')) {
|
||||
Expect.equals(new File(relative).absolute.path, '$current$relative');
|
||||
} else {
|
||||
Expect.equals(new File(relative).absolute.path, '$current\\$relative');
|
||||
}
|
||||
Expect.isTrue(new File(relative).absolute.isAbsolute);
|
||||
}
|
||||
for (String absolute in [
|
||||
'c:/abd',
|
||||
'D:\\rf',
|
||||
'\\\\a_share\\folder',
|
||||
'\\\\?\\c:\\prefixed\path\\'
|
||||
]) {
|
||||
Expect.isTrue(new File(absolute).absolute.path == absolute);
|
||||
Expect.isTrue(new File(absolute).absolute.isAbsolute);
|
||||
}
|
||||
}
|
||||
|
||||
testPosix() {
|
||||
String current = Directory.current.path;
|
||||
for (String relative in ['abd', '..', '.', 'efg/hij', 'abc/']) {
|
||||
if (current.endsWith('/')) {
|
||||
Expect.equals(new File(relative).absolute.path, '$current$relative');
|
||||
} else {
|
||||
Expect.equals(new File(relative).absolute.path, '$current/$relative');
|
||||
}
|
||||
Expect.isTrue(new File(relative).absolute.isAbsolute);
|
||||
Expect.equals(new Directory(relative).absolute.path,
|
||||
new Link(relative).absolute.path);
|
||||
Expect.isTrue(new File(relative).absolute is File);
|
||||
Expect.isTrue(new Directory(relative).absolute is Directory);
|
||||
Expect.isTrue(new Link(relative).absolute is Link);
|
||||
}
|
||||
for (String absolute in ['/abd', '/', '/./..\\', '/efg/hij', '/abc/']) {
|
||||
Expect.equals(new File(absolute).absolute.path, absolute);
|
||||
Expect.isTrue(new File(absolute).absolute.isAbsolute);
|
||||
}
|
||||
}
|
33
tests/standalone/io/file_blocking_lock_script.dart
Normal file
33
tests/standalone/io/file_blocking_lock_script.dart
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
//
|
||||
// Script used by the file_lock_test.dart test.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
Future<int> testLockWholeFile(File file, int len) async {
|
||||
var raf = await file.open(mode: FileMode.append);
|
||||
await raf.setPosition(0);
|
||||
int nextToWrite = 1;
|
||||
await raf.lock(FileLock.blockingExclusive, 0, len);
|
||||
|
||||
// Make sure the peer fails a non-blocking lock at some point.
|
||||
await new Future.delayed(const Duration(seconds: 1));
|
||||
|
||||
int p = 0;
|
||||
while (p < len) {
|
||||
await raf.writeByte(1);
|
||||
p++;
|
||||
}
|
||||
await raf.unlock(0, len);
|
||||
await raf.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
main(List<String> args) async {
|
||||
File file = new File(args[0]);
|
||||
int len = int.parse(args[1]);
|
||||
exit(await testLockWholeFile(file, len));
|
||||
}
|
102
tests/standalone/io/file_blocking_lock_test.dart
Normal file
102
tests/standalone/io/file_blocking_lock_test.dart
Normal file
|
@ -0,0 +1,102 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
|
||||
// OtherResources=file_blocking_lock_script.dart
|
||||
|
||||
// This test works by spawning a new process running
|
||||
// file_blocking_lock_script.dart, trading the file lock back and forth,
|
||||
// writing bytes 1 ... 25 in order to the file. There are checks to ensure
|
||||
// that the bytes are written in order, that one process doesn't write all the
|
||||
// bytes and that a non-blocking lock fails such that a blocking lock must
|
||||
// be taken, which succeeds.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
import "package:path/path.dart";
|
||||
|
||||
// Check whether the file is locked or not.
|
||||
runPeer(String path, int len, FileLock mode) {
|
||||
var script =
|
||||
Platform.script.resolve('file_blocking_lock_script.dart').toFilePath();
|
||||
var arguments = <String>[]
|
||||
..addAll(Platform.executableArguments)
|
||||
..add(script)
|
||||
..add(path)
|
||||
..add(len.toString());
|
||||
return Process.start(Platform.executable, arguments).then((process) {
|
||||
process.stdout.transform(utf8.decoder).listen((data) {
|
||||
print(data);
|
||||
});
|
||||
process.stderr.transform(utf8.decoder).listen((data) {
|
||||
print(data);
|
||||
});
|
||||
return process;
|
||||
});
|
||||
}
|
||||
|
||||
const int peerTimeoutMilliseconds = 30000;
|
||||
|
||||
Future<bool> waitForPeer(RandomAccessFile raf, int length) async {
|
||||
Stopwatch s = new Stopwatch();
|
||||
s.start();
|
||||
while (true) {
|
||||
await raf.unlock(0, length);
|
||||
if (s.elapsedMilliseconds > peerTimeoutMilliseconds) {
|
||||
s.stop();
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
await raf.lock(FileLock.exclusive, 0, length);
|
||||
} catch (_) {
|
||||
await raf.lock(FileLock.blockingExclusive, 0, length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
s.stop();
|
||||
return true;
|
||||
}
|
||||
|
||||
testLockWholeFile() async {
|
||||
const int length = 25;
|
||||
Directory directory = await Directory.systemTemp.createTemp('dart_file_lock');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
await file.writeAsBytes(new List.filled(length, 0));
|
||||
var raf = await file.open(mode: FileMode.append);
|
||||
await raf.lock(FileLock.blockingExclusive, 0, length);
|
||||
Process peer = await runPeer(file.path, length, FileLock.blockingExclusive);
|
||||
|
||||
// If the peer doesn't come up within the timeout, then give up on the test
|
||||
// to avoid the test being flaky.
|
||||
if (!await waitForPeer(raf, length)) {
|
||||
await raf.close();
|
||||
await directory.delete(recursive: true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check that the peer wrote to the file.
|
||||
int p = 0;
|
||||
await raf.setPosition(0);
|
||||
while (p < length) {
|
||||
int at = await raf.readByte();
|
||||
Expect.equals(1, at);
|
||||
p++;
|
||||
}
|
||||
await raf.unlock(0, length);
|
||||
|
||||
// Check that the peer exited successfully.
|
||||
int v = await peer.exitCode;
|
||||
Expect.equals(0, v);
|
||||
await raf.close();
|
||||
await directory.delete(recursive: true);
|
||||
}
|
||||
|
||||
main() async {
|
||||
asyncStart();
|
||||
await testLockWholeFile();
|
||||
asyncEnd();
|
||||
}
|
16
tests/standalone/io/file_constructor_test.dart
Normal file
16
tests/standalone/io/file_constructor_test.dart
Normal file
|
@ -0,0 +1,16 @@
|
|||
// 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:io';
|
||||
|
||||
void main() {
|
||||
new File('blåbærgrød');
|
||||
new File('foo.txt');
|
||||
try {
|
||||
dynamic one = 1;
|
||||
new File(one);
|
||||
Expect.fail('Error expected.');
|
||||
} on TypeError catch (e) {}
|
||||
}
|
79
tests/standalone/io/file_copy_test.dart
Normal file
79
tests/standalone/io/file_copy_test.dart
Normal file
|
@ -0,0 +1,79 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Dart test program for testing File.copy*
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
const FILE_CONTENT1 = 'some string';
|
||||
const FILE_CONTENT2 = 'some other string';
|
||||
|
||||
void testCopySync() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart-file-copy');
|
||||
|
||||
var file1 = new File('${tmp.path}/file1');
|
||||
file1.writeAsStringSync(FILE_CONTENT1);
|
||||
Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
|
||||
|
||||
// Copy to new file works.
|
||||
var file2 = file1.copySync('${tmp.path}/file2');
|
||||
Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
|
||||
Expect.equals(FILE_CONTENT1, file2.readAsStringSync());
|
||||
|
||||
// Override works for files.
|
||||
file2.writeAsStringSync(FILE_CONTENT2);
|
||||
file2.copySync(file1.path);
|
||||
Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
|
||||
Expect.equals(FILE_CONTENT2, file2.readAsStringSync());
|
||||
|
||||
// Fail when coping to directory.
|
||||
var dir = new Directory('${tmp.path}/dir')..createSync();
|
||||
Expect.throws(() => file1.copySync(dir.path));
|
||||
Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
|
||||
|
||||
tmp.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
void testCopy() {
|
||||
asyncStart();
|
||||
var tmp = Directory.systemTemp.createTempSync('dart-file-copy');
|
||||
|
||||
var file1 = new File('${tmp.path}/file1');
|
||||
file1.writeAsStringSync(FILE_CONTENT1);
|
||||
Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
|
||||
|
||||
// Copy to new file works.
|
||||
file1.copy('${tmp.path}/file2').then((file2) {
|
||||
Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
|
||||
Expect.equals(FILE_CONTENT1, file2.readAsStringSync());
|
||||
|
||||
// Override works for files.
|
||||
file2.writeAsStringSync(FILE_CONTENT2);
|
||||
return file2.copy(file1.path).then((_) {
|
||||
Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
|
||||
Expect.equals(FILE_CONTENT2, file2.readAsStringSync());
|
||||
|
||||
// Fail when coping to directory.
|
||||
var dir = new Directory('${tmp.path}/dir')..createSync();
|
||||
|
||||
return file1
|
||||
.copy(dir.path)
|
||||
.then((_) => Expect.fail('expected error'), onError: (_) {})
|
||||
.then((_) {
|
||||
Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
|
||||
});
|
||||
});
|
||||
}).whenComplete(() {
|
||||
tmp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
testCopySync();
|
||||
testCopy();
|
||||
}
|
44
tests/standalone/io/file_create_test.dart
Normal file
44
tests/standalone/io/file_create_test.dart
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
//
|
||||
// Dart test program for testing file creation.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:path/path.dart";
|
||||
|
||||
testCreate() async {
|
||||
Directory tmp = await Directory.systemTemp.createTemp('file_test_create');
|
||||
Expect.isTrue(await tmp.exists());
|
||||
String filePath = "${tmp.path}/foo";
|
||||
File file = new File(filePath);
|
||||
File createdFile = await file.create();
|
||||
Expect.equals(file, createdFile);
|
||||
Expect.isTrue(await createdFile.exists());
|
||||
await tmp.delete(recursive: true);
|
||||
}
|
||||
|
||||
testBadCreate() async {
|
||||
Directory tmp = await Directory.systemTemp.createTemp('file_test_create');
|
||||
Expect.isTrue(await tmp.exists());
|
||||
Directory tmp2 = await tmp.createTemp('file_test_create');
|
||||
Expect.isTrue(await tmp2.exists());
|
||||
String badFilePath = tmp2.path;
|
||||
File badFile = new File(badFilePath);
|
||||
try {
|
||||
await badFile.create();
|
||||
Expect.fail('Should be unreachable');
|
||||
} catch (e) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
Expect.isNotNull(e.osError);
|
||||
}
|
||||
await tmp.delete(recursive: true);
|
||||
}
|
||||
|
||||
main() async {
|
||||
await testCreate();
|
||||
await testBadCreate();
|
||||
}
|
31
tests/standalone/io/file_error2_test.dart
Normal file
31
tests/standalone/io/file_error2_test.dart
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright (c) 2017, 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.
|
||||
//
|
||||
// Dart test program for testing error handling in file I/O.
|
||||
//
|
||||
// Customize ASAN options for this test with 'allocator_may_return_null=1' as
|
||||
// it tries to allocate a large memory buffer.
|
||||
// Environment=ASAN_OPTIONS=handle_segv=0:detect_stack_use_after_return=1:allocator_may_return_null=1
|
||||
// Environment=LSAN_OPTIONS=handle_segv=0:detect_stack_use_after_return=1:allocator_may_return_null=1
|
||||
// Environment=MSAN_OPTIONS=handle_segv=0:detect_stack_use_after_return=1:allocator_may_return_null=1
|
||||
|
||||
import "dart:io";
|
||||
|
||||
import "file_error_test.dart" show createTestFile;
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
testReadSyncBigInt() {
|
||||
createTestFile((file, done) {
|
||||
var bigint = 9223372036854775807;
|
||||
var openedFile = file.openSync();
|
||||
Expect.throws(
|
||||
() => openedFile.readSync(bigint), (e) => e is FileSystemException);
|
||||
openedFile.closeSync();
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
testReadSyncBigInt();
|
||||
}
|
427
tests/standalone/io/file_error_test.dart
Normal file
427
tests/standalone/io/file_error_test.dart
Normal file
|
@ -0,0 +1,427 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Dart test program for testing error handling in file I/O.
|
||||
|
||||
import "dart:convert";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
Directory tempDir() {
|
||||
return Directory.systemTemp.createTempSync('dart_file_error');
|
||||
}
|
||||
|
||||
bool checkNonExistentFileSystemException(e, str) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
Expect.isTrue(e.osError != null);
|
||||
Expect.isTrue(e.toString().indexOf(str) != -1);
|
||||
// File not not found has error code 2 on all supported platforms.
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkOpenNonExistentFileSystemException(e) {
|
||||
return checkNonExistentFileSystemException(e, "Cannot open file");
|
||||
}
|
||||
|
||||
bool checkDeleteNonExistentFileSystemException(e) {
|
||||
return checkNonExistentFileSystemException(e, "Cannot delete file");
|
||||
}
|
||||
|
||||
bool checkLengthNonExistentFileSystemException(e) {
|
||||
return checkNonExistentFileSystemException(
|
||||
e, "Cannot retrieve length of file");
|
||||
}
|
||||
|
||||
void testOpenNonExistent() {
|
||||
asyncStart();
|
||||
Directory temp = tempDir();
|
||||
var file = new File("${temp.path}/nonExistentFile");
|
||||
|
||||
// Non-existing file should throw exception.
|
||||
Expect.throws(
|
||||
() => file.openSync(), (e) => checkOpenNonExistentFileSystemException(e));
|
||||
|
||||
var openFuture = file.open(mode: FileMode.read);
|
||||
openFuture.then((raf) => Expect.fail("Unreachable code")).catchError((error) {
|
||||
checkOpenNonExistentFileSystemException(error);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testDeleteNonExistent() {
|
||||
asyncStart();
|
||||
Directory temp = tempDir();
|
||||
var file = new File("${temp.path}/nonExistentFile");
|
||||
|
||||
// Non-existing file should throw exception.
|
||||
Expect.throws(() => file.deleteSync(),
|
||||
(e) => checkDeleteNonExistentFileSystemException(e));
|
||||
|
||||
var delete = file.delete();
|
||||
delete.then((ignore) => Expect.fail("Unreachable code")).catchError((error) {
|
||||
checkDeleteNonExistentFileSystemException(error);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testLengthNonExistent() {
|
||||
asyncStart();
|
||||
Directory temp = tempDir();
|
||||
var file = new File("${temp.path}/nonExistentFile");
|
||||
|
||||
// Non-existing file should throw exception.
|
||||
Expect.throws(() => file.lengthSync(),
|
||||
(e) => checkLengthNonExistentFileSystemException(e));
|
||||
|
||||
var lenFuture = file.length();
|
||||
lenFuture.then((len) => Expect.fail("Unreachable code")).catchError((error) {
|
||||
checkLengthNonExistentFileSystemException(error);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
bool checkCreateInNonExistentFileSystemException(e) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
Expect.isTrue(e.osError != null);
|
||||
Expect.isTrue(e.toString().indexOf("Cannot create file") != -1);
|
||||
if (Platform.operatingSystem == "linux") {
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
} else if (Platform.operatingSystem == "macos") {
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
} else if (Platform.operatingSystem == "windows") {
|
||||
Expect.equals(3, e.osError.errorCode);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void testCreateInNonExistentDirectory() {
|
||||
asyncStart();
|
||||
Directory temp = tempDir();
|
||||
var file = new File("${temp.path}/nonExistentDirectory/newFile");
|
||||
|
||||
// Create in non-existent directory should throw exception.
|
||||
Expect.throws(() => file.createSync(),
|
||||
(e) => checkCreateInNonExistentFileSystemException(e));
|
||||
|
||||
var create = file.create();
|
||||
create.then((ignore) => Expect.fail("Unreachable code")).catchError((error) {
|
||||
checkCreateInNonExistentFileSystemException(error);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
bool checkResolveSymbolicLinksOnNonExistentFileSystemException(e) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
Expect.isTrue(e.osError != null);
|
||||
Expect.isTrue(e.toString().indexOf("Cannot resolve symbolic links") != -1);
|
||||
// File not not found has error code 2 on all supported platforms.
|
||||
Expect.equals(2, e.osError.errorCode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void testResolveSymbolicLinksOnNonExistentDirectory() {
|
||||
asyncStart();
|
||||
Directory temp = tempDir();
|
||||
var file = new File("${temp.path}/nonExistentDirectory");
|
||||
|
||||
// Full path non-existent directory should throw exception.
|
||||
Expect.throws(() => file.resolveSymbolicLinksSync(),
|
||||
(e) => checkResolveSymbolicLinksOnNonExistentFileSystemException(e));
|
||||
|
||||
var resolvedFuture = file.resolveSymbolicLinks();
|
||||
resolvedFuture
|
||||
.then((path) => Expect.fail("Unreachable code $path"))
|
||||
.catchError((error) {
|
||||
checkResolveSymbolicLinksOnNonExistentFileSystemException(error);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testReadAsBytesNonExistent() {
|
||||
asyncStart();
|
||||
Directory temp = tempDir();
|
||||
var file = new File("${temp.path}/nonExistentFile3");
|
||||
|
||||
// Non-existing file should throw exception.
|
||||
Expect.throws(() => file.readAsBytesSync(),
|
||||
(e) => checkOpenNonExistentFileSystemException(e));
|
||||
|
||||
var readAsBytesFuture = file.readAsBytes();
|
||||
readAsBytesFuture
|
||||
.then((data) => Expect.fail("Unreachable code"))
|
||||
.catchError((error) {
|
||||
checkOpenNonExistentFileSystemException(error);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testReadAsTextNonExistent() {
|
||||
asyncStart();
|
||||
Directory temp = tempDir();
|
||||
var file = new File("${temp.path}/nonExistentFile4");
|
||||
|
||||
// Non-existing file should throw exception.
|
||||
Expect.throws(() => file.readAsStringSync(),
|
||||
(e) => checkOpenNonExistentFileSystemException(e));
|
||||
|
||||
var readAsStringFuture = file.readAsString(encoding: ascii);
|
||||
readAsStringFuture
|
||||
.then((data) => Expect.fail("Unreachable code"))
|
||||
.catchError((error) {
|
||||
checkOpenNonExistentFileSystemException(error);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
testReadAsLinesNonExistent() {
|
||||
asyncStart();
|
||||
Directory temp = tempDir();
|
||||
var file = new File("${temp.path}/nonExistentFile5");
|
||||
|
||||
// Non-existing file should throw exception.
|
||||
Expect.throws(() => file.readAsLinesSync(),
|
||||
(e) => checkOpenNonExistentFileSystemException(e));
|
||||
|
||||
var readAsLinesFuture = file.readAsLines(encoding: ascii);
|
||||
readAsLinesFuture
|
||||
.then((data) => Expect.fail("Unreachable code"))
|
||||
.catchError((error) {
|
||||
checkOpenNonExistentFileSystemException(error);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
bool checkWriteReadOnlyFileSystemException(e) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
Expect.isTrue(e.osError != null);
|
||||
Expect.isTrue(e.osError.errorCode != OSError.noErrorCode);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create a test file in a temporary directory. Setup a port to signal
|
||||
// when the temporary directory should be deleted. Pass the file and
|
||||
// the port to the callback argument.
|
||||
createTestFile(callback) {
|
||||
asyncStart();
|
||||
Directory temp = tempDir();
|
||||
var file = new File("${temp.path}/test_file");
|
||||
file.createSync();
|
||||
callback(file, () {
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
testWriteByteToReadOnlyFile() {
|
||||
createTestFile((file, done) {
|
||||
var openedFile = file.openSync(mode: FileMode.read);
|
||||
|
||||
// Writing to read only file should throw an exception.
|
||||
Expect.throws(() => openedFile.writeByteSync(0),
|
||||
(e) => checkWriteReadOnlyFileSystemException(e));
|
||||
|
||||
var writeByteFuture = openedFile.writeByte(0);
|
||||
writeByteFuture.catchError((error) {
|
||||
checkWriteReadOnlyFileSystemException(error);
|
||||
openedFile.close().then((_) => done());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
testWriteFromToReadOnlyFile() {
|
||||
createTestFile((file, done) {
|
||||
var openedFile = file.openSync(mode: FileMode.read);
|
||||
|
||||
List data = [0, 1, 2, 3];
|
||||
// Writing to read only file should throw an exception.
|
||||
Expect.throws(() => openedFile.writeFromSync(data, 0, data.length),
|
||||
(e) => checkWriteReadOnlyFileSystemException(e));
|
||||
|
||||
var writeFromFuture = openedFile.writeFrom(data, 0, data.length);
|
||||
writeFromFuture.catchError((error) {
|
||||
checkWriteReadOnlyFileSystemException(error);
|
||||
openedFile.close().then((_) => done());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
testTruncateReadOnlyFile() {
|
||||
createTestFile((file, done) {
|
||||
var openedFile = file.openSync(mode: FileMode.write);
|
||||
openedFile.writeByteSync(0);
|
||||
openedFile.closeSync();
|
||||
openedFile = file.openSync(mode: FileMode.read);
|
||||
|
||||
// Truncating read only file should throw an exception.
|
||||
Expect.throws(() => openedFile.truncateSync(0),
|
||||
(e) => checkWriteReadOnlyFileSystemException(e));
|
||||
|
||||
var truncateFuture = openedFile.truncate(0);
|
||||
truncateFuture
|
||||
.then((ignore) => Expect.fail("Unreachable code"))
|
||||
.catchError((error) {
|
||||
checkWriteReadOnlyFileSystemException(error);
|
||||
openedFile.close().then((_) => done());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
bool checkFileClosedException(e) {
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
Expect.isTrue(e.toString().indexOf("File closed") != -1);
|
||||
Expect.isTrue(e.osError == null);
|
||||
return true;
|
||||
}
|
||||
|
||||
testOperateOnClosedFile() {
|
||||
createTestFile((file, done) {
|
||||
var openedFile = file.openSync(mode: FileMode.read);
|
||||
openedFile.closeSync();
|
||||
|
||||
List data = [0, 1, 2, 3];
|
||||
Expect.throws(
|
||||
() => openedFile.readByteSync(), (e) => checkFileClosedException(e));
|
||||
Expect.throws(
|
||||
() => openedFile.writeByteSync(0), (e) => checkFileClosedException(e));
|
||||
Expect.throws(() => openedFile.writeFromSync(data, 0, data.length),
|
||||
(e) => checkFileClosedException(e));
|
||||
Expect.throws(() => openedFile.readIntoSync(data, 0, data.length),
|
||||
(e) => checkFileClosedException(e));
|
||||
Expect.throws(() => openedFile.writeStringSync("Hello"),
|
||||
(e) => checkFileClosedException(e));
|
||||
Expect.throws(
|
||||
() => openedFile.positionSync(), (e) => checkFileClosedException(e));
|
||||
Expect.throws(() => openedFile.setPositionSync(0),
|
||||
(e) => checkFileClosedException(e));
|
||||
Expect.throws(
|
||||
() => openedFile.truncateSync(0), (e) => checkFileClosedException(e));
|
||||
Expect.throws(
|
||||
() => openedFile.lengthSync(), (e) => checkFileClosedException(e));
|
||||
Expect.throws(
|
||||
() => openedFile.flushSync(), (e) => checkFileClosedException(e));
|
||||
|
||||
var errorCount = 0;
|
||||
|
||||
_errorHandler(error) {
|
||||
checkFileClosedException(error);
|
||||
if (--errorCount == 0) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
|
||||
var readByteFuture = openedFile.readByte();
|
||||
readByteFuture
|
||||
.then((byte) => Expect.fail("Unreachable code"))
|
||||
.catchError(_errorHandler);
|
||||
errorCount++;
|
||||
var writeByteFuture = openedFile.writeByte(0);
|
||||
writeByteFuture
|
||||
.then((ignore) => Expect.fail("Unreachable code"))
|
||||
.catchError(_errorHandler);
|
||||
errorCount++;
|
||||
var readIntoFuture = openedFile.readInto(data, 0, data.length);
|
||||
readIntoFuture
|
||||
.then((bytesRead) => Expect.fail("Unreachable code"))
|
||||
.catchError(_errorHandler);
|
||||
errorCount++;
|
||||
var writeFromFuture = openedFile.writeFrom(data, 0, data.length);
|
||||
writeFromFuture
|
||||
.then((ignore) => Expect.fail("Unreachable code"))
|
||||
.catchError(_errorHandler);
|
||||
errorCount++;
|
||||
var writeStringFuture = openedFile.writeString("Hello");
|
||||
writeStringFuture
|
||||
.then((ignore) => Expect.fail("Unreachable code"))
|
||||
.catchError(_errorHandler);
|
||||
errorCount++;
|
||||
var positionFuture = openedFile.position();
|
||||
positionFuture
|
||||
.then((position) => Expect.fail("Unreachable code"))
|
||||
.catchError(_errorHandler);
|
||||
errorCount++;
|
||||
var setPositionFuture = openedFile.setPosition(0);
|
||||
setPositionFuture
|
||||
.then((ignore) => Expect.fail("Unreachable code"))
|
||||
.catchError(_errorHandler);
|
||||
errorCount++;
|
||||
var truncateFuture = openedFile.truncate(0);
|
||||
truncateFuture
|
||||
.then((ignore) => Expect.fail("Unreachable code"))
|
||||
.catchError(_errorHandler);
|
||||
errorCount++;
|
||||
var lenFuture = openedFile.length();
|
||||
lenFuture
|
||||
.then((length) => Expect.fail("Unreachable code"))
|
||||
.catchError(_errorHandler);
|
||||
errorCount++;
|
||||
var flushFuture = openedFile.flush();
|
||||
flushFuture
|
||||
.then((ignore) => Expect.fail("Unreachable code"))
|
||||
.catchError(_errorHandler);
|
||||
errorCount++;
|
||||
});
|
||||
}
|
||||
|
||||
testRepeatedlyCloseFile() {
|
||||
createTestFile((file, done) {
|
||||
var openedFile = file.openSync();
|
||||
openedFile.close().then((ignore) {
|
||||
var closeFuture = openedFile.close();
|
||||
closeFuture.then((ignore) => null).catchError((error) {
|
||||
Expect.isTrue(error is FileSystemException);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
testRepeatedlyCloseFileSync() {
|
||||
createTestFile((file, done) {
|
||||
var openedFile = file.openSync();
|
||||
openedFile.closeSync();
|
||||
Expect.throws(openedFile.closeSync, (e) => e is FileSystemException);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
testReadSyncClosedFile() {
|
||||
createTestFile((file, done) {
|
||||
var openedFile = file.openSync();
|
||||
openedFile.closeSync();
|
||||
Expect.throws(
|
||||
() => openedFile.readSync(1), (e) => e is FileSystemException);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
testOpenNonExistent();
|
||||
testDeleteNonExistent();
|
||||
testLengthNonExistent();
|
||||
testCreateInNonExistentDirectory();
|
||||
testResolveSymbolicLinksOnNonExistentDirectory();
|
||||
testReadAsBytesNonExistent();
|
||||
testReadAsTextNonExistent();
|
||||
testReadAsLinesNonExistent();
|
||||
testWriteByteToReadOnlyFile();
|
||||
testWriteFromToReadOnlyFile();
|
||||
testTruncateReadOnlyFile();
|
||||
testOperateOnClosedFile();
|
||||
testRepeatedlyCloseFile();
|
||||
testRepeatedlyCloseFileSync();
|
||||
testReadSyncClosedFile();
|
||||
}
|
126
tests/standalone/io/file_fuzz_test.dart
Normal file
126
tests/standalone/io/file_fuzz_test.dart
Normal file
|
@ -0,0 +1,126 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
// 'fuzz' test the file APIs by providing unexpected type arguments. The test
|
||||
// passes if the VM does not crash.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'fuzz_support.dart';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
fuzzSyncMethods() {
|
||||
typeMapping.forEach((k, v) {
|
||||
late File f;
|
||||
doItSync(() => f = new File(v as String));
|
||||
if (f == null) return;
|
||||
doItSync(f.existsSync);
|
||||
doItSync(f.createSync);
|
||||
doItSync(f.deleteSync);
|
||||
doItSync(f.lengthSync);
|
||||
doItSync(f.lastModifiedSync);
|
||||
doItSync(() => f.path);
|
||||
doItSync(() => f.openRead().listen((_) {}, onError: (e) {}));
|
||||
doItSync(f.readAsBytesSync);
|
||||
doItSync(f.readAsStringSync);
|
||||
doItSync(f.readAsLinesSync);
|
||||
typeMapping.forEach((k2, v2) {
|
||||
doItSync(() => f.openSync(mode: v2 as FileMode));
|
||||
doItSync(() => f.openWrite(mode: v2 as FileMode));
|
||||
doItSync(() => f.readAsStringSync(encoding: v2 as Encoding));
|
||||
doItSync(() => f.readAsLinesSync(encoding: v2 as Encoding));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fuzzAsyncMethods() {
|
||||
asyncStart();
|
||||
var futures = <Future>[];
|
||||
typeMapping.forEach((k, v) {
|
||||
late File f;
|
||||
doItSync(() => f = new File(v as String));
|
||||
if (f == null) return;
|
||||
futures.add(doItAsync(f.exists));
|
||||
futures.add(doItAsync(f.delete));
|
||||
futures.add(doItAsync(() => f.parent));
|
||||
futures.add(doItAsync(f.length));
|
||||
futures.add(doItAsync(f.lastModified));
|
||||
futures.add(doItAsync(f.open));
|
||||
futures.add(doItAsync(() => f.path));
|
||||
futures.add(doItAsync(f.readAsBytes));
|
||||
futures.add(doItAsync(f.readAsLines));
|
||||
futures.add(doItAsync(f.readAsString));
|
||||
typeMapping.forEach((k2, v2) {
|
||||
futures.add(doItAsync(() => f.open(mode: v2 as FileMode)));
|
||||
futures.add(doItAsync(() => f.readAsString(encoding: v2 as Encoding)));
|
||||
futures.add(doItAsync(() => f.readAsLines(encoding: v2 as Encoding)));
|
||||
});
|
||||
});
|
||||
Future.wait(futures).then((_) => asyncEnd());
|
||||
}
|
||||
|
||||
fuzzSyncRandomAccessMethods() {
|
||||
var temp = Directory.systemTemp.createTempSync('dart_file_fuzz');
|
||||
var file = new File('${temp.path}/x');
|
||||
file.createSync();
|
||||
var modes = [FileMode.read, FileMode.write, FileMode.append];
|
||||
for (var m in modes) {
|
||||
var opened = file.openSync(mode: m);
|
||||
typeMapping.forEach((k, v) {
|
||||
doItSync(() => opened.setPositionSync(v as int));
|
||||
doItSync(() => opened.truncateSync(v as int));
|
||||
doItSync(() => opened.writeByteSync(v as int));
|
||||
});
|
||||
for (var p in typePermutations(2)) {
|
||||
doItSync(() => opened.writeStringSync(p[0], encoding: p[1]));
|
||||
}
|
||||
for (var p in typePermutations(3)) {
|
||||
doItSync(() => opened.readIntoSync(p[0], p[1], p[2]));
|
||||
doItSync(() => opened.writeFromSync(p[0], p[1], p[2]));
|
||||
}
|
||||
opened.closeSync();
|
||||
}
|
||||
temp.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
fuzzAsyncRandomAccessMethods() {
|
||||
var temp = Directory.systemTemp.createTempSync('dart_file_fuzz');
|
||||
var file = new File('${temp.path}/x');
|
||||
file.createSync();
|
||||
var modes = [FileMode.read, FileMode.write, FileMode.append];
|
||||
var futures = <Future>[];
|
||||
var openedFiles = [];
|
||||
for (var m in modes) {
|
||||
var opened = file.openSync(mode: m);
|
||||
openedFiles.add(opened);
|
||||
typeMapping.forEach((k, v) {
|
||||
futures.add(doItAsync(() => opened.setPosition(v as int)));
|
||||
futures.add(doItAsync(() => opened.truncate(v as int)));
|
||||
futures.add(doItAsync(() => opened.writeByte(v as int)));
|
||||
});
|
||||
for (var p in typePermutations(2)) {
|
||||
futures.add(doItAsync(() => opened.writeString(p[0], encoding: p[1])));
|
||||
}
|
||||
for (var p in typePermutations(3)) {
|
||||
futures.add(doItAsync(() => opened.readInto(p[0], p[1], p[2])));
|
||||
futures.add(doItAsync(() => opened.writeFrom(p[0], p[1], p[2])));
|
||||
}
|
||||
}
|
||||
Future.wait(futures).then((ignore) {
|
||||
for (var opened in openedFiles) {
|
||||
opened.closeSync();
|
||||
}
|
||||
temp.deleteSync(recursive: true);
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
fuzzSyncMethods();
|
||||
fuzzAsyncMethods();
|
||||
fuzzSyncRandomAccessMethods();
|
||||
fuzzAsyncRandomAccessMethods();
|
||||
}
|
249
tests/standalone/io/file_input_stream_test.dart
Normal file
249
tests/standalone/io/file_input_stream_test.dart
Normal file
|
@ -0,0 +1,249 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
// Testing file input stream, VM-only, standalone test.
|
||||
//
|
||||
// OtherResources=readuntil_test.dat
|
||||
// OtherResources=readline_test1.dat
|
||||
// OtherResources=readline_test2.dat
|
||||
|
||||
import "dart:convert";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
String getFilename(String path) {
|
||||
return Platform.script.resolve(path).toFilePath();
|
||||
}
|
||||
|
||||
void testStringLineSplitter() {
|
||||
String fileName = getFilename("readuntil_test.dat");
|
||||
// File contains "Hello Dart\nwassup!\n"
|
||||
File file = new File(fileName);
|
||||
int linesRead = 0;
|
||||
var lineStream = file
|
||||
.openRead()
|
||||
.cast<List<int>>()
|
||||
.transform(utf8.decoder)
|
||||
.transform(new LineSplitter());
|
||||
lineStream.listen((line) {
|
||||
linesRead++;
|
||||
if (linesRead == 1) {
|
||||
Expect.equals("Hello Dart", line);
|
||||
} else if (linesRead == 2) {
|
||||
Expect.equals("wassup!", line);
|
||||
} else {
|
||||
Expect.fail("More or less than 2 lines read ($linesRead lines read).");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void testOpenStreamAsync() {
|
||||
asyncStart();
|
||||
String fileName = getFilename("readuntil_test.dat");
|
||||
// File contains "Hello Dart\nwassup!\n"
|
||||
var expected = "Hello Dart\nwassup!\n".codeUnits;
|
||||
var byteCount = 0;
|
||||
(new File(fileName)).openRead().listen((d) => byteCount += d.length,
|
||||
onDone: () {
|
||||
Expect.equals(expected.length, byteCount);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
// Create a file that is big enough that a file stream will
|
||||
// read it in multiple chunks.
|
||||
int writeLongFileSync(File file) {
|
||||
file.createSync();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (var i = 0; i < 50000; i++) {
|
||||
buffer.write("Hello, world");
|
||||
}
|
||||
file.writeAsStringSync(buffer.toString());
|
||||
var length = file.lengthSync();
|
||||
Expect.equals(buffer.length, length);
|
||||
return length;
|
||||
}
|
||||
|
||||
void testInputStreamTruncate() {
|
||||
asyncStart();
|
||||
var temp = Directory.systemTemp.createTempSync('file_input_stream_test');
|
||||
var file = new File('${temp.path}/input_stream_truncate.txt');
|
||||
var originalLength = writeLongFileSync(file);
|
||||
// Start streaming the file. Pause after first chunk. Truncate
|
||||
// underlying file and check that the streaming stops with or
|
||||
// without getting all data.
|
||||
var streamedBytes = 0;
|
||||
var subscription;
|
||||
subscription = file.openRead().listen((d) {
|
||||
if (streamedBytes == 0) {
|
||||
subscription.pause();
|
||||
// Truncate the file by opening it for writing.
|
||||
file.open(mode: FileMode.write).then((opened) {
|
||||
opened.close().then((_) {
|
||||
Expect.equals(0, file.lengthSync());
|
||||
subscription.resume();
|
||||
});
|
||||
});
|
||||
}
|
||||
streamedBytes += d.length;
|
||||
}, onDone: () {
|
||||
Expect.isTrue(streamedBytes > 0 && streamedBytes <= originalLength);
|
||||
temp.delete(recursive: true).then((_) => asyncEnd());
|
||||
}, onError: (e) {
|
||||
Expect.fail("Unexpected error");
|
||||
});
|
||||
}
|
||||
|
||||
void testInputStreamDelete() {
|
||||
asyncStart();
|
||||
var temp = Directory.systemTemp.createTempSync('file_input_stream_test');
|
||||
var file = new File('${temp.path}/input_stream_delete.txt');
|
||||
var originalLength = writeLongFileSync(file);
|
||||
// Start streaming the file. Pause after first chunk. Truncate
|
||||
// underlying file and check that the streaming stops with or
|
||||
// without getting all data.
|
||||
var streamedBytes = 0;
|
||||
var subscription;
|
||||
subscription = file.openRead().listen((d) {
|
||||
if (streamedBytes == 0) {
|
||||
subscription.pause();
|
||||
// Delete the underlying file by opening it for writing.
|
||||
file.delete().then((deleted) {
|
||||
Expect.isFalse(deleted.existsSync());
|
||||
subscription.resume();
|
||||
}).catchError((e) {
|
||||
// On Windows, you cannot delete a file that is open
|
||||
// somewhere else. The stream has this file open
|
||||
// and therefore we get an error on deletion on Windows.
|
||||
Expect.equals('windows', Platform.operatingSystem);
|
||||
subscription.resume();
|
||||
});
|
||||
}
|
||||
streamedBytes += d.length;
|
||||
}, onDone: () {
|
||||
Expect.equals(originalLength, streamedBytes);
|
||||
temp.delete(recursive: true).then((_) => asyncEnd());
|
||||
}, onError: (e) {
|
||||
Expect.fail("Unexpected error");
|
||||
});
|
||||
}
|
||||
|
||||
void testInputStreamAppend() {
|
||||
asyncStart();
|
||||
var temp = Directory.systemTemp.createTempSync('file_input_stream_test');
|
||||
var file = new File('${temp.path}/input_stream_append.txt');
|
||||
var originalLength = writeLongFileSync(file);
|
||||
// Start streaming the file. Pause after first chunk. Append to
|
||||
// underlying file and check that the stream gets all the data.
|
||||
var streamedBytes = 0;
|
||||
var subscription;
|
||||
subscription = file.openRead().listen((d) {
|
||||
if (streamedBytes == 0) {
|
||||
subscription.pause();
|
||||
// Double the length of the underlying file.
|
||||
file.readAsBytes().then((bytes) {
|
||||
file.writeAsBytes(bytes, mode: FileMode.append).then((_) {
|
||||
Expect.equals(2 * originalLength, file.lengthSync());
|
||||
subscription.resume();
|
||||
});
|
||||
});
|
||||
}
|
||||
streamedBytes += d.length;
|
||||
}, onDone: () {
|
||||
Expect.equals(2 * originalLength, streamedBytes);
|
||||
temp.delete(recursive: true).then((_) => asyncEnd());
|
||||
}, onError: (e) {
|
||||
Expect.fail("Unexpected error");
|
||||
});
|
||||
}
|
||||
|
||||
void testInputStreamOffset() {
|
||||
void test(int? start, int? end, int expectedBytes) {
|
||||
asyncStart();
|
||||
var temp = Directory.systemTemp.createTempSync('file_input_stream_test');
|
||||
var file = new File('${temp.path}/input_stream_offset.txt');
|
||||
var originalLength = writeLongFileSync(file);
|
||||
var streamedBytes = 0;
|
||||
if (expectedBytes < 0) expectedBytes = originalLength + expectedBytes;
|
||||
file.openRead(start, end).listen((d) {
|
||||
streamedBytes += d.length;
|
||||
}, onDone: () {
|
||||
Expect.equals(expectedBytes, streamedBytes);
|
||||
temp.delete(recursive: true).then((_) => asyncEnd());
|
||||
}, onError: (e) {
|
||||
Expect.fail("Unexpected error");
|
||||
});
|
||||
}
|
||||
|
||||
test(10, 20, 10);
|
||||
test(10, 11, 1);
|
||||
test(10, 10, 0);
|
||||
test(100000000, null, 0);
|
||||
test(null, 0, 0);
|
||||
test(null, 1, 1);
|
||||
test(1, null, -1);
|
||||
test(20, null, -20);
|
||||
}
|
||||
|
||||
void testInputStreamBadOffset() {
|
||||
void test(int? start, int? end) {
|
||||
asyncStart();
|
||||
var temp = Directory.systemTemp.createTempSync('file_input_stream_test');
|
||||
var file = new File('${temp.path}/input_stream_bad_offset.txt');
|
||||
var originalLength = writeLongFileSync(file);
|
||||
var streamedBytes = 0;
|
||||
bool error = false;
|
||||
file.openRead(start, end).listen((d) {
|
||||
streamedBytes += d.length;
|
||||
}, onDone: () {
|
||||
Expect.isTrue(error);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
}, onError: (e) {
|
||||
error = true;
|
||||
});
|
||||
}
|
||||
|
||||
test(-1, null);
|
||||
test(100, 99);
|
||||
test(null, -1);
|
||||
}
|
||||
|
||||
void testStringLineSplitterEnding(String name, int length) {
|
||||
String fileName = getFilename(name);
|
||||
// File contains 10 lines.
|
||||
File file = new File(fileName);
|
||||
Expect.equals(length, file.lengthSync());
|
||||
var lineStream = file
|
||||
.openRead()
|
||||
.cast<List<int>>()
|
||||
.transform(utf8.decoder)
|
||||
.transform(new LineSplitter());
|
||||
int lineCount = 0;
|
||||
lineStream.listen((line) {
|
||||
lineCount++;
|
||||
Expect.isTrue(lineCount <= 10);
|
||||
if (line[0] != "#") {
|
||||
Expect.equals("Line $lineCount", line);
|
||||
}
|
||||
}, onDone: () {
|
||||
Expect.equals(10, lineCount);
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
testStringLineSplitter();
|
||||
testOpenStreamAsync();
|
||||
testInputStreamTruncate();
|
||||
testInputStreamDelete();
|
||||
testInputStreamAppend();
|
||||
testInputStreamOffset();
|
||||
testInputStreamBadOffset();
|
||||
// Check the length of these files as both are text files where one
|
||||
// is without a terminating line separator which can easily be added
|
||||
// back if accidentally opened in a text editor.
|
||||
testStringLineSplitterEnding("readline_test1.dat", 111);
|
||||
testStringLineSplitterEnding("readline_test2.dat", 114);
|
||||
}
|
32
tests/standalone/io/file_lock_script.dart
Normal file
32
tests/standalone/io/file_lock_script.dart
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) 2015, 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.
|
||||
//
|
||||
// Script used by the file_lock_test.dart test.
|
||||
|
||||
import "dart:io";
|
||||
|
||||
main(List<String> args) {
|
||||
File file = new File(args[0]);
|
||||
int start = 0;
|
||||
int end = -1;
|
||||
var mode = FileLock.exclusive;
|
||||
if (args[1] == 'SHARED') {
|
||||
mode = FileLock.shared;
|
||||
}
|
||||
if (args[2] != 'null') {
|
||||
start = int.parse(args[2]);
|
||||
}
|
||||
if (args[3] != 'null') {
|
||||
end = int.parse(args[3]);
|
||||
}
|
||||
var raf = file.openSync(mode: FileMode.write);
|
||||
try {
|
||||
raf.lockSync(mode, start, end);
|
||||
print('LOCK SUCCEEDED');
|
||||
} catch (e) {
|
||||
print('LOCK FAILED');
|
||||
} finally {
|
||||
raf.closeSync();
|
||||
}
|
||||
}
|
317
tests/standalone/io/file_lock_test.dart
Normal file
317
tests/standalone/io/file_lock_test.dart
Normal file
|
@ -0,0 +1,317 @@
|
|||
// Copyright (c) 2015, 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.
|
||||
|
||||
// OtherResources=file_lock_script.dart
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
import "package:path/path.dart";
|
||||
|
||||
// Check whether the file is locked or not.
|
||||
check(String path, int start, int end, FileLock mode, {required bool locked}) {
|
||||
// Client process returns either 'LOCK FAILED' or 'LOCK SUCCEEDED'.
|
||||
var expected = locked ? 'LOCK FAILED' : 'LOCK SUCCEEDED';
|
||||
var arguments = <String>[]
|
||||
..addAll(Platform.executableArguments)
|
||||
..add(Platform.script.resolve('file_lock_script.dart').toFilePath())
|
||||
..add(path)
|
||||
..add(mode == FileLock.exclusive ? 'EXCLUSIVE' : 'SHARED')
|
||||
..add('$start')
|
||||
..add('$end');
|
||||
var stacktrace = StackTrace.current;
|
||||
return Process.run(Platform.executable, arguments)
|
||||
.then((ProcessResult result) {
|
||||
if (result.exitCode != 0 || !result.stdout.contains(expected)) {
|
||||
print("Client failed, exit code ${result.exitCode}");
|
||||
print(" stdout:");
|
||||
print(result.stdout);
|
||||
print(" stderr:");
|
||||
print(result.stderr);
|
||||
print(" arguments:");
|
||||
print(arguments);
|
||||
print(" call stack:");
|
||||
print(stacktrace);
|
||||
Expect.fail('Client subprocess exit code: ${result.exitCode}');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
checkLocked(String path,
|
||||
[int start = 0, int end = -1, FileLock mode = FileLock.exclusive]) =>
|
||||
check(path, start, end, mode, locked: true);
|
||||
|
||||
checkNotLocked(String path,
|
||||
[int start = 0, int end = -1, FileLock mode = FileLock.exclusive]) =>
|
||||
check(path, start, end, mode, locked: false);
|
||||
|
||||
void testLockWholeFile() {
|
||||
Directory directory = Directory.systemTemp.createTempSync('dart_file_lock');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
file.writeAsBytesSync(new List.filled(10, 0));
|
||||
var raf = file.openSync(mode: FileMode.write);
|
||||
raf.lockSync();
|
||||
asyncStart();
|
||||
checkLocked(file.path).then((_) {
|
||||
return checkLocked(file.path, 0, 2).then((_) {
|
||||
raf.unlockSync();
|
||||
return checkNotLocked(file.path).then((_) {});
|
||||
});
|
||||
}).whenComplete(() {
|
||||
raf.closeSync();
|
||||
directory.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testLockWholeFileAsync() {
|
||||
Directory directory = Directory.systemTemp.createTempSync('dart_file_lock');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
file.writeAsBytesSync(new List.filled(10, 0));
|
||||
var raf = file.openSync(mode: FileMode.write);
|
||||
asyncStart();
|
||||
Future.forEach<Function>([
|
||||
() => raf.lock(),
|
||||
() => checkLocked(file.path, 0, 2),
|
||||
() => checkLocked(file.path),
|
||||
() => raf.unlock(),
|
||||
() => checkNotLocked(file.path),
|
||||
], (f) => f()).whenComplete(() {
|
||||
raf.closeSync();
|
||||
directory.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testLockRange() {
|
||||
Directory directory = Directory.systemTemp.createTempSync('dart_file_lock');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
file.writeAsBytesSync(new List.filled(10, 0));
|
||||
var raf1 = file.openSync(mode: FileMode.write);
|
||||
var raf2 = file.openSync(mode: FileMode.write);
|
||||
asyncStart();
|
||||
var tests = [
|
||||
() => raf1.lockSync(FileLock.exclusive, 2, 3),
|
||||
() => raf2.lockSync(FileLock.exclusive, 5, 7),
|
||||
() => checkNotLocked(file.path, 0, 2),
|
||||
() => checkLocked(file.path, 0, 3),
|
||||
() => checkNotLocked(file.path, 4, 5),
|
||||
() => checkLocked(file.path, 4, 6),
|
||||
() => checkLocked(file.path, 6),
|
||||
() => checkNotLocked(file.path, 7),
|
||||
() => raf1.unlockSync(2, 3),
|
||||
() => checkNotLocked(file.path, 0, 5),
|
||||
() => checkLocked(file.path, 4, 6),
|
||||
() => checkLocked(file.path, 6),
|
||||
() => checkNotLocked(file.path, 7),
|
||||
];
|
||||
// On Windows regions unlocked must match regions locked.
|
||||
if (!Platform.isWindows) {
|
||||
tests.addAll([
|
||||
() => raf1.unlockSync(5, 6),
|
||||
() => checkNotLocked(file.path, 0, 6),
|
||||
() => checkLocked(file.path, 6),
|
||||
() => checkNotLocked(file.path, 7),
|
||||
() => raf2.unlockSync(6, 7),
|
||||
() => checkNotLocked(file.path)
|
||||
]);
|
||||
} else {
|
||||
tests
|
||||
.addAll([() => raf2.unlockSync(5, 7), () => checkNotLocked(file.path)]);
|
||||
}
|
||||
Future.forEach<Function>(tests, (f) => f()).whenComplete(() {
|
||||
raf1.closeSync();
|
||||
raf2.closeSync();
|
||||
directory.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testLockRangeAsync() {
|
||||
Directory directory = Directory.systemTemp.createTempSync('dart_file_lock');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
file.writeAsBytesSync(new List.filled(10, 0));
|
||||
var raf1 = file.openSync(mode: FileMode.write);
|
||||
var raf2 = file.openSync(mode: FileMode.write);
|
||||
asyncStart();
|
||||
var tests = [
|
||||
() => raf1.lock(FileLock.exclusive, 2, 3),
|
||||
() => raf2.lock(FileLock.exclusive, 5, 7),
|
||||
() => checkNotLocked(file.path, 0, 2),
|
||||
() => checkLocked(file.path, 0, 3),
|
||||
() => checkNotLocked(file.path, 4, 5),
|
||||
() => checkLocked(file.path, 4, 6),
|
||||
() => checkLocked(file.path, 6),
|
||||
() => checkNotLocked(file.path, 7),
|
||||
() => raf1.unlock(2, 3),
|
||||
() => checkNotLocked(file.path, 0, 5),
|
||||
() => checkLocked(file.path, 4, 6),
|
||||
() => checkLocked(file.path, 6),
|
||||
() => checkNotLocked(file.path, 7),
|
||||
];
|
||||
// On Windows regions unlocked must match regions locked.
|
||||
if (!Platform.isWindows) {
|
||||
tests.addAll([
|
||||
() => raf1.unlock(5, 6),
|
||||
() => checkNotLocked(file.path, 0, 6),
|
||||
() => checkLocked(file.path, 6),
|
||||
() => checkNotLocked(file.path, 7),
|
||||
() => raf2.unlock(6, 7),
|
||||
() => checkNotLocked(file.path)
|
||||
]);
|
||||
} else {
|
||||
tests.addAll([() => raf2.unlock(5, 7), () => checkNotLocked(file.path)]);
|
||||
}
|
||||
Future.forEach<Function>(tests, (f) => f()).whenComplete(() {
|
||||
raf1.closeSync();
|
||||
raf2.closeSync();
|
||||
directory.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testLockEnd() {
|
||||
Directory directory = Directory.systemTemp.createTempSync('dart_file_lock');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
file.writeAsBytesSync(new List.filled(10, 0));
|
||||
var raf = file.openSync(mode: FileMode.append);
|
||||
asyncStart();
|
||||
Future.forEach<Function>([
|
||||
() => raf.lockSync(FileLock.exclusive, 2),
|
||||
() => checkNotLocked(file.path, 0, 2),
|
||||
() => checkLocked(file.path, 0, 3),
|
||||
() => checkLocked(file.path, 9),
|
||||
() => raf.writeFromSync(new List.filled(10, 0)),
|
||||
() => checkLocked(file.path, 10),
|
||||
() => checkLocked(file.path, 19),
|
||||
() => raf.unlockSync(2),
|
||||
() => checkNotLocked(file.path)
|
||||
], (f) => f()).whenComplete(() {
|
||||
raf.closeSync();
|
||||
directory.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testLockEndAsync() {
|
||||
Directory directory = Directory.systemTemp.createTempSync('dart_file_lock');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
file.writeAsBytesSync(new List.filled(10, 0));
|
||||
var raf = file.openSync(mode: FileMode.append);
|
||||
asyncStart();
|
||||
Future.forEach<Function>([
|
||||
() => raf.lock(FileLock.exclusive, 2),
|
||||
() => checkNotLocked(file.path, 0, 2),
|
||||
() => checkLocked(file.path, 0, 3),
|
||||
() => checkLocked(file.path, 9),
|
||||
() => raf.writeFromSync(new List.filled(10, 0)),
|
||||
() => checkLocked(file.path, 10),
|
||||
() => checkLocked(file.path, 19),
|
||||
() => raf.unlock(2),
|
||||
() => checkNotLocked(file.path)
|
||||
], (f) => f()).whenComplete(() {
|
||||
raf.closeSync();
|
||||
directory.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testLockShared() {
|
||||
Directory directory = Directory.systemTemp.createTempSync('dart_file_lock');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
file.writeAsBytesSync(new List.filled(10, 0));
|
||||
var raf = file.openSync();
|
||||
asyncStart();
|
||||
Future.forEach<Function>([
|
||||
() => raf.lock(FileLock.shared),
|
||||
() => checkLocked(file.path),
|
||||
() => checkLocked(file.path, 0, 2),
|
||||
() => checkNotLocked(file.path, 0, 2, FileLock.shared)
|
||||
], (f) => f()).then((_) {
|
||||
raf.closeSync();
|
||||
directory.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testLockSharedAsync() {
|
||||
Directory directory = Directory.systemTemp.createTempSync('dart_file_lock');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
file.writeAsBytesSync(new List.filled(10, 0));
|
||||
var raf = file.openSync();
|
||||
asyncStart();
|
||||
Future.forEach<Function>([
|
||||
() => raf.lock(FileLock.shared),
|
||||
() => checkLocked(file.path),
|
||||
() => checkLocked(file.path, 0, 2),
|
||||
() => checkNotLocked(file.path, 0, 2, FileLock.shared)
|
||||
], (f) => f()).whenComplete(() {
|
||||
raf.closeSync();
|
||||
directory.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testLockAfterLength() {
|
||||
Directory directory = Directory.systemTemp.createTempSync('dart_file_lock');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
file.writeAsBytesSync(new List.filled(10, 0));
|
||||
var raf = file.openSync(mode: FileMode.append);
|
||||
asyncStart();
|
||||
Future.forEach<Function>([
|
||||
() => raf.lockSync(FileLock.exclusive, 2, 15),
|
||||
() => checkNotLocked(file.path, 0, 2),
|
||||
() => checkLocked(file.path, 0, 3),
|
||||
() => checkLocked(file.path, 9),
|
||||
() => checkLocked(file.path, 14),
|
||||
() => raf.writeFromSync(new List.filled(10, 0)),
|
||||
() => checkLocked(file.path, 10),
|
||||
() => checkNotLocked(file.path, 15),
|
||||
() => raf.unlockSync(2, 15),
|
||||
() => checkNotLocked(file.path)
|
||||
], (f) => f()).whenComplete(() {
|
||||
raf.closeSync();
|
||||
directory.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testLockAfterLengthAsync() {
|
||||
Directory directory = Directory.systemTemp.createTempSync('dart_file_lock');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
file.writeAsBytesSync(new List.filled(10, 0));
|
||||
var raf = file.openSync(mode: FileMode.append);
|
||||
asyncStart();
|
||||
Future.forEach<Function>([
|
||||
() => raf.lock(FileLock.exclusive, 2, 15),
|
||||
() => checkNotLocked(file.path, 0, 2),
|
||||
() => checkLocked(file.path, 0, 3),
|
||||
() => checkLocked(file.path, 9),
|
||||
() => checkLocked(file.path, 14),
|
||||
() => raf.writeFromSync(new List.filled(10, 0)),
|
||||
() => checkLocked(file.path, 10),
|
||||
() => checkNotLocked(file.path, 15),
|
||||
() => raf.unlock(2, 15),
|
||||
() => checkNotLocked(file.path)
|
||||
], (f) => f()).whenComplete(() {
|
||||
raf.closeSync();
|
||||
directory.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
testLockWholeFile();
|
||||
testLockWholeFileAsync();
|
||||
testLockRange();
|
||||
testLockRangeAsync();
|
||||
testLockEnd();
|
||||
testLockEndAsync();
|
||||
testLockShared();
|
||||
testLockSharedAsync();
|
||||
testLockAfterLength();
|
||||
testLockAfterLengthAsync();
|
||||
}
|
32
tests/standalone/io/file_non_ascii_sync_test.dart
Normal file
32
tests/standalone/io/file_non_ascii_sync_test.dart
Normal file
|
@ -0,0 +1,32 @@
|
|||
// 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:io';
|
||||
|
||||
main() {
|
||||
Directory tempDir =
|
||||
Directory.systemTemp.createTempSync('dart_file_non_ascii_sync');
|
||||
Directory nonAsciiDir = new Directory('${tempDir.path}/æøå');
|
||||
nonAsciiDir.createSync();
|
||||
Expect.isTrue(nonAsciiDir.existsSync());
|
||||
File nonAsciiFile = new File('${nonAsciiDir.path}/æøå.txt');
|
||||
nonAsciiFile.writeAsStringSync('æøå');
|
||||
Expect.isTrue(nonAsciiFile.existsSync());
|
||||
// On MacOS you get the decomposed utf8 form of file and directory
|
||||
// names from the system. Therefore, we have to check for both here.
|
||||
var precomposed = 'æøå';
|
||||
var decomposed = new String.fromCharCodes([47, 230, 248, 97, 778]);
|
||||
// The contents of the file is precomposed utf8.
|
||||
Expect.equals(precomposed, nonAsciiFile.readAsStringSync());
|
||||
nonAsciiFile.createSync();
|
||||
var path = nonAsciiFile.parent.path;
|
||||
Expect.isTrue(path.endsWith(precomposed) || path.endsWith(decomposed));
|
||||
Expect.equals(6, nonAsciiFile.lengthSync());
|
||||
nonAsciiFile.lastModifiedSync();
|
||||
path = nonAsciiFile.resolveSymbolicLinksSync();
|
||||
Expect.isTrue(path.endsWith('${precomposed}.txt') ||
|
||||
path.endsWith('${decomposed}.txt'));
|
||||
tempDir.deleteSync(recursive: true);
|
||||
}
|
55
tests/standalone/io/file_non_ascii_test.dart
Normal file
55
tests/standalone/io/file_non_ascii_test.dart
Normal file
|
@ -0,0 +1,55 @@
|
|||
// 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.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
main() {
|
||||
asyncStart();
|
||||
|
||||
// On MacOS you get the decomposed utf8 form of file and directory
|
||||
// names from the system. Therefore, we have to check for both here.
|
||||
var precomposed = 'æøå';
|
||||
var decomposed = new String.fromCharCodes([47, 230, 248, 97, 778]);
|
||||
|
||||
Directory.systemTemp.createTemp('dart_file_non_ascii').then((tempDir) {
|
||||
Directory nonAsciiDir = new Directory('${tempDir.path}/æøå');
|
||||
nonAsciiDir.create().then((nonAsciiDir) {
|
||||
nonAsciiDir.exists().then((result) {
|
||||
Expect.isTrue(result);
|
||||
File nonAsciiFile = new File('${nonAsciiDir.path}/æøå.txt');
|
||||
nonAsciiFile.writeAsString('æøå').then((_) {
|
||||
nonAsciiFile.exists().then((result) {
|
||||
Expect.isTrue(result);
|
||||
nonAsciiFile.readAsString().then((contents) {
|
||||
// The contents of the file is precomposed utf8.
|
||||
Expect.equals(precomposed, contents);
|
||||
nonAsciiFile.create().then((_) {
|
||||
var d = nonAsciiFile.parent;
|
||||
Expect.isTrue(d.path.endsWith(precomposed) ||
|
||||
d.path.endsWith(decomposed));
|
||||
nonAsciiFile.length().then((length) {
|
||||
Expect.equals(6, length);
|
||||
nonAsciiFile.lastModified().then((_) {
|
||||
nonAsciiFile.resolveSymbolicLinks().then((path) {
|
||||
Expect.isTrue(path.endsWith('${precomposed}.txt') ||
|
||||
path.endsWith('${decomposed}.txt'));
|
||||
tempDir.delete(recursive: true).then((_) {
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}).catchError((e) {
|
||||
Expect.fail("File not found");
|
||||
});
|
||||
}
|
33
tests/standalone/io/file_output_stream_test.dart
Normal file
33
tests/standalone/io/file_output_stream_test.dart
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
// Testing file input stream, VM-only, standalone test.
|
||||
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void testOpenOutputStreamSync() {
|
||||
Directory tempDirectory =
|
||||
Directory.systemTemp.createTempSync('dart_file_output_stream');
|
||||
|
||||
asyncStart();
|
||||
String fileName = "${tempDirectory.path}/test";
|
||||
File file = new File(fileName);
|
||||
file.createSync();
|
||||
IOSink x = file.openWrite();
|
||||
var data = [65, 66, 67];
|
||||
x.add(data);
|
||||
x.close();
|
||||
x.done.then((_) {
|
||||
Expect.listEquals(file.readAsBytesSync(), data);
|
||||
file.deleteSync();
|
||||
tempDirectory.deleteSync();
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
testOpenOutputStreamSync();
|
||||
}
|
50
tests/standalone/io/file_read_encoded_test.dart
Normal file
50
tests/standalone/io/file_read_encoded_test.dart
Normal file
|
@ -0,0 +1,50 @@
|
|||
// 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'dart:io';
|
||||
|
||||
void testReadAsString() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_read_encoded');
|
||||
|
||||
var file = new File('${tmp.path}/file');
|
||||
file.createSync();
|
||||
|
||||
file.writeAsBytesSync([0xb0]);
|
||||
|
||||
Expect.throws(file.readAsStringSync, (e) => e is FileSystemException);
|
||||
|
||||
asyncStart();
|
||||
file.readAsString().then((_) {
|
||||
Expect.fail("expected exception");
|
||||
}).catchError((e) {
|
||||
tmp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
}, test: (e) => e is FileSystemException);
|
||||
}
|
||||
|
||||
void testReadAsLines() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_read_encoded');
|
||||
|
||||
var file = new File('${tmp.path}/file');
|
||||
file.createSync();
|
||||
|
||||
file.writeAsBytesSync([0xb0]);
|
||||
|
||||
Expect.throws(file.readAsLinesSync, (e) => e is FileSystemException);
|
||||
|
||||
asyncStart();
|
||||
file.readAsLines().then((_) {
|
||||
Expect.fail("expected exception");
|
||||
}).catchError((e) {
|
||||
tmp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
}, test: (e) => e is FileSystemException);
|
||||
}
|
||||
|
||||
void main() {
|
||||
testReadAsString();
|
||||
testReadAsLines();
|
||||
}
|
34
tests/standalone/io/file_read_special_device_test.dart
Normal file
34
tests/standalone/io/file_read_special_device_test.dart
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
// OtherResources=file_read_stdio_script.dart
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'dart:io';
|
||||
|
||||
void openAndWriteScript(String script) {
|
||||
script = Platform.script.resolve(script).toFilePath();
|
||||
var executable = Platform.executable;
|
||||
var file = script; // Use script as file.
|
||||
Process.start("bash", [
|
||||
"-c",
|
||||
"$executable ${Platform.executableArguments.join(' ')} $script < $file"
|
||||
]).then((process) {
|
||||
process.exitCode.then((exitCode) {
|
||||
Expect.equals(0, exitCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testReadStdio() {
|
||||
openAndWriteScript("file_read_stdio_script.dart");
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Special unix devices do not exist on Windows.
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
testReadStdio();
|
||||
}
|
||||
}
|
13
tests/standalone/io/file_read_stdio_script.dart
Normal file
13
tests/standalone/io/file_read_stdio_script.dart
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
void main() {
|
||||
var expected = new File(Platform.script.toFilePath()).readAsStringSync();
|
||||
var stdin = new File('/dev/fd/0').readAsStringSync();
|
||||
if (expected != stdin) {
|
||||
throw "stdin not equal expected file";
|
||||
}
|
||||
}
|
119
tests/standalone/io/file_stat_test.dart
Normal file
119
tests/standalone/io/file_stat_test.dart
Normal file
|
@ -0,0 +1,119 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Dart test program for testing dart:io FileSystemEntity.Stat().
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
import "package:path/path.dart";
|
||||
|
||||
void testStat() {
|
||||
Directory directory = Directory.systemTemp.createTempSync('dart_file_stat');
|
||||
File file = new File(join(directory.path, "file"));
|
||||
FileStat fileStat = FileStat.statSync(file.path);
|
||||
FileStat fileStatDirect = file.statSync();
|
||||
Expect.equals(FileSystemEntityType.notFound, fileStat.type);
|
||||
Expect.equals(FileSystemEntityType.notFound, fileStatDirect.type);
|
||||
file.writeAsStringSync("Dart IO library test of FileStat");
|
||||
new Timer(const Duration(seconds: 2), () {
|
||||
file.readAsStringSync();
|
||||
directory.listSync();
|
||||
FileStat fileStat = FileStat.statSync(file.path);
|
||||
FileStat fileStatDirect = file.statSync();
|
||||
Expect.equals(FileSystemEntityType.file, fileStat.type);
|
||||
Expect.equals(32, fileStat.size);
|
||||
Expect.equals(FileSystemEntityType.file, fileStatDirect.type);
|
||||
Expect.equals(32, fileStatDirect.size);
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
|
||||
Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0);
|
||||
}
|
||||
Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw.
|
||||
FileStat directoryStat = FileStat.statSync(directory.path);
|
||||
FileStat directoryStatDirect = directory.statSync();
|
||||
Expect.equals(FileSystemEntityType.directory, directoryStat.type);
|
||||
Expect.equals(FileSystemEntityType.directory, directoryStatDirect.type);
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
Expect.isTrue(
|
||||
directoryStat.modified.compareTo(directoryStat.accessed) < 0);
|
||||
Expect.isTrue(
|
||||
directoryStat.changed.compareTo(directoryStat.accessed) < 0);
|
||||
}
|
||||
Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx.
|
||||
directory.deleteSync(recursive: true);
|
||||
});
|
||||
}
|
||||
|
||||
Future testStatAsync() {
|
||||
return Directory.systemTemp.createTemp('dart_file_stat').then((directory) {
|
||||
File file = new File(join(directory.path, "file"));
|
||||
return FileStat.stat(file.path)
|
||||
.then((fileStat) =>
|
||||
Expect.equals(FileSystemEntityType.notFound, fileStat.type))
|
||||
.then((_) => file.stat())
|
||||
.then((fileStat) =>
|
||||
Expect.equals(FileSystemEntityType.notFound, fileStat.type))
|
||||
.then((_) => file.writeAsString("Dart IO library test of FileStat"))
|
||||
.then((_) => new Future.delayed(const Duration(seconds: 2)))
|
||||
.then((_) => file.readAsString())
|
||||
.then((_) => directory.list().last)
|
||||
.then((_) => FileStat.stat(file.path))
|
||||
.then((FileStat fileStat) {
|
||||
Expect.equals(FileSystemEntityType.file, fileStat.type);
|
||||
Expect.equals(32, fileStat.size);
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
|
||||
Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0);
|
||||
}
|
||||
Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw.
|
||||
return file.stat();
|
||||
}).then((FileStat fileStat) {
|
||||
Expect.equals(FileSystemEntityType.file, fileStat.type);
|
||||
Expect.equals(32, fileStat.size);
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
|
||||
Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0);
|
||||
}
|
||||
Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw.
|
||||
return FileStat.stat(directory.path);
|
||||
}).then((FileStat directoryStat) {
|
||||
Expect.equals(FileSystemEntityType.directory, directoryStat.type);
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
Expect.isTrue(
|
||||
directoryStat.modified.compareTo(directoryStat.accessed) < 0);
|
||||
Expect.isTrue(
|
||||
directoryStat.changed.compareTo(directoryStat.accessed) < 0);
|
||||
}
|
||||
Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx.
|
||||
return directory.stat();
|
||||
}).then((FileStat directoryStat) {
|
||||
Expect.equals(FileSystemEntityType.directory, directoryStat.type);
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
Expect.isTrue(
|
||||
directoryStat.modified.compareTo(directoryStat.accessed) < 0);
|
||||
Expect.isTrue(
|
||||
directoryStat.changed.compareTo(directoryStat.accessed) < 0);
|
||||
}
|
||||
Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx.
|
||||
return new Link(directory.path).stat();
|
||||
}).then((FileStat linkStat) {
|
||||
Expect.equals(FileSystemEntityType.directory, linkStat.type);
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
Expect.isTrue(linkStat.modified.compareTo(linkStat.accessed) < 0);
|
||||
Expect.isTrue(linkStat.changed.compareTo(linkStat.accessed) < 0);
|
||||
}
|
||||
Expect.equals(7 << 6, linkStat.mode & (7 << 6)); // Includes +urwx.
|
||||
return directory.delete(recursive: true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
asyncStart();
|
||||
testStat();
|
||||
testStatAsync().then((_) => asyncEnd());
|
||||
}
|
64
tests/standalone/io/file_stream_test.dart
Normal file
64
tests/standalone/io/file_stream_test.dart
Normal file
|
@ -0,0 +1,64 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void testPauseResumeCancelStream() {
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_file_stream').then((d) {
|
||||
var file = new File("${d.path}/file");
|
||||
new File(Platform.executable)
|
||||
.openRead()
|
||||
.cast<List<int>>()
|
||||
.pipe(file.openWrite())
|
||||
.then((_) {
|
||||
var subscription;
|
||||
subscription = file.openRead().listen((data) {
|
||||
subscription.pause();
|
||||
subscription.resume();
|
||||
void close() {
|
||||
d.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
}
|
||||
|
||||
var future = subscription.cancel();
|
||||
if (future != null) {
|
||||
future.whenComplete(close);
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
}, onDone: () {
|
||||
Expect.fail('the stream was canceled, onDone should not happen');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testStreamIsEmpty() {
|
||||
asyncStart();
|
||||
Directory.systemTemp.createTemp('dart_file_stream').then((d) {
|
||||
var file = new File("${d.path}/file");
|
||||
new File(Platform.executable)
|
||||
.openRead()
|
||||
.cast<List<int>>()
|
||||
.pipe(file.openWrite())
|
||||
.then((_) {
|
||||
// isEmpty will cancel the stream after first data event.
|
||||
file.openRead().isEmpty.then((empty) {
|
||||
Expect.isFalse(empty);
|
||||
d.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
testPauseResumeCancelStream();
|
||||
testStreamIsEmpty();
|
||||
}
|
234
tests/standalone/io/file_system_async_links_test.dart
Normal file
234
tests/standalone/io/file_system_async_links_test.dart
Normal file
|
@ -0,0 +1,234 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class FutureExpect {
|
||||
static Future isTrue(Future<bool> result) =>
|
||||
result.then((value) => Expect.isTrue(value));
|
||||
static Future isFalse(Future<bool> result) =>
|
||||
result.then((value) => Expect.isFalse(value));
|
||||
static Future equals(expected, Future result) =>
|
||||
result.then((value) => Expect.equals(expected, value));
|
||||
static Future listEquals(expected, Future result) =>
|
||||
result.then((value) => Expect.listEquals(expected, value));
|
||||
static Future throws(Future result) => result.then((value) {
|
||||
throw new ExpectException(
|
||||
"FutureExpect.throws received $value instead of an exception");
|
||||
}, onError: (_) => null);
|
||||
}
|
||||
|
||||
Future testFileExistsCreate() {
|
||||
return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) {
|
||||
var x = '${temp.path}${Platform.pathSeparator}x';
|
||||
var y = '${temp.path}${Platform.pathSeparator}y';
|
||||
return new Link(y)
|
||||
.create(x)
|
||||
.then((link) => Expect.equals(y, link.path))
|
||||
.then((_) => FutureExpect.isFalse(new File(y).exists()))
|
||||
.then((_) => FutureExpect.isFalse(new File(x).exists()))
|
||||
.then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(y)))
|
||||
.then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(x)))
|
||||
.then((_) => FutureExpect.equals(
|
||||
FileSystemEntityType.notFound, FileSystemEntity.type(y)))
|
||||
.then((_) => FutureExpect.equals(
|
||||
FileSystemEntityType.notFound, FileSystemEntity.type(x)))
|
||||
.then((_) => FutureExpect.equals(FileSystemEntityType.link,
|
||||
FileSystemEntity.type(y, followLinks: false)))
|
||||
.then((_) => FutureExpect.equals(FileSystemEntityType.notFound,
|
||||
FileSystemEntity.type(x, followLinks: false)))
|
||||
.then((_) => FutureExpect.equals(x, new Link(y).target()))
|
||||
.then((_) => new File(y).create())
|
||||
.then((yFile) => Expect.equals(y, yFile.path))
|
||||
.then((_) => FutureExpect.isTrue(new File(y).exists()))
|
||||
.then((_) => FutureExpect.isTrue(new File(x).exists()))
|
||||
.then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(y)))
|
||||
.then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(x)))
|
||||
.then((_) => FutureExpect.isTrue(FileSystemEntity.isFile(y)))
|
||||
.then((_) => FutureExpect.isTrue(FileSystemEntity.isFile(x)))
|
||||
.then((_) => FutureExpect.equals(
|
||||
FileSystemEntityType.file, FileSystemEntity.type(y)))
|
||||
.then((_) => FutureExpect.equals(
|
||||
FileSystemEntityType.file, FileSystemEntity.type(x)))
|
||||
.then((_) => FutureExpect.equals(FileSystemEntityType.link,
|
||||
FileSystemEntity.type(y, followLinks: false)))
|
||||
.then((_) => FutureExpect.equals(FileSystemEntityType.file,
|
||||
FileSystemEntity.type(x, followLinks: false)))
|
||||
.then((_) => FutureExpect.equals(x, new Link(y).target()))
|
||||
.then((_) => new File(x).delete())
|
||||
.then((xDeletedFile) => Expect.equals(x, xDeletedFile.path))
|
||||
.then((_) => new Directory(x).create())
|
||||
.then((xCreatedDirectory) => Expect.equals(x, xCreatedDirectory.path))
|
||||
.then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(y)))
|
||||
.then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(x)))
|
||||
.then((_) => FutureExpect.isTrue(FileSystemEntity.isDirectory(y)))
|
||||
.then((_) => FutureExpect.isTrue(FileSystemEntity.isDirectory(x)))
|
||||
.then((_) => FutureExpect.equals(
|
||||
FileSystemEntityType.directory, FileSystemEntity.type(y)))
|
||||
.then((_) => FutureExpect.equals(
|
||||
FileSystemEntityType.directory, FileSystemEntity.type(x)))
|
||||
.then((_) => FutureExpect.equals(FileSystemEntityType.link,
|
||||
FileSystemEntity.type(y, followLinks: false)))
|
||||
.then((_) => FutureExpect.equals(FileSystemEntityType.directory,
|
||||
FileSystemEntity.type(x, followLinks: false)))
|
||||
.then((_) => FutureExpect.equals(x, new Link(y).target()))
|
||||
.then((_) => new Link(y).delete())
|
||||
.then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(y)))
|
||||
.then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(x)))
|
||||
.then((_) => FutureExpect.equals(
|
||||
FileSystemEntityType.notFound, FileSystemEntity.type(y)))
|
||||
.then(
|
||||
(_) => FutureExpect.equals(FileSystemEntityType.directory, FileSystemEntity.type(x)))
|
||||
.then((_) => FutureExpect.throws(new Link(y).target()))
|
||||
.then((_) => temp.delete(recursive: true));
|
||||
});
|
||||
}
|
||||
|
||||
Future testFileDelete() {
|
||||
return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) {
|
||||
var x = '${temp.path}${Platform.pathSeparator}x';
|
||||
var y = '${temp.path}${Platform.pathSeparator}y';
|
||||
return new File(x)
|
||||
.create()
|
||||
.then((_) => new Link(y).create(x))
|
||||
.then((_) => FutureExpect.isTrue(new File(x).exists()))
|
||||
.then((_) => FutureExpect.isTrue(new File(y).exists()))
|
||||
.then((_) => new File(y).delete())
|
||||
.then((_) => FutureExpect.isTrue(new File(x).exists()))
|
||||
.then((_) => FutureExpect.isFalse(new File(y).exists()))
|
||||
.then((_) => new Link(y).create(x))
|
||||
.then((_) => FutureExpect.isTrue(new File(x).exists()))
|
||||
.then((_) => FutureExpect.isTrue(new File(y).exists()))
|
||||
.then((_) => new File(y).delete())
|
||||
.then((_) => FutureExpect.isTrue(new File(x).exists()))
|
||||
.then((_) => FutureExpect.isFalse(new File(y).exists()))
|
||||
.then((_) => temp.delete(recursive: true));
|
||||
});
|
||||
}
|
||||
|
||||
Future testFileWriteRead() {
|
||||
return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) {
|
||||
var x = '${temp.path}${Platform.pathSeparator}x';
|
||||
var y = '${temp.path}${Platform.pathSeparator}y';
|
||||
var data = "asdf".codeUnits;
|
||||
return new File(x)
|
||||
.create()
|
||||
.then((_) => new Link(y).create(x))
|
||||
.then((_) =>
|
||||
(new File(y).openWrite(mode: FileMode.write)..add(data)).close())
|
||||
.then((_) => FutureExpect.listEquals(data, new File(y).readAsBytes()))
|
||||
.then((_) => FutureExpect.listEquals(data, new File(x).readAsBytes()))
|
||||
.then((_) => temp.delete(recursive: true));
|
||||
});
|
||||
}
|
||||
|
||||
Future testDirectoryExistsCreate() {
|
||||
return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) {
|
||||
var x = '${temp.path}${Platform.pathSeparator}x';
|
||||
var y = '${temp.path}${Platform.pathSeparator}y';
|
||||
return new Link(y)
|
||||
.create(x)
|
||||
.then((_) => FutureExpect.isFalse(new Directory(x).exists()))
|
||||
.then((_) => FutureExpect.isFalse(new Directory(y).exists()))
|
||||
.then((_) => FutureExpect.throws(new Directory(y).create()))
|
||||
.then((_) => temp.delete(recursive: true));
|
||||
});
|
||||
}
|
||||
|
||||
Future testDirectoryDelete() {
|
||||
return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) {
|
||||
return Directory.systemTemp
|
||||
.createTemp('dart_file_system_async')
|
||||
.then((temp2) {
|
||||
var y = '${temp.path}${Platform.pathSeparator}y';
|
||||
var x = '${temp2.path}${Platform.pathSeparator}x';
|
||||
var link = new Directory(y);
|
||||
return new File(x)
|
||||
.create()
|
||||
.then((_) => new Link(y).create(temp2.path))
|
||||
.then((_) => FutureExpect.isTrue(link.exists()))
|
||||
.then((_) => FutureExpect.isTrue(temp2.exists()))
|
||||
.then((_) => link.delete())
|
||||
.then((_) => FutureExpect.isFalse(link.exists()))
|
||||
.then((_) => FutureExpect.isTrue(temp2.exists()))
|
||||
.then((_) => new Link(y).create(temp2.path))
|
||||
.then((_) => FutureExpect.isTrue(link.exists()))
|
||||
.then((_) => temp.delete(recursive: true))
|
||||
.then((_) => FutureExpect.isFalse(link.exists()))
|
||||
.then((_) => FutureExpect.isFalse(temp.exists()))
|
||||
.then((_) => FutureExpect.isTrue(temp2.exists()))
|
||||
.then((_) => FutureExpect.isTrue(new File(x).exists()))
|
||||
.then((_) => temp2.delete(recursive: true));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future testDirectoryListing() {
|
||||
return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) {
|
||||
return Directory.systemTemp
|
||||
.createTemp('dart_file_system_async_links')
|
||||
.then((temp2) {
|
||||
var sep = Platform.pathSeparator;
|
||||
var y = '${temp.path}${sep}y';
|
||||
var x = '${temp2.path}${sep}x';
|
||||
return new File(x)
|
||||
.create()
|
||||
.then((_) => new Link(y).create(temp2.path))
|
||||
.then((_) =>
|
||||
temp.list(recursive: true).singleWhere((entry) => entry is File))
|
||||
.then((file) => Expect.isTrue(file.path.endsWith('$y${sep}x')))
|
||||
.then((_) => temp
|
||||
.list(recursive: true)
|
||||
.singleWhere((entry) => entry is Directory))
|
||||
.then((dir) => Expect.isTrue(dir.path.endsWith('y')))
|
||||
.then((_) => temp.delete(recursive: true))
|
||||
.then((_) => temp2.delete(recursive: true));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future testDirectoryListingBrokenLink() {
|
||||
return Directory.systemTemp.createTemp('dart_file_system_async').then((temp) {
|
||||
var x = '${temp.path}${Platform.pathSeparator}x';
|
||||
var link = '${temp.path}${Platform.pathSeparator}link';
|
||||
var doesNotExist = 'this_thing_does_not_exist';
|
||||
bool sawFile = false;
|
||||
bool sawLink = false;
|
||||
return new File(x)
|
||||
.create()
|
||||
.then((_) => new Link(link).create(doesNotExist))
|
||||
.then((_) => temp.list(recursive: true).forEach((entity) {
|
||||
if (entity is File) {
|
||||
Expect.isFalse(sawFile);
|
||||
sawFile = true;
|
||||
Expect.isTrue(entity.path.endsWith(x));
|
||||
} else {
|
||||
Expect.isTrue(entity is Link);
|
||||
Expect.isFalse(sawLink);
|
||||
sawLink = true;
|
||||
Expect.isTrue(entity.path.endsWith(link));
|
||||
}
|
||||
}))
|
||||
.then((_) => temp.delete(recursive: true));
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
// Links on Windows are tested by windows_file_system_[async_]links_test.
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
asyncStart();
|
||||
testFileExistsCreate()
|
||||
.then((_) => testFileDelete())
|
||||
.then((_) => testFileWriteRead())
|
||||
.then((_) => testDirectoryExistsCreate())
|
||||
.then((_) => testDirectoryDelete())
|
||||
.then((_) => testDirectoryListing())
|
||||
.then((_) => testDirectoryListingBrokenLink())
|
||||
.then((_) => asyncEnd());
|
||||
}
|
||||
}
|
371
tests/standalone/io/file_system_delete_test.dart
Normal file
371
tests/standalone/io/file_system_delete_test.dart
Normal file
|
@ -0,0 +1,371 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
Future throws(callback()) {
|
||||
return new Future.value().then((_) => callback()).then((_) {
|
||||
throw "Expected error";
|
||||
}, onError: (_) {});
|
||||
}
|
||||
|
||||
void testDeleteFileSync() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_system_delete');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
|
||||
var file = new File("${path}myFile");
|
||||
|
||||
file.createSync();
|
||||
|
||||
Expect.isTrue(file.existsSync());
|
||||
new File(file.path).deleteSync();
|
||||
Expect.isFalse(file.existsSync());
|
||||
|
||||
file.createSync();
|
||||
|
||||
Expect.isTrue(file.existsSync());
|
||||
new Directory(file.path).deleteSync(recursive: true);
|
||||
Expect.isFalse(file.existsSync());
|
||||
|
||||
file.createSync();
|
||||
|
||||
Expect.isTrue(file.existsSync());
|
||||
Expect.throws(() => new Directory(file.path).deleteSync());
|
||||
Expect.isTrue(file.existsSync());
|
||||
|
||||
Expect.isTrue(file.existsSync());
|
||||
Expect.throws(() => new Link(file.path).deleteSync());
|
||||
Expect.isTrue(file.existsSync());
|
||||
|
||||
file.deleteSync();
|
||||
Expect.isFalse(file.existsSync());
|
||||
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
void testDeleteFile() {
|
||||
Directory.systemTemp.createTemp('dart_file_system_delete').then((tmp) {
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
var file = new File("${path}myFile");
|
||||
return file
|
||||
.create()
|
||||
.then((_) => file.exists().then(Expect.isTrue))
|
||||
.then((_) => new File(file.path).delete())
|
||||
.then((_) => file.exists().then(Expect.isFalse))
|
||||
.then((_) => file.create())
|
||||
.then((_) => file.exists().then(Expect.isTrue))
|
||||
.then((_) => new Directory(file.path).delete(recursive: true))
|
||||
.then((_) => file.exists().then(Expect.isFalse))
|
||||
.then((_) => file.create())
|
||||
.then((_) => file.exists().then(Expect.isTrue))
|
||||
.then((_) => throws(() => new Directory(file.path).delete()))
|
||||
.then((_) => file.exists().then(Expect.isTrue))
|
||||
.then((_) => file.exists().then(Expect.isTrue))
|
||||
.then((_) => throws(() => new Link(file.path).delete()))
|
||||
.then((_) => file.exists().then(Expect.isTrue))
|
||||
.then((_) => file.delete())
|
||||
.then((_) => tmp.delete());
|
||||
});
|
||||
}
|
||||
|
||||
void testDeleteDirectorySync() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_system_delete');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
|
||||
var dir = new Directory("${path}myDirectory");
|
||||
|
||||
dir.createSync();
|
||||
|
||||
Expect.isTrue(dir.existsSync());
|
||||
new Directory(dir.path).deleteSync();
|
||||
Expect.isFalse(dir.existsSync());
|
||||
|
||||
dir.createSync();
|
||||
|
||||
Expect.isTrue(dir.existsSync());
|
||||
new Directory(dir.path).deleteSync(recursive: true);
|
||||
Expect.isFalse(dir.existsSync());
|
||||
|
||||
dir.createSync();
|
||||
|
||||
Expect.isTrue(dir.existsSync());
|
||||
Expect.throws(() => new File(dir.path).deleteSync());
|
||||
Expect.isTrue(dir.existsSync());
|
||||
|
||||
Expect.isTrue(dir.existsSync());
|
||||
Expect.throws(() => new Link(dir.path).deleteSync());
|
||||
Expect.isTrue(dir.existsSync());
|
||||
|
||||
dir.deleteSync();
|
||||
Expect.isFalse(dir.existsSync());
|
||||
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
void testDeleteDirectory() {
|
||||
Directory.systemTemp.createTemp('dart_file_system_delete').then((tmp) {
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
var dir = new Directory("${path}myDirectory");
|
||||
return dir
|
||||
.create()
|
||||
.then((_) => dir.exists().then(Expect.isTrue))
|
||||
.then((_) => new Directory(dir.path).delete())
|
||||
.then((_) => dir.exists().then(Expect.isFalse))
|
||||
.then((_) => dir.create())
|
||||
.then((_) => dir.exists().then(Expect.isTrue))
|
||||
.then((_) => new Directory(dir.path).delete(recursive: true))
|
||||
.then((_) => dir.exists().then(Expect.isFalse))
|
||||
.then((_) => dir.create())
|
||||
.then((_) => dir.exists().then(Expect.isTrue))
|
||||
.then((_) => throws(() => new File(dir.path).delete()))
|
||||
.then((_) => dir.exists().then(Expect.isTrue))
|
||||
.then((_) => dir.exists().then(Expect.isTrue))
|
||||
.then((_) => throws(() => new Link(dir.path).delete()))
|
||||
.then((_) => dir.exists().then(Expect.isTrue))
|
||||
.then((_) => dir.delete())
|
||||
.then((_) => tmp.delete());
|
||||
});
|
||||
}
|
||||
|
||||
void testDeleteFileLinkSync() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_system_delete');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
|
||||
var file = new File("${path}myFile");
|
||||
file.createSync();
|
||||
|
||||
var link = new Link("${path}myLink");
|
||||
|
||||
link.createSync(file.path);
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
new File(link.path).deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
link.createSync(file.path);
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
new Link(link.path).deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
link.createSync(file.path);
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
new Directory(link.path).deleteSync(recursive: true);
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
link.createSync(file.path);
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
Expect.throws(() => new Directory(link.path).deleteSync());
|
||||
Expect.isTrue(link.existsSync());
|
||||
|
||||
link.deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
Expect.isTrue(file.existsSync());
|
||||
file.deleteSync();
|
||||
Expect.isFalse(file.existsSync());
|
||||
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
void testDeleteFileLink() {
|
||||
Directory.systemTemp.createTemp('dart_file_system_delete').then((tmp) {
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
var file = new File("${path}myFile");
|
||||
var link = new Link("${path}myLink");
|
||||
return file
|
||||
.create()
|
||||
.then((_) => link.create(file.path))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => new File(link.path).delete())
|
||||
.then((_) => link.exists().then(Expect.isFalse))
|
||||
.then((_) => link.create(file.path))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => new Link(link.path).delete())
|
||||
.then((_) => link.exists().then(Expect.isFalse))
|
||||
.then((_) => link.create(file.path))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => new Directory(link.path).delete(recursive: true))
|
||||
.then((_) => link.exists().then(Expect.isFalse))
|
||||
.then((_) => link.create(file.path))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => throws(() => new Directory(link.path).delete()))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => link.deleteSync())
|
||||
.then((_) => link.exists().then(Expect.isFalse))
|
||||
.then((_) => file.exists().then(Expect.isTrue))
|
||||
.then((_) => file.delete())
|
||||
.then((_) => file.exists().then(Expect.isFalse))
|
||||
.then((_) => tmp.delete());
|
||||
});
|
||||
}
|
||||
|
||||
void testDeleteDirectoryLinkSync() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_system_delete');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
|
||||
var directory = new Directory("${path}myDirectory");
|
||||
directory.createSync();
|
||||
|
||||
var link = new Link("${path}myLink");
|
||||
|
||||
link.createSync(directory.path);
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
new Link(link.path).deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
link.createSync(directory.path);
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
new Directory(link.path).deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
link.createSync(directory.path);
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
new Directory(link.path).deleteSync(recursive: true);
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
link.createSync(directory.path);
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
Expect.throws(() => new File(link.path).deleteSync());
|
||||
Expect.isTrue(link.existsSync());
|
||||
|
||||
link.deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
Expect.isTrue(directory.existsSync());
|
||||
directory.deleteSync();
|
||||
Expect.isFalse(directory.existsSync());
|
||||
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
void testDeleteDirectoryLink() {
|
||||
Directory.systemTemp.createTemp('dart_file_system_delete').then((tmp) {
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
var dir = new Directory("${path}myDir");
|
||||
var link = new Link("${path}myLink");
|
||||
return dir
|
||||
.create()
|
||||
.then((_) => link.create(dir.path))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => new Directory(link.path).delete())
|
||||
.then((_) => link.exists().then(Expect.isFalse))
|
||||
.then((_) => link.create(dir.path))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => new Directory(link.path).delete(recursive: true))
|
||||
.then((_) => link.exists().then(Expect.isFalse))
|
||||
.then((_) => link.create(dir.path))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => new Link(link.path).delete())
|
||||
.then((_) => link.exists().then(Expect.isFalse))
|
||||
.then((_) => link.create(dir.path))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => throws(() => new File(link.path).delete()))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => link.deleteSync())
|
||||
.then((_) => link.exists().then(Expect.isFalse))
|
||||
.then((_) => dir.exists().then(Expect.isTrue))
|
||||
.then((_) => dir.delete())
|
||||
.then((_) => dir.exists().then(Expect.isFalse))
|
||||
.then((_) => tmp.delete());
|
||||
});
|
||||
}
|
||||
|
||||
void testDeleteBrokenLinkSync() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_system_delete');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
|
||||
var directory = new Directory("${path}myDirectory");
|
||||
directory.createSync();
|
||||
|
||||
var link = new Link("${path}myLink");
|
||||
|
||||
link.createSync(directory.path);
|
||||
directory.deleteSync();
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
new Link(link.path).deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
directory.createSync();
|
||||
link.createSync(directory.path);
|
||||
directory.deleteSync();
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
new Directory(link.path).deleteSync(recursive: true);
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
directory.createSync();
|
||||
link.createSync(directory.path);
|
||||
directory.deleteSync();
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
Expect.throws(() => new Directory(link.path).deleteSync());
|
||||
Expect.isTrue(link.existsSync());
|
||||
|
||||
Expect.isTrue(link.existsSync());
|
||||
Expect.throws(() => new File(link.path).deleteSync());
|
||||
Expect.isTrue(link.existsSync());
|
||||
|
||||
link.deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
void testDeleteBrokenLink() {
|
||||
Directory.systemTemp.createTemp('dart_file_system_delete').then((tmp) {
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
var dir = new Directory("${path}myDir");
|
||||
var link = new Link("${path}myLink");
|
||||
return dir
|
||||
.create()
|
||||
.then((_) => link.create(dir.path))
|
||||
.then((_) => dir.delete())
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => new Link(link.path).delete())
|
||||
.then((_) => link.exists().then(Expect.isFalse))
|
||||
.then((_) => dir.create())
|
||||
.then((_) => link.create(dir.path))
|
||||
.then((_) => dir.delete())
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => new Directory(link.path).delete(recursive: true))
|
||||
.then((_) => link.exists().then(Expect.isFalse))
|
||||
.then((_) => dir.create())
|
||||
.then((_) => link.create(dir.path))
|
||||
.then((_) => dir.delete())
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => throws(() => new Directory(link.path).delete()))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => throws(() => new File(link.path).delete()))
|
||||
.then((_) => link.exists().then(Expect.isTrue))
|
||||
.then((_) => link.deleteSync())
|
||||
.then((_) => link.exists().then(Expect.isFalse))
|
||||
.then((_) => tmp.delete());
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
testDeleteFileSync();
|
||||
testDeleteFile();
|
||||
testDeleteDirectorySync();
|
||||
testDeleteDirectory();
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
testDeleteFileLinkSync();
|
||||
testDeleteFileLink();
|
||||
}
|
||||
testDeleteDirectoryLinkSync();
|
||||
testDeleteDirectoryLink();
|
||||
testDeleteBrokenLinkSync();
|
||||
testDeleteBrokenLink();
|
||||
}
|
201
tests/standalone/io/file_system_exists_test.dart
Normal file
201
tests/standalone/io/file_system_exists_test.dart
Normal file
|
@ -0,0 +1,201 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "dart:io";
|
||||
|
||||
void testFileExistsSync() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_system_exists');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
|
||||
var file = new File("${path}myFile");
|
||||
file.createSync();
|
||||
|
||||
Expect.isTrue(new File(file.path).existsSync());
|
||||
Expect.isFalse(new Directory(file.path).existsSync());
|
||||
Expect.isFalse(new Link(file.path).existsSync());
|
||||
|
||||
file.deleteSync();
|
||||
Expect.isFalse(file.existsSync());
|
||||
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
void testFileExists() {
|
||||
Directory.systemTemp.createTemp('dart_file_system_exists').then((tmp) {
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
var file = new File("${path}myFile");
|
||||
return file
|
||||
.create()
|
||||
.then((_) => new File(file.path).exists().then(Expect.isTrue))
|
||||
.then((_) => new Directory(file.path).exists().then(Expect.isFalse))
|
||||
.then((_) => new Link(file.path).exists().then(Expect.isFalse))
|
||||
.then((_) => file.delete())
|
||||
.then((_) => tmp.delete());
|
||||
});
|
||||
}
|
||||
|
||||
void testDirectoryExistsSync() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_system_exists');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
|
||||
var dir = new Directory("${path}myDirectory");
|
||||
dir.createSync();
|
||||
|
||||
Expect.isFalse(new File(dir.path).existsSync());
|
||||
Expect.isTrue(new Directory(dir.path).existsSync());
|
||||
Expect.isFalse(new Link(dir.path).existsSync());
|
||||
|
||||
dir.deleteSync();
|
||||
Expect.isFalse(dir.existsSync());
|
||||
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
void testDirectoryExists() {
|
||||
Directory.systemTemp.createTemp('dart_file_system_exists').then((tmp) {
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
var dir = new Directory("${path}myDirectory");
|
||||
return dir
|
||||
.create()
|
||||
.then((_) => new File(dir.path).exists().then(Expect.isFalse))
|
||||
.then((_) => new Directory(dir.path).exists().then(Expect.isTrue))
|
||||
.then((_) => new Link(dir.path).exists().then(Expect.isFalse))
|
||||
.then((_) => dir.delete())
|
||||
.then((_) => tmp.delete());
|
||||
});
|
||||
}
|
||||
|
||||
void testFileLinkExistsSync() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_system_exists');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
|
||||
var file = new File("${path}myFile");
|
||||
file.createSync();
|
||||
|
||||
var link = new Link("${path}myLink");
|
||||
link.createSync(file.path);
|
||||
|
||||
Expect.isTrue(new File(link.path).existsSync());
|
||||
Expect.isFalse(new Directory(link.path).existsSync());
|
||||
Expect.isTrue(new Link(link.path).existsSync());
|
||||
|
||||
link.deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
file.deleteSync();
|
||||
Expect.isFalse(file.existsSync());
|
||||
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
void testFileLinkExists() {
|
||||
Directory.systemTemp.createTemp('dart_file_system_exists').then((tmp) {
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
var file = new File("${path}myFile");
|
||||
var link = new Link("${path}myLink");
|
||||
return file
|
||||
.create()
|
||||
.then((_) => link.create(file.path))
|
||||
.then((_) => new File(link.path).exists().then(Expect.isTrue))
|
||||
.then((_) => new Directory(link.path).exists().then(Expect.isFalse))
|
||||
.then((_) => new Link(link.path).exists().then(Expect.isTrue))
|
||||
.then((_) => link.delete())
|
||||
.then((_) => file.delete())
|
||||
.then((_) => tmp.delete());
|
||||
});
|
||||
}
|
||||
|
||||
void testDirectoryLinkExistsSync() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_system_exists');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
|
||||
var directory = new Directory("${path}myDirectory");
|
||||
directory.createSync();
|
||||
|
||||
var link = new Link("${path}myLink");
|
||||
link.createSync(directory.path);
|
||||
|
||||
Expect.isFalse(new File(link.path).existsSync());
|
||||
Expect.isTrue(new Directory(link.path).existsSync());
|
||||
Expect.isTrue(new Link(link.path).existsSync());
|
||||
|
||||
link.deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
directory.deleteSync();
|
||||
Expect.isFalse(directory.existsSync());
|
||||
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
void testDirectoryLinkExists() {
|
||||
Directory.systemTemp.createTemp('dart_file_system_exists').then((tmp) {
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
var dir = new Directory("${path}myDir");
|
||||
var link = new Link("${path}myLink");
|
||||
return dir
|
||||
.create()
|
||||
.then((_) => link.create(dir.path))
|
||||
.then((_) => new File(link.path).exists().then(Expect.isFalse))
|
||||
.then((_) => new Directory(link.path).exists().then(Expect.isTrue))
|
||||
.then((_) => new Link(link.path).exists().then(Expect.isTrue))
|
||||
.then((_) => link.delete())
|
||||
.then((_) => dir.delete())
|
||||
.then((_) => tmp.delete());
|
||||
});
|
||||
}
|
||||
|
||||
void testBrokenLinkExistsSync() {
|
||||
var tmp = Directory.systemTemp.createTempSync('dart_file_system_exists');
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
|
||||
var directory = new Directory("${path}myDirectory");
|
||||
directory.createSync();
|
||||
|
||||
var link = new Link("${path}myLink");
|
||||
link.createSync(directory.path);
|
||||
directory.deleteSync();
|
||||
|
||||
Expect.isFalse(new File(link.path).existsSync());
|
||||
Expect.isFalse(new Directory(link.path).existsSync());
|
||||
Expect.isTrue(new Link(link.path).existsSync());
|
||||
|
||||
link.deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
|
||||
tmp.deleteSync();
|
||||
}
|
||||
|
||||
void testBrokenLinkExists() {
|
||||
Directory.systemTemp.createTemp('dart_file_system_exists').then((tmp) {
|
||||
var path = "${tmp.path}${Platform.pathSeparator}";
|
||||
var dir = new Directory("${path}myDir");
|
||||
var link = new Link("${path}myLink");
|
||||
return dir
|
||||
.create()
|
||||
.then((_) => link.create(dir.path))
|
||||
.then((_) => dir.delete())
|
||||
.then((_) => new File(link.path).exists().then(Expect.isFalse))
|
||||
.then((_) => new Directory(link.path).exists().then(Expect.isFalse))
|
||||
.then((_) => new Link(link.path).exists().then(Expect.isTrue))
|
||||
.then((_) => link.delete())
|
||||
.then((_) => tmp.delete());
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
testFileExistsSync();
|
||||
testFileExists();
|
||||
testDirectoryExistsSync();
|
||||
testDirectoryExists();
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
testFileLinkExistsSync();
|
||||
testFileLinkExists();
|
||||
}
|
||||
testDirectoryLinkExistsSync();
|
||||
testDirectoryLinkExists();
|
||||
testBrokenLinkExistsSync();
|
||||
testBrokenLinkExists();
|
||||
}
|
242
tests/standalone/io/file_system_links_test.dart
Normal file
242
tests/standalone/io/file_system_links_test.dart
Normal file
|
@ -0,0 +1,242 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import "dart:io";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
createLink(String dst, String link, void callback()) {
|
||||
new Link(link).create(dst).then((_) => callback());
|
||||
}
|
||||
|
||||
testFileExistsCreate() {
|
||||
var temp = Directory.systemTemp.createTempSync('dart_file_system_links');
|
||||
var x = '${temp.path}${Platform.pathSeparator}x';
|
||||
var y = '${temp.path}${Platform.pathSeparator}y';
|
||||
createLink(x, y, () {
|
||||
Expect.isFalse(new File(y).existsSync());
|
||||
Expect.isFalse(new File(x).existsSync());
|
||||
Expect.isTrue(FileSystemEntity.isLinkSync(y));
|
||||
Expect.isFalse(FileSystemEntity.isLinkSync(x));
|
||||
Expect.equals(FileSystemEntityType.notFound, FileSystemEntity.typeSync(y));
|
||||
Expect.equals(FileSystemEntityType.notFound, FileSystemEntity.typeSync(x));
|
||||
Expect.equals(FileSystemEntityType.link,
|
||||
FileSystemEntity.typeSync(y, followLinks: false));
|
||||
Expect.equals(FileSystemEntityType.notFound,
|
||||
FileSystemEntity.typeSync(x, followLinks: false));
|
||||
Expect.equals(x, new Link(y).targetSync());
|
||||
|
||||
new File(y).createSync();
|
||||
Expect.isTrue(new File(y).existsSync());
|
||||
Expect.isTrue(new File(x).existsSync());
|
||||
Expect.isTrue(FileSystemEntity.isLinkSync(y));
|
||||
Expect.isFalse(FileSystemEntity.isLinkSync(x));
|
||||
Expect.isTrue(FileSystemEntity.isFileSync(y));
|
||||
Expect.isTrue(FileSystemEntity.isFileSync(x));
|
||||
Expect.equals(FileSystemEntityType.file, FileSystemEntity.typeSync(y));
|
||||
Expect.equals(FileSystemEntityType.file, FileSystemEntity.typeSync(x));
|
||||
Expect.equals(FileSystemEntityType.link,
|
||||
FileSystemEntity.typeSync(y, followLinks: false));
|
||||
Expect.equals(FileSystemEntityType.file,
|
||||
FileSystemEntity.typeSync(x, followLinks: false));
|
||||
Expect.equals(x, new Link(y).targetSync());
|
||||
|
||||
new File(x).deleteSync();
|
||||
new Directory(x).createSync();
|
||||
Expect.isTrue(FileSystemEntity.isLinkSync(y));
|
||||
Expect.isFalse(FileSystemEntity.isLinkSync(x));
|
||||
Expect.isTrue(FileSystemEntity.isDirectorySync(y));
|
||||
Expect.isTrue(FileSystemEntity.isDirectorySync(x));
|
||||
Expect.equals(FileSystemEntityType.directory, FileSystemEntity.typeSync(y));
|
||||
Expect.equals(FileSystemEntityType.directory, FileSystemEntity.typeSync(x));
|
||||
Expect.equals(FileSystemEntityType.link,
|
||||
FileSystemEntity.typeSync(y, followLinks: false));
|
||||
Expect.equals(FileSystemEntityType.directory,
|
||||
FileSystemEntity.typeSync(x, followLinks: false));
|
||||
Expect.equals(x, new Link(y).targetSync());
|
||||
|
||||
new Link(y).deleteSync();
|
||||
Expect.isFalse(FileSystemEntity.isLinkSync(y));
|
||||
Expect.isFalse(FileSystemEntity.isLinkSync(x));
|
||||
Expect.equals(FileSystemEntityType.notFound, FileSystemEntity.typeSync(y));
|
||||
Expect.equals(FileSystemEntityType.directory, FileSystemEntity.typeSync(x));
|
||||
Expect.throws(() => new Link(y).targetSync());
|
||||
|
||||
temp.deleteSync(recursive: true);
|
||||
});
|
||||
}
|
||||
|
||||
testFileDelete() {
|
||||
var temp = Directory.systemTemp.createTempSync('dart_file_system_links');
|
||||
var x = '${temp.path}${Platform.pathSeparator}x';
|
||||
var y = '${temp.path}${Platform.pathSeparator}y';
|
||||
new File(x).createSync();
|
||||
createLink(x, y, () {
|
||||
Expect.isTrue(new File(x).existsSync());
|
||||
Expect.isTrue(new File(y).existsSync());
|
||||
new File(y).deleteSync();
|
||||
Expect.isTrue(new File(x).existsSync());
|
||||
Expect.isFalse(new File(y).existsSync());
|
||||
createLink(x, y, () {
|
||||
Expect.isTrue(new File(x).existsSync());
|
||||
Expect.isTrue(new File(y).existsSync());
|
||||
new File(y).deleteSync();
|
||||
Expect.isTrue(new File(x).existsSync());
|
||||
Expect.isFalse(new File(y).existsSync());
|
||||
temp.deleteSync(recursive: true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
testFileWriteRead() {
|
||||
var temp = Directory.systemTemp.createTempSync('dart_file_system_links');
|
||||
var x = '${temp.path}${Platform.pathSeparator}x';
|
||||
var y = '${temp.path}${Platform.pathSeparator}y';
|
||||
new File(x).createSync();
|
||||
createLink(x, y, () {
|
||||
var data = "asdf".codeUnits;
|
||||
var output = new File(y).openWrite(mode: FileMode.write);
|
||||
output.add(data);
|
||||
output.close();
|
||||
output.done.then((_) {
|
||||
var read = new File(y).readAsBytesSync();
|
||||
Expect.listEquals(data, read);
|
||||
var read2 = new File(x).readAsBytesSync();
|
||||
Expect.listEquals(data, read2);
|
||||
temp.deleteSync(recursive: true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
testDirectoryExistsCreate() {
|
||||
var temp = Directory.systemTemp.createTempSync('dart_file_system_links');
|
||||
var x = '${temp.path}${Platform.pathSeparator}x';
|
||||
var y = '${temp.path}${Platform.pathSeparator}y';
|
||||
createLink(x, y, () {
|
||||
Expect.isFalse(new Directory(x).existsSync());
|
||||
Expect.isFalse(new Directory(y).existsSync());
|
||||
Expect.throws(new Directory(y).createSync);
|
||||
temp.deleteSync(recursive: true);
|
||||
});
|
||||
}
|
||||
|
||||
testDirectoryDelete() {
|
||||
var temp = Directory.systemTemp.createTempSync('dart_file_system_links');
|
||||
var temp2 = Directory.systemTemp.createTempSync('dart_file_system_links');
|
||||
var y = '${temp.path}${Platform.pathSeparator}y';
|
||||
var x = '${temp2.path}${Platform.pathSeparator}x';
|
||||
new File(x).createSync();
|
||||
createLink(temp2.path, y, () {
|
||||
var link = new Directory(y);
|
||||
Expect.isTrue(link.existsSync());
|
||||
Expect.isTrue(temp2.existsSync());
|
||||
link.deleteSync();
|
||||
Expect.isFalse(link.existsSync());
|
||||
Expect.isTrue(temp2.existsSync());
|
||||
createLink(temp2.path, y, () {
|
||||
Expect.isTrue(link.existsSync());
|
||||
temp.deleteSync(recursive: true);
|
||||
Expect.isFalse(link.existsSync());
|
||||
Expect.isTrue(temp2.existsSync());
|
||||
Expect.isTrue(new File(x).existsSync());
|
||||
temp2.deleteSync(recursive: true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
testDirectoryListing() {
|
||||
asyncStart();
|
||||
var temp = Directory.systemTemp.createTempSync('dart_file_system_links');
|
||||
var temp2 = Directory.systemTemp.createTempSync('dart_file_system_links');
|
||||
var y = '${temp.path}${Platform.pathSeparator}y';
|
||||
var x = '${temp2.path}${Platform.pathSeparator}x';
|
||||
new File(x).createSync();
|
||||
createLink(temp2.path, y, () {
|
||||
var files = [];
|
||||
var dirs = [];
|
||||
for (var entry in temp.listSync(recursive: true)) {
|
||||
if (entry is File) {
|
||||
files.add(entry.path);
|
||||
} else {
|
||||
Expect.isTrue(entry is Directory);
|
||||
dirs.add(entry.path);
|
||||
}
|
||||
}
|
||||
Expect.equals(1, files.length);
|
||||
Expect.isTrue(files[0].endsWith('$y${Platform.pathSeparator}x'));
|
||||
Expect.equals(1, dirs.length);
|
||||
Expect.isTrue(dirs[0].endsWith(y));
|
||||
|
||||
files = [];
|
||||
dirs = [];
|
||||
var lister = temp.list(recursive: true).listen((entity) {
|
||||
if (entity is File) {
|
||||
files.add(entity.path);
|
||||
} else {
|
||||
Expect.isTrue(entity is Directory);
|
||||
dirs.add(entity.path);
|
||||
}
|
||||
}, onDone: () {
|
||||
Expect.equals(1, files.length);
|
||||
Expect.isTrue(files[0].endsWith('$y${Platform.pathSeparator}x'));
|
||||
Expect.equals(1, dirs.length);
|
||||
Expect.isTrue(dirs[0].endsWith(y));
|
||||
temp.deleteSync(recursive: true);
|
||||
temp2.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
testDirectoryListingBrokenLink() {
|
||||
asyncStart();
|
||||
var temp = Directory.systemTemp.createTempSync('dart_file_system_links');
|
||||
var x = '${temp.path}${Platform.pathSeparator}x';
|
||||
var link = '${temp.path}${Platform.pathSeparator}link';
|
||||
var doesNotExist = 'this_thing_does_not_exist';
|
||||
new File(x).createSync();
|
||||
createLink(doesNotExist, link, () {
|
||||
temp.listSync(recursive: true); // No exceptions.
|
||||
var files = [];
|
||||
var dirs = [];
|
||||
var links = [];
|
||||
var errors = [];
|
||||
temp.list(recursive: true).listen(
|
||||
(entity) {
|
||||
if (entity is File) {
|
||||
files.add(entity.path);
|
||||
} else if (entity is Link) {
|
||||
links.add(entity.path);
|
||||
} else {
|
||||
Expect.isTrue(entity is Directory);
|
||||
dirs.add(entity.path);
|
||||
}
|
||||
},
|
||||
onError: (e) => errors.add(e),
|
||||
onDone: () {
|
||||
Expect.equals(1, files.length);
|
||||
Expect.isTrue(files[0].endsWith(x));
|
||||
Expect.equals(1, links.length);
|
||||
Expect.isTrue(links[0].endsWith(link));
|
||||
Expect.equals(0, dirs.length);
|
||||
Expect.equals(0, errors.length);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
// Links on Windows are tested by windows_file_system_[async_]links_test.
|
||||
if (Platform.operatingSystem != 'windows') {
|
||||
testFileExistsCreate();
|
||||
testFileDelete();
|
||||
testFileWriteRead();
|
||||
testDirectoryExistsCreate();
|
||||
testDirectoryDelete();
|
||||
testDirectoryListing();
|
||||
testDirectoryListingBrokenLink();
|
||||
}
|
||||
}
|
42
tests/standalone/io/file_system_uri_test.dart
Normal file
42
tests/standalone/io/file_system_uri_test.dart
Normal file
|
@ -0,0 +1,42 @@
|
|||
// Copyright (c) 2015, 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.
|
||||
|
||||
import "dart:io";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
testFile(String input) {
|
||||
if (Platform.isWindows) {
|
||||
input = input.replaceAll('/', '\\');
|
||||
}
|
||||
var file = new File(input);
|
||||
var uri = file.uri;
|
||||
var file2 = new File.fromUri(uri);
|
||||
Expect.equals(file.path, file2.path, input);
|
||||
}
|
||||
|
||||
testDirectory(String input, [String? output]) {
|
||||
if (output == null) output = input;
|
||||
if (Platform.isWindows) {
|
||||
input = input.replaceAll('/', '\\');
|
||||
output = output.replaceAll('/', '\\');
|
||||
}
|
||||
var dir = new Directory(input);
|
||||
var uri = dir.uri;
|
||||
var dir2 = new Directory.fromUri(uri);
|
||||
Expect.equals(output, dir2.path, input);
|
||||
}
|
||||
|
||||
void main() {
|
||||
testFile("");
|
||||
testFile("/");
|
||||
testFile("foo/bar");
|
||||
testFile("/foo/bar");
|
||||
testFile("/foo/bar/");
|
||||
|
||||
testDirectory("");
|
||||
testDirectory("/");
|
||||
testDirectory("foo/bar", "foo/bar/");
|
||||
testDirectory("/foo/bar", "/foo/bar/");
|
||||
testDirectory("/foo/bar/");
|
||||
}
|
480
tests/standalone/io/file_system_watcher_test.dart
Normal file
480
tests/standalone/io/file_system_watcher_test.dart
Normal file
|
@ -0,0 +1,480 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
// VMOptions=--enable-isolate-groups
|
||||
// VMOptions=--no-enable-isolate-groups
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
import "dart:isolate";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
import "package:path/path.dart";
|
||||
|
||||
void testWatchCreateFile() {
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
var file = new File(join(dir.path, 'file'));
|
||||
|
||||
var watcher = dir.watch();
|
||||
|
||||
asyncStart();
|
||||
var sub;
|
||||
sub = watcher.listen((event) {
|
||||
if (event is FileSystemCreateEvent && event.path.endsWith('file')) {
|
||||
Expect.isFalse(event.isDirectory);
|
||||
asyncEnd();
|
||||
sub.cancel();
|
||||
dir.deleteSync(recursive: true);
|
||||
}
|
||||
}, onError: (e) {
|
||||
dir.deleteSync(recursive: true);
|
||||
throw e;
|
||||
});
|
||||
|
||||
file.createSync();
|
||||
}
|
||||
|
||||
void testWatchCreateDir() {
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
var subdir = new Directory(join(dir.path, 'dir'));
|
||||
|
||||
var watcher = dir.watch();
|
||||
|
||||
asyncStart();
|
||||
var sub;
|
||||
sub = watcher.listen((event) {
|
||||
if (event is FileSystemCreateEvent && event.path.endsWith('dir')) {
|
||||
Expect.isTrue(event.isDirectory);
|
||||
asyncEnd();
|
||||
sub.cancel();
|
||||
dir.deleteSync(recursive: true);
|
||||
}
|
||||
}, onError: (e) {
|
||||
dir.deleteSync(recursive: true);
|
||||
throw e;
|
||||
});
|
||||
|
||||
subdir.createSync();
|
||||
}
|
||||
|
||||
void testWatchModifyFile() {
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
var file = new File(join(dir.path, 'file'));
|
||||
file.createSync();
|
||||
|
||||
var watcher = dir.watch();
|
||||
|
||||
asyncStart();
|
||||
var sub;
|
||||
sub = watcher.listen((event) {
|
||||
if (event is FileSystemModifyEvent) {
|
||||
Expect.isTrue(event.path.endsWith('file'));
|
||||
sub.cancel();
|
||||
asyncEnd();
|
||||
dir.deleteSync(recursive: true);
|
||||
}
|
||||
}, onError: (e) {
|
||||
dir.deleteSync(recursive: true);
|
||||
throw e;
|
||||
});
|
||||
|
||||
file.writeAsStringSync('a');
|
||||
}
|
||||
|
||||
void testWatchMoveFile() {
|
||||
// Mac OS doesn't report move events.
|
||||
if (Platform.isMacOS) return;
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
var file = new File(join(dir.path, 'file'));
|
||||
file.createSync();
|
||||
|
||||
var watcher = dir.watch();
|
||||
|
||||
asyncStart();
|
||||
var sub;
|
||||
sub = watcher.listen((event) {
|
||||
if (event is FileSystemMoveEvent) {
|
||||
Expect.isTrue(event.path.endsWith('file'));
|
||||
final destination = event.destination;
|
||||
if (destination != null) {
|
||||
Expect.isTrue(destination.endsWith('file2'));
|
||||
}
|
||||
sub.cancel();
|
||||
asyncEnd();
|
||||
dir.deleteSync(recursive: true);
|
||||
}
|
||||
}, onError: (e) {
|
||||
dir.deleteSync(recursive: true);
|
||||
throw e;
|
||||
});
|
||||
|
||||
file.renameSync(join(dir.path, 'file2'));
|
||||
}
|
||||
|
||||
void testWatchDeleteFile() {
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
var file = new File(join(dir.path, 'file'));
|
||||
file.createSync();
|
||||
|
||||
var watcher = dir.watch();
|
||||
|
||||
asyncStart();
|
||||
var sub;
|
||||
sub = watcher.listen((event) {
|
||||
if (event is FileSystemDeleteEvent) {
|
||||
Expect.isTrue(event.path.endsWith('file'));
|
||||
sub.cancel();
|
||||
asyncEnd();
|
||||
dir.deleteSync(recursive: true);
|
||||
}
|
||||
}, onError: (e) {
|
||||
dir.deleteSync(recursive: true);
|
||||
throw e;
|
||||
});
|
||||
|
||||
file.deleteSync();
|
||||
}
|
||||
|
||||
void testWatchDeleteDir() {
|
||||
// Windows keeps the directory handle open, even though it's deleted. It'll
|
||||
// be flushed completely, once the watcher is closed as well.
|
||||
if (Platform.isWindows) return;
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
var watcher = dir.watch(events: 0);
|
||||
|
||||
asyncStart();
|
||||
watcher.listen((event) {
|
||||
if (event is FileSystemDeleteEvent) {
|
||||
Expect.isTrue(event.path == dir.path);
|
||||
}
|
||||
}, onDone: () {
|
||||
asyncEnd();
|
||||
});
|
||||
|
||||
dir.deleteSync();
|
||||
}
|
||||
|
||||
void testWatchOnlyModifyFile() {
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
var file = new File(join(dir.path, 'file'));
|
||||
|
||||
var watcher = dir.watch(events: FileSystemEvent.modify);
|
||||
|
||||
asyncStart();
|
||||
var sub;
|
||||
sub = watcher.listen((event) {
|
||||
Expect.isTrue(event is FileSystemModifyEvent);
|
||||
Expect.isTrue(event.path.endsWith('file'));
|
||||
sub.cancel();
|
||||
asyncEnd();
|
||||
dir.deleteSync(recursive: true);
|
||||
}, onError: (e) {
|
||||
dir.deleteSync(recursive: true);
|
||||
throw e;
|
||||
});
|
||||
|
||||
file.createSync();
|
||||
file.writeAsStringSync('a');
|
||||
}
|
||||
|
||||
void testMultipleEvents() {
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
var file = new File(join(dir.path, 'file'));
|
||||
var file2 = new File(join(dir.path, 'file2'));
|
||||
|
||||
var watcher = dir.watch();
|
||||
|
||||
asyncStart();
|
||||
int state = 0;
|
||||
var sub;
|
||||
sub = watcher.listen((event) {
|
||||
int newState = 0;
|
||||
switch (event.type) {
|
||||
case FileSystemEvent.create:
|
||||
newState = 1;
|
||||
break;
|
||||
|
||||
case FileSystemEvent.modify:
|
||||
newState = 2;
|
||||
break;
|
||||
|
||||
case FileSystemEvent.move:
|
||||
newState = 3;
|
||||
break;
|
||||
|
||||
case FileSystemEvent.delete:
|
||||
newState = 4;
|
||||
sub.cancel();
|
||||
asyncEnd();
|
||||
dir.deleteSync();
|
||||
break;
|
||||
}
|
||||
if (!Platform.isMacOS) {
|
||||
if (newState < state) throw "Bad state";
|
||||
}
|
||||
state = newState;
|
||||
});
|
||||
|
||||
file.createSync();
|
||||
file.writeAsStringSync('a');
|
||||
file.renameSync(file2.path);
|
||||
file2.deleteSync();
|
||||
}
|
||||
|
||||
void testWatchRecursive() {
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
if (Platform.isLinux) {
|
||||
Expect.throws(() => dir.watch(recursive: true));
|
||||
return;
|
||||
}
|
||||
var dir2 = new Directory(join(dir.path, 'dir'));
|
||||
dir2.createSync();
|
||||
var file = new File(join(dir.path, 'dir/file'));
|
||||
|
||||
var watcher = dir.watch(recursive: true);
|
||||
|
||||
asyncStart();
|
||||
var sub;
|
||||
sub = watcher.listen((event) {
|
||||
if (event.path.endsWith('file')) {
|
||||
sub.cancel();
|
||||
asyncEnd();
|
||||
dir.deleteSync(recursive: true);
|
||||
}
|
||||
}, onError: (e) {
|
||||
dir.deleteSync(recursive: true);
|
||||
throw e;
|
||||
});
|
||||
|
||||
file.createSync();
|
||||
}
|
||||
|
||||
void testWatchNonRecursive() {
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
var dir2 = new Directory(join(dir.path, 'dir'));
|
||||
dir2.createSync();
|
||||
var file = new File(join(dir.path, 'dir/file'));
|
||||
|
||||
var watcher = dir.watch(recursive: false);
|
||||
|
||||
asyncStart();
|
||||
var sub;
|
||||
sub = watcher.listen((event) {
|
||||
if (event.path.endsWith('file')) {
|
||||
throw "File change event not expected";
|
||||
}
|
||||
}, onError: (e) {
|
||||
dir.deleteSync(recursive: true);
|
||||
throw e;
|
||||
});
|
||||
|
||||
file.createSync();
|
||||
|
||||
new Timer(const Duration(milliseconds: 300), () {
|
||||
sub.cancel();
|
||||
asyncEnd();
|
||||
dir.deleteSync(recursive: true);
|
||||
});
|
||||
}
|
||||
|
||||
void testWatchNonExisting() {
|
||||
// MacOS allows listening on non-existing paths.
|
||||
if (Platform.isMacOS) return;
|
||||
asyncStart();
|
||||
new Directory('__some_none_existing_dir__').watch().listen((_) {
|
||||
Expect.fail('unexpected error');
|
||||
}, onError: (e) {
|
||||
asyncEnd();
|
||||
Expect.isTrue(e is FileSystemException);
|
||||
});
|
||||
}
|
||||
|
||||
void testWatchMoveSelf() {
|
||||
// Windows keeps the directory handle open, even though it's deleted. It'll
|
||||
// be flushed completely, once the watcher is closed as well.
|
||||
if (Platform.isWindows) return;
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
var dir2 = new Directory(join(dir.path, 'dir'))..createSync();
|
||||
|
||||
var watcher = dir2.watch();
|
||||
|
||||
asyncStart();
|
||||
bool gotDelete = false;
|
||||
watcher.listen((event) {
|
||||
if (event is FileSystemDeleteEvent) {
|
||||
Expect.isTrue(event.path.endsWith('dir'));
|
||||
gotDelete = true;
|
||||
}
|
||||
}, onDone: () {
|
||||
Expect.isTrue(gotDelete);
|
||||
dir.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
|
||||
dir2.renameSync(join(dir.path, 'new_dir'));
|
||||
}
|
||||
|
||||
testWatchConsistentModifiedFile() async {
|
||||
// When file modification starts before the watcher listen() is called and the first event
|
||||
// happens in a very short period of time the modifying event will be missed before the
|
||||
// stream listen has been set up and the watcher will hang forever.
|
||||
// Bug: https://github.com/dart-lang/sdk/issues/37233
|
||||
// Bug: https://github.com/dart-lang/sdk/issues/37909
|
||||
asyncStart();
|
||||
ReceivePort receivePort = ReceivePort();
|
||||
Completer<bool> exiting = Completer<bool>();
|
||||
|
||||
late Directory dir;
|
||||
Completer<bool> modificationEventReceived = Completer<bool>();
|
||||
|
||||
late StreamSubscription receiverSubscription;
|
||||
late SendPort workerSendPort;
|
||||
receiverSubscription = receivePort.listen((object) async {
|
||||
if (object == 'modification_started') {
|
||||
var watcher = dir.watch();
|
||||
var subscription;
|
||||
// Wait for event and check the type
|
||||
subscription = watcher.listen((data) async {
|
||||
if (data is FileSystemModifyEvent) {
|
||||
Expect.isTrue(data.path.endsWith('file'));
|
||||
await subscription.cancel();
|
||||
modificationEventReceived.complete(true);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (object == 'end') {
|
||||
await receiverSubscription.cancel();
|
||||
exiting.complete(true);
|
||||
return;
|
||||
}
|
||||
// init event
|
||||
workerSendPort = object[0];
|
||||
dir = new Directory(object[1]);
|
||||
});
|
||||
|
||||
Completer<bool> workerExitedCompleter = Completer();
|
||||
RawReceivePort exitReceivePort = RawReceivePort((object) {
|
||||
workerExitedCompleter.complete(true);
|
||||
});
|
||||
RawReceivePort errorReceivePort = RawReceivePort((object) {
|
||||
print('worker errored: $object');
|
||||
});
|
||||
Isolate isolate = await Isolate.spawn(modifyFiles, receivePort.sendPort,
|
||||
onExit: exitReceivePort.sendPort, onError: errorReceivePort.sendPort);
|
||||
|
||||
await modificationEventReceived.future;
|
||||
workerSendPort.send('end');
|
||||
|
||||
await exiting.future;
|
||||
await workerExitedCompleter.future;
|
||||
exitReceivePort.close();
|
||||
errorReceivePort.close();
|
||||
// Stop modifier isolate
|
||||
isolate.kill();
|
||||
asyncEnd();
|
||||
}
|
||||
|
||||
void modifyFiles(SendPort sendPort) async {
|
||||
// Send sendPort back to listen for modification signal.
|
||||
ReceivePort receivePort = ReceivePort();
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
|
||||
// Create file within the directory and keep modifying.
|
||||
var file = new File(join(dir.path, 'file'));
|
||||
file.createSync();
|
||||
bool done = false;
|
||||
var subscription;
|
||||
subscription = receivePort.listen((object) async {
|
||||
if (object == 'end') {
|
||||
await subscription.cancel();
|
||||
done = true;
|
||||
}
|
||||
});
|
||||
sendPort.send([receivePort.sendPort, dir.path]);
|
||||
bool notificationSent = false;
|
||||
while (!done) {
|
||||
// Start modifying the file continuously before watcher start watching.
|
||||
for (int i = 0; i < 100; i++) {
|
||||
file.writeAsStringSync('a');
|
||||
}
|
||||
if (!notificationSent) {
|
||||
sendPort.send('modification_started');
|
||||
notificationSent = true;
|
||||
}
|
||||
await Future.delayed(Duration());
|
||||
}
|
||||
// Clean up the directory and files
|
||||
dir.deleteSync(recursive: true);
|
||||
sendPort.send('end');
|
||||
}
|
||||
|
||||
testWatchOverflow() async {
|
||||
// When underlying buffer for ReadDirectoryChangesW overflows(on Windows),
|
||||
// it will send an exception to Stream which has been listened.
|
||||
// Bug: https://github.com/dart-lang/sdk/issues/37233
|
||||
asyncStart();
|
||||
ReceivePort receivePort = ReceivePort();
|
||||
Completer<bool> exiting = Completer<bool>();
|
||||
|
||||
Directory dir =
|
||||
Directory.systemTemp.createTempSync('dart_file_system_watcher');
|
||||
var file = new File(join(dir.path, 'file'));
|
||||
file.createSync();
|
||||
|
||||
Isolate isolate =
|
||||
await Isolate.spawn(watcher, receivePort.sendPort, paused: true);
|
||||
|
||||
var subscription;
|
||||
subscription = receivePort.listen((object) async {
|
||||
if (object == 'end') {
|
||||
exiting.complete(true);
|
||||
subscription.cancel();
|
||||
// Clean up the directory and files
|
||||
dir.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
} else if (object == 'start') {
|
||||
isolate.pause(isolate.pauseCapability);
|
||||
// Populate the buffer to overflows and check for exception
|
||||
for (int i = 0; i < 2000; i++) {
|
||||
file.writeAsStringSync('a');
|
||||
}
|
||||
isolate.resume(isolate.pauseCapability!);
|
||||
}
|
||||
});
|
||||
// Resume paused isolate to create watcher
|
||||
isolate.resume(isolate.pauseCapability!);
|
||||
|
||||
await exiting.future;
|
||||
isolate.kill();
|
||||
}
|
||||
|
||||
void watcher(SendPort sendPort) async {
|
||||
runZoned(() {
|
||||
var watcher = Directory.systemTemp.watch(recursive: true);
|
||||
watcher.listen((data) async {});
|
||||
sendPort.send('start');
|
||||
}, onError: (error) {
|
||||
print(error);
|
||||
sendPort.send('end');
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
if (!FileSystemEntity.isWatchSupported) return;
|
||||
testWatchCreateFile();
|
||||
testWatchCreateDir();
|
||||
testWatchModifyFile();
|
||||
testWatchMoveFile();
|
||||
testWatchDeleteFile();
|
||||
testWatchDeleteDir();
|
||||
testWatchOnlyModifyFile();
|
||||
testMultipleEvents();
|
||||
testWatchNonRecursive();
|
||||
testWatchNonExisting();
|
||||
testWatchMoveSelf();
|
||||
testWatchConsistentModifiedFile();
|
||||
if (Platform.isWindows) testWatchOverflow();
|
||||
}
|
1684
tests/standalone/io/file_test.dart
Normal file
1684
tests/standalone/io/file_test.dart
Normal file
File diff suppressed because it is too large
Load diff
63
tests/standalone/io/file_test.txt
Normal file
63
tests/standalone/io/file_test.txt
Normal file
|
@ -0,0 +1,63 @@
|
|||
// 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.
|
||||
|
||||
#include "bin/file.h"
|
||||
#include "platform/assert.h"
|
||||
#include "platform/globals.h"
|
||||
#include "vm/unit_test.h"
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
// Helper method to be able to run the test from the runtime
|
||||
// directory, or the top directory.
|
||||
static const char* GetFileName(const char* name) {
|
||||
if (File::Exists(name)) {
|
||||
return name;
|
||||
} else {
|
||||
static const int kRuntimeLength = strlen("runtime/");
|
||||
return name + kRuntimeLength;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE(Read) {
|
||||
const char* kFilename = GetFileName("runtime/bin/file_test.cc");
|
||||
File* file = File::Open(kFilename, File::kRead);
|
||||
EXPECT(file != NULL);
|
||||
char buffer[16];
|
||||
buffer[0] = '\0';
|
||||
EXPECT(file->ReadFully(buffer, 13)); // ReadFully returns true.
|
||||
buffer[13] = '\0';
|
||||
EXPECT_STREQ("// Copyright ", buffer);
|
||||
EXPECT(!file->WriteByte(1)); // Cannot write to a read-only file.
|
||||
file->Release();
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE(FileLength) {
|
||||
const char* kFilename =
|
||||
GetFileName("runtime/tests/vm/data/fixed_length_file");
|
||||
File* file = File::Open(kFilename, File::kRead);
|
||||
EXPECT(file != NULL);
|
||||
EXPECT_EQ(42, file->Length());
|
||||
file->Release();
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE(FilePosition) {
|
||||
char buf[42];
|
||||
const char* kFilename =
|
||||
GetFileName("runtime/tests/vm/data/fixed_length_file");
|
||||
File* file = File::Open(kFilename, File::kRead);
|
||||
EXPECT(file != NULL);
|
||||
EXPECT(file->ReadFully(buf, 12));
|
||||
EXPECT_EQ(12, file->Position());
|
||||
EXPECT(file->ReadFully(buf, 6));
|
||||
EXPECT_EQ(18, file->Position());
|
||||
file->Release();
|
||||
}
|
||||
|
||||
} // namespace bin
|
||||
} // namespace dart
|
366
tests/standalone/io/file_typed_data_test.dart
Normal file
366
tests/standalone/io/file_typed_data_test.dart
Normal file
|
@ -0,0 +1,366 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Dart test program for testing file I/O.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void testWriteInt8ListAndView() {
|
||||
asyncStart();
|
||||
const int LIST_LENGTH = 8;
|
||||
const int OFFSET_IN_BYTES_FOR_VIEW = 2 * Int8List.bytesPerElement;
|
||||
const int VIEW_LENGTH = 4;
|
||||
Int8List list = new Int8List(LIST_LENGTH);
|
||||
for (int i = 0; i < LIST_LENGTH; i++) list[i] = i;
|
||||
var view =
|
||||
new Int8List.view(list.buffer, OFFSET_IN_BYTES_FOR_VIEW, VIEW_LENGTH);
|
||||
|
||||
Directory.systemTemp.createTemp('dart_file_typed_data').then((temp) {
|
||||
var file = new File("${temp.path}/test");
|
||||
file.open(mode: FileMode.write).then((raf) {
|
||||
return raf.writeFrom(list, 0, LIST_LENGTH);
|
||||
}).then((raf) {
|
||||
return raf.writeFrom(view, 0, VIEW_LENGTH);
|
||||
}).then((raf) {
|
||||
return raf.close();
|
||||
}).then((_) {
|
||||
var expected = [];
|
||||
expected.addAll(list);
|
||||
expected.addAll(view);
|
||||
var content = file.readAsBytesSync();
|
||||
Expect.listEquals(expected, content);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testWriteUint8ListAndView() {
|
||||
asyncStart();
|
||||
const int LIST_LENGTH = 8;
|
||||
const int OFFSET_IN_BYTES_FOR_VIEW = 2 * Uint8List.bytesPerElement;
|
||||
const int VIEW_LENGTH = 4;
|
||||
Uint8List list = new Uint8List(LIST_LENGTH);
|
||||
for (int i = 0; i < LIST_LENGTH; i++) list[i] = i;
|
||||
var view =
|
||||
new Uint8List.view(list.buffer, OFFSET_IN_BYTES_FOR_VIEW, VIEW_LENGTH);
|
||||
|
||||
Directory.systemTemp.createTemp('dart_file_typed_data').then((temp) {
|
||||
var file = new File("${temp.path}/test");
|
||||
file.open(mode: FileMode.write).then((raf) {
|
||||
return raf.writeFrom(list, 0, LIST_LENGTH);
|
||||
}).then((raf) {
|
||||
return raf.writeFrom(view, 0, VIEW_LENGTH);
|
||||
}).then((raf) {
|
||||
return raf.close();
|
||||
}).then((_) {
|
||||
var expected = [];
|
||||
expected.addAll(list);
|
||||
expected.addAll(view);
|
||||
var content = file.readAsBytesSync();
|
||||
Expect.listEquals(expected, content);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testWriteUint8ClampedListAndView() {
|
||||
asyncStart();
|
||||
const int LIST_LENGTH = 8;
|
||||
const int OFFSET_IN_BYTES_FOR_VIEW = 2 * Uint8ClampedList.bytesPerElement;
|
||||
const int VIEW_LENGTH = 4;
|
||||
Uint8ClampedList list = new Uint8ClampedList(LIST_LENGTH);
|
||||
for (int i = 0; i < LIST_LENGTH; i++) list[i] = i;
|
||||
var view = new Uint8ClampedList.view(
|
||||
list.buffer, OFFSET_IN_BYTES_FOR_VIEW, VIEW_LENGTH);
|
||||
|
||||
Directory.systemTemp.createTemp('dart_file_typed_data').then((temp) {
|
||||
var file = new File("${temp.path}/test");
|
||||
file.open(mode: FileMode.write).then((raf) {
|
||||
return raf.writeFrom(list, 0, LIST_LENGTH);
|
||||
}).then((raf) {
|
||||
return raf.writeFrom(view, 0, VIEW_LENGTH);
|
||||
}).then((raf) {
|
||||
return raf.close();
|
||||
}).then((_) {
|
||||
var expected = [];
|
||||
expected.addAll(list);
|
||||
expected.addAll(view);
|
||||
var content = file.readAsBytesSync();
|
||||
Expect.listEquals(expected, content);
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testWriteInt16ListAndView() {
|
||||
asyncStart();
|
||||
const int LIST_LENGTH = 8;
|
||||
const int LIST_LENGTH_IN_BYTES = LIST_LENGTH * Int16List.bytesPerElement;
|
||||
const int OFFSET_IN_BYTES_FOR_VIEW = 2 * Int16List.bytesPerElement;
|
||||
const int VIEW_LENGTH = 4;
|
||||
const int VIEW_LENGTH_IN_BYTES = VIEW_LENGTH * Int16List.bytesPerElement;
|
||||
var list = new Int16List(LIST_LENGTH);
|
||||
for (int i = 0; i < LIST_LENGTH; i++) list[i] = i;
|
||||
var view =
|
||||
new Int16List.view(list.buffer, OFFSET_IN_BYTES_FOR_VIEW, VIEW_LENGTH);
|
||||
|
||||
Directory.systemTemp.createTemp('dart_file_typed_data').then((temp) {
|
||||
var file = new File("${temp.path}/test");
|
||||
file.open(mode: FileMode.write).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(list.buffer), 0, LIST_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(
|
||||
view.buffer, view.offsetInBytes, view.lengthInBytes),
|
||||
0,
|
||||
VIEW_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.close();
|
||||
}).then((_) {
|
||||
var expected = [];
|
||||
expected.addAll(list);
|
||||
expected.addAll(view);
|
||||
var content = file.readAsBytesSync();
|
||||
var typed_data_content = new Uint8List(content.length);
|
||||
for (int i = 0; i < content.length; i++) {
|
||||
typed_data_content[i] = content[i];
|
||||
}
|
||||
Expect.listEquals(
|
||||
expected, new Int16List.view(typed_data_content.buffer));
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testWriteUint16ListAndView() {
|
||||
asyncStart();
|
||||
const int LIST_LENGTH = 8;
|
||||
const int LIST_LENGTH_IN_BYTES = LIST_LENGTH * Uint16List.bytesPerElement;
|
||||
const int OFFSET_IN_BYTES_FOR_VIEW = 2 * Uint16List.bytesPerElement;
|
||||
const int VIEW_LENGTH = 4;
|
||||
const int VIEW_LENGTH_IN_BYTES = VIEW_LENGTH * Uint16List.bytesPerElement;
|
||||
var list = new Uint16List(LIST_LENGTH);
|
||||
for (int i = 0; i < LIST_LENGTH; i++) list[i] = i;
|
||||
var view =
|
||||
new Uint16List.view(list.buffer, OFFSET_IN_BYTES_FOR_VIEW, VIEW_LENGTH);
|
||||
|
||||
Directory.systemTemp.createTemp('dart_file_typed_data').then((temp) {
|
||||
var file = new File("${temp.path}/test");
|
||||
file.open(mode: FileMode.write).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(list.buffer), 0, LIST_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(
|
||||
view.buffer, view.offsetInBytes, view.lengthInBytes),
|
||||
0,
|
||||
VIEW_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.close();
|
||||
}).then((_) {
|
||||
var expected = [];
|
||||
expected.addAll(list);
|
||||
expected.addAll(view);
|
||||
var content = file.readAsBytesSync();
|
||||
var typed_data_content = new Uint8List(content.length);
|
||||
for (int i = 0; i < content.length; i++) {
|
||||
typed_data_content[i] = content[i];
|
||||
}
|
||||
Expect.listEquals(
|
||||
expected, new Uint16List.view(typed_data_content.buffer));
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testWriteInt32ListAndView() {
|
||||
asyncStart();
|
||||
const int LIST_LENGTH = 8;
|
||||
const int LIST_LENGTH_IN_BYTES = LIST_LENGTH * Int32List.bytesPerElement;
|
||||
const int OFFSET_IN_BYTES_FOR_VIEW = 2 * Int32List.bytesPerElement;
|
||||
const int VIEW_LENGTH = 4;
|
||||
const int VIEW_LENGTH_IN_BYTES = VIEW_LENGTH * Int32List.bytesPerElement;
|
||||
var list = new Int32List(LIST_LENGTH);
|
||||
for (int i = 0; i < LIST_LENGTH; i++) list[i] = i;
|
||||
var view =
|
||||
new Int32List.view(list.buffer, OFFSET_IN_BYTES_FOR_VIEW, VIEW_LENGTH);
|
||||
|
||||
Directory.systemTemp.createTemp('dart_file_typed_data').then((temp) {
|
||||
var file = new File("${temp.path}/test");
|
||||
file.open(mode: FileMode.write).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(list.buffer), 0, LIST_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(
|
||||
view.buffer, view.offsetInBytes, view.lengthInBytes),
|
||||
0,
|
||||
VIEW_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.close();
|
||||
}).then((_) {
|
||||
var expected = [];
|
||||
expected.addAll(list);
|
||||
expected.addAll(view);
|
||||
var content = file.readAsBytesSync();
|
||||
var typed_data_content = new Uint8List(content.length);
|
||||
for (int i = 0; i < content.length; i++) {
|
||||
typed_data_content[i] = content[i];
|
||||
}
|
||||
Expect.listEquals(
|
||||
expected, new Int32List.view(typed_data_content.buffer));
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testWriteUint32ListAndView() {
|
||||
asyncStart();
|
||||
const int LIST_LENGTH = 8;
|
||||
const int LIST_LENGTH_IN_BYTES = LIST_LENGTH * Int32List.bytesPerElement;
|
||||
const int OFFSET_IN_BYTES_FOR_VIEW = 2 * Int32List.bytesPerElement;
|
||||
const int VIEW_LENGTH = 4;
|
||||
const int VIEW_LENGTH_IN_BYTES = VIEW_LENGTH * Int32List.bytesPerElement;
|
||||
var list = new Uint32List(LIST_LENGTH);
|
||||
for (int i = 0; i < LIST_LENGTH; i++) list[i] = i;
|
||||
var view =
|
||||
new Uint32List.view(list.buffer, OFFSET_IN_BYTES_FOR_VIEW, VIEW_LENGTH);
|
||||
|
||||
Directory.systemTemp.createTemp('dart_file_typed_data').then((temp) {
|
||||
var file = new File("${temp.path}/test");
|
||||
file.open(mode: FileMode.write).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(list.buffer), 0, LIST_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(
|
||||
view.buffer, view.offsetInBytes, view.lengthInBytes),
|
||||
0,
|
||||
VIEW_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.close();
|
||||
}).then((_) {
|
||||
var expected = [];
|
||||
expected.addAll(list);
|
||||
expected.addAll(view);
|
||||
var content = file.readAsBytesSync();
|
||||
var typed_data_content = new Uint8List(content.length);
|
||||
for (int i = 0; i < content.length; i++) {
|
||||
typed_data_content[i] = content[i];
|
||||
}
|
||||
Expect.listEquals(
|
||||
expected, new Uint32List.view(typed_data_content.buffer));
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testWriteInt64ListAndView() {
|
||||
asyncStart();
|
||||
const int LIST_LENGTH = 8;
|
||||
const int LIST_LENGTH_IN_BYTES = LIST_LENGTH * Int64List.bytesPerElement;
|
||||
const int OFFSET_IN_BYTES_FOR_VIEW = 2 * Int64List.bytesPerElement;
|
||||
const int VIEW_LENGTH = 4;
|
||||
const int VIEW_LENGTH_IN_BYTES = VIEW_LENGTH * Int64List.bytesPerElement;
|
||||
var list = new Int64List(LIST_LENGTH);
|
||||
for (int i = 0; i < LIST_LENGTH; i++) list[i] = i;
|
||||
var view =
|
||||
new Int64List.view(list.buffer, OFFSET_IN_BYTES_FOR_VIEW, VIEW_LENGTH);
|
||||
|
||||
Directory.systemTemp.createTemp('dart_file_typed_data').then((temp) {
|
||||
var file = new File("${temp.path}/test");
|
||||
file.open(mode: FileMode.write).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(list.buffer), 0, LIST_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(
|
||||
view.buffer, view.offsetInBytes, view.lengthInBytes),
|
||||
0,
|
||||
VIEW_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.close();
|
||||
}).then((_) {
|
||||
var expected = [];
|
||||
expected.addAll(list);
|
||||
expected.addAll(view);
|
||||
var content = file.readAsBytesSync();
|
||||
var typed_data_content = new Uint8List(content.length);
|
||||
for (int i = 0; i < content.length; i++) {
|
||||
typed_data_content[i] = content[i];
|
||||
}
|
||||
Expect.listEquals(
|
||||
expected, new Int64List.view(typed_data_content.buffer));
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testWriteUint64ListAndView() {
|
||||
asyncStart();
|
||||
const int LIST_LENGTH = 8;
|
||||
const int LIST_LENGTH_IN_BYTES = LIST_LENGTH * Uint64List.bytesPerElement;
|
||||
const int OFFSET_IN_BYTES_FOR_VIEW = 2 * Uint64List.bytesPerElement;
|
||||
const int VIEW_LENGTH = 4;
|
||||
const int VIEW_LENGTH_IN_BYTES = VIEW_LENGTH * Uint64List.bytesPerElement;
|
||||
var list = new Uint64List(LIST_LENGTH);
|
||||
for (int i = 0; i < LIST_LENGTH; i++) list[i] = i;
|
||||
var view =
|
||||
new Uint64List.view(list.buffer, OFFSET_IN_BYTES_FOR_VIEW, VIEW_LENGTH);
|
||||
|
||||
Directory.systemTemp.createTemp('dart_file_typed_data').then((temp) {
|
||||
var file = new File("${temp.path}/test");
|
||||
file.open(mode: FileMode.write).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(list.buffer), 0, LIST_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.writeFrom(
|
||||
new Uint8List.view(
|
||||
view.buffer, view.offsetInBytes, view.lengthInBytes),
|
||||
0,
|
||||
VIEW_LENGTH_IN_BYTES);
|
||||
}).then((raf) {
|
||||
return raf.close();
|
||||
}).then((_) {
|
||||
var expected = [];
|
||||
expected.addAll(list);
|
||||
expected.addAll(view);
|
||||
var content = file.readAsBytesSync();
|
||||
var typed_data_content = new Uint8List(content.length);
|
||||
for (int i = 0; i < content.length; i++) {
|
||||
typed_data_content[i] = content[i];
|
||||
}
|
||||
Expect.listEquals(
|
||||
expected, new Uint64List.view(typed_data_content.buffer));
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
testWriteInt8ListAndView();
|
||||
testWriteUint8ListAndView();
|
||||
testWriteUint8ClampedListAndView();
|
||||
testWriteInt16ListAndView();
|
||||
testWriteUint16ListAndView();
|
||||
testWriteInt32ListAndView();
|
||||
testWriteUint32ListAndView();
|
||||
testWriteInt64ListAndView();
|
||||
testWriteUint64ListAndView();
|
||||
}
|
44
tests/standalone/io/file_uri_test.dart
Normal file
44
tests/standalone/io/file_uri_test.dart
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void testFromUri() {
|
||||
asyncStart();
|
||||
Directory originalWorkingDirectory = Directory.current;
|
||||
Directory.systemTemp.createTemp('file_uri').then((temp) {
|
||||
String filename = temp.path + '/from_uri';
|
||||
Uri fileUri = new Uri.file(filename);
|
||||
File file = new File.fromUri(fileUri);
|
||||
Expect.isTrue(fileUri.isAbsolute);
|
||||
Expect.isTrue(fileUri.path.startsWith('/'));
|
||||
file.createSync();
|
||||
Expect.isTrue(new File.fromUri(fileUri).existsSync());
|
||||
Expect.isTrue(new File.fromUri(Uri.base.resolveUri(fileUri)).existsSync());
|
||||
Directory.current = temp.path;
|
||||
Expect.isTrue(new File.fromUri(Uri.parse('from_uri')).existsSync());
|
||||
Expect.isTrue(new File.fromUri(Uri.base.resolve('from_uri')).existsSync());
|
||||
Directory.current = originalWorkingDirectory;
|
||||
file.deleteSync();
|
||||
temp.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
void testFromUriUnsupported() {
|
||||
Expect.throwsUnsupportedError(
|
||||
() => new File.fromUri(Uri.parse('http://localhost:8080/index.html')));
|
||||
Expect.throwsUnsupportedError(
|
||||
() => new File.fromUri(Uri.parse('ftp://localhost/tmp/xxx')));
|
||||
Expect.throwsUnsupportedError(
|
||||
() => new File.fromUri(Uri.parse('name#fragment')));
|
||||
}
|
||||
|
||||
void main() {
|
||||
testFromUri();
|
||||
testFromUriUnsupported();
|
||||
}
|
28
tests/standalone/io/file_windows_test.dart
Normal file
28
tests/standalone/io/file_windows_test.dart
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void testDeleteLongPathPrefix() {
|
||||
var dir = Directory.systemTemp.createTempSync('dart_file_win');
|
||||
var dirPath = "\\\\?\\${dir.path}";
|
||||
var subPath = dirPath;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
subPath += "\\a-long-path-segment";
|
||||
dir = new Directory(subPath)..createSync();
|
||||
}
|
||||
Expect.isTrue(dir.path.length > 256);
|
||||
var prefixDir = new Directory(dirPath);
|
||||
Expect.isTrue(prefixDir.existsSync());
|
||||
prefixDir.deleteSync(recursive: true);
|
||||
Expect.isFalse(dir.existsSync());
|
||||
Expect.isFalse(prefixDir.existsSync());
|
||||
}
|
||||
|
||||
void main() {
|
||||
if (!Platform.isWindows) return;
|
||||
testDeleteLongPathPrefix();
|
||||
}
|
82
tests/standalone/io/file_write_as_test.dart
Normal file
82
tests/standalone/io/file_write_as_test.dart
Normal file
|
@ -0,0 +1,82 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
testWriteAsBytesSync(dir) {
|
||||
var f = new File('${dir.path}/bytes_sync.txt');
|
||||
var data = [50, 50, 50];
|
||||
f.writeAsBytesSync(data);
|
||||
Expect.listEquals(data, f.readAsBytesSync());
|
||||
f.writeAsBytesSync(data, mode: FileMode.append, flush: true);
|
||||
var expected = [50, 50, 50, 50, 50, 50];
|
||||
Expect.listEquals(expected, f.readAsBytesSync());
|
||||
}
|
||||
|
||||
testWriteAsStringSync(dir) {
|
||||
var f = new File('${dir.path}/string_sync.txt');
|
||||
var data = 'asdf';
|
||||
f.writeAsStringSync(data);
|
||||
Expect.equals(data, f.readAsStringSync());
|
||||
f.writeAsStringSync(data, mode: FileMode.append, flush: true);
|
||||
Expect.equals('$data$data', f.readAsStringSync());
|
||||
}
|
||||
|
||||
Future testWriteAsBytes(dir) {
|
||||
var completer = new Completer();
|
||||
var f = new File('${dir.path}/bytes.txt');
|
||||
var data = [50, 50, 50];
|
||||
f.writeAsBytes(data).then((file) {
|
||||
Expect.equals(f, file);
|
||||
f.readAsBytes().then((bytes) {
|
||||
Expect.listEquals(data, bytes);
|
||||
f.writeAsBytes(data, mode: FileMode.append, flush: true).then((file) {
|
||||
Expect.equals(f, file);
|
||||
f.readAsBytes().then((bytes) {
|
||||
var expected = [50, 50, 50, 50, 50, 50];
|
||||
Expect.listEquals(expected, bytes);
|
||||
completer.complete(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future testWriteAsString(dir) {
|
||||
var completer = new Completer();
|
||||
var f = new File('${dir.path}/strings.txt');
|
||||
var data = 'asdf';
|
||||
f.writeAsString(data).then((file) {
|
||||
Expect.equals(f, file);
|
||||
f.readAsString().then((str) {
|
||||
Expect.equals(data, str);
|
||||
f.writeAsString(data, mode: FileMode.append, flush: true).then((file) {
|
||||
Expect.equals(f, file);
|
||||
f.readAsString().then((str) {
|
||||
Expect.equals('$data$data', str);
|
||||
completer.complete(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncStart();
|
||||
var tempDir = Directory.systemTemp.createTempSync('dart_file_write_as');
|
||||
testWriteAsBytesSync(tempDir);
|
||||
testWriteAsStringSync(tempDir);
|
||||
testWriteAsBytes(tempDir).then((_) {
|
||||
return testWriteAsString(tempDir);
|
||||
}).then((_) {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
83
tests/standalone/io/file_write_only_test.dart
Normal file
83
tests/standalone/io/file_write_only_test.dart
Normal file
|
@ -0,0 +1,83 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
//
|
||||
// Dart test program for testing file I/O.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
Future withTempDir(String prefix, Future<void> test(Directory dir)) async {
|
||||
var tempDir = Directory.systemTemp.createTempSync(prefix);
|
||||
try {
|
||||
await test(tempDir);
|
||||
} finally {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
void withTempDirSync(String prefix, void test(Directory dir)) {
|
||||
var tempDir = Directory.systemTemp.createTempSync(prefix);
|
||||
try {
|
||||
test(tempDir);
|
||||
} finally {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
Future expectThrowsAsync(Future future, String message) {
|
||||
return future.then((r) => Expect.fail(message)).catchError((e) {});
|
||||
}
|
||||
|
||||
Future write(Directory dir) async {
|
||||
var f = new File("${dir.path}${Platform.pathSeparator}write");
|
||||
var raf = await f.open(mode: FileMode.writeOnly);
|
||||
await raf.writeString('Hello');
|
||||
await raf.setPosition(0);
|
||||
await raf.writeString('Hello');
|
||||
await raf.setPosition(0);
|
||||
await expectThrowsAsync(
|
||||
raf.readByte(), 'Read from write only file succeeded');
|
||||
await raf.close();
|
||||
raf = await f.open(mode: FileMode.writeOnlyAppend);
|
||||
await raf.writeString('Hello');
|
||||
await expectThrowsAsync(
|
||||
raf.readByte(), 'Read from write only file succeeded');
|
||||
await raf.setPosition(0);
|
||||
await raf.writeString('Hello');
|
||||
await raf.close();
|
||||
Expect.equals(f.lengthSync(), 10);
|
||||
}
|
||||
|
||||
void writeSync(Directory dir) {
|
||||
var f = new File("${dir.path}${Platform.pathSeparator}write_sync");
|
||||
var raf = f.openSync(mode: FileMode.writeOnly);
|
||||
raf.writeStringSync('Hello');
|
||||
raf.setPositionSync(0);
|
||||
raf.writeStringSync('Hello');
|
||||
raf.setPositionSync(0);
|
||||
Expect.throws(() => raf.readByteSync());
|
||||
raf.closeSync();
|
||||
}
|
||||
|
||||
Future openWrite(Directory dir) async {
|
||||
var f = new File("${dir.path}${Platform.pathSeparator}open_write");
|
||||
var sink = f.openWrite(mode: FileMode.writeOnly);
|
||||
sink.write('Hello');
|
||||
await sink.close();
|
||||
sink = await f.openWrite(mode: FileMode.writeOnlyAppend);
|
||||
sink.write('Hello');
|
||||
await sink.close();
|
||||
Expect.equals(f.lengthSync(), 10);
|
||||
}
|
||||
|
||||
main() async {
|
||||
asyncStart();
|
||||
await withTempDir('file_write_only_test_1_', write);
|
||||
withTempDirSync('file_write_only_test_2_', writeSync);
|
||||
await withTempDir('file_write_only_test_3_', openWrite);
|
||||
asyncEnd();
|
||||
}
|
1
tests/standalone/io/fixed_length_file
Normal file
1
tests/standalone/io/fixed_length_file
Normal file
|
@ -0,0 +1 @@
|
|||
This file should contain exactly 42 bytes.
|
0
tests/standalone/io/fixed_length_file_out
Normal file
0
tests/standalone/io/fixed_length_file_out
Normal file
58
tests/standalone/io/fuzz_support.dart
Normal file
58
tests/standalone/io/fuzz_support.dart
Normal file
|
@ -0,0 +1,58 @@
|
|||
// 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 fuzz_support;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
const typeMapping = const {
|
||||
'null': null,
|
||||
'int': 0,
|
||||
'int64': -9000000000000000000,
|
||||
'String': 'a',
|
||||
'FileMode': FileMode.read,
|
||||
'num': 0.50,
|
||||
'List<int>': const [1, 2, 3],
|
||||
'Map<String, int>': const {"a": 23}
|
||||
};
|
||||
|
||||
typePermutations(int argCount) {
|
||||
var result = [];
|
||||
if (argCount == 2) {
|
||||
typeMapping.forEach((k, v) {
|
||||
typeMapping.forEach((k2, v2) {
|
||||
result.add([v, v2]);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
Expect.isTrue(argCount == 3);
|
||||
typeMapping.forEach((k, v) {
|
||||
typeMapping.forEach((k2, v2) {
|
||||
typeMapping.forEach((k3, v3) {
|
||||
result.add([v, v2, v3]);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Perform sync operation and ignore all exceptions.
|
||||
doItSync(Function f) {
|
||||
try {
|
||||
f();
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// Perform async operation and transform the future for the operation
|
||||
// into a future that never fails by treating errors as normal
|
||||
// completion.
|
||||
Future doItAsync(FutureOr f()) {
|
||||
// Ignore value and errors.
|
||||
return new Future.delayed(Duration.zero, f)
|
||||
.catchError((_) {})
|
||||
.then((_) => true);
|
||||
}
|
73
tests/standalone/io/http_100_continue.dart
Normal file
73
tests/standalone/io/http_100_continue.dart
Normal file
|
@ -0,0 +1,73 @@
|
|||
// Copyright (c) 2015, 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.
|
||||
|
||||
import "dart:async";
|
||||
import 'dart:convert';
|
||||
import "dart:io";
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void test(responseBytes, bodyLength) async {
|
||||
fullRequest(bytes) {
|
||||
var len = bytes.length;
|
||||
return len > 4 &&
|
||||
bytes[len - 4] == 13 &&
|
||||
bytes[len - 3] == 10 &&
|
||||
bytes[len - 2] == 13 &&
|
||||
bytes[len - 1] == 10;
|
||||
}
|
||||
|
||||
handleSocket(socket) async {
|
||||
var bytes = [];
|
||||
await for (var data in socket) {
|
||||
bytes.addAll(data);
|
||||
if (fullRequest(bytes)) {
|
||||
socket.add(responseBytes);
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var server = await ServerSocket.bind('127.0.0.1', 0);
|
||||
server.listen(handleSocket);
|
||||
|
||||
var client = new HttpClient();
|
||||
var request =
|
||||
await client.getUrl(Uri.parse('http://127.0.0.1:${server.port}/'));
|
||||
var response = await request.close();
|
||||
Expect.equals(response.statusCode, 200);
|
||||
Expect.equals(bodyLength,
|
||||
(await response.fold<List<int>>(<int>[], (p, e) => p..addAll(e))).length);
|
||||
server.close();
|
||||
}
|
||||
|
||||
main() {
|
||||
var r1 = '''
|
||||
HTTP/1.1 100 Continue\r
|
||||
\r
|
||||
HTTP/1.1 200 OK\r
|
||||
\r
|
||||
''';
|
||||
|
||||
var r2 = '''
|
||||
HTTP/1.1 100 Continue\r
|
||||
My-Header-1: hello\r
|
||||
My-Header-2: world\r
|
||||
\r
|
||||
HTTP/1.1 200 OK\r
|
||||
\r
|
||||
''';
|
||||
|
||||
var r3 = '''
|
||||
HTTP/1.1 100 Continue\r
|
||||
\r
|
||||
HTTP/1.1 200 OK\r
|
||||
Content-Length: 2\r
|
||||
\r
|
||||
AB''';
|
||||
|
||||
test(ascii.encode(r1), 0);
|
||||
test(ascii.encode(r2), 0);
|
||||
test(ascii.encode(r3), 2);
|
||||
}
|
215
tests/standalone/io/http_10_test.dart
Normal file
215
tests/standalone/io/http_10_test.dart
Normal file
|
@ -0,0 +1,215 @@
|
|||
// (c) 2013, 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.
|
||||
|
||||
// VMOptions=
|
||||
// VMOptions=--short_socket_read
|
||||
// VMOptions=--short_socket_write
|
||||
// VMOptions=--short_socket_read --short_socket_write
|
||||
|
||||
import "dart:async";
|
||||
import "dart:isolate";
|
||||
import "dart:io";
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
// Client makes a HTTP 1.0 request without connection keep alive. The
|
||||
// server sets a content length but still needs to close the
|
||||
// connection as there is no keep alive.
|
||||
void testHttp10NoKeepAlive() {
|
||||
HttpServer.bind("127.0.0.1", 0).then((server) {
|
||||
server.listen((HttpRequest request) {
|
||||
Expect.isNull(request.headers.value('content-length'));
|
||||
Expect.equals(-1, request.contentLength);
|
||||
var response = request.response;
|
||||
response.contentLength = 1;
|
||||
Expect.equals("1.0", request.protocolVersion);
|
||||
response.done
|
||||
.then((_) => Expect.fail("Unexpected response completion"))
|
||||
.catchError((error) => Expect.isTrue(error is HttpException));
|
||||
response.write("Z");
|
||||
response.write("Z");
|
||||
response.close();
|
||||
Expect.throws(() {
|
||||
response.write("x");
|
||||
}, (e) => e is StateError);
|
||||
}, onError: (e, trace) {
|
||||
String msg = "Unexpected error $e";
|
||||
if (trace != null) msg += "\nStackTrace: $trace";
|
||||
Expect.fail(msg);
|
||||
});
|
||||
|
||||
int count = 0;
|
||||
makeRequest() {
|
||||
Socket.connect("127.0.0.1", server.port).then((socket) {
|
||||
socket.write("GET / HTTP/1.0\r\n\r\n");
|
||||
|
||||
List<int> response = [];
|
||||
socket.listen(response.addAll, onDone: () {
|
||||
count++;
|
||||
socket.destroy();
|
||||
String s = new String.fromCharCodes(response).toLowerCase();
|
||||
Expect.equals(-1, s.indexOf("keep-alive"));
|
||||
if (count < 10) {
|
||||
makeRequest();
|
||||
} else {
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
makeRequest();
|
||||
});
|
||||
}
|
||||
|
||||
// Client makes a HTTP 1.0 request and the server does not set a
|
||||
// content length so it has to close the connection to mark the end of
|
||||
// the response.
|
||||
void testHttp10ServerClose() {
|
||||
HttpServer.bind("127.0.0.1", 0).then((server) {
|
||||
server.listen((HttpRequest request) {
|
||||
Expect.isNull(request.headers.value('content-length'));
|
||||
Expect.equals(-1, request.contentLength);
|
||||
request.listen((_) {}, onDone: () {
|
||||
var response = request.response;
|
||||
Expect.equals("1.0", request.protocolVersion);
|
||||
response.write("Z");
|
||||
response.close();
|
||||
});
|
||||
}, onError: (e, trace) {
|
||||
String msg = "Unexpected error $e";
|
||||
if (trace != null) msg += "\nStackTrace: $trace";
|
||||
Expect.fail(msg);
|
||||
});
|
||||
|
||||
int count = 0;
|
||||
makeRequest() {
|
||||
Socket.connect("127.0.0.1", server.port).then((socket) {
|
||||
socket.write("GET / HTTP/1.0\r\n");
|
||||
socket.write("Connection: Keep-Alive\r\n\r\n");
|
||||
|
||||
List<int> response = [];
|
||||
socket.listen(response.addAll,
|
||||
onDone: () {
|
||||
socket.destroy();
|
||||
count++;
|
||||
String s = new String.fromCharCodes(response).toLowerCase();
|
||||
Expect.equals("z", s[s.length - 1]);
|
||||
Expect.equals(-1, s.indexOf("content-length:"));
|
||||
Expect.equals(-1, s.indexOf("keep-alive"));
|
||||
if (count < 10) {
|
||||
makeRequest();
|
||||
} else {
|
||||
server.close();
|
||||
}
|
||||
},
|
||||
onError: (e) => print(e));
|
||||
});
|
||||
}
|
||||
|
||||
makeRequest();
|
||||
});
|
||||
}
|
||||
|
||||
// Client makes a HTTP 1.0 request with connection keep alive. The
|
||||
// server sets a content length so the persistent connection can be
|
||||
// used.
|
||||
void testHttp10KeepAlive() {
|
||||
HttpServer.bind("127.0.0.1", 0).then((server) {
|
||||
server.listen((HttpRequest request) {
|
||||
Expect.isNull(request.headers.value('content-length'));
|
||||
Expect.equals(-1, request.contentLength);
|
||||
var response = request.response;
|
||||
response.contentLength = 1;
|
||||
response.persistentConnection = true;
|
||||
Expect.equals("1.0", request.protocolVersion);
|
||||
response.write("Z");
|
||||
response.close();
|
||||
}, onError: (e, trace) {
|
||||
String msg = "Unexpected error $e";
|
||||
if (trace != null) msg += "\nStackTrace: $trace";
|
||||
Expect.fail(msg);
|
||||
});
|
||||
|
||||
Socket.connect("127.0.0.1", server.port).then((socket) {
|
||||
void sendRequest() {
|
||||
socket.write("GET / HTTP/1.0\r\n");
|
||||
socket.write("Connection: Keep-Alive\r\n\r\n");
|
||||
}
|
||||
|
||||
List<int> response = [];
|
||||
int count = 0;
|
||||
socket.listen((d) {
|
||||
response.addAll(d);
|
||||
if (response[response.length - 1] == "Z".codeUnitAt(0)) {
|
||||
String s = new String.fromCharCodes(response).toLowerCase();
|
||||
Expect.isTrue(s.indexOf("\r\nconnection: keep-alive\r\n") > 0);
|
||||
Expect.isTrue(s.indexOf("\r\ncontent-length: 1\r\n") > 0);
|
||||
count++;
|
||||
if (count < 10) {
|
||||
response = [];
|
||||
sendRequest();
|
||||
} else {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
}, onDone: () {
|
||||
socket.destroy();
|
||||
server.close();
|
||||
});
|
||||
sendRequest();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Client makes a HTTP 1.0 request with connection keep alive. The
|
||||
// server does not set a content length so it cannot honor connection
|
||||
// keep alive.
|
||||
void testHttp10KeepAliveServerCloses() {
|
||||
HttpServer.bind("127.0.0.1", 0).then((server) {
|
||||
server.listen((HttpRequest request) {
|
||||
Expect.isNull(request.headers.value('content-length'));
|
||||
Expect.equals(-1, request.contentLength);
|
||||
var response = request.response;
|
||||
Expect.equals("1.0", request.protocolVersion);
|
||||
response.write("Z");
|
||||
response.close();
|
||||
}, onError: (e, trace) {
|
||||
String msg = "Unexpected error $e";
|
||||
if (trace != null) msg += "\nStackTrace: $trace";
|
||||
Expect.fail(msg);
|
||||
});
|
||||
|
||||
int count = 0;
|
||||
makeRequest() {
|
||||
Socket.connect("127.0.0.1", server.port).then((socket) {
|
||||
socket.write("GET / HTTP/1.0\r\n");
|
||||
socket.write("Connection: Keep-Alive\r\n\r\n");
|
||||
|
||||
List<int> response = [];
|
||||
socket.listen(response.addAll, onDone: () {
|
||||
socket.destroy();
|
||||
count++;
|
||||
String s = new String.fromCharCodes(response).toLowerCase();
|
||||
Expect.equals("z", s[s.length - 1]);
|
||||
Expect.equals(-1, s.indexOf("content-length"));
|
||||
Expect.equals(-1, s.indexOf("connection"));
|
||||
if (count < 10) {
|
||||
makeRequest();
|
||||
} else {
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
makeRequest();
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
testHttp10NoKeepAlive();
|
||||
testHttp10ServerClose();
|
||||
testHttp10KeepAlive();
|
||||
testHttp10KeepAliveServerCloses();
|
||||
}
|
423
tests/standalone/io/http_advanced_test.dart
Normal file
423
tests/standalone/io/http_advanced_test.dart
Normal file
|
@ -0,0 +1,423 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
// VMOptions=--enable-isolate-groups
|
||||
// VMOptions=--no-enable-isolate-groups
|
||||
//
|
||||
// VMOptions=
|
||||
// VMOptions=--short_socket_read
|
||||
// VMOptions=--short_socket_write
|
||||
// VMOptions=--short_socket_read --short_socket_write
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
class IsolatedHttpServer {
|
||||
IsolatedHttpServer() : _statusPort = new ReceivePort();
|
||||
|
||||
void setServerStartedHandler(void startedCallback(int port)) {
|
||||
_startedCallback = startedCallback;
|
||||
}
|
||||
|
||||
void start() {
|
||||
ReceivePort receivePort = new ReceivePort();
|
||||
var remote = Isolate.spawn(startIsolatedHttpServer, receivePort.sendPort);
|
||||
receivePort.first.then((port) {
|
||||
_serverPort = port;
|
||||
|
||||
// Send server start message to the server.
|
||||
var command = new IsolatedHttpServerCommand.start();
|
||||
port.send([command, _statusPort.sendPort]);
|
||||
});
|
||||
|
||||
// Handle status messages from the server.
|
||||
_statusPort.listen((var status) {
|
||||
if (status.isStarted) {
|
||||
_startedCallback(status.port);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
// Send server stop message to the server.
|
||||
_serverPort
|
||||
.send([new IsolatedHttpServerCommand.stop(), _statusPort.sendPort]);
|
||||
_statusPort.close();
|
||||
}
|
||||
|
||||
void chunkedEncoding() {
|
||||
// Send chunked encoding message to the server.
|
||||
_serverPort.send([
|
||||
new IsolatedHttpServerCommand.chunkedEncoding(),
|
||||
_statusPort.sendPort
|
||||
]);
|
||||
}
|
||||
|
||||
ReceivePort _statusPort; // Port for receiving messages from the server.
|
||||
late SendPort _serverPort; // Port for sending messages to the server.
|
||||
var _startedCallback;
|
||||
}
|
||||
|
||||
class IsolatedHttpServerCommand {
|
||||
static const START = 0;
|
||||
static const STOP = 1;
|
||||
static const CHUNKED_ENCODING = 2;
|
||||
|
||||
IsolatedHttpServerCommand.start() : _command = START;
|
||||
IsolatedHttpServerCommand.stop() : _command = STOP;
|
||||
IsolatedHttpServerCommand.chunkedEncoding() : _command = CHUNKED_ENCODING;
|
||||
|
||||
bool get isStart => _command == START;
|
||||
bool get isStop => _command == STOP;
|
||||
bool get isChunkedEncoding => _command == CHUNKED_ENCODING;
|
||||
|
||||
int _command;
|
||||
}
|
||||
|
||||
class IsolatedHttpServerStatus {
|
||||
static const STARTED = 0;
|
||||
static const STOPPED = 1;
|
||||
static const ERROR = 2;
|
||||
|
||||
IsolatedHttpServerStatus.started(this._port) : _state = STARTED;
|
||||
IsolatedHttpServerStatus.stopped() : _state = STOPPED;
|
||||
IsolatedHttpServerStatus.error() : _state = ERROR;
|
||||
|
||||
bool get isStarted => _state == STARTED;
|
||||
bool get isStopped => _state == STOPPED;
|
||||
bool get isError => _state == ERROR;
|
||||
|
||||
int get port => _port;
|
||||
|
||||
int _state;
|
||||
int _port = 0;
|
||||
}
|
||||
|
||||
void startIsolatedHttpServer(Object replyToObj) {
|
||||
final replyTo = replyToObj as SendPort;
|
||||
var server = new TestServer();
|
||||
server.init();
|
||||
replyTo.send(server.dispatchSendPort);
|
||||
}
|
||||
|
||||
class TestServer {
|
||||
// Return a 404.
|
||||
void _notFoundHandler(HttpRequest request) {
|
||||
var response = request.response;
|
||||
response.statusCode = HttpStatus.notFound;
|
||||
response.headers.set("Content-Type", "text/html; charset=UTF-8");
|
||||
response.write("Page not found");
|
||||
response.close();
|
||||
}
|
||||
|
||||
// Check the "Host" header.
|
||||
void _hostHandler(HttpRequest request) {
|
||||
var response = request.response;
|
||||
Expect.equals(1, request.headers["Host"]!.length);
|
||||
Expect.equals("www.dartlang.org:1234", request.headers["Host"]![0]);
|
||||
Expect.equals("www.dartlang.org", request.headers.host);
|
||||
Expect.equals(1234, request.headers.port);
|
||||
response.statusCode = HttpStatus.ok;
|
||||
response.close();
|
||||
}
|
||||
|
||||
// Set the "Expires" header using the expires property.
|
||||
void _expires1Handler(HttpRequest request) {
|
||||
var response = request.response;
|
||||
DateTime date = new DateTime.utc(1999, DateTime.june, 11, 18, 46, 53, 0);
|
||||
response.headers.expires = date;
|
||||
Expect.equals(date, response.headers.expires);
|
||||
response.close();
|
||||
}
|
||||
|
||||
// Set the "Expires" header.
|
||||
void _expires2Handler(HttpRequest request) {
|
||||
var response = request.response;
|
||||
response.headers.set("Expires", "Fri, 11 Jun 1999 18:46:53 GMT");
|
||||
DateTime date = new DateTime.utc(1999, DateTime.june, 11, 18, 46, 53, 0);
|
||||
Expect.equals(date, response.headers.expires);
|
||||
response.close();
|
||||
}
|
||||
|
||||
void _contentType1Handler(HttpRequest request) {
|
||||
var response = request.response;
|
||||
Expect.equals("text/html", request.headers.contentType!.value);
|
||||
Expect.equals("text", request.headers.contentType!.primaryType);
|
||||
Expect.equals("html", request.headers.contentType!.subType);
|
||||
Expect.equals("utf-8", request.headers.contentType!.parameters["charset"]);
|
||||
|
||||
ContentType contentType = new ContentType("text", "html", charset: "utf-8");
|
||||
response.headers.contentType = contentType;
|
||||
response.close();
|
||||
}
|
||||
|
||||
void _contentType2Handler(HttpRequest request) {
|
||||
var response = request.response;
|
||||
Expect.equals("text/html", request.headers.contentType!.value);
|
||||
Expect.equals("text", request.headers.contentType!.primaryType);
|
||||
Expect.equals("html", request.headers.contentType!.subType);
|
||||
Expect.equals("utf-8", request.headers.contentType!.parameters["charset"]);
|
||||
|
||||
response.headers
|
||||
.set(HttpHeaders.contentTypeHeader, "text/html; charset = utf-8");
|
||||
response.close();
|
||||
}
|
||||
|
||||
void _cookie1Handler(HttpRequest request) {
|
||||
var response = request.response;
|
||||
|
||||
// No cookies passed with this request.
|
||||
Expect.equals(0, request.cookies.length);
|
||||
|
||||
Cookie cookie1 = new Cookie("name1", "value1");
|
||||
DateTime date = new DateTime.utc(2014, DateTime.january, 5, 23, 59, 59, 0);
|
||||
cookie1.expires = date;
|
||||
cookie1.domain = "www.example.com";
|
||||
cookie1.httpOnly = true;
|
||||
response.cookies.add(cookie1);
|
||||
Cookie cookie2 = new Cookie("name2", "value2");
|
||||
cookie2.maxAge = 100;
|
||||
cookie2.domain = ".example.com";
|
||||
cookie2.path = "/shop";
|
||||
response.cookies.add(cookie2);
|
||||
response.close();
|
||||
}
|
||||
|
||||
void _cookie2Handler(HttpRequest request) {
|
||||
var response = request.response;
|
||||
|
||||
// Two cookies passed with this request.
|
||||
Expect.equals(2, request.cookies.length);
|
||||
response.close();
|
||||
}
|
||||
|
||||
void init() {
|
||||
// Setup request handlers.
|
||||
_requestHandlers["/host"] = _hostHandler;
|
||||
_requestHandlers["/expires1"] = _expires1Handler;
|
||||
_requestHandlers["/expires2"] = _expires2Handler;
|
||||
_requestHandlers["/contenttype1"] = _contentType1Handler;
|
||||
_requestHandlers["/contenttype2"] = _contentType2Handler;
|
||||
_requestHandlers["/cookie1"] = _cookie1Handler;
|
||||
_requestHandlers["/cookie2"] = _cookie2Handler;
|
||||
_dispatchPort.listen(dispatch);
|
||||
}
|
||||
|
||||
SendPort get dispatchSendPort => _dispatchPort.sendPort;
|
||||
|
||||
void dispatch(message) {
|
||||
IsolatedHttpServerCommand command = message[0];
|
||||
SendPort replyTo = message[1];
|
||||
if (command.isStart) {
|
||||
try {
|
||||
HttpServer.bind("127.0.0.1", 0).then((server) {
|
||||
_server = server;
|
||||
_server.listen(_requestReceivedHandler);
|
||||
replyTo.send(new IsolatedHttpServerStatus.started(_server.port));
|
||||
});
|
||||
} catch (e) {
|
||||
replyTo.send(new IsolatedHttpServerStatus.error());
|
||||
}
|
||||
} else if (command.isStop) {
|
||||
_server.close();
|
||||
_dispatchPort.close();
|
||||
replyTo.send(new IsolatedHttpServerStatus.stopped());
|
||||
} else if (command.isChunkedEncoding) {
|
||||
_chunkedEncoding = true;
|
||||
}
|
||||
}
|
||||
|
||||
void _requestReceivedHandler(HttpRequest request) {
|
||||
var requestHandler = _requestHandlers[request.uri.path];
|
||||
if (requestHandler != null) {
|
||||
requestHandler(request);
|
||||
} else {
|
||||
_notFoundHandler(request);
|
||||
}
|
||||
}
|
||||
|
||||
late HttpServer _server; // HTTP server instance.
|
||||
final _dispatchPort = new ReceivePort();
|
||||
final _requestHandlers = {};
|
||||
bool _chunkedEncoding = false;
|
||||
}
|
||||
|
||||
Future testHost() {
|
||||
Completer completer = new Completer();
|
||||
IsolatedHttpServer server = new IsolatedHttpServer();
|
||||
server.setServerStartedHandler((int port) {
|
||||
HttpClient httpClient = new HttpClient();
|
||||
httpClient.get("127.0.0.1", port, "/host").then((request) {
|
||||
Expect.equals("127.0.0.1:$port", request.headers["host"]![0]);
|
||||
request.headers.host = "www.dartlang.com";
|
||||
Expect.equals("www.dartlang.com:$port", request.headers["host"]![0]);
|
||||
Expect.equals("www.dartlang.com", request.headers.host);
|
||||
Expect.equals(port, request.headers.port);
|
||||
request.headers.port = 1234;
|
||||
Expect.equals("www.dartlang.com:1234", request.headers["host"]![0]);
|
||||
Expect.equals(1234, request.headers.port);
|
||||
request.headers.port = HttpClient.defaultHttpPort;
|
||||
Expect.equals(HttpClient.defaultHttpPort, request.headers.port);
|
||||
Expect.equals("www.dartlang.com", request.headers["host"]![0]);
|
||||
request.headers.set("Host", "www.dartlang.org");
|
||||
Expect.equals("www.dartlang.org", request.headers.host);
|
||||
Expect.equals(HttpClient.defaultHttpPort, request.headers.port);
|
||||
request.headers.set("Host", "www.dartlang.org:");
|
||||
Expect.equals("www.dartlang.org", request.headers.host);
|
||||
Expect.equals(HttpClient.defaultHttpPort, request.headers.port);
|
||||
request.headers.set("Host", "www.dartlang.org:1234");
|
||||
Expect.equals("www.dartlang.org", request.headers.host);
|
||||
Expect.equals(1234, request.headers.port);
|
||||
return request.close();
|
||||
}).then((response) {
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
response.listen((_) {}, onDone: () {
|
||||
httpClient.close();
|
||||
server.shutdown();
|
||||
completer.complete(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
server.start();
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future testExpires() {
|
||||
Completer completer = new Completer();
|
||||
IsolatedHttpServer server = new IsolatedHttpServer();
|
||||
server.setServerStartedHandler((int port) {
|
||||
int responses = 0;
|
||||
HttpClient httpClient = new HttpClient();
|
||||
|
||||
void processResponse(HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
Expect.equals(
|
||||
"Fri, 11 Jun 1999 18:46:53 GMT", response.headers["expires"]![0]);
|
||||
Expect.equals(new DateTime.utc(1999, DateTime.june, 11, 18, 46, 53, 0),
|
||||
response.headers.expires);
|
||||
response.listen((_) {}, onDone: () {
|
||||
responses++;
|
||||
if (responses == 2) {
|
||||
httpClient.close();
|
||||
server.shutdown();
|
||||
completer.complete(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
httpClient
|
||||
.get("127.0.0.1", port, "/expires1")
|
||||
.then((request) => request.close())
|
||||
.then(processResponse);
|
||||
httpClient
|
||||
.get("127.0.0.1", port, "/expires2")
|
||||
.then((request) => request.close())
|
||||
.then(processResponse);
|
||||
});
|
||||
server.start();
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future testContentType() {
|
||||
Completer completer = new Completer();
|
||||
IsolatedHttpServer server = new IsolatedHttpServer();
|
||||
server.setServerStartedHandler((int port) {
|
||||
int responses = 0;
|
||||
HttpClient httpClient = new HttpClient();
|
||||
|
||||
void processResponse(HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
Expect.equals(
|
||||
"text/html; charset=utf-8", response.headers.contentType.toString());
|
||||
Expect.equals("text/html", response.headers.contentType!.value);
|
||||
Expect.equals("text", response.headers.contentType!.primaryType);
|
||||
Expect.equals("html", response.headers.contentType!.subType);
|
||||
Expect.equals(
|
||||
"utf-8", response.headers.contentType!.parameters["charset"]);
|
||||
response.listen((_) {}, onDone: () {
|
||||
responses++;
|
||||
if (responses == 2) {
|
||||
httpClient.close();
|
||||
server.shutdown();
|
||||
completer.complete(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
httpClient.get("127.0.0.1", port, "/contenttype1").then((request) {
|
||||
request.headers.contentType =
|
||||
new ContentType("text", "html", charset: "utf-8");
|
||||
return request.close();
|
||||
}).then(processResponse);
|
||||
|
||||
httpClient.get("127.0.0.1", port, "/contenttype2").then((request) {
|
||||
request.headers
|
||||
.set(HttpHeaders.contentTypeHeader, "text/html; charset = utf-8");
|
||||
return request.close();
|
||||
}).then(processResponse);
|
||||
});
|
||||
server.start();
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future testCookies() {
|
||||
Completer completer = new Completer();
|
||||
IsolatedHttpServer server = new IsolatedHttpServer();
|
||||
server.setServerStartedHandler((int port) {
|
||||
int responses = 0;
|
||||
HttpClient httpClient = new HttpClient();
|
||||
|
||||
httpClient
|
||||
.get("127.0.0.1", port, "/cookie1")
|
||||
.then((request) => request.close())
|
||||
.then((response) {
|
||||
Expect.equals(2, response.cookies.length);
|
||||
response.cookies.forEach((cookie) {
|
||||
if (cookie.name == "name1") {
|
||||
Expect.equals("value1", cookie.value);
|
||||
DateTime date =
|
||||
new DateTime.utc(2014, DateTime.january, 5, 23, 59, 59, 0);
|
||||
Expect.equals(date, cookie.expires);
|
||||
Expect.equals("www.example.com", cookie.domain);
|
||||
Expect.isTrue(cookie.httpOnly);
|
||||
} else if (cookie.name == "name2") {
|
||||
Expect.equals("value2", cookie.value);
|
||||
Expect.equals(100, cookie.maxAge);
|
||||
Expect.equals(".example.com", cookie.domain);
|
||||
Expect.equals("/shop", cookie.path);
|
||||
} else {
|
||||
Expect.fail("Unexpected cookie");
|
||||
}
|
||||
});
|
||||
|
||||
response.listen((_) {}, onDone: () {
|
||||
httpClient.get("127.0.0.1", port, "/cookie2").then((request) {
|
||||
request.cookies.add(response.cookies[0]);
|
||||
request.cookies.add(response.cookies[1]);
|
||||
return request.close();
|
||||
}).then((response) {
|
||||
response.listen((_) {}, onDone: () {
|
||||
httpClient.close();
|
||||
server.shutdown();
|
||||
completer.complete(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
server.start();
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
void main() {
|
||||
testHost().then((_) {
|
||||
return testExpires().then((_) {
|
||||
return testContentType().then((_) {
|
||||
return testCookies();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
381
tests/standalone/io/http_auth_digest_test.dart
Normal file
381
tests/standalone/io/http_auth_digest_test.dart
Normal file
|
@ -0,0 +1,381 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import "package:convert/convert.dart";
|
||||
import "package:crypto/crypto.dart";
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
class Server {
|
||||
late HttpServer server;
|
||||
int unauthCount = 0; // Counter of the 401 responses.
|
||||
int successCount = 0; // Counter of the successful responses.
|
||||
int nonceCount = 0; // Counter of use of current nonce.
|
||||
var ha1;
|
||||
|
||||
static Future<Server> start(String? algorithm, String? qop,
|
||||
{int? nonceStaleAfter, bool useNextNonce: false}) {
|
||||
return new Server()._start(algorithm, qop, nonceStaleAfter, useNextNonce);
|
||||
}
|
||||
|
||||
Future<Server> _start(String? serverAlgorithm, String? serverQop,
|
||||
int? nonceStaleAfter, bool useNextNonce) {
|
||||
Set ncs = new Set();
|
||||
// Calculate ha1.
|
||||
String realm = "test";
|
||||
String username = "dart";
|
||||
String password = "password";
|
||||
var hasher = md5.convert("${username}:${realm}:${password}".codeUnits);
|
||||
ha1 = hex.encode(hasher.bytes);
|
||||
|
||||
var nonce = "12345678"; // No need for random nonce in test.
|
||||
|
||||
var completer = new Completer<Server>();
|
||||
HttpServer.bind("127.0.0.1", 0).then((s) {
|
||||
server = s;
|
||||
server.listen((HttpRequest request) {
|
||||
sendUnauthorizedResponse(HttpResponse response, {stale: false}) {
|
||||
response.statusCode = HttpStatus.unauthorized;
|
||||
StringBuffer authHeader = new StringBuffer();
|
||||
authHeader.write('Digest');
|
||||
authHeader.write(', realm="$realm"');
|
||||
authHeader.write(', nonce="$nonce"');
|
||||
if (stale) authHeader.write(', stale="true"');
|
||||
if (serverAlgorithm != null) {
|
||||
authHeader.write(', algorithm=$serverAlgorithm');
|
||||
}
|
||||
authHeader.write(', domain="/digest/"');
|
||||
if (serverQop != null) authHeader.write(', qop="$serverQop"');
|
||||
response.headers.set(HttpHeaders.wwwAuthenticateHeader, authHeader);
|
||||
unauthCount++;
|
||||
}
|
||||
|
||||
var response = request.response;
|
||||
if (request.headers[HttpHeaders.authorizationHeader] != null) {
|
||||
Expect.equals(
|
||||
1, request.headers[HttpHeaders.authorizationHeader]!.length);
|
||||
String authorization =
|
||||
request.headers[HttpHeaders.authorizationHeader]![0];
|
||||
HeaderValue header =
|
||||
HeaderValue.parse(authorization, parameterSeparator: ",");
|
||||
if (header.value.toLowerCase() == "basic") {
|
||||
sendUnauthorizedResponse(response);
|
||||
} else if (!useNextNonce && nonceCount == nonceStaleAfter) {
|
||||
nonce = "87654321";
|
||||
nonceCount = 0;
|
||||
sendUnauthorizedResponse(response, stale: true);
|
||||
} else {
|
||||
var uri = header.parameters["uri"];
|
||||
var qop = header.parameters["qop"];
|
||||
var cnonce = header.parameters["cnonce"];
|
||||
var nc = header.parameters["nc"];
|
||||
Expect.equals("digest", header.value.toLowerCase());
|
||||
Expect.equals("dart", header.parameters["username"]);
|
||||
Expect.equals(realm, header.parameters["realm"]);
|
||||
Expect.equals("MD5", header.parameters["algorithm"]);
|
||||
Expect.equals(nonce, header.parameters["nonce"]);
|
||||
Expect.equals(request.uri.toString(), uri);
|
||||
if (qop != null) {
|
||||
// A server qop of auth-int is downgraded to none by the client.
|
||||
Expect.equals("auth", serverQop);
|
||||
Expect.equals("auth", header.parameters["qop"]);
|
||||
Expect.isNotNull(cnonce);
|
||||
Expect.isNotNull(nc);
|
||||
Expect.isFalse(ncs.contains(nc));
|
||||
ncs.add(nc);
|
||||
} else {
|
||||
Expect.isNull(cnonce);
|
||||
Expect.isNull(nc);
|
||||
}
|
||||
Expect.isNotNull(header.parameters["response"]);
|
||||
|
||||
var hasher = md5.convert("${request.method}:${uri}".codeUnits);
|
||||
var ha2 = hex.encode(hasher.bytes);
|
||||
|
||||
var x;
|
||||
Digest digest;
|
||||
if (qop == null || qop == "" || qop == "none") {
|
||||
digest = md5.convert("$ha1:${nonce}:$ha2".codeUnits);
|
||||
} else {
|
||||
digest = md5.convert(
|
||||
"$ha1:${nonce}:${nc}:${cnonce}:${qop}:$ha2".codeUnits);
|
||||
}
|
||||
Expect.equals(
|
||||
hex.encode(digest.bytes), header.parameters["response"]);
|
||||
|
||||
successCount++;
|
||||
nonceCount++;
|
||||
|
||||
// Add a bogus Authentication-Info for testing.
|
||||
var info = 'rspauth="77180d1ab3d6c9de084766977790f482", '
|
||||
'cnonce="8f971178", '
|
||||
'nc=000002c74, '
|
||||
'qop=auth';
|
||||
if (useNextNonce && nonceCount == nonceStaleAfter) {
|
||||
nonce = "abcdef01";
|
||||
info += ', nextnonce="$nonce"';
|
||||
}
|
||||
response.headers.set("Authentication-Info", info);
|
||||
}
|
||||
} else {
|
||||
sendUnauthorizedResponse(response);
|
||||
}
|
||||
response.close();
|
||||
});
|
||||
completer.complete(this);
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
server.close();
|
||||
}
|
||||
|
||||
int get port => server.port;
|
||||
}
|
||||
|
||||
void testNoCredentials(String? algorithm, String? qop) {
|
||||
Server.start(algorithm, qop).then((server) {
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
// Add digest credentials which does not match the path requested.
|
||||
client.addCredentials(Uri.parse("http://127.0.0.1:${server.port}/xxx"),
|
||||
"test", new HttpClientDigestCredentials("dart", "password"));
|
||||
|
||||
// Add basic credentials for the path requested.
|
||||
client.addCredentials(Uri.parse("http://127.0.0.1:${server.port}/digest"),
|
||||
"test", new HttpClientBasicCredentials("dart", "password"));
|
||||
|
||||
Future makeRequest(Uri url) {
|
||||
return client
|
||||
.getUrl(url)
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.unauthorized, response.statusCode);
|
||||
return response.fold(null, (x, y) {});
|
||||
});
|
||||
}
|
||||
|
||||
var futures = <Future>[];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
futures.add(
|
||||
makeRequest(Uri.parse("http://127.0.0.1:${server.port}/digest")));
|
||||
}
|
||||
Future.wait(futures).then((_) {
|
||||
server.shutdown();
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testCredentials(String? algorithm, String? qop) {
|
||||
Server.start(algorithm, qop).then((server) {
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
Future makeRequest(Uri url) {
|
||||
return client
|
||||
.getUrl(url)
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
Expect.equals(1, response.headers["Authentication-Info"]?.length);
|
||||
return response.fold(null, (x, y) {});
|
||||
});
|
||||
}
|
||||
|
||||
client.addCredentials(Uri.parse("http://127.0.0.1:${server.port}/digest"),
|
||||
"test", new HttpClientDigestCredentials("dart", "password"));
|
||||
|
||||
var futures = <Future>[];
|
||||
for (int i = 0; i < 2; i++) {
|
||||
String uriBase = "http://127.0.0.1:${server.port}/digest";
|
||||
futures.add(makeRequest(Uri.parse(uriBase)));
|
||||
futures.add(makeRequest(Uri.parse("$uriBase?querystring")));
|
||||
futures.add(makeRequest(Uri.parse("$uriBase?querystring#fragment")));
|
||||
}
|
||||
Future.wait(futures).then((_) {
|
||||
server.shutdown();
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testAuthenticateCallback(String? algorithm, String? qop) {
|
||||
Server.start(algorithm, qop).then((server) {
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
client.authenticate = (Uri url, String scheme, String realm) {
|
||||
Expect.equals("Digest", scheme);
|
||||
Expect.equals("test", realm);
|
||||
final completer = new Completer<bool>();
|
||||
new Timer(const Duration(milliseconds: 10), () {
|
||||
client.addCredentials(
|
||||
Uri.parse("http://127.0.0.1:${server.port}/digest"),
|
||||
"test",
|
||||
new HttpClientDigestCredentials("dart", "password"));
|
||||
completer.complete(true);
|
||||
});
|
||||
return completer.future;
|
||||
};
|
||||
|
||||
Future makeRequest(Uri url) {
|
||||
return client
|
||||
.getUrl(url)
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
Expect.equals(1, response.headers["Authentication-Info"]?.length);
|
||||
return response.fold(null, (x, y) {});
|
||||
});
|
||||
}
|
||||
|
||||
var futures = <Future>[];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
futures.add(
|
||||
makeRequest(Uri.parse("http://127.0.0.1:${server.port}/digest")));
|
||||
}
|
||||
Future.wait(futures).then((_) {
|
||||
server.shutdown();
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testStaleNonce() {
|
||||
Server.start("MD5", "auth", nonceStaleAfter: 2).then((server) {
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
Future makeRequest(Uri url) {
|
||||
return client
|
||||
.getUrl(url)
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
Expect.equals(1, response.headers["Authentication-Info"]?.length);
|
||||
return response.fold(null, (x, y) {});
|
||||
});
|
||||
}
|
||||
|
||||
Uri uri = Uri.parse("http://127.0.0.1:${server.port}/digest");
|
||||
var credentials = new HttpClientDigestCredentials("dart", "password");
|
||||
client.addCredentials(uri, "test", credentials);
|
||||
|
||||
makeRequest(uri)
|
||||
.then((_) => makeRequest(uri))
|
||||
.then((_) => makeRequest(uri))
|
||||
.then((_) => makeRequest(uri))
|
||||
.then((_) {
|
||||
Expect.equals(2, server.unauthCount);
|
||||
Expect.equals(4, server.successCount);
|
||||
server.shutdown();
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testNextNonce() {
|
||||
Server.start("MD5", "auth", nonceStaleAfter: 2, useNextNonce: true)
|
||||
.then((server) {
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
Future makeRequest(Uri url) {
|
||||
return client
|
||||
.getUrl(url)
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
Expect.equals(1, response.headers["Authentication-Info"]?.length);
|
||||
return response.fold(null, (x, y) {});
|
||||
});
|
||||
}
|
||||
|
||||
Uri uri = Uri.parse("http://127.0.0.1:${server.port}/digest");
|
||||
var credentials = new HttpClientDigestCredentials("dart", "password");
|
||||
client.addCredentials(uri, "test", credentials);
|
||||
|
||||
makeRequest(uri)
|
||||
.then((_) => makeRequest(uri))
|
||||
.then((_) => makeRequest(uri))
|
||||
.then((_) => makeRequest(uri))
|
||||
.then((_) {
|
||||
Expect.equals(1, server.unauthCount);
|
||||
Expect.equals(4, server.successCount);
|
||||
server.shutdown();
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// An Apache virtual directory configuration like this can be used for
|
||||
// running the local server tests.
|
||||
//
|
||||
// <Directory "/usr/local/prj/website/digest/">
|
||||
// AllowOverride None
|
||||
// Order deny,allow
|
||||
// Deny from all
|
||||
// Allow from 127.0.0.0/255.0.0.0 ::1/128
|
||||
// AuthType Digest
|
||||
// AuthName "test"
|
||||
// AuthDigestDomain /digest/
|
||||
// AuthDigestAlgorithm MD5
|
||||
// AuthDigestQop auth
|
||||
// AuthDigestNonceLifetime 10
|
||||
// AuthDigestProvider file
|
||||
// AuthUserFile /usr/local/prj/apache/passwd/digest-passwd
|
||||
// Require valid-user
|
||||
// </Directory>
|
||||
//
|
||||
|
||||
void testLocalServerDigest() {
|
||||
int count = 0;
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
Future makeRequest() {
|
||||
return client
|
||||
.getUrl(Uri.parse("http://127.0.0.1/digest/test"))
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
count++;
|
||||
if (count % 100 == 0) print(count);
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
return response.fold(null, (x, y) {});
|
||||
});
|
||||
}
|
||||
|
||||
client.addCredentials(Uri.parse("http://127.0.0.1/digest"), "test",
|
||||
new HttpClientDigestCredentials("dart", "password"));
|
||||
|
||||
client.authenticate = (Uri url, String scheme, String realm) {
|
||||
client.addCredentials(Uri.parse("http://127.0.0.1/digest"), "test",
|
||||
new HttpClientDigestCredentials("dart", "password"));
|
||||
return new Future.value(true);
|
||||
};
|
||||
|
||||
next() {
|
||||
makeRequest().then((_) => next());
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
main() {
|
||||
testNoCredentials(null, null);
|
||||
testNoCredentials("MD5", null);
|
||||
testNoCredentials("MD5", "auth");
|
||||
testCredentials(null, null);
|
||||
testCredentials("MD5", null);
|
||||
testCredentials("MD5", "auth");
|
||||
testCredentials("MD5", "auth-int");
|
||||
testAuthenticateCallback(null, null);
|
||||
testAuthenticateCallback("MD5", null);
|
||||
testAuthenticateCallback("MD5", "auth");
|
||||
testAuthenticateCallback("MD5", "auth-int");
|
||||
testStaleNonce();
|
||||
testNextNonce();
|
||||
// These teste are not normally run. They can be used for locally
|
||||
// testing with another web server (e.g. Apache).
|
||||
//testLocalServerDigest();
|
||||
}
|
258
tests/standalone/io/http_auth_test.dart
Normal file
258
tests/standalone/io/http_auth_test.dart
Normal file
|
@ -0,0 +1,258 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
import "package:crypto/crypto.dart";
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
import 'dart:convert';
|
||||
|
||||
class Server {
|
||||
late HttpServer server;
|
||||
bool passwordChanged = false;
|
||||
|
||||
Future<Server> start() {
|
||||
var completer = new Completer<Server>();
|
||||
HttpServer.bind("127.0.0.1", 0).then((s) {
|
||||
server = s;
|
||||
server.listen((HttpRequest request) {
|
||||
var response = request.response;
|
||||
if (request.uri.path == "/passwdchg") {
|
||||
passwordChanged = true;
|
||||
response.close();
|
||||
return;
|
||||
}
|
||||
;
|
||||
|
||||
String username;
|
||||
String password;
|
||||
if (request.uri.path == "/") {
|
||||
username = "username";
|
||||
password = "password";
|
||||
} else {
|
||||
username = request.uri.path.substring(1, 6);
|
||||
password = request.uri.path.substring(1, 6);
|
||||
}
|
||||
if (passwordChanged) password = "${password}1";
|
||||
if (request.headers[HttpHeaders.authorizationHeader] != null) {
|
||||
Expect.equals(
|
||||
1, request.headers[HttpHeaders.authorizationHeader]!.length);
|
||||
String authorization =
|
||||
request.headers[HttpHeaders.authorizationHeader]![0];
|
||||
List<String> tokens = authorization.split(" ");
|
||||
Expect.equals("Basic", tokens[0]);
|
||||
String auth = base64.encode(utf8.encode("$username:$password"));
|
||||
if (passwordChanged && auth != tokens[1]) {
|
||||
response.statusCode = HttpStatus.unauthorized;
|
||||
response.headers
|
||||
.set(HttpHeaders.wwwAuthenticateHeader, "Basic, realm=realm");
|
||||
} else {
|
||||
Expect.equals(auth, tokens[1]);
|
||||
}
|
||||
} else {
|
||||
response.statusCode = HttpStatus.unauthorized;
|
||||
response.headers
|
||||
.set(HttpHeaders.wwwAuthenticateHeader, "Basic, realm=realm");
|
||||
}
|
||||
response.close();
|
||||
});
|
||||
completer.complete(this);
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
server.close();
|
||||
}
|
||||
|
||||
int get port => server.port;
|
||||
}
|
||||
|
||||
Future<Server> setupServer() {
|
||||
return new Server().start();
|
||||
}
|
||||
|
||||
void testUrlUserInfo() {
|
||||
setupServer().then((server) {
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
client
|
||||
.getUrl(Uri.parse("http://username:password@127.0.0.1:${server.port}/"))
|
||||
.then((request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
response.listen((_) {}, onDone: () {
|
||||
server.shutdown();
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testBasicNoCredentials() {
|
||||
setupServer().then((server) {
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
Future makeRequest(Uri url) {
|
||||
return client
|
||||
.getUrl(url)
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.unauthorized, response.statusCode);
|
||||
return response.fold(null, (x, y) {});
|
||||
});
|
||||
}
|
||||
|
||||
var futures = <Future>[];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
futures.add(
|
||||
makeRequest(Uri.parse("http://127.0.0.1:${server.port}/test$i")));
|
||||
futures.add(
|
||||
makeRequest(Uri.parse("http://127.0.0.1:${server.port}/test$i/xxx")));
|
||||
}
|
||||
Future.wait(futures).then((_) {
|
||||
server.shutdown();
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testBasicCredentials() {
|
||||
setupServer().then((server) {
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
Future makeRequest(Uri url) {
|
||||
return client
|
||||
.getUrl(url)
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
return response.fold(null, (x, y) {});
|
||||
});
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
client.addCredentials(Uri.parse("http://127.0.0.1:${server.port}/test$i"),
|
||||
"realm", new HttpClientBasicCredentials("test$i", "test$i"));
|
||||
}
|
||||
|
||||
var futures = <Future>[];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
futures.add(
|
||||
makeRequest(Uri.parse("http://127.0.0.1:${server.port}/test$i")));
|
||||
futures.add(
|
||||
makeRequest(Uri.parse("http://127.0.0.1:${server.port}/test$i/xxx")));
|
||||
}
|
||||
Future.wait(futures).then((_) {
|
||||
server.shutdown();
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testBasicAuthenticateCallback() {
|
||||
setupServer().then((server) {
|
||||
HttpClient client = new HttpClient();
|
||||
bool passwordChanged = false;
|
||||
|
||||
client.authenticate = (Uri url, String scheme, String realm) {
|
||||
Expect.equals("Basic", scheme);
|
||||
Expect.equals("realm", realm);
|
||||
String username = url.path.substring(1, 6);
|
||||
String password = url.path.substring(1, 6);
|
||||
if (passwordChanged) password = "${password}1";
|
||||
final completer = new Completer<bool>();
|
||||
new Timer(const Duration(milliseconds: 10), () {
|
||||
client.addCredentials(
|
||||
url, realm, new HttpClientBasicCredentials(username, password));
|
||||
completer.complete(true);
|
||||
});
|
||||
return completer.future;
|
||||
};
|
||||
|
||||
Future makeRequest(Uri url) {
|
||||
return client
|
||||
.getUrl(url)
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
return response.fold(null, (x, y) {});
|
||||
});
|
||||
}
|
||||
|
||||
List<Future> makeRequests() {
|
||||
var futures = <Future>[];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
futures.add(
|
||||
makeRequest(Uri.parse("http://127.0.0.1:${server.port}/test$i")));
|
||||
futures.add(makeRequest(
|
||||
Uri.parse("http://127.0.0.1:${server.port}/test$i/xxx")));
|
||||
}
|
||||
return futures;
|
||||
}
|
||||
|
||||
Future.wait(makeRequests()).then((_) {
|
||||
makeRequest(Uri.parse("http://127.0.0.1:${server.port}/passwdchg"))
|
||||
.then((_) {
|
||||
passwordChanged = true;
|
||||
Future.wait(makeRequests()).then((_) {
|
||||
server.shutdown();
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testLocalServerBasic() {
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
client.authenticate = (Uri url, String scheme, String realm) {
|
||||
client.addCredentials(Uri.parse("http://127.0.0.1/basic"), "test",
|
||||
new HttpClientBasicCredentials("test", "test"));
|
||||
return new Future.value(true);
|
||||
};
|
||||
|
||||
client
|
||||
.getUrl(Uri.parse("http://127.0.0.1/basic/test"))
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
response.drain().then((_) {
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void testLocalServerDigest() {
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
client.authenticate = (Uri url, String scheme, String realm) {
|
||||
print("url: $url, scheme: $scheme, realm: $realm");
|
||||
client.addCredentials(Uri.parse("http://127.0.0.1/digest"), "test",
|
||||
new HttpClientDigestCredentials("test", "test"));
|
||||
return new Future.value(true);
|
||||
};
|
||||
|
||||
client
|
||||
.getUrl(Uri.parse("http://127.0.0.1/digest/test"))
|
||||
.then((HttpClientRequest request) => request.close())
|
||||
.then((HttpClientResponse response) {
|
||||
Expect.equals(HttpStatus.ok, response.statusCode);
|
||||
response.drain().then((_) {
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main() {
|
||||
testUrlUserInfo();
|
||||
testBasicNoCredentials();
|
||||
testBasicCredentials();
|
||||
testBasicAuthenticateCallback();
|
||||
// These teste are not normally run. They can be used for locally
|
||||
// testing with another web server (e.g. Apache).
|
||||
//testLocalServerBasic();
|
||||
//testLocalServerDigest();
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue