Back to index

lightning-sunbird  0.9+nobinonly
wspproxytest.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   John Bandhauer (jband@netscape.com)
00024  *   Vidur Apparao (vidur@netscape.com)
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsCOMPtr.h"
00041 #include "wspproxytest.h"
00042 #include "nsString.h"
00043 #include "nsIInterfaceInfoManager.h"
00044 #include "nsIServiceManager.h"
00045 #include "nsIProperty.h"
00046 #include "nsIVariant.h"
00047 
00048 const PRUint8 sInt8Val = 2;
00049 const PRInt16 sInt16Val = 0x1234;
00050 const PRInt32 sInt32Val = 0x12345678;
00051 const PRInt64 sInt64Val = LL_INIT(0x12345678, 0x87654321);
00052 const PRUint8  sUint8Val = 2;
00053 const PRUint16 sUint16Val = 0x1234;
00054 const PRUint32 sUint32Val = 0x12345678;
00055 const PRUint64 sUint64Val = LL_INIT(0x12345678, 0x87654321);
00056 const PRBool sBoolVal = PR_TRUE;
00057 const float sFloatVal = 0.0;
00058 const double sDoubleVal = 0.03;
00059 const char sCharVal = 'a';
00060 const PRUnichar sWcharVal = PRUnichar('a');
00061 #define STRING_VAL "Hello world"
00062 const PRUint32 sArray1Length = 3;
00063 const PRUint32 sArray1[] = { 4, 23, 37 };
00064 const PRUint32 sArray2Length = 4;
00065 const double sArray2[] = { 4.234, 23.97, 3434.2945, 0.03 };
00066 
00067 WSPProxyTest::WSPProxyTest()
00068 {
00069 }
00070 
00071 WSPProxyTest::~WSPProxyTest()
00072 {
00073 }
00074 
00075 NS_IMPL_ISUPPORTS4_CI(WSPProxyTest,
00076                       nsIWSPProxyTest,
00077                       nsIWSDLLoadListener,
00078                       nsIWebServiceErrorHandler,
00079                       SpheonJSAOPStatisticsPortTypeListener)
00080 
00081 nsresult
00082 WSPProxyTest::CreateComplexTypeWrapper(nsIWebServiceComplexTypeWrapper** aWrapper,
00083                                        nsIInterfaceInfo** aInfo)
00084 {
00085   static nsIID sComplexTypeIID = NS_GET_IID(nsIWSPTestComplexType);
00086   nsCOMPtr<WSPTestComplexType> ct = new WSPTestComplexType();
00087   if (!ct) {
00088     return NS_ERROR_OUT_OF_MEMORY;
00089   }
00090 
00091   nsresult rv;
00092   nsCOMPtr<nsIInterfaceInfoManager> manager = do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv);
00093   if (NS_FAILED(rv)) {
00094     return rv;
00095   }
00096 
00097   nsCOMPtr<nsIInterfaceInfo> iinfo;
00098   rv = manager->GetInfoForIID(&sComplexTypeIID, getter_AddRefs(iinfo));
00099   if (NS_FAILED(rv)) {
00100     return rv;
00101   }
00102   *aInfo = iinfo;
00103   NS_ADDREF(*aInfo);
00104 
00105   nsCOMPtr<nsIWebServiceComplexTypeWrapper> wrapper = do_CreateInstance(NS_WEBSERVICECOMPLEXTYPEWRAPPER_CONTRACTID, &rv);
00106   if (NS_FAILED(rv)) {
00107     return rv;
00108   }
00109   rv = wrapper->Init(ct, iinfo);
00110   if (NS_FAILED(rv)) {
00111     return rv;
00112   }
00113 
00114   *aWrapper = wrapper;
00115   NS_ADDREF(*aWrapper);
00116   return NS_OK;
00117 }
00118 
00119 NS_IMETHODIMP
00120 WSPProxyTest::TestComplexTypeWrapper(nsAString& aResult)
00121 {
00122   nsCOMPtr<nsIInterfaceInfo> info;
00123   nsCOMPtr<nsIWebServiceComplexTypeWrapper> wrapper;
00124   nsresult rv = CreateComplexTypeWrapper(getter_AddRefs(wrapper),
00125                                          getter_AddRefs(info));
00126   if (NS_FAILED(rv)) {
00127     aResult.AssignLiteral("WSPProxyTest: Failed creating complex type wrapper");
00128     return NS_OK;
00129   }
00130 
00131   nsCOMPtr<nsIPropertyBag> propBag = do_QueryInterface(wrapper);
00132   if (!propBag) {
00133     aResult.AssignLiteral("WSPProxyTest: Wrapper is not property bag");
00134     return NS_ERROR_FAILURE;
00135   }
00136 
00137   TestComplexTypeWrapperInstance(propBag, aResult);
00138 
00139   return NS_OK;
00140 }
00141 
00142 
00143 nsresult
00144 WSPProxyTest::TestComplexTypeWrapperInstance(nsIPropertyBag* propBag,
00145                                              nsAString& aResult)
00146 {
00147   nsCOMPtr<nsISimpleEnumerator> enumerator;
00148   nsresult rv = propBag->GetEnumerator(getter_AddRefs(enumerator));
00149   if (NS_FAILED(rv)) {
00150     aResult.AssignLiteral("WSPProxyTest: Failed getting property bag enumerator");
00151     return rv;
00152   }
00153 
00154   nsCOMPtr<nsISupports> sup;
00155   nsCOMPtr<nsIProperty> prop;
00156   nsCOMPtr<nsIVariant> val;
00157   nsAutoString propName;
00158 
00159 #define GET_AND_TEST_NAME(_name)                                          \
00160     rv = enumerator->GetNext(getter_AddRefs(sup));                        \
00161     if (NS_FAILED(rv)) {                                                  \
00162       aResult.Assign(NS_LITERAL_STRING("WSPProxyTest: Failed getting property ") + NS_LITERAL_STRING(#_name));    \
00163       return rv;                                                          \
00164     }                                                                     \
00165                                                                           \
00166     prop = do_QueryInterface(sup, &rv);                                   \
00167     if (NS_FAILED(rv)) {                                                  \
00168       return rv;                                                          \
00169     }                                                                     \
00170                                                                           \
00171     prop->GetName(propName);                                              \
00172     if (!propName.EqualsLiteral(#_name)) {                    \
00173       aResult.Assign(NS_LITERAL_STRING("WSPProxyTest: Name doesn't match for property ") + NS_LITERAL_STRING(#_name)); \
00174       return NS_ERROR_FAILURE;                                            \
00175     }                                                                     \
00176     prop->GetValue(getter_AddRefs(val));                                  \
00177     if (!val) {                                                           \
00178       return NS_ERROR_FAILURE;                                            \
00179     }                                                                     
00180 
00181 #define GET_AND_TEST(_t, _n, _name, _val)                                   \
00182     GET_AND_TEST_NAME(_name)                                                \
00183     _t _name;                                                               \
00184     rv = val->GetAs##_n(&_name);                                            \
00185     if (NS_FAILED(rv)) {                                                    \
00186       aResult.Assign(NS_LITERAL_STRING("WSPProxyTest: Failed getting value for property ") + NS_LITERAL_STRING(#_name)); \
00187       return rv;                                                            \
00188     }                                                                       \
00189     if (_name != _val) {                                                    \
00190       aResult.Assign(NS_LITERAL_STRING("WSPProxyTest: Value doesn't match for property ") + NS_LITERAL_STRING(#_name)); \
00191       return NS_ERROR_FAILURE;                                              \
00192     }                                                                       
00193                                                                              
00194   GET_AND_TEST(PRUint8, Int8, i8, sInt8Val)
00195   GET_AND_TEST(PRInt16, Int16, i16, sInt16Val)
00196   GET_AND_TEST(PRInt32, Int32, i32, sInt32Val)
00197   GET_AND_TEST(PRInt64, Int64, i64, sInt64Val)
00198   GET_AND_TEST(PRUint8, Uint8, u8, sUint8Val)
00199   GET_AND_TEST(PRUint16, Uint16, u16, sUint16Val)
00200   GET_AND_TEST(PRUint32, Uint32, u32, sUint32Val)
00201   GET_AND_TEST(PRUint64, Uint64, u64, sUint64Val)
00202   GET_AND_TEST(PRBool, Bool, b, sBoolVal)
00203   GET_AND_TEST(float, Float, f, sFloatVal)
00204   GET_AND_TEST(double, Double, d, sDoubleVal)
00205   GET_AND_TEST(char, Char, c, sCharVal)
00206   GET_AND_TEST(PRUnichar, WChar, wc, sWcharVal)
00207 
00208   GET_AND_TEST_NAME(s);
00209   nsAutoString str;
00210   rv = val->GetAsAString(str);
00211   if (NS_FAILED(rv)) {
00212     aResult.AssignLiteral("WSPProxyTest: Failed getting value for property s");
00213     return rv;
00214   }
00215 
00216   if (!str.EqualsLiteral(STRING_VAL)) {
00217     aResult.AssignLiteral("WSPProxyTest: Value doesn't match for property s");
00218     return NS_ERROR_FAILURE;
00219   }
00220 
00221   GET_AND_TEST_NAME(p)
00222   nsCOMPtr<nsISupports> supVal;  
00223   rv = val->GetAsISupports(getter_AddRefs(supVal));  
00224   if (NS_FAILED(rv)) {
00225     aResult.AssignLiteral("WSPProxyTest: Failed getting value for property p");
00226     return rv;
00227   }
00228   nsCOMPtr<nsIPropertyBag> propBagVal = do_QueryInterface(supVal, &rv);
00229   if (NS_FAILED(rv)) {
00230     aResult.AssignLiteral("WSPProxyTest: Value doesn't match for property p");
00231     return rv;
00232   }
00233 
00234   GET_AND_TEST_NAME(p2)
00235   PRUint16 dataType;
00236   val->GetDataType(&dataType);
00237   if (dataType != nsIDataType::VTYPE_EMPTY) {
00238     aResult.AssignLiteral("WSPProxyTest: Value doesn't match for property p");
00239     return NS_ERROR_FAILURE;
00240   }
00241 
00242   PRUint16 type;
00243   PRUint32 index, count;
00244   PRUint32* arrayVal1;
00245 
00246   GET_AND_TEST_NAME(array1)
00247   nsIID iid;
00248   rv = val->GetAsArray(&type, &iid, &count, (void**)&arrayVal1);
00249   if (NS_FAILED(rv)) {
00250     aResult.AssignLiteral("WSPProxyTest: Failed getting value for property array1");
00251     return rv;
00252   }
00253   for (index = 0; index < count; index++) {
00254     if (arrayVal1[index] != sArray1[index]) {
00255       aResult.AssignLiteral("WSPProxyTest: Value doesn't match for element of property array1");
00256       return rv;      
00257     }
00258   }
00259   nsMemory::Free(arrayVal1);
00260 
00261   double* arrayVal2;
00262   GET_AND_TEST_NAME(array2)
00263   rv = val->GetAsArray(&type, &iid, &count, (void**)&arrayVal2);
00264   if (NS_FAILED(rv)) {
00265     aResult.AssignLiteral("WSPProxyTest: Failed getting value for property array2");
00266     return rv;
00267   }
00268   for (index = 0; index < count; index++) {
00269     if (arrayVal2[index] != sArray2[index]) {
00270       aResult.AssignLiteral("WSPProxyTest: Value doesn't match for element of property array2");
00271       return rv;      
00272     }
00273   }
00274   nsMemory::Free(arrayVal2);
00275 
00276   nsISupports** arrayVal3;
00277   GET_AND_TEST_NAME(array3)
00278   rv = val->GetAsArray(&type, &iid, &count, (void**)&arrayVal3);
00279   if (NS_FAILED(rv)) {
00280     aResult.AssignLiteral("WSPProxyTest: Failed getting value for property array3");
00281     return rv;
00282   }
00283   propBagVal = do_QueryInterface(arrayVal3[0], &rv);
00284   if (NS_FAILED(rv)) {
00285     aResult.AssignLiteral("WSPProxyTest: Value doesn't match for element of property array3");
00286     return rv;
00287   }
00288   if (arrayVal3[1] != nsnull) {
00289     aResult.AssignLiteral("WSPProxyTest: Value doesn't match for element of  property array3");
00290     return NS_ERROR_FAILURE;
00291   }
00292   NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, arrayVal3);
00293 
00294 #undef GET_AND_TEST
00295 #undef GET_AND_TEST_NAME
00296 
00297   aResult.AssignLiteral("WSPProxyTest: Test Succeeded!");
00298   return NS_OK;
00299 }
00300 
00301 
00302 NS_IMETHODIMP
00303 WSPProxyTest::TestPropertyBagWrapper(nsAString& aResult)
00304 {
00305   nsCOMPtr<nsIInterfaceInfo> info;
00306   nsCOMPtr<nsIWebServiceComplexTypeWrapper> ctwrapper;
00307   nsresult rv = CreateComplexTypeWrapper(getter_AddRefs(ctwrapper),
00308                                          getter_AddRefs(info));
00309   if (NS_FAILED(rv)) {
00310     aResult.AssignLiteral("WSPProxyTest: Failed creating complex type wrapper");
00311     return NS_OK;
00312   }
00313 
00314   nsCOMPtr<nsIPropertyBag> propBag = do_QueryInterface(ctwrapper);
00315   if (!propBag) {
00316     aResult.AssignLiteral("WSPProxyTest: Wrapper is not property bag");
00317     return NS_OK;
00318   }
00319 
00320   nsCOMPtr<nsIWebServicePropertyBagWrapper> wrapper = do_CreateInstance(NS_WEBSERVICEPROPERTYBAGWRAPPER_CONTRACTID, &rv);
00321   if (NS_FAILED(rv)) {
00322     aResult.AssignLiteral("WSPProxyTest: Failed creating property bag wrapper");
00323     return NS_OK;
00324   }
00325   rv = wrapper->Init(propBag, info);
00326   if (NS_FAILED(rv)) {
00327     aResult.AssignLiteral("WSPProxyTest: Failed initializing property bag wrapper");
00328     return NS_OK;
00329   }
00330 
00331   nsCOMPtr<nsIWSPTestComplexType> ct = do_QueryInterface(wrapper, &rv);
00332   if (NS_FAILED(rv)) {
00333     aResult.AssignLiteral("WSPProxyTest: Property bag wrapper doesn't QI correctly");
00334     return NS_OK;
00335   }
00336   
00337 #define GET_AND_TEST(_t, _name, _val)                                       \
00338   _t _name;                                                                 \
00339   rv = ct->Get##_name(&_name);                                              \
00340   if (NS_FAILED(rv)) {                                                      \
00341     aResult.Assign(NS_LITERAL_STRING("WSPProxyTest: Failed to get value for attribute") + NS_LITERAL_STRING(#_name)); \
00342     return NS_OK;                                                           \
00343   }                                                                         \
00344   if (_name != _val) {                                                      \
00345     aResult.Assign(NS_LITERAL_STRING("WSPProxyTest: Value doesn't match for attribute ") + NS_LITERAL_STRING(#_name)); \
00346     return NS_OK;                                                           \
00347   }
00348                                                                            
00349   GET_AND_TEST(PRUint8, I8, sInt8Val)
00350   GET_AND_TEST(PRInt16, I16, sInt16Val)
00351   GET_AND_TEST(PRInt32, I32, sInt32Val)
00352   GET_AND_TEST(PRInt64, I64, sInt64Val)
00353   GET_AND_TEST(PRUint8, U8, sUint8Val)
00354   GET_AND_TEST(PRUint16, U16, sUint16Val)
00355   GET_AND_TEST(PRUint32, U32, sUint32Val)
00356   GET_AND_TEST(PRUint64, U64, sUint64Val)
00357   GET_AND_TEST(float, F, sFloatVal)
00358   GET_AND_TEST(double, D, sDoubleVal)
00359   GET_AND_TEST(PRBool, B, sBoolVal)
00360   GET_AND_TEST(char, C, sCharVal)
00361   GET_AND_TEST(PRUnichar, Wc, sWcharVal)
00362 
00363   nsAutoString str;
00364   rv = ct->GetS(str);
00365   if (NS_FAILED(rv)) {
00366     aResult.AssignLiteral("WSPProxyTest: Failed to get value for attribute s");
00367     return NS_OK;
00368   }
00369   if (!str.EqualsLiteral(STRING_VAL)) {
00370     aResult.AssignLiteral("WSPProxyTest: Value doesn't match for attribute s");
00371     return NS_OK;
00372   }
00373 
00374   nsCOMPtr<nsIWSPTestComplexType> p;
00375   rv = ct->GetP(getter_AddRefs(p));
00376   if (NS_FAILED(rv)) {
00377     aResult.AssignLiteral("WSPProxyTest: Failed to get value for attribute p");
00378     return NS_OK;
00379   }
00380 
00381   rv = ct->GetP2(getter_AddRefs(p));
00382   if (NS_FAILED(rv)) {
00383     aResult.AssignLiteral("WSPProxyTest: Failed to get value for attribute p2");
00384     return NS_OK;
00385   }
00386   if (p) {
00387     aResult.AssignLiteral("WSPProxyTest: Value doesn't match for attribute p2");
00388     return NS_OK;
00389   }
00390 
00391   PRUint32 index, count;
00392 
00393   PRUint32* array1;
00394   rv = ct->Array1(&count, &array1);
00395   if (NS_FAILED(rv)) {
00396     aResult.AssignLiteral("WSPProxyTest: Failed to get value for attribute array1");
00397     return NS_OK;
00398   }
00399   for (index = 0; index < count; index++) {
00400     if (array1[index] != sArray1[index]) {
00401       aResult.AssignLiteral("WSPProxyTest: Value doesn't match for element of attribute array1");
00402       return NS_OK;
00403     }
00404   }
00405   nsMemory::Free(array1);
00406 
00407   double* array2;
00408   rv = ct->Array2(&count, &array2);
00409   if (NS_FAILED(rv)) {
00410     aResult.AssignLiteral("WSPProxyTest: Failed to get value for attribute array2");
00411     return NS_OK;
00412   }
00413   for (index = 0; index < count; index++) {
00414     if (array2[index] != sArray2[index]) {
00415       aResult.AssignLiteral("WSPProxyTest: Value doesn't match for element of attribute array2");
00416       return NS_OK;
00417     }
00418   }
00419   nsMemory::Free(array2);
00420 
00421   nsIWSPTestComplexType** array3;
00422   rv = ct->Array3(&count, &array3);
00423   if (NS_FAILED(rv)) {
00424     aResult.AssignLiteral("WSPProxyTest: Failed to get value for attribute array3");
00425     return NS_OK;
00426   }
00427   if (!array3[0] || array3[1]) {
00428     aResult.AssignLiteral("WSPProxyTest: Value doesn't match for element of attribute array3");
00429     return NS_OK;
00430   }
00431   NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, array3);
00432 
00433 #undef GET_AND_TEST
00434 
00435   aResult.AssignLiteral("WSPProxyTest: Test Succeeded!");
00436   return NS_OK;
00437 }
00438 
00439 /* void testIsPrimeProxy(nsIWSPProxyTestListener* aListener); */
00440 NS_IMETHODIMP
00441 WSPProxyTest::TestIsPrimeProxy(nsIWSPProxyTestListener* aListener)
00442 {
00443   mListener = aListener;
00444   nsCOMPtr<nsIWSDLLoader> loader = do_CreateInstance(NS_WSDLLOADER_CONTRACTID);
00445   if (!loader) {
00446     mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Couldn't create WSDL loader"));
00447     return NS_OK;
00448   }
00449   
00450 #define ISPRIMEURL "http://ray.dsl.xmission.com:8080/wsdl/statistics.wsdl"
00451 #define ISPRIMEPORT "SpheonJSAOPStatisticsPort"
00452   nsresult rv = loader->LoadAsync(NS_LITERAL_STRING(ISPRIMEURL),
00453                                   NS_LITERAL_STRING(ISPRIMEPORT),
00454                                   this);
00455   if (NS_FAILED(rv)) {
00456     mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Failed loading WSDL file"));
00457   }
00458   return NS_OK;
00459 }
00460 
00461 /* void onLoad (in nsIWSDLPort port); */
00462 NS_IMETHODIMP 
00463 WSPProxyTest::OnLoad(nsIWSDLPort *port)
00464 {
00465   nsresult rv;
00466   nsCOMPtr<nsIInterfaceInfoManager> manager = do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv);
00467   if (NS_FAILED(rv)) {
00468     mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Couldn't create interface info manager"));
00469     return NS_OK;
00470   }
00471 
00472   static nsIID sPortIID = NS_GET_IID(SpheonJSAOPStatisticsPortTypeAsync);
00473   nsCOMPtr<nsIInterfaceInfo> iinfo;
00474   rv = manager->GetInfoForIID(&sPortIID, getter_AddRefs(iinfo));
00475   if (NS_FAILED(rv)) {
00476     mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Couldn't find interface info for port"));
00477     return NS_OK;
00478   }
00479 
00480   nsCOMPtr<nsIWebServiceProxy> proxy(do_CreateInstance(NS_WEBSERVICEPROXY_CONTRACTID));
00481   if (!proxy) {
00482     mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Couldn't create proxy"));
00483     return NS_OK;    
00484   }
00485 
00486   proxy->Init(port, iinfo, manager, NS_LITERAL_STRING("foo"), PR_TRUE);
00487 
00488   mProxy = do_QueryInterface(proxy);
00489   if (!mProxy) {
00490     mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Couldn't QI proxy to isPrime interface"));
00491     return NS_OK;
00492   }
00493 
00494   mProxy->SetListener(this);
00495 
00496   nsCOMPtr<nsIWebServiceCallContext> context;
00497   rv = mProxy->IsPrimeNumber(5, getter_AddRefs(context));
00498   if (NS_FAILED(rv)) {
00499     mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Failed call to IsPrimeNumber"));
00500     return NS_OK;
00501   }
00502 
00503   return NS_OK;
00504 }
00505 
00506 /* void onError (in nsresult status, in AString statusMessage); */
00507 NS_IMETHODIMP 
00508 WSPProxyTest::OnError(nsresult status, const nsAString & statusMessage)
00509 {
00510   return NS_ERROR_NOT_IMPLEMENTED;
00511 }
00512 
00513 /* void onError (in nsIException error, in nsIWebServiceCallContext cx); */
00514 NS_IMETHODIMP WSPProxyTest::OnError(nsIException *error, nsIWebServiceCallContext *cx)
00515 {
00516   nsXPIDLCString str;
00517   error->ToString(getter_Copies(str));
00518   mListener->OnIsPrimeProxyTestComplete(NS_ConvertASCIItoUCS2(str.get()));
00519   return NS_OK;
00520 }
00521 
00522 /* void getStatisticsCallback (in statisticStruct retval, in nsIWebServiceCallContext cx); */
00523 NS_IMETHODIMP WSPProxyTest::GetStatisticsCallback(statisticStruct *retval, nsIWebServiceCallContext *cx)
00524 {
00525   if (!retval) {
00526     mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Incorrect value returned from IsPrimeNumber"));
00527   }
00528   else {
00529     double average;
00530     retval->GetAverage(&average);
00531     if (average != 2.725) {
00532       mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Incorrect value returned from IsPrimeNumber"));
00533     }
00534     else {
00535       mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Test Succeeded!"));
00536     }
00537   }
00538 
00539   return NS_OK;
00540 }
00541 
00542 /* void isPrimeNumberCallback (in boolean retval, in nsIWebServiceCallContext cx); */
00543 NS_IMETHODIMP WSPProxyTest::IsPrimeNumberCallback(PRBool retval, nsIWebServiceCallContext *cx)
00544 {
00545   if (!retval) {
00546     mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Incorrect value returned from IsPrimeNumber"));
00547   }
00548   else {
00549     // Success!!
00550     mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Test Succeeded!"));
00551 #if 0
00552     static double vals[4] = { 1.7, 3.4, 5.6, 0.2 };
00553     nsCOMPtr<nsIWebServiceCallContext> context;
00554     nsresult rv = mProxy->GetStatistics(sizeof(vals)/sizeof(double), vals, 
00555                                         getter_AddRefs(context));
00556     if (NS_FAILED(rv)) {
00557       mListener->OnIsPrimeProxyTestComplete(NS_LITERAL_STRING("Failed call to GetStatistics"));
00558     }
00559 #endif
00560   }
00561 
00562   return NS_OK;
00563 }
00564 
00565 /* void crossSumCallback (in PRInt32 retval, in nsIWebServiceCallContext cx); */
00566 NS_IMETHODIMP WSPProxyTest::CrossSumCallback(PRInt32 retval, nsIWebServiceCallContext *cx)
00567 {
00568     return NS_ERROR_NOT_IMPLEMENTED;
00569 }
00570 
00572 //
00573 // Implementation of WSPTestComplexType
00574 //
00576 WSPTestComplexType::WSPTestComplexType()
00577 {
00578 }
00579 
00580 WSPTestComplexType::~WSPTestComplexType()
00581 {
00582 }
00583 
00584 NS_IMPL_ISUPPORTS1(WSPTestComplexType, nsIWSPTestComplexType)
00585 
00586 /* readonly attribute PRUint8 i8; */
00587 NS_IMETHODIMP 
00588 WSPTestComplexType::GetI8(PRUint8 *aI8)
00589 {
00590   *aI8 = sInt8Val;
00591   return NS_OK;
00592 }
00593 
00594 /* readonly attribute PRInt16 i16; */
00595 NS_IMETHODIMP 
00596 WSPTestComplexType::GetI16(PRInt16 *aI16)
00597 {
00598   *aI16 = sInt16Val;
00599   return NS_OK;
00600 }
00601 
00602 /* readonly attribute PRInt32 i32; */
00603 NS_IMETHODIMP 
00604 WSPTestComplexType::GetI32(PRInt32 *aI32)
00605 {
00606   *aI32 = sInt32Val;
00607   return NS_OK;
00608 }
00609 
00610 /* readonly attribute PRInt64 i64; */
00611 NS_IMETHODIMP 
00612 WSPTestComplexType::GetI64(PRInt64 *aI64)
00613 {
00614   *aI64 = sInt64Val;
00615   return NS_OK;
00616 }
00617 
00618 /* readonly attribute PRUint8 u8; */
00619 NS_IMETHODIMP 
00620 WSPTestComplexType::GetU8(PRUint8 *aU8)
00621 {
00622   *aU8 = sUint8Val;
00623   return NS_OK;
00624 }
00625 
00626 /* readonly attribute PRUint16 u16; */
00627 NS_IMETHODIMP 
00628 WSPTestComplexType::GetU16(PRUint16 *aU16)
00629 {
00630   *aU16 = sUint16Val;
00631   return NS_OK;
00632 }
00633 
00634 /* readonly attribute PRUint32 u32; */
00635 NS_IMETHODIMP 
00636 WSPTestComplexType::GetU32(PRUint32 *aU32)
00637 {
00638   *aU32 = sUint32Val;
00639   return NS_OK;
00640 }
00641 
00642 /* readonly attribute PRUint64 u64; */
00643 NS_IMETHODIMP 
00644 WSPTestComplexType::GetU64(PRUint64 *aU64)
00645 {
00646   *aU64 = sUint64Val;
00647   return NS_OK;
00648 }
00649 
00650 /* readonly attribute PRBool b; */
00651 NS_IMETHODIMP 
00652 WSPTestComplexType::GetB(PRBool *aB)
00653 {
00654   *aB = sBoolVal;
00655   return NS_OK;
00656 }
00657 
00658 /* readonly attribute float f; */
00659 NS_IMETHODIMP 
00660 WSPTestComplexType::GetF(float *aF)
00661 {
00662   *aF = sFloatVal;
00663   return NS_OK;
00664 }
00665 
00666 /* readonly attribute double d; */
00667 NS_IMETHODIMP 
00668 WSPTestComplexType::GetD(double *aD)
00669 {
00670   *aD = sDoubleVal;
00671   return NS_OK;
00672 }
00673 
00674 /* readonly attribute char c */
00675 NS_IMETHODIMP
00676 WSPTestComplexType::GetC(char *aC)
00677 {
00678   *aC = sCharVal;
00679   return NS_OK;
00680 }
00681 
00682 /* readonly attribute wchar wc */
00683 NS_IMETHODIMP
00684 WSPTestComplexType::GetWc(PRUnichar *aWC)
00685 {
00686   *aWC = sWcharVal;
00687   return NS_OK;
00688 }
00689 
00690 /* readonly attribute nsIWSPTestComplexType p; */
00691 NS_IMETHODIMP 
00692 WSPTestComplexType::GetP(nsIWSPTestComplexType * *aP)
00693 {
00694   WSPTestComplexType* inst = new WSPTestComplexType();
00695   if (!inst) {
00696     return NS_ERROR_OUT_OF_MEMORY;
00697   }
00698   *aP = inst;
00699   NS_ADDREF(*aP);
00700   return NS_OK;
00701 }
00702 
00703 /* readonly attribute nsIWSPTestComplexType p2; */
00704 NS_IMETHODIMP 
00705 WSPTestComplexType::GetP2(nsIWSPTestComplexType * *aP2)
00706 {
00707   *aP2 = nsnull;
00708   return NS_OK;
00709 }
00710 
00711 /* readonly attribute AString s; */
00712 NS_IMETHODIMP 
00713 WSPTestComplexType::GetS(nsAString & aS)
00714 {
00715   aS.AssignLiteral(STRING_VAL);
00716   return NS_OK;
00717 }
00718 
00719 /* void array1 (out PRUint32 length, [array, size_is (length), retval] out PRUint32 array1); */
00720 NS_IMETHODIMP 
00721 WSPTestComplexType::Array1(PRUint32 *length, PRUint32 **array1)
00722 {
00723   PRUint32* ptr = (PRUint32*)nsMemory::Alloc(sArray1Length * sizeof(PRUint32));
00724   if (!ptr) {
00725     return NS_ERROR_OUT_OF_MEMORY;
00726   }
00727   PRUint32 index;
00728   for (index = 0; index < sArray1Length; index++) {
00729     ptr[index] = sArray1[index];
00730   }
00731   
00732   *length = sArray1Length;
00733   *array1 = ptr;
00734 
00735   return NS_OK;
00736 }
00737 
00738 /* void array2 (out PRUint32 length, [array, size_is (length), retval] out double array2); */
00739 NS_IMETHODIMP 
00740 WSPTestComplexType::Array2(PRUint32 *length, double **array2)
00741 {
00742   double* ptr = (double*)nsMemory::Alloc(sArray2Length * sizeof(double));
00743   if (!ptr) {
00744     return NS_ERROR_OUT_OF_MEMORY;
00745   }
00746   PRUint32 index;
00747   for (index = 0; index < sArray2Length; index++) {
00748     ptr[index] = sArray2[index];
00749   }
00750   
00751   *length = sArray2Length;
00752   *array2 = ptr;
00753 
00754   return NS_OK;
00755 }
00756 
00757 /* void array3 (out PRUint32 length, [array, size_is (length), retval] out nsIWSPTestComplexType array3); */
00758 NS_IMETHODIMP 
00759 WSPTestComplexType::Array3(PRUint32 *length, nsIWSPTestComplexType ***array3)
00760 {
00761   nsIWSPTestComplexType** ptr = (nsIWSPTestComplexType**)nsMemory::Alloc(2 * 
00762                                                          sizeof(nsISupports*));
00763   if (!ptr) {
00764     return NS_ERROR_OUT_OF_MEMORY;
00765   }
00766   WSPTestComplexType* inst = new WSPTestComplexType();
00767   if (!inst) {
00768     nsMemory::Free((void *) ptr);
00769     return NS_ERROR_OUT_OF_MEMORY;
00770   }
00771   ptr[0] = inst;
00772   NS_ADDREF(ptr[0]);
00773   ptr[1] = nsnull;
00774 
00775   *length = 2;
00776   *array3 = ptr;
00777   
00778   return NS_OK;
00779 }