1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/tests/unit/test_pipe.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +const Cc = Components.classes; 1.11 +const Ci = Components.interfaces; 1.12 +const Cr = Components.results; 1.13 +const CC = Components.Constructor; 1.14 + 1.15 +var Pipe = CC("@mozilla.org/pipe;1", "nsIPipe", "init"); 1.16 + 1.17 +function run_test() 1.18 +{ 1.19 + test_not_initialized(); 1.20 + test_ends_are_threadsafe(); 1.21 +} 1.22 + 1.23 +function test_not_initialized() 1.24 +{ 1.25 + var p = Cc["@mozilla.org/pipe;1"] 1.26 + .createInstance(Ci.nsIPipe); 1.27 + try 1.28 + { 1.29 + var dummy = p.outputStream; 1.30 + throw Cr.NS_ERROR_FAILURE; 1.31 + } 1.32 + catch (e) 1.33 + { 1.34 + if (e.result != Cr.NS_ERROR_NOT_INITIALIZED) 1.35 + do_throw("using a pipe before initializing it should throw NS_ERROR_NOT_INITIALIZED"); 1.36 + } 1.37 +} 1.38 + 1.39 +function test_ends_are_threadsafe() 1.40 +{ 1.41 + var p, is, os; 1.42 + 1.43 + p = new Pipe(true, true, 1024, 1, null); 1.44 + is = p.inputStream.QueryInterface(Ci.nsIClassInfo); 1.45 + os = p.outputStream.QueryInterface(Ci.nsIClassInfo); 1.46 + do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); 1.47 + do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); 1.48 + 1.49 + p = new Pipe(true, false, 1024, 1, null); 1.50 + is = p.inputStream.QueryInterface(Ci.nsIClassInfo); 1.51 + os = p.outputStream.QueryInterface(Ci.nsIClassInfo); 1.52 + do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); 1.53 + do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); 1.54 + 1.55 + p = new Pipe(false, true, 1024, 1, null); 1.56 + is = p.inputStream.QueryInterface(Ci.nsIClassInfo); 1.57 + os = p.outputStream.QueryInterface(Ci.nsIClassInfo); 1.58 + do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); 1.59 + do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); 1.60 + 1.61 + p = new Pipe(false, false, 1024, 1, null); 1.62 + is = p.inputStream.QueryInterface(Ci.nsIClassInfo); 1.63 + os = p.outputStream.QueryInterface(Ci.nsIClassInfo); 1.64 + do_check_true(Boolean(is.flags & Ci.nsIClassInfo.THREADSAFE)); 1.65 + do_check_true(Boolean(os.flags & Ci.nsIClassInfo.THREADSAFE)); 1.66 +}