Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 function write_atomic(file, str) {
7 var stream = Cc["@mozilla.org/network/atomic-file-output-stream;1"]
8 .createInstance(Ci.nsIFileOutputStream);
9 stream.init(file, -1, -1, 0);
10 do {
11 var written = stream.write(str, str.length);
12 if (written == str.length)
13 break;
14 str = str.substring(written);
15 } while (1);
16 stream.QueryInterface(Ci.nsISafeOutputStream).finish();
17 stream.close();
18 }
20 function write(file, str) {
21 var stream = Cc["@mozilla.org/network/safe-file-output-stream;1"]
22 .createInstance(Ci.nsIFileOutputStream);
23 stream.init(file, -1, -1, 0);
24 do {
25 var written = stream.write(str, str.length);
26 if (written == str.length)
27 break;
28 str = str.substring(written);
29 } while (1);
30 stream.QueryInterface(Ci.nsISafeOutputStream).finish();
31 stream.close();
32 }
34 function checkFile(file, str) {
35 var stream = Cc["@mozilla.org/network/file-input-stream;1"]
36 .createInstance(Ci.nsIFileInputStream);
37 stream.init(file, -1, -1, 0);
39 var scriptStream = Cc["@mozilla.org/scriptableinputstream;1"]
40 .createInstance(Ci.nsIScriptableInputStream);
41 scriptStream.init(stream);
43 do_check_eq(scriptStream.read(scriptStream.available()), str);
44 scriptStream.close();
45 }
47 function run_test()
48 {
49 var filename = "\u0913";
50 var file = Cc["@mozilla.org/file/directory_service;1"]
51 .getService(Ci.nsIProperties)
52 .get("TmpD", Ci.nsIFile);
53 file.append(filename);
55 write(file, "First write");
56 checkFile(file, "First write");
58 write(file, "Second write");
59 checkFile(file, "Second write");
61 write_atomic(file, "First write: Atomic");
62 checkFile(file, "First write: Atomic");
64 write_atomic(file, "Second write: Atomic");
65 checkFile(file, "Second write: Atomic");
66 }