Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / extensions / java / xpcom / tests / testparams / xpctests.js
blob052828f88e60260be2ee3268a67290852d8f8727
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
12 * License.
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.
20 * Contributor(s):
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 /***********************************************************
38 constants
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 /***********************************************************
52 class definition
53 ***********************************************************/
55 //class constructor
56 function XPCTests() {
59 // class definition
60 XPCTests.prototype = {
62 // ----------------------------------
63 // nsISupports
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;
73 return this;
76 // ----------------------------------
77 // nsIEcho
78 // ----------------------------------
80 In2OutOneString: function(input) {
81 return input;
84 In2OutOneDOMString: function(input) {
85 return input;
88 In2OutOneAString: function(input) {
89 return input;
92 In2OutOneUTF8String: function(input) {
93 return input;
96 In2OutOneCString: function(input) {
97 return input;
100 _string: null,
102 SetAString: function(str) {
103 _string = str;
106 GetAString: function() {
107 return _string;
110 // ----------------------------------
111 // nsIXPCTestIn
112 // ----------------------------------
114 EchoLong: function(l) {
115 return l;
118 EchoShort: function(a) {
119 return a;
122 EchoChar: function(c) {
123 return c;
126 EchoBoolean: function(b) {
127 return b;
130 EchoOctet: function(o) {
131 return o;
134 EchoLongLong: function(ll) {
135 return ll;
138 EchoUnsignedShort: function(us) {
139 return us;
142 EchoUnsignedLong: function(ul) {
143 return ul;
146 EchoFloat: function(f) {
147 return f;
150 EchoDouble: function(d) {
151 return d;
154 EchoWchar: function(wc) {
155 return wc;
158 EchoString: function(ws) {
159 return ws;
162 EchoPRBool: function(b) {
163 return b;
166 EchoPRInt32: function(l) {
167 return l;
170 EchoPRInt16: function(l) {
171 return l;
174 EchoPRInt64: function(i) {
175 return i;
178 EchoPRUint8: function(i) {
179 return i;
182 EchoPRUint16: function(i) {
183 return i;
186 EchoPRUint32: function(i) {
187 return i;
190 EchoPRUint64: function(i) {
191 return i;
194 EchoVoid: function() {},
196 // ----------------------------------
197 // nsIXPCTestArray
198 // ----------------------------------
200 MultiplyEachItemInIntegerArray : function(val, len, a) {
201 for(var i = 0; i < len; i++)
202 a.value[i] *= val;
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++) {
211 outStr += inStr[k];
212 outStr += inStr[k];
214 outArray.push(outStr);
215 outArray.push(outStr);
217 len.value *= 2;
218 a.value = outArray;
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) {
242 return srcArray;
245 copyByteArray: function(srcArray, count, dstArray) {
246 dstArray.value = srcArray.slice();
249 returnByteArray: function(srcArray, count) {
250 return srcArray;
253 copySizedString: function(srcString, count, dstString) {
254 dstString.value = srcString.slice();
257 returnSizedString: function(srcString, count) {
258 return srcString;
261 copySizedWString: function(srcString, count, dstString) {
262 dstString.value = srcString.slice();
265 returnSizedWString: function(srcString, count) {
266 return srcString;
270 /***********************************************************
271 class factory
272 ***********************************************************/
273 var XPCTestsFactory = {
274 createInstance: function (aOuter, aIID)
276 if (aOuter != null)
277 throw Components.results.NS_ERROR_NO_AGGREGATION;
278 return (new XPCTests()).QueryInterface(aIID);
282 /***********************************************************
283 module definition (xpcom registration)
284 ***********************************************************/
285 var XPCTestsModule = {
286 _firstTime: true,
287 registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
289 aCompMgr = aCompMgr.
290 QueryInterface(Components.interfaces.nsIComponentRegistrar);
291 aCompMgr.registerFactoryLocation(CLASS_ID, CLASS_NAME,
292 CONTRACT_ID, aFileSpec, aLocation, aType);
295 unregisterSelf: function(aCompMgr, aLocation, aType)
297 aCompMgr = aCompMgr.
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)
315 return true;
319 /***********************************************************
320 module initialization
321 ***********************************************************/
322 function NSGetModule(aCompMgr, aFileSpec)
324 return XPCTestsModule;