|
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 sts=2 et: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 const Cc = Components.classes; |
|
8 const Ci = Components.interfaces; |
|
9 const Cr = Components.results; |
|
10 const CC = Components.Constructor; |
|
11 |
|
12 var Pipe = CC("@mozilla.org/pipe;1", "nsIPipe", "init"); |
|
13 |
|
14 function run_test() |
|
15 { |
|
16 test_not_initialized(); |
|
17 test_ends_are_threadsafe(); |
|
18 } |
|
19 |
|
20 function test_not_initialized() |
|
21 { |
|
22 var p = Cc["@mozilla.org/pipe;1"] |
|
23 .createInstance(Ci.nsIPipe); |
|
24 try |
|
25 { |
|
26 var dummy = p.outputStream; |
|
27 throw Cr.NS_ERROR_FAILURE; |
|
28 } |
|
29 catch (e) |
|
30 { |
|
31 if (e.result != Cr.NS_ERROR_NOT_INITIALIZED) |
|
32 do_throw("using a pipe before initializing it should throw NS_ERROR_NOT_INITIALIZED"); |
|
33 } |
|
34 } |
|
35 |
|
36 function test_ends_are_threadsafe() |
|
37 { |
|
38 var p, is, os; |
|
39 |
|
40 p = new Pipe(true, true, 1024, 1, null); |
|
41 is = p.inputStream.QueryInterface(Ci.nsIClassInfo); |
|
42 os = p.outputStream.QueryInterface(Ci.nsIClassInfo); |
|
43 do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); |
|
44 do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); |
|
45 |
|
46 p = new Pipe(true, false, 1024, 1, null); |
|
47 is = p.inputStream.QueryInterface(Ci.nsIClassInfo); |
|
48 os = p.outputStream.QueryInterface(Ci.nsIClassInfo); |
|
49 do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); |
|
50 do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); |
|
51 |
|
52 p = new Pipe(false, true, 1024, 1, null); |
|
53 is = p.inputStream.QueryInterface(Ci.nsIClassInfo); |
|
54 os = p.outputStream.QueryInterface(Ci.nsIClassInfo); |
|
55 do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); |
|
56 do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); |
|
57 |
|
58 p = new Pipe(false, false, 1024, 1, null); |
|
59 is = p.inputStream.QueryInterface(Ci.nsIClassInfo); |
|
60 os = p.outputStream.QueryInterface(Ci.nsIClassInfo); |
|
61 do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); |
|
62 do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); |
|
63 } |