Back to index

lightning-sunbird  0.9+nobinonly
TestParams.java
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Java XPCOM Bindings.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * IBM Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2005
00019  * IBM Corporation. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Javier Pedemonte (jhpedemonte@gmail.com)
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 import org.mozilla.xpcom.*;
00039 import java.io.*;
00040 
00041 
00042 public class TestParams
00043 {
00044   public static final String TESTPARAMS_CID =
00045     "{3f64f1ad-bbbc-4c2f-88c8-e5b6b67bb0cc}";
00046 
00047   public static void main(String [] args)
00048   {
00049     System.loadLibrary("javaxpcom");
00050 
00051     String mozillaPath = System.getProperty("MOZILLA_FIVE_HOME");
00052     if (mozillaPath == null) {
00053       throw new RuntimeException("MOZILLA_FIVE_HOME system property not set.");
00054     }
00055 
00056     File localFile = new File(mozillaPath);
00057     XPCOM.initXPCOM(localFile, null);
00058 
00059     nsIComponentManager componentManager = XPCOM.getComponentManager();
00060     ITestParams p = (ITestParams)
00061       componentManager.createInstance(TESTPARAMS_CID, null,
00062                                       ITestParams.ITESTPARAMS_IID);
00063     if (p == null) {
00064       throw new RuntimeException("Failed to create ITestParams.");
00065     }
00066 
00067     testArrayParams(p);
00068 
00069     XPCOM.shutdownXPCOM(null);
00070   }
00071 
00072   static void testArrayParams(ITestParams p)
00073   {
00074     testArrayParamsIn(p);
00075     testArrayParamsOut(p);
00076     testArrayParamsInOut(p);
00077     testArrayParamsRetval(p);
00078   }
00079 
00080   static void testArrayParamsIn(ITestParams p)
00081   {
00082     int count = 4;
00083     short[] byte_array = new short[count];
00084     for (short i = 0; i < count; i++) {
00085       byte_array[i] = i;
00086     }
00087     p.testSimpleTypeArrayIn(count, byte_array);
00088 
00089     count = 3;
00090     String[] str_array = new String[count];
00091     str_array[0] = "three";
00092     str_array[1] = "two";
00093     str_array[2] = "one";
00094     p.testCharStrTypeArrayIn(count, str_array);
00095 
00096     count = 4;
00097     str_array = new String[count];
00098     str_array[0] = "foúr";
00099     str_array[1] = "threë";
00100     str_array[2] = "twò";
00101     str_array[3] = "ône";
00102     p.testWCharStrTypeArrayIn(count, str_array);
00103 
00104     count = 2;
00105     String[] iid_array = new String[count];
00106     iid_array[0] = nsISupports.NS_ISUPPORTS_IID;
00107     iid_array[1] = nsISupportsWeakReference.NS_ISUPPORTSWEAKREFERENCE_IID;
00108     p.testIIDTypeArrayIn(count, iid_array);
00109 
00110     count = 3;
00111     nsILocalFile[] iface_array = new nsILocalFile[count];
00112     iface_array[0] = XPCOM.newLocalFile("/usr/bin", false);
00113     iface_array[1] = XPCOM.newLocalFile("/var/log", false);
00114     iface_array[2] = XPCOM.newLocalFile("/home", false);
00115     p.testIfaceTypeArrayIn(count, iface_array);
00116   }
00117 
00118   static void testArrayParamsOut(ITestParams p)
00119   {
00120     long[] count = new long[1];
00121     char[][] char_array = new char[1][];
00122     p.testSimpleTypeArrayOut(count, char_array);
00123     for (int i = 0; i < count[0]; i++) {
00124       System.out.println("[" + i + "]  " + char_array[0][i]);
00125     }
00126 
00127     String[][] str_array = new String[1][];
00128     p.testCharStrTypeArrayOut(count, str_array);
00129     for (int i = 0; i < count[0]; i++) {
00130       System.out.println("[" + i + "]  " + str_array[0][i]);
00131     }
00132 
00133     str_array = new String[1][];
00134     p.testWCharStrTypeArrayOut(count, str_array);
00135     for (int i = 0; i < count[0]; i++) {
00136       System.out.println("[" + i + "]  " + str_array[0][i]);
00137     }
00138 
00139     str_array = new String[1][];
00140     p.testIIDTypeArrayOut(count, str_array);
00141     for (int i = 0; i < count[0]; i++) {
00142       System.out.println("[" + i + "]  " + str_array[0][i]);
00143     }
00144 
00145     nsILocalFile[][] file_array = new nsILocalFile[1][];
00146     p.testIfaceTypeArrayOut(count, file_array);
00147     for (int i = 0; i < count[0]; i++) {
00148       System.out.println("[" + i + "]  " + file_array[0][i].getPath());
00149     }
00150   }
00151 
00152   static void testArrayParamsInOut(ITestParams p)
00153   {
00154     int count = 5;
00155     short[][] short_array = new short[1][count];
00156     for (short i = 0; i < count; i++) {
00157       short_array[0][i] = i;
00158     }
00159     p.testSimpleTypeArrayInOut(count, short_array);
00160     System.out.println("out:");
00161     for (int i = 0; i < count; i++) {
00162       System.out.println("[" + i + "]  " + short_array[0][i]);
00163     }
00164 
00165     count = 3;
00166     String[][] str_array = new String[1][count];
00167     str_array[0][0] = "three";
00168     str_array[0][1] = "two";
00169     str_array[0][2] = "one";
00170     p.testCharStrTypeArrayInOut(count, str_array);
00171     System.out.println("out:");
00172     for (int i = 0; i < count; i++) {
00173       System.out.println("[" + i + "]  " + str_array[0][i]);
00174     }
00175 
00176     count = 4;
00177     str_array = new String[1][count];
00178     str_array[0][0] = "foúr";
00179     str_array[0][1] = "threë";
00180     str_array[0][2] = "twò";
00181     str_array[0][3] = "ône";
00182     p.testWCharStrTypeArrayInOut(count, str_array);
00183     System.out.println("out:");
00184     for (int i = 0; i < count; i++) {
00185       System.out.println("[" + i + "]  " + str_array[0][i]);
00186     }
00187 
00188     count = 2;
00189     String[][] iid_array = new String[1][count];
00190     iid_array[0][0] = nsISupports.NS_ISUPPORTS_IID;
00191     iid_array[0][1] = nsISupportsWeakReference.NS_ISUPPORTSWEAKREFERENCE_IID;
00192     p.testIIDTypeArrayInOut(count, iid_array);
00193     System.out.println("out:");
00194     for (int i = 0; i < count; i++) {
00195       System.out.println("[" + i + "]  " + iid_array[0][i]);
00196     }
00197 
00198     count = 3;
00199     nsILocalFile[][] iface_array = new nsILocalFile[1][count];
00200     iface_array[0][0] = XPCOM.newLocalFile("/usr/bin", false);
00201     iface_array[0][1] = XPCOM.newLocalFile("/var/log", false);
00202     iface_array[0][2] = XPCOM.newLocalFile("/home", false);
00203     p.testIfaceTypeArrayInOut(count, iface_array);
00204     System.out.println("out:");
00205     for (int i = 0; i < count; i++) {
00206       System.out.println("[" + i + "]  " + iface_array[0][i].getPath());
00207     }
00208   }
00209 
00210   static void testArrayParamsRetval(ITestParams p)
00211   {
00212     long[] count = new long[1];
00213     long[] int_array = p.returnSimpleTypeArray(count);
00214     for (int i = 0; i < count[0]; i++) {
00215       System.out.println("[" + i + "]  " + int_array[i]);
00216     }
00217 
00218     String[] str_array = p.returnCharStrTypeArray(count);
00219     for (int i = 0; i < count[0]; i++) {
00220       System.out.println("[" + i + "]  " + str_array[i]);
00221     }
00222 
00223     str_array = p.returnWCharStrTypeArray(count);
00224     for (int i = 0; i < count[0]; i++) {
00225       System.out.println("[" + i + "]  " + str_array[i]);
00226     }
00227 
00228     str_array = p.returnIIDTypeArray(count);
00229     for (int i = 0; i < count[0]; i++) {
00230       System.out.println("[" + i + "]  " + str_array[i]);
00231     }
00232 
00233     nsILocalFile[] file_array = (nsILocalFile[]) p.returnIfaceTypeArray(count);
00234     for (int i = 0; i < count[0]; i++) {
00235       System.out.println("[" + i + "]  " + file_array[i].getPath());
00236     }
00237   }
00238 }
00239