michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cr = Components.results; michael@0: const CC = Components.Constructor; michael@0: michael@0: var Pipe = CC("@mozilla.org/pipe;1", "nsIPipe", "init"); michael@0: michael@0: function run_test() michael@0: { michael@0: test_not_initialized(); michael@0: test_ends_are_threadsafe(); michael@0: } michael@0: michael@0: function test_not_initialized() michael@0: { michael@0: var p = Cc["@mozilla.org/pipe;1"] michael@0: .createInstance(Ci.nsIPipe); michael@0: try michael@0: { michael@0: var dummy = p.outputStream; michael@0: throw Cr.NS_ERROR_FAILURE; michael@0: } michael@0: catch (e) michael@0: { michael@0: if (e.result != Cr.NS_ERROR_NOT_INITIALIZED) michael@0: do_throw("using a pipe before initializing it should throw NS_ERROR_NOT_INITIALIZED"); michael@0: } michael@0: } michael@0: michael@0: function test_ends_are_threadsafe() michael@0: { michael@0: var p, is, os; michael@0: michael@0: p = new Pipe(true, true, 1024, 1, null); michael@0: is = p.inputStream.QueryInterface(Ci.nsIClassInfo); michael@0: os = p.outputStream.QueryInterface(Ci.nsIClassInfo); michael@0: do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); michael@0: do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); michael@0: michael@0: p = new Pipe(true, false, 1024, 1, null); michael@0: is = p.inputStream.QueryInterface(Ci.nsIClassInfo); michael@0: os = p.outputStream.QueryInterface(Ci.nsIClassInfo); michael@0: do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); michael@0: do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); michael@0: michael@0: p = new Pipe(false, true, 1024, 1, null); michael@0: is = p.inputStream.QueryInterface(Ci.nsIClassInfo); michael@0: os = p.outputStream.QueryInterface(Ci.nsIClassInfo); michael@0: do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); michael@0: do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); michael@0: michael@0: p = new Pipe(false, false, 1024, 1, null); michael@0: is = p.inputStream.QueryInterface(Ci.nsIClassInfo); michael@0: os = p.outputStream.QueryInterface(Ci.nsIClassInfo); michael@0: do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); michael@0: do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); michael@0: }