1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is Java XPCOM Bindings.
16 * The Initial Developer of the Original Code is IBM Corporation.
17 * Portions created by the Initial Developer are Copyright (C) 2007
18 * IBM Corporation. All Rights Reserved.
21 * Javier Pedemonte (jhpedemonte@gmail.com)
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 /***********************************************************
39 ***********************************************************/
41 const nsISupports
= Components
.interfaces
.nsISupports
;
42 const nsIEcho
= Components
.interfaces
.nsIEcho
;
43 const nsIXPCTestIn
= Components
.interfaces
.nsIXPCTestIn
;
44 const nsIXPCTestArray
= Components
.interfaces
.nsIXPCTestArray
;
45 const nsIJXTestArrayParams
= Components
.interfaces
.nsIJXTestArrayParams
;
47 const CLASS_ID
= Components
.ID("{9e45a36d-7cf7-4f2a-a415-d0b07e54945b}");
48 const CLASS_NAME
= "XPConnect Tests in Javascript";
49 const CONTRACT_ID
= "@mozilla.org/javaxpcom/tests/xpc;1";
51 /***********************************************************
53 ***********************************************************/
60 XPCTests
.prototype = {
62 // ----------------------------------
64 // ----------------------------------
66 QueryInterface: function(aIID
) {
67 if (!aIID
.equals(nsIEcho
) &&
68 !aIID
.equals(nsIXPCTestIn
) &&
69 !aIID
.equals(nsIXPCTestArray
) &&
70 !aIID
.equals(nsIJXTestArrayParams
) &&
71 !aIID
.equals(nsISupports
))
72 throw Components
.results
.NS_ERROR_NO_INTERFACE
;
76 // ----------------------------------
78 // ----------------------------------
80 In2OutOneString: function(input
) {
84 In2OutOneDOMString: function(input
) {
88 In2OutOneAString: function(input
) {
92 In2OutOneUTF8String: function(input
) {
96 In2OutOneCString: function(input
) {
102 SetAString: function(str
) {
106 GetAString: function() {
110 // ----------------------------------
112 // ----------------------------------
114 EchoLong: function(l
) {
118 EchoShort: function(a
) {
122 EchoChar: function(c
) {
126 EchoBoolean: function(b
) {
130 EchoOctet: function(o
) {
134 EchoLongLong: function(ll
) {
138 EchoUnsignedShort: function(us
) {
142 EchoUnsignedLong: function(ul
) {
146 EchoFloat: function(f
) {
150 EchoDouble: function(d
) {
154 EchoWchar: function(wc
) {
158 EchoString: function(ws
) {
162 EchoPRBool: function(b
) {
166 EchoPRInt32: function(l
) {
170 EchoPRInt16: function(l
) {
174 EchoPRInt64: function(i
) {
178 EchoPRUint8: function(i
) {
182 EchoPRUint16: function(i
) {
186 EchoPRUint32: function(i
) {
190 EchoPRUint64: function(i
) {
194 EchoVoid: function() {},
196 // ----------------------------------
198 // ----------------------------------
200 MultiplyEachItemInIntegerArray : function(val
, len
, a
) {
201 for(var i
= 0; i
< len
; i
++)
205 DoubleStringArray : function(len
, a
) {
206 var outArray
= new Array();
207 for(var i
= 0; i
< len
.value
; i
++) {
208 var inStr
= a
.value
[i
];
209 var outStr
= new String();
210 for(var k
= 0; k
< inStr
.length
; k
++) {
214 outArray
.push(outStr
);
215 outArray
.push(outStr
);
221 ReverseStringArray : function(len
, a
) {
222 for(var i
= 0; i
< len
/2; i
++) {
223 var temp
= a
.value
[i
];
224 a
.value
[i
] = a
.value
[len
-1-i
];
225 a
.value
[len
-1-i
] = temp
;
229 // ----------------------------------
230 // nsIJXTestArrayParams
231 // ----------------------------------
233 multiplyEachItemInIntegerArray2 : function(val
, a
, len
) {
234 this.MultiplyEachItemInIntegerArray(val
, len
, a
);
237 copyIntArray: function(srcArray
, count
, dstArray
) {
238 dstArray
.value
= srcArray
.slice();
241 returnIntArray: function(srcArray
, count
) {
245 copyByteArray: function(srcArray
, count
, dstArray
) {
246 dstArray
.value
= srcArray
.slice();
249 returnByteArray: function(srcArray
, count
) {
253 copySizedString: function(srcString
, count
, dstString
) {
254 dstString
.value
= srcString
.slice();
257 returnSizedString: function(srcString
, count
) {
261 copySizedWString: function(srcString
, count
, dstString
) {
262 dstString
.value
= srcString
.slice();
265 returnSizedWString: function(srcString
, count
) {
270 /***********************************************************
272 ***********************************************************/
273 var XPCTestsFactory
= {
274 createInstance: function (aOuter
, aIID
)
277 throw Components
.results
.NS_ERROR_NO_AGGREGATION
;
278 return (new XPCTests()).QueryInterface(aIID
);
282 /***********************************************************
283 module definition (xpcom registration)
284 ***********************************************************/
285 var XPCTestsModule
= {
287 registerSelf: function(aCompMgr
, aFileSpec
, aLocation
, aType
)
290 QueryInterface(Components
.interfaces
.nsIComponentRegistrar
);
291 aCompMgr
.registerFactoryLocation(CLASS_ID
, CLASS_NAME
,
292 CONTRACT_ID
, aFileSpec
, aLocation
, aType
);
295 unregisterSelf: function(aCompMgr
, aLocation
, aType
)
298 QueryInterface(Components
.interfaces
.nsIComponentRegistrar
);
299 aCompMgr
.unregisterFactoryLocation(CLASS_ID
, aLocation
);
302 getClassObject: function(aCompMgr
, aCID
, aIID
)
304 if (!aIID
.equals(Components
.interfaces
.nsIFactory
))
305 throw Components
.results
.NS_ERROR_NOT_IMPLEMENTED
;
307 if (aCID
.equals(CLASS_ID
))
308 return XPCTestsFactory
;
310 throw Components
.results
.NS_ERROR_NO_INTERFACE
;
313 canUnload: function(aCompMgr
)
319 /***********************************************************
320 module initialization
321 ***********************************************************/
322 function NSGetModule(aCompMgr
, aFileSpec
)
324 return XPCTestsModule
;