1 /* atomic-file-output-stream and safe-file-output-stream should throw and
2 * exception if PR_APPEND is explicity specified without PR_TRUNCATE. */
5 const PR_WRONLY = 0x02;
6 const PR_CREATE_FILE = 0x08;
7 const PR_APPEND = 0x10;
8 const PR_TRUNCATE = 0x20;
10 function check_flag(file, contractID, flags, throws) {
11 let stream = Cc[contractID].createInstance(Ci.nsIFileOutputStream);
14 /* NS_ERROR_INVALID_ARG is reported as NS_ERROR_ILLEGAL_VALUE, since they
17 () => stream.init(file, flags, 0o644, 0),
18 /NS_ERROR_ILLEGAL_VALUE/
21 stream.init(file, flags, 0o644, 0);
27 let filename = "test.txt";
28 let file = Services.dirsvc.get("TmpD", Ci.nsIFile);
29 file.append(filename);
32 [PR_WRONLY | PR_CREATE_FILE | PR_APPEND | PR_TRUNCATE, false],
33 [PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, false],
34 [PR_WRONLY | PR_CREATE_FILE | PR_APPEND, true],
37 for (let contractID of [
38 "@mozilla.org/network/atomic-file-output-stream;1",
39 "@mozilla.org/network/safe-file-output-stream;1",
41 for (let [flags, throws] of tests) {
42 check_flag(file, contractID, flags, throws);