xpcom/tests/unit/test_pipe.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     7 const Cc = Components.classes;
     8 const Ci = Components.interfaces;
     9 const Cr = Components.results;
    10 const CC = Components.Constructor;
    12 var Pipe = CC("@mozilla.org/pipe;1", "nsIPipe", "init");
    14 function run_test()
    15 {
    16   test_not_initialized();
    17   test_ends_are_threadsafe();
    18 }
    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 }
    36 function test_ends_are_threadsafe()
    37 {
    38   var p, is, os;
    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));
    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));
    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));
    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 }

mercurial