3
* Test and demo application for:
4
* nsIPipeConsole, nsIIPCBuffer, nsIPipeFilterListener
6
* The contents of this file are subject to the Mozilla Public
7
* License Version 1.1 (the "MPL"); you may not use this file
8
* except in compliance with the MPL. You may obtain a copy of
9
* the MPL at http://www.mozilla.org/MPL/
11
* Software distributed under the MPL is distributed on an "AS
12
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
13
* implied. See the MPL for the specific language governing
14
* rights and limitations under the MPL.
16
* The Original Code is protoZilla.
18
* The Initial Developer of the Original Code is Ramalingam Saravanan.
19
* Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
20
* Copyright (C) 2001 Ramalingam Saravanan. All Rights Reserved.
23
* Patrick Brunschwig <patrick@mozilla-enigmail.org>
25
* Alternatively, the contents of this file may be used under the
26
* terms of the GNU General Public License (the "GPL"), in which case
27
* the provisions of the GPL are applicable instead of
28
* those above. If you wish to allow use of your version of this
29
* file only under the terms of the GPL and not to allow
30
* others to use your version of this file under the MPL, indicate
31
* your decision by deleting the provisions above and replace them
32
* with the notice and other provisions required by the GPL.
33
* If you do not delete the provisions above, a recipient
34
* may use your version of this file under either the MPL or the
40
const NS_PIPECONSOLE_CONTRACTID = "@mozilla.org/process/pipe-console;1";
41
const NS_IPCBUFFER_CONTRACTID = "@mozilla.org/process/ipc-buffer;1";
42
const NS_PIPEFILTERLISTENER_CONTRACTID = "@mozilla.org/process/pipe-filter-listener;1";
44
function escape_cr(str) {
45
return str.replace(/\r/g, "\\r");
48
const InputStream = new Components.Constructor( "@mozilla.org/scriptableinputstream;1", "nsIScriptableInputStream" );
50
dump("Testing IPC service etc.\n");
53
dump("\nTesting getEnv('PATH')\n");
54
dump(" PATH="+getEnv('PATH')+"\n");
57
dump("\nTesting PipeConsole\n");
59
var pipeConsole = Components.classes[NS_PIPECONSOLE_CONTRACTID].createInstance(Components.interfaces.nsIPipeConsole);
60
pipeConsole.open(24, 80, false);
61
pipeConsole.write("PipeConsole initialized\n");
63
if (pipeConsole.hasNewData) {
64
dump("data='"+pipeConsole.getData()+"'\n");
66
dump(" Error in pipeConsole\n");
68
pipeConsole.shutdown();
71
dump("\nTesting IPCBuffer\n");
73
var ipcBuffer = Components.classes[NS_IPCBUFFER_CONTRACTID].createInstance(Components.interfaces.nsIIPCBuffer);
75
ipcBuffer.open(10, true);
76
ipcBuffer.write("IPCBuffer initialized\n");
77
ipcBuffer.onStopRequest(null, null, 0);
79
var totalBytes = ipcBuffer.totalBytes;
80
dump("totalBytes="+totalBytes+"\n");
82
dump("data='"+ipcBuffer.getData()+"'\n");
84
var rawInStream = ipcBuffer.openInputStream();
85
var scriptableInStream = new InputStream();
86
scriptableInStream.init(rawInStream);
88
var available = scriptableInStream.available();
89
dump("available="+available+"\n");
91
var bufData = scriptableInStream.read(available-3);
94
dump("bufData='"+bufData+"'\n");
98
// Test PipeFilterListener
99
dump("\nTesting PipeFilterListener\n");
101
var listener = Components.classes[NS_IPCBUFFER_CONTRACTID].createInstance(Components.interfaces.nsIIPCBuffer);
103
listener.open(2000, false);
105
var listener2 = Components.classes[NS_IPCBUFFER_CONTRACTID].createInstance(Components.interfaces.nsIIPCBuffer);
107
listener2.open(2000, false);
109
var pipeFilter = Components.classes[NS_PIPEFILTERLISTENER_CONTRACTID].createInstance(Components.interfaces.nsIPipeFilterListener);
111
pipeFilter.init(listener, null, "", "", 0, true, true, listener2);
113
var lines = ["--Boundary",
115
" --Boundary\r\n\r\n",
117
"\nPart 2\r\nPL2\r\nx\r\n--Boundary--\r\n"];
119
for (var j=0; j<lines.length; j++) {
120
pipeFilter.write(lines[j], lines[j].length, null, null);
122
pipeFilter.onStopRequest(null, null, 0);
124
dump("listener.getData()='"+escape_cr(listener.getData())+"'\n");
125
dump("listener2.getData()='"+escape_cr(listener2.getData())+"'\n");
127
var linebreak = ["CRLF", "LF", "CR"];
129
for (var j=0; j<linebreak.length; j++) {
130
listener = Components.classes[NS_IPCBUFFER_CONTRACTID].createInstance(Components.interfaces.nsIIPCBuffer);
132
listener.open(2000, false);
134
pipeFilter = Components.classes[NS_PIPEFILTERLISTENER_CONTRACTID].createInstance(Components.interfaces.nsIPipeFilterListener);
136
pipeFilter.init(listener, null, "", "", 1, (j != 0), true, null);
138
for (var k=0; k<lines.length; k++) {
140
if (j == 1) line = line.replace(/\r/g, "");
141
if (j == 2) line = line.replace(/\n/g, "");
142
pipeFilter.write(line, line.length, null, null);
145
pipeFilter.onStopRequest(null, null, 0);
147
dump(linebreak[j]+" listener.getData()='"+escape_cr(listener.getData())+"'\n");