Back to index

lightning-sunbird  0.9+nobinonly
TestParams.cpp
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 #include "TestParams.h"
00039 #include "nsIGenericFactory.h"
00040 #include "nsMemory.h"
00041 #include "prmem.h"
00042 #include "nsString.h"
00043 #include "nsWeakReference.h"
00044 #include "nsILocalFile.h"
00045 #include "stdio.h"
00046 
00047 
00048 /* TestParams */
00049 
00050 NS_IMPL_ISUPPORTS1(TestParams, ITestParams)
00051 
00052 TestParams::TestParams()
00053 {
00054   /* member initializers and constructor code */
00055 }
00056 
00057 TestParams::~TestParams()
00058 {
00059   /* destructor code */
00060 }
00061 
00062 NS_IMETHODIMP
00063 TestParams::TestSimpleTypeArrayIn(PRUint32 aCount, PRUint8* aArray)
00064 {
00065   printf("-> TestSimpleTypeArrayIn()\n");
00066 
00067   for (PRUint32 i = 0; i < aCount; i++) {
00068     printf("[%d]  %u\n", i, aArray[i]);
00069   }
00070   return NS_OK;
00071 }
00072 
00073 NS_IMETHODIMP
00074 TestParams::TestCharStrTypeArrayIn(PRUint32 aCount, const char** aArray)
00075 {
00076   printf("-> TestCharStrTypeArrayIn()\n");
00077 
00078   for (PRUint32 i = 0; i < aCount; i++) {
00079     printf("[%d]  %s\n", i, aArray[i]);
00080   }
00081   return NS_OK;
00082 }
00083 
00084 NS_IMETHODIMP
00085 TestParams::TestWCharStrTypeArrayIn(PRUint32 aCount, const PRUnichar** aArray)
00086 {
00087   printf("-> TestWCharStrTypeArrayIn()\n");
00088 
00089   for (PRUint32 i = 0; i < aCount; i++) {
00090     nsAutoString tmp(aArray[i]);
00091     printf("[%d]  %s\n", i, NS_LossyConvertUCS2toASCII(tmp).get());
00092   }
00093   return NS_OK;
00094 }
00095 
00096 NS_IMETHODIMP
00097 TestParams::TestIIDTypeArrayIn(PRUint32 aCount, const nsIID** aArray)
00098 {
00099   printf("-> TestIIDTypeArrayIn()\n");
00100 
00101   for (PRUint32 i = 0; i < aCount; i++) {
00102     char* iid = aArray[i]->ToString();
00103     printf("[%d]  %s\n", i, iid);
00104     PR_Free(iid);
00105   }
00106   return NS_OK;
00107 }
00108 
00109 NS_IMETHODIMP
00110 TestParams::TestIfaceTypeArrayIn(PRUint32 aCount, nsILocalFile** aArray)
00111 {
00112   printf("-> TestIfaceTypeArrayIn()\n");
00113 
00114   for (PRUint32 i = 0; i < aCount; i++) {
00115     nsAutoString path;
00116     aArray[i]->GetPath(path);
00117     printf("[%d]  %s\n", i, NS_LossyConvertUCS2toASCII(path).get());
00118   }
00119   return NS_OK;
00120 }
00121 
00122 NS_IMETHODIMP
00123 TestParams::TestSimpleTypeArrayOut(PRUint32* aCount, char** aResult)
00124 {
00125   printf("-> TestSimpleTypeArrayOut()\n");
00126 
00127   PRUint32 count = 4;
00128   char* array = (char*) nsMemory::Alloc(count * sizeof(char));
00129   array[0] = 's';
00130   array[1] = 't';
00131   array[2] = 'u';
00132   array[3] = 'v';
00133 
00134   *aCount = count;
00135   *aResult = array;
00136   return NS_OK;
00137 }
00138 
00139 NS_IMETHODIMP
00140 TestParams::TestCharStrTypeArrayOut(PRUint32* aCount, char*** aResult)
00141 {
00142   printf("-> TestCharStrTypeArrayOut()\n");
00143 
00144   PRUint32 count = 3;
00145   char** array = (char**) nsMemory::Alloc(count * sizeof(char*));
00146 
00147   array[0] = (char*) nsMemory::Alloc(4 * sizeof(char));
00148   strcpy(array[0], "one");
00149   array[1] = (char*) nsMemory::Alloc(4 * sizeof(char));
00150   strcpy(array[1], "two");
00151   array[2] = (char*) nsMemory::Alloc(6 * sizeof(char));
00152   strcpy(array[2], "three");
00153 
00154   *aCount = count;
00155   *aResult = array;
00156   return NS_OK;
00157 }
00158 
00159 NS_IMETHODIMP
00160 TestParams::TestWCharStrTypeArrayOut(PRUint32* aCount, PRUnichar*** aResult)
00161 {
00162   printf("-> TestWCharStrTypeArrayOut()\n");
00163 
00164   PRUint32 count = 3;
00165   PRUnichar** array = (PRUnichar**) nsMemory::Alloc(count * sizeof(PRUnichar*));
00166 
00167   NS_NAMED_LITERAL_STRING(one, "ône");
00168   NS_NAMED_LITERAL_STRING(two, "twò");
00169   NS_NAMED_LITERAL_STRING(three, "threë");
00170 
00171   array[0] = (PRUnichar*) nsMemory::Alloc(4 * sizeof(PRUnichar));
00172   memcpy(array[0], one.get(), 4 * sizeof(PRUnichar));
00173   array[1] = (PRUnichar*) nsMemory::Alloc(4 * sizeof(PRUnichar));
00174   memcpy(array[1], two.get(), 4 * sizeof(PRUnichar));
00175   array[2] = (PRUnichar*) nsMemory::Alloc(6 * sizeof(PRUnichar));
00176   memcpy(array[2], three.get(), 6 * sizeof(PRUnichar));
00177 
00178   *aCount = count;
00179   *aResult = array;
00180   return NS_OK;
00181 }
00182 
00183 NS_IMETHODIMP
00184 TestParams::TestIIDTypeArrayOut(PRUint32* aCount, nsIID*** aResult)
00185 {
00186   printf("-> TestIIDTypeArrayOut()\n");
00187 
00188   PRUint32 count = 2;
00189   nsIID** array = (nsIID**) nsMemory::Alloc(count * sizeof(nsIID*));
00190 
00191   const nsIID& iid = NS_GET_IID(nsISupports);
00192   array[0] = (nsIID*) nsMemory::Clone(&iid, sizeof(iid));
00193   const nsIID& iid2 = NS_GET_IID(nsISupportsWeakReference);
00194   array[1] = (nsIID*) nsMemory::Clone(&iid2, sizeof(iid2));
00195 
00196   *aCount = count;
00197   *aResult = array;
00198   return NS_OK;
00199 }
00200 
00201 NS_IMETHODIMP
00202 TestParams::TestIfaceTypeArrayOut(PRUint32* aCount, nsILocalFile*** aResult)
00203 {
00204   printf("-> TestIfaceTypeArrayOut()\n");
00205 
00206   PRUint32 count = 3;
00207   nsILocalFile** array = (nsILocalFile**)
00208                                  nsMemory::Alloc(count * sizeof(nsILocalFile*));
00209 
00210   nsILocalFile* dir1;
00211   NS_NewLocalFile(NS_LITERAL_STRING("/usr/local/share"), PR_FALSE, &dir1);
00212   array[0] = dir1;
00213   nsILocalFile* dir2;
00214   NS_NewLocalFile(NS_LITERAL_STRING("/home"), PR_FALSE, &dir2);
00215   array[1] = dir2;
00216   nsILocalFile* dir3;
00217   NS_NewLocalFile(NS_LITERAL_STRING("/var/log"), PR_FALSE, &dir3);
00218   array[2] = dir3;
00219 
00220   *aCount = count;
00221   *aResult = array;
00222   return NS_OK;
00223 }
00224 
00225 NS_IMETHODIMP
00226 TestParams::TestSimpleTypeArrayInOut(PRUint32 aCount, PRInt16** aArray)
00227 {
00228   printf("-> TestSimpleTypeArrayInOut()\n");
00229 
00230   printf("in:\n");
00231   PRUint32 i;
00232   for (i = 0; i < aCount; i++) {
00233     printf("[%d]  %d\n", i, aArray[0][i]);
00234   }
00235 
00236   for (i = 0; i < aCount/2; i++) {
00237     PRUint32 index = aCount - 1 - i;
00238     PRUint16 temp = aArray[0][index];
00239     aArray[0][index] = aArray[0][i];
00240     aArray[0][i] = temp;
00241   }
00242 
00243   return NS_OK;
00244 }
00245 
00246 NS_IMETHODIMP
00247 TestParams::TestCharStrTypeArrayInOut(PRUint32 aCount, char*** aArray)
00248 {
00249   printf("-> TestCharStrTypeArrayInOut()\n");
00250 
00251   printf("in:\n");
00252   PRUint32 i;
00253   for (i = 0; i < aCount; i++) {
00254     printf("[%d]  %s\n", i, aArray[0][i]);
00255   }
00256 
00257   for (i = 0; i < aCount/2; i++) {
00258     PRUint32 index = aCount - 1 - i;
00259     char* temp = aArray[0][index];
00260     aArray[0][index] = aArray[0][i];
00261     aArray[0][i] = temp;
00262   }
00263 
00264   return NS_OK;
00265 }
00266 
00267 NS_IMETHODIMP
00268 TestParams::TestWCharStrTypeArrayInOut(PRUint32 aCount, PRUnichar*** aArray)
00269 {
00270   printf("-> TestWCharStrTypeArrayInOut()\n");
00271 
00272   printf("in:\n");
00273   PRUint32 i;
00274   for (i = 0; i < aCount; i++) {
00275     nsAutoString tmp(aArray[0][i]);
00276     printf("[%d]  %s\n", i, NS_LossyConvertUCS2toASCII(tmp).get());
00277   }
00278 
00279   for (i = 0; i < aCount/2; i++) {
00280     PRUint32 index = aCount - 1 - i;
00281     PRUnichar* temp = aArray[0][index];
00282     aArray[0][index] = aArray[0][i];
00283     aArray[0][i] = temp;
00284   }
00285 
00286   return NS_OK;
00287 }
00288 
00289 NS_IMETHODIMP
00290 TestParams::TestIIDTypeArrayInOut(PRUint32 aCount, nsIID*** aArray)
00291 {
00292   printf("-> TestIIDTypeArrayInOut()\n");
00293 
00294   printf("in:\n");
00295   PRUint32 i;
00296   for (i = 0; i < aCount; i++) {
00297     char* iid = aArray[0][i]->ToString();
00298     printf("[%d]  %s\n", i, iid);
00299     PR_Free(iid);
00300   }
00301 
00302   for (i = 0; i < aCount/2; i++) {
00303     PRUint32 index = aCount - 1 - i;
00304     nsID* temp = aArray[0][index];
00305     aArray[0][index] = aArray[0][i];
00306     aArray[0][i] = temp;
00307   }
00308 
00309   return NS_OK;
00310 }
00311 
00312 NS_IMETHODIMP
00313 TestParams::TestIfaceTypeArrayInOut(PRUint32 aCount, nsILocalFile*** aArray)
00314 {
00315   printf("-> TestIfaceTypeArrayInOut()\n");
00316 
00317   printf("in:\n");
00318   PRUint32 i;
00319   for (i = 0; i < aCount; i++) {
00320     nsAutoString path;
00321     aArray[0][i]->GetPath(path);
00322     printf("[%d]  %s\n", i, NS_LossyConvertUCS2toASCII(path).get());
00323   }
00324 
00325   for (i = 0; i < aCount/2; i++) {
00326     PRUint32 index = aCount - 1 - i;
00327     nsILocalFile* temp = aArray[0][index];
00328     aArray[0][index] = aArray[0][i];
00329     aArray[0][i] = temp;
00330   }
00331 
00332   return NS_OK;
00333 }
00334 
00335 NS_IMETHODIMP
00336 TestParams::ReturnSimpleTypeArray(PRUint32* aCount, PRUint32** aResult)
00337 {
00338   printf("-> ReturnSimpleArrayType()\n");
00339 
00340   PRUint32 count = 5;
00341   PRUint32* array = (PRUint32*) nsMemory::Alloc(count * sizeof(PRUint32));
00342   for (PRUint32 i = 0, j = 1; i < count; i++ ) {
00343     array[i] = j;
00344     j *= 13;
00345   }
00346 
00347   *aCount = count;
00348   *aResult = array;
00349   return NS_OK;
00350 }
00351 
00352 NS_IMETHODIMP
00353 TestParams::ReturnCharStrTypeArray(PRUint32* aCount, char*** aResult)
00354 {
00355   printf("-> ReturnCharStrTypeArray()\n");
00356 
00357   PRUint32 count = 3;
00358   char** array = (char**) nsMemory::Alloc(count * sizeof(char*));
00359 
00360   array[0] = (char*) nsMemory::Alloc(4 * sizeof(char));
00361   strcpy(array[0], "one");
00362   array[1] = (char*) nsMemory::Alloc(4 * sizeof(char));
00363   strcpy(array[1], "two");
00364   array[2] = (char*) nsMemory::Alloc(6 * sizeof(char));
00365   strcpy(array[2], "three");
00366 
00367   *aCount = count;
00368   *aResult = array;
00369   return NS_OK;
00370 }
00371 
00372 NS_IMETHODIMP
00373 TestParams::ReturnWCharStrTypeArray(PRUint32* aCount, PRUnichar*** aResult)
00374 {
00375   printf("-> ReturnWCharStrTypeArray()\n");
00376 
00377   PRUint32 count = 3;
00378   PRUnichar** array = (PRUnichar**) nsMemory::Alloc(count * sizeof(PRUnichar*));
00379 
00380   NS_NAMED_LITERAL_STRING(one, "one");
00381   NS_NAMED_LITERAL_STRING(two, "two");
00382   NS_NAMED_LITERAL_STRING(three, "three");
00383 
00384   array[0] = (PRUnichar*) nsMemory::Alloc(4 * sizeof(PRUnichar));
00385   memcpy(array[0], one.get(), 4 * sizeof(PRUnichar));
00386   array[1] = (PRUnichar*) nsMemory::Alloc(4 * sizeof(PRUnichar));
00387   memcpy(array[1], two.get(), 4 * sizeof(PRUnichar));
00388   array[2] = (PRUnichar*) nsMemory::Alloc(6 * sizeof(PRUnichar));
00389   memcpy(array[2], three.get(), 6 * sizeof(PRUnichar));
00390 
00391   *aCount = count;
00392   *aResult = array;
00393   return NS_OK;
00394 }
00395 
00396 NS_IMETHODIMP
00397 TestParams::ReturnIIDTypeArray(PRUint32* aCount, nsIID*** aResult)
00398 {
00399   printf("-> ReturnIIDTypeArray()\n");
00400 
00401   PRUint32 count = 2;
00402   nsIID** array = (nsIID**) nsMemory::Alloc(count * sizeof(nsIID*));
00403 
00404   const nsIID& iid = NS_GET_IID(nsISupports);
00405   array[0] = (nsIID*) nsMemory::Clone(&iid, sizeof(iid));
00406   const nsIID& iid2 = NS_GET_IID(nsISupportsWeakReference);
00407   array[1] = (nsIID*) nsMemory::Clone(&iid2, sizeof(iid2));
00408 
00409   *aCount = count;
00410   *aResult = array;
00411   return NS_OK;
00412 }
00413 
00414 NS_IMETHODIMP
00415 TestParams::ReturnIfaceTypeArray(PRUint32* aCount, nsILocalFile*** aResult)
00416 {
00417   printf("-> ReturnIfaceTypeArray()\n");
00418 
00419   PRUint32 count = 3;
00420   nsILocalFile** array = (nsILocalFile**)
00421                                  nsMemory::Alloc(count * sizeof(nsILocalFile*));
00422 
00423   nsILocalFile* dir1;
00424   NS_NewLocalFile(NS_LITERAL_STRING("/usr/local/share"), PR_FALSE, &dir1);
00425   array[0] = dir1;
00426   nsILocalFile* dir2;
00427   NS_NewLocalFile(NS_LITERAL_STRING("/home"), PR_FALSE, &dir2);
00428   array[1] = dir2;
00429   nsILocalFile* dir3;
00430   NS_NewLocalFile(NS_LITERAL_STRING("/var/log"), PR_FALSE, &dir3);
00431   array[2] = dir3;
00432 
00433   *aCount = count;
00434   *aResult = array;
00435   return NS_OK;
00436 }
00437 
00438 
00439 /* TestParamsFactory */
00440 
00441 NS_GENERIC_FACTORY_CONSTRUCTOR(TestParams)
00442 
00443 static const nsModuleComponentInfo components[] = {
00444   { "TestParams", TESTPARAMS_CID, nsnull, TestParamsConstructor }
00445 };
00446 
00447 NS_IMPL_NSGETMODULE(TestParamsFactory, components)
00448 
00449