You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by pr...@apache.org on 2006/01/18 16:49:12 UTC

svn commit: r370170 - in /webservices/axis/trunk/c/tests/auto_build/testcases/client/cpp: CalculatorClient.cpp FaultMappingClient.cpp

Author: prestonf
Date: Wed Jan 18 07:49:07 2006
New Revision: 370170

URL: http://svn.apache.org/viewcvs?rev=370170&view=rev
Log:
Tidy files to make them easier to read and remove warnings.

Added:
    webservices/axis/trunk/c/tests/auto_build/testcases/client/cpp/CalculatorClient.cpp
Modified:
    webservices/axis/trunk/c/tests/auto_build/testcases/client/cpp/FaultMappingClient.cpp

Added: webservices/axis/trunk/c/tests/auto_build/testcases/client/cpp/CalculatorClient.cpp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/auto_build/testcases/client/cpp/CalculatorClient.cpp?rev=370170&view=auto
==============================================================================
--- webservices/axis/trunk/c/tests/auto_build/testcases/client/cpp/CalculatorClient.cpp (added)
+++ webservices/axis/trunk/c/tests/auto_build/testcases/client/cpp/CalculatorClient.cpp Wed Jan 18 07:49:07 2006
@@ -0,0 +1,150 @@
+// Copyright 2003-2004 The Apache Software Foundation.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// 
+//        http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Calculator.hpp"
+#include <axis/AxisException.hpp>
+#include <iostream>
+
+bool IsNumber( const char *p);
+
+static void usage( char * programName, char * defaultURL)
+{
+    cout << "\nUsage:\n"
+	<< programName << " [-? | div number1 number2 [service_url]]\n"
+	<< "    -?             Show this help.\n"
+	<< "    service_url    URL of the service.\n"
+	<< "    Default service URL is assumed to be " << defaultURL << endl;
+}
+
+int main( int argc, char * argv[])
+{
+    char *	pszURL = "http://localhost/axis/calculator";
+
+    // Set default service URL
+
+    try
+    {
+		if( argc == 1)
+		{
+			usage( argv[0], pszURL);
+	    
+			return 2;
+		}
+
+		if( argc > 1)
+		{
+			if( argv[1] == "-")
+			{
+// Check for - only so that it works for -?, -h or --help; -anything 
+
+				usage( argv[0], pszURL);
+		
+				return 2;
+			}
+
+// Less than minimum number of args OR greater than maximum number of args
+			else if( argc < 4 || argc > 5)
+			{
+				usage( argv[0], pszURL);
+			
+				return 2;
+			}
+			else if( argc == 5)
+			{
+				pszURL = argv[4];
+			}
+		}
+
+		cout << endl << " Using service at " << pszURL << endl << endl;
+	
+		Calculator ws( pszURL);
+
+		char *	pszOperation = argv[1];
+		char *	pValue1 = argv[2];
+		char *	pValue2 = argv[3];
+
+		if( !IsNumber( pValue1))
+		{
+			cout << "Invalid value for first <parameter> " << pValue1 << endl << endl;
+
+            usage( argv[0], pszURL);
+	    
+			return 2;
+		}
+
+		if( !IsNumber( pValue2))
+		{
+			cout << "Invalid value for second <parameter> " << pValue2 << endl << endl;
+
+            usage( argv[0], pszURL);
+	    
+			return 2;
+		}
+
+		int	iValue1 = atoi( pValue1);
+		int	iValue2 = atoi( pValue2);
+
+		if( strcmp( pszOperation, "add") == 0)
+		{
+		    cout << ws.add( iValue1, iValue2) << endl;
+		}
+		else if( strcmp( pszOperation, "sub") == 0)
+		{
+		    cout << ws.sub( iValue1, iValue2) << endl;
+		}
+		else if( strcmp( pszOperation, "mul") == 0)
+		{
+		    cout << ws.mul( iValue1, iValue2) << endl;
+		}
+		else if( strcmp( pszOperation, "div") == 0)
+		{
+		    cout << ws.div( iValue1, iValue2) << endl;
+		}
+		else
+		{
+		    cout << "Invalid operation " << pszOperation << endl << endl;
+
+			usage( argv[0], pszURL);
+
+			return 2;
+		}
+    }
+    catch (AxisException & e)
+    {
+		cout << "Exception : " << e.what () << endl;
+    }
+    catch (exception & e)
+    {
+		cout << "Unknown exception has occurred : " << e.what () << endl;
+    }
+    catch (...)
+    {
+		cout << "Unknown exception has occurred" << endl;
+    }
+
+    return 0;
+}
+
+bool IsNumber( const char * p)
+{
+    for( int x = 0; x < (int) strlen( p); x++)
+    {
+		if( !isdigit( p[x]))
+		{
+			return false;
+		}
+    }
+
+    return true;
+}

Modified: webservices/axis/trunk/c/tests/auto_build/testcases/client/cpp/FaultMappingClient.cpp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/tests/auto_build/testcases/client/cpp/FaultMappingClient.cpp?rev=370170&r1=370169&r2=370170&view=diff
==============================================================================
--- webservices/axis/trunk/c/tests/auto_build/testcases/client/cpp/FaultMappingClient.cpp (original)
+++ webservices/axis/trunk/c/tests/auto_build/testcases/client/cpp/FaultMappingClient.cpp Wed Jan 18 07:49:07 2006
@@ -22,139 +22,176 @@
 void sig_handler(int);
 using namespace std;
 
-int main(int argc, char* argv[])
+typedef struct
 {
-	char endpoint[256];
-	const char* server="localhost";
-	const char* url="http://localhost:80/axis/MathOps";
-	const char* port="80";
-	const char* op = 0;
-	const char* p1 = 0;
-	const char* p2 = 0;
-	int i1=0, i2=0;
-	int iResult;
-	char* pcDetail;
-
-	signal(SIGILL, sig_handler);
-	signal(SIGABRT, sig_handler);
-	signal(SIGSEGV, sig_handler);
-	//signal(SIGQUIT, sig_handler);
-	//signal(SIGBUS, sig_handler);
-	signal(SIGFPE, sig_handler);
+	int	iValue1;
+	int	iValue2;
+} MathOperationData;
 
-	url = argv[1];
+int main( int argc, char * argv[])
+{
+	char *				pszURL = "http://localhost:80/axis/MathOps";
+	const char *		pszOperation = NULL;
+	MathOperationData	sMathOperationData[] = {{  10,  5},
+												{  10,  0},
+												{1000,  5},
+												{  10, -5},
+												{   0,  0}};
+
+	signal( SIGILL,  sig_handler);
+	signal( SIGABRT, sig_handler);
+	signal( SIGSEGV, sig_handler);
+//  signal( SIGQUIT, sig_handler);
+//  signal( SIGBUS,  sig_handler);
+	signal( SIGFPE,  sig_handler);
 
-	sprintf(endpoint, "%s", url);
+	pszURL = argv[1];
 
-	op = "div";
+	pszOperation = "div";
 
-	if (strcmp(op, "div") == 0)
+	if( strcmp( pszOperation, "div") == 0)
 	{
-	    for(int i = 0; i < 4; i++)
+	    int	iMathDataCount = 0;
+
+		while( sMathOperationData[iMathDataCount].iValue1 != 0 &&
+			   sMathOperationData[iMathDataCount].iValue1 != sMathOperationData[iMathDataCount].iValue2)
 	    {
-            cout << i << endl;
+			bool bSuccess = false;
+			int	iRetryIterationCount = 3;
 
-			switch(i)
-			{
-				case 0: i1 = 10; i2 = 5; break;
-				case 1: i1 = 10; i2 = 0; break;
-				case 2: i1 = 1000; i2 = 5; break;
-				case 3: i1 = 10; i2 = -5; break;
-			}
-		bool bSuccess = false;
-		int	iRetryIterationCount = 3;
-
-		do
-		{
-			try
-			{
-				MathOps ws(endpoint);
-				if( iRetryIterationCount == 3)
-					cout << "Trying to " << op << " " << i1 << " by " << i2 << endl;
-				iResult = ws.div(i1, i2);		
-				cout << "Result is " << iResult << endl;
-				bSuccess = true;
-			}
-			catch(DivByZeroStruct& dbzs)
-			{
-				cout << "DivByZeroStruct Fault: \"" 
-					<< dbzs.varString 
-					<< "\", " 
-					<< dbzs.varInt 
-					<< ", " 
-					<< dbzs.varFloat 
-					<< endl; 
-				bSuccess = true;
-			}
-			catch(SpecialDetailStruct& sds)
-			{
-				cout << "SpecialDetailStruct Fault: \"" 
-					<< sds.varString 
-					<< "\"" 
-					<< endl;
-				bSuccess = true;
-			}
-			catch(OutOfBoundStruct& oobs)
-			{
-				cout << "OutOfBoundStruct Fault: \"" 
-					<< oobs.varString 
-					<< "\", " 
-					<< oobs.varInt 
-					<< ", \"" 
-					<< oobs.specialDetail->varString 
-					<< "\"" 
-					<< endl;
-				bSuccess = true;
-			}
-			catch(SoapFaultException& sfe)
-			{
-				cout << "SoapFaultException: " << sfe.what() << endl;
-			}
-			catch(AxisException& e)
-			{
-			bool bSilent = false;
+            cout << iMathDataCount << endl;
 
-			if( e.getExceptionCode() == CLIENT_TRANSPORT_OPEN_CONNECTION_FAILED)
+			do
 			{
-				if( iRetryIterationCount > 0)
+				try
+				{
+					MathOps	ws( pszURL);
+
+					if( iRetryIterationCount == 3)
+					{
+						cout << "Trying to "
+							 << pszOperation
+							 << " "
+							 << sMathOperationData[iMathDataCount].iValue1
+							 << " by "
+							 << sMathOperationData[iMathDataCount].iValue2
+							 << endl;
+					}
+
+// HTTP/1.1 500 Internal Server Error
+// :
+// <soapenv:Header/>
+// <faultcode xmlns:ns2144481696="http://soapinterop.org/types"
+//                         xmlns="">ns2144481696:DivByZeroStruct</faultcode>
+// <faultstring xmlns="">org.soapinterop.DivByZeroStruct</faultstring>
+// <detail xmlns="">
+// <faultstruct1 href="#id0"/>
+// </detail>
+// </soapenv:Fault>
+// <multiRef id="id0"
+//           soapenc:root="0"
+//           soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
+//           xsi:type="ns2144481696:DivByZeroStruct"
+//           xmlns:ns2144481696="http://soapinterop.org/types"
+//           xmlns="">
+// <varString xsi:type="xsd:string">Division by zero exception</varString>
+
+					int	iResult = ws.div( sMathOperationData[iMathDataCount].iValue1,
+										  sMathOperationData[iMathDataCount].iValue2);
+				
+					cout << "Result is " << iResult << endl;
+				
+					bSuccess = true;
+				}
+				catch( DivByZeroStruct& dbzs)
 				{
-					bSilent = true;
+					cout << "DivByZeroStruct Fault: \""
+						 << dbzs.varString
+						 << "\", "
+						 << dbzs.varInt
+						 << ", "
+						 << dbzs.varFloat
+						 << endl;
+
+					bSuccess = true;
 				}
-			}
-			else
-			{
-				iRetryIterationCount = 0;
-			}
+				catch( SpecialDetailStruct& sds)
+				{
+					cout << "SpecialDetailStruct Fault: \""
+						 << sds.varString
+						 << "\""
+						 << endl;
 
-            if( !bSilent)
-			{
-				cout << "Exception : " << e.what() << endl;
-			}
-			}
-			catch(exception& e)
-			{
-                cout << "Unknown Exception: " << endl;
-			}
-			catch(...)
-			{
-                cout << "Unspecified Exception: " << endl;
-			}
-		iRetryIterationCount--;
-		} while( iRetryIterationCount > 0 && !bSuccess);
+					bSuccess = true;
+				}
+				catch( OutOfBoundStruct& oobs)
+				{
+					cout << "OutOfBoundStruct Fault: \""
+						 << oobs.varString
+						 << "\", "
+						 << oobs.varInt
+						 << ", \""
+						 << oobs.specialDetail->varString
+						 << "\""
+						 << endl;
+
+					bSuccess = true;
+				}
+				catch( SoapFaultException& sfe)
+				{
+					cout << "SoapFaultException: " << sfe.what() << endl;
+				}
+				catch( AxisException& e)
+				{
+					bool bSilent = false;
+
+					if( e.getExceptionCode() == CLIENT_TRANSPORT_OPEN_CONNECTION_FAILED)
+					{
+						if( iRetryIterationCount > 1)
+						{
+							bSilent = true;
+						}
+					}
+					else
+					{
+						iRetryIterationCount = 0;
+					}
+
+		            if( !bSilent)
+					{
+						cout << "Exception : " << e.what() << endl;
+					}
+				}
+				catch( exception& e)
+				{
+		            cout << "Unknown Exception: " << e.what() << endl;
+				}
+				catch(...)
+				{
+		            cout << "Unspecified Exception: " << endl;
+				}
+
+				iRetryIterationCount--;
+			} while( iRetryIterationCount > 0 && !bSuccess);
+
+			iMathDataCount++;
 	    }
 	}
 	else 
 	{
-		cout << "Invalid operation " << op << endl;
+		cout << "Invalid operation " << pszOperation << endl;
 	}
-	cout << "---------------------- TEST COMPLETE -----------------------------"<< endl;
+
+	cout << "---------------------- TEST COMPLETE -----------------------------" << endl;
 	
 	return 0;
 }
 
-void sig_handler(int sig) {
-	signal(sig, sig_handler);
+void sig_handler( int sig)
+{
+	signal( sig, sig_handler);
+
     cout << "SIGNAL RECEIVED " << sig << endl;
-	exit(1);
-}
 
+	exit(1);
+}
\ No newline at end of file