You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ja...@apache.org on 2005/03/09 04:24:47 UTC
cvs commit: ws-axis/c/tests/auto_build/testcases/client/cpp ExceptionTestDoc_TTestClient.cpp RecurseTypes_TTestClient.cpp MathOpsDoc_TTestClient.cpp ManyTypeRefRoot_TTestClient.cpp SimpleArrayDoc_TTestClient.cpp LargeReturningString_TTestClient.cpp FaultMappingDoc_TTestClient.cpp
jamejose 2005/03/08 19:24:47
Added: c/tests/auto_build/testcases/client/cpp
ExceptionTestDoc_TTestClient.cpp
RecurseTypes_TTestClient.cpp
MathOpsDoc_TTestClient.cpp
ManyTypeRefRoot_TTestClient.cpp
SimpleArrayDoc_TTestClient.cpp
LargeReturningString_TTestClient.cpp
FaultMappingDoc_TTestClient.cpp
Log:
Revision Changes Path
1.1 ws-axis/c/tests/auto_build/testcases/client/cpp/ExceptionTestDoc_TTestClient.cpp
Index: ExceptionTestDoc_TTestClient.cpp
===================================================================
/* This program will create 10 Threads and each thread will invoke ExceptionTest Service
@Author James
*/
#include "MathOps.hpp"
#include <axis/AxisException.hpp>
//#include <exception>
#include <ctype.h>
#include <iostream>
#include <stdlib.h>
#include <axis/Axis.hpp>
#include <signal.h>
/* Defining platform specific constants */
#ifdef WIN32
#include <windows.h>
#define RETTYPE DWORD WINAPI
#define ARGTYPE LPVOID
#else
#include <pthread.h>
#include <unistd.h>
#define RETTYPE void*
#define ARGTYPE void*
#endif
//#define MACRO_NUM_THREADS 10
//int NUM_THREADS = MACRO_NUM_THREADS;
#define NUM_THREADS 10
void sig_handler(int);
/* In windows the entry point function return type is DWORD WINAPI
In linux it is void * */
RETTYPE ThreadFunc(ARGTYPE Param)
{
/*Type casting the url to char * */
char *p=(char *)Param;
char endpoint[256];
const char* server="localhost";
const char* port="80";
const char* url="http://localhost:80/ExceptionTest/services/MathOps";
if(p!=NULL)
url=p;
const char* op = 0;
char* p1 = 0;
const char* p2 = 0;
int p3 = 0;
int i1=0, i2=0;
int iResult;
char* pcDetail;
signal(SIGILL, sig_handler);
signal(SIGABRT, sig_handler);
signal(SIGSEGV, sig_handler);
signal(SIGFPE, sig_handler);
op = "div";
i1 = 10;
i2 = 5;
if (strcmp(op, "div") == 0)
{
for(p3 = 0; p3 < 3; p3++)
{
try
{
switch(p3)
{
case 0:
/* Sends a normal request. the result should be the division of
* two numbers the user has provided
*/
//sprintf(endpoint, "http://%s:%s/axis/MathOps", server, port);
sprintf(endpoint, "%s", url);
break;
case 1:
/* Service name is missing. The message
* Exception : AxisSoapException:Soap action is empty
* should be returned to the user.
*/
//sprintf(endpoint, "http://%s:%s/axis", server, port);
sprintf(endpoint, "%s", url);
p1 = strrchr(endpoint, '/');
*p1 = (char)NULL; // Set a NULL at the last '/' char to strip the service endpoint interface
break;
case 2:
/* Service name is wrong. The message
* Exception : AxisWsddException:Requested service not found
* should be returned to the user.
*/
//sprintf(endpoint, "http://%s:%s/axis/Math", server, port);
sprintf(endpoint, "%s", url);
p1 = endpoint + (strlen(endpoint) - 3);
*p1 = (char)NULL; // Set a NULL to strip the last 3 chars
break;
case 3:
/* Service path is empty. The message
* The corresponding http fail message
* should be returned to the user.
*/
/*sprintf(endpoint, "http://%s:%s/", server, port);*/
cout << "This test has been temporarily terminated"
<< " due to an unresolved bug"<< endl;
exit(0); /* This is temporary code*/
break;
case 4:
/* Exception : AxisTransportException:Unexpected string
* received. Most probably server returned an empty stream
*/
sprintf(endpoint, "", server, port);
//sprintf(endpoint, "http://%s:%s", server, port);
break;
default:
cout << "Invalid option for the last parameter"<<endl<<endl;
return 0;
}
//sprintf(endpoint, "http://%s:%s/axis/MathOps", server, port);
MathOps ws(endpoint);
iResult = ws.div(i1, i2);
//cout << "Result is:" << iResult << endl;
}
catch(AxisException& e)
{
// cout << "AxisException has occured: " << e.what()<<endl;
if(p3==2)
cout << "Success" << endl;
}
catch(exception& e)
{
cout << "Unknown exception has occured"<< endl;
}
catch(...)
{
cout << "Unspecified exception has occured" << endl;
}
}
}
else
{
cout << "Invalid operation " << op <<endl<<endl;
//PrintUsage();
}
#ifndef WIN32
pthread_exit(0);
#endif
return 0;
}
int main(int argc, char *argv[])
{
Axis::initialize(false);
try{
int i;
#ifdef WIN32
/*Windows specific code comes here */
HANDLE hThread[NUM_THREADS];
for(i=0;i<NUM_THREADS;i++){
DWORD dwThreadId;
//LPVOID dwThrdParam = LPVOID(argv[1]);
hThread[i] = CreateThread(
NULL, // no security attributes
0, // use default stack size
ThreadFunc, // thread function
LPVOID(argv[1]), // argument to thread function
0,
&dwThreadId); // returns the thread identifier
if (hThread[i] == NULL)
{
cout<<"Thread creation Failed";
}
}
/* Waiting for threads to terminate */
WaitForMultipleObjects(NUM_THREADS,hThread,true, INFINITE);
for(i=0;i<NUM_THREADS;i++)
CloseHandle( hThread[i] );
#else
pthread_t thread[NUM_THREADS];
pthread_attr_t attr;
int rc, t, status = 0;
// Initialize and set thread detached attribute
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for (t = 0; t < NUM_THREADS; t++)
{
/*Creating threads */
rc = pthread_create(&thread[t], &attr, ThreadFunc,(void *)argv[1]);
if (rc)
{
cout<<"Thread Creation Failed";
}
}
//Free attribute and wait for the other threads
pthread_attr_destroy(&attr);
/* Wait for the threads to terminate */
for(t=0;t<NUM_THREADS;t++){
rc = pthread_join(thread[t], (void **)&status);
if (rc)
{
cout<<"ERROR from pthread_join()"<<endl;
}
}
#endif
}catch(exception &e){
cout<< e.what();
}
cout<<endl<<"----------------------------------TEST COMPLETE--------------------------------"<<endl;
}
void sig_handler(int sig) {
signal(sig, sig_handler);
cout << "SIGNAL RECEIVED " << sig << endl;
exit(1);
}
1.1 ws-axis/c/tests/auto_build/testcases/client/cpp/RecurseTypes_TTestClient.cpp
Index: RecurseTypes_TTestClient.cpp
===================================================================
/* This program will create 10 Threads and each thread will invoke RecurseTypes Service
@Author James
*/
#include "RecurseTypesWS.hpp"
#include <axis/AxisException.hpp>
#include <exception>
#include <ctype.h>
#include <iostream>
#include <stdlib.h>
#include <axis/Axis.hpp>
/* Defining platform specific constants */
#ifdef WIN32
#include <windows.h>
#define RETTYPE DWORD WINAPI
#define ARGTYPE LPVOID
#else
#include <pthread.h>
#include <unistd.h>
#define RETTYPE void*
#define ARGTYPE void*
#endif
//#define MACRO_NUM_THREADS 10
//int NUM_THREADS = MACRO_NUM_THREADS;
#define NUM_THREADS 10
/* In windows the entry point function return type is DWORD WINAPI
In linux it is void * */
RETTYPE ThreadFunc(ARGTYPE Param)
{
/*Type casting the url to char * */
char *p=(char *)Param;
char endpoint[256];
const char* url="http://puppet.in.ibm.com:9060/Calculator/services/Calculator";
if(p!=NULL)
url=p;
RecurseTypesWS *ws;
try
{
sprintf(endpoint, "%s", url);
ws = new RecurseTypesWS(endpoint, APTHTTP1_1);
Kind inputAtt,*outputAtt;
Type1 *input,*output,*pTemp;
int i;
input = new Type1 ();
input->att_kind = Kind_CHEQUE;
input->kind = "Check In";
input->followings.m_Array = new Type1[10];
input->followings.m_Size = 10;
pTemp = input->followings.m_Array;
for ( i = 0; i < 10; i++ ) {
pTemp->kind = "Sample";
pTemp++;
}
output = ws->getInput(input);
if ( output == NULL )
cout << "Invoke failed" << endl;
else {
cout<<output->att_kind << endl;
}
}catch(AxisException& e)
{
cout << "Exception : " << e.what() << endl;
}
catch(exception& e)
{
cout << "Unknown exception has occured" << endl;
}
catch(...)
{
cout << "Unknown exception has occured" << endl;
}
#ifndef WIN32
pthread_exit(0);
#endif
return 0;
}
int main(int argc, char *argv[])
{
Axis::initialize(false);
try{
int i;
#ifdef WIN32
/*Windows specific code comes here */
HANDLE hThread[NUM_THREADS];
for(i=0;i<NUM_THREADS;i++){
DWORD dwThreadId;
//LPVOID dwThrdParam = LPVOID(argv[1]);
hThread[i] = CreateThread(
NULL, // no security attributes
0, // use default stack size
ThreadFunc, // thread function
LPVOID(argv[1]), // argument to thread function
0,
&dwThreadId); // returns the thread identifier
if (hThread[i] == NULL)
{
cout<<"Thread creation Failed";
}
}
/* Waiting for threads to terminate */
WaitForMultipleObjects(NUM_THREADS,hThread,true, INFINITE);
for(i=0;i<NUM_THREADS;i++)
CloseHandle( hThread[i] );
#else
pthread_t thread[NUM_THREADS];
pthread_attr_t attr;
int rc, t, status = 0;
// Initialize and set thread detached attribute
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for (t = 0; t < NUM_THREADS; t++)
{
/*Creating threads */
rc = pthread_create(&thread[t], &attr, ThreadFunc,(void *)argv[1]);
if (rc)
{
cout<<"Thread Creation Failed";
}
}
//Free attribute and wait for the other threads
pthread_attr_destroy(&attr);
/* Wait for the threads to terminate */
for(t=0;t<NUM_THREADS;t++){
rc = pthread_join(thread[t], (void **)&status);
if (rc)
{
cout<<"ERROR from pthread_join()"<<endl;
}
}
#endif
}catch(exception &e){
cout<< e.what();
}
cout<<"----------------------------------TEST COMPLETE--------------------------------"<<endl;
}
1.1 ws-axis/c/tests/auto_build/testcases/client/cpp/MathOpsDoc_TTestClient.cpp
Index: MathOpsDoc_TTestClient.cpp
===================================================================
/* This program will create 10 Threads and each thread will invoke MathOps Service
@Author James
*/
#include "MathOps.hpp"
#include <axis/AxisException.hpp>
#include <exception>
#include <ctype.h>
#include <iostream>
#include <stdlib.h>
#include <axis/Axis.hpp>
/* Defining platform specific constants */
#ifdef WIN32
#include <windows.h>
#define RETTYPE DWORD WINAPI
#define ARGTYPE LPVOID
#else
#include <pthread.h>
#include <unistd.h>
#define RETTYPE void*
#define ARGTYPE void*
#endif
//#define MACRO_NUM_THREADS 10
//int NUM_THREADS = MACRO_NUM_THREADS;
#define NUM_THREADS 10
/* In windows the entry point function return type is DWORD WINAPI
In linux it is void * */
RETTYPE ThreadFunc(ARGTYPE Param)
{
/*Type casting the url to char * */
char *p=(char *)Param;
char endpoint[256];
const char* url="http://localhost:80/axis/MathOps";
if(p!=NULL)
url=p;
const char* op = 0;
const char* p1 = 0;
const char* p2 = 0;
int i1=0, i2=0;
int iResult;
try
{
sprintf(endpoint, "%s", url);
MathOps ws(endpoint);
op = "div";/*Operation name*/
i1 = 10;/*First parameter*/
i2 = 5;/*Second parameter*/
if (strcmp(op, "div") == 0)
{
iResult = ws.div(i1, i2);
cout << iResult;
}
else
{
cout << "Invalid operation "<< op<< endl<<endl;
}
}catch(AxisException& e)
{
cout << "Exception : " << e.what() << endl;
}
catch(exception& e)
{
cout << "Unknown exception has occured" << endl;
}
catch(...)
{
cout << "Unknown exception has occured" << endl;
}
#ifndef WIN32
pthread_exit(0);
#endif
return 0;
}
int main(int argc, char *argv[])
{
Axis::initialize(false);
try{
int i;
#ifdef WIN32
/*Windows specific code comes here */
HANDLE hThread[NUM_THREADS];
for(i=0;i<NUM_THREADS;i++){
DWORD dwThreadId;
//LPVOID dwThrdParam = LPVOID(argv[1]);
hThread[i] = CreateThread(
NULL, // no security attributes
0, // use default stack size
ThreadFunc, // thread function
LPVOID(argv[1]), // argument to thread function
0,
&dwThreadId); // returns the thread identifier
if (hThread[i] == NULL)
{
cout<<"Thread creation Failed";
}
}
/* Waiting for threads to terminate */
WaitForMultipleObjects(NUM_THREADS,hThread,true, INFINITE);
for(i=0;i<NUM_THREADS;i++)
CloseHandle( hThread[i] );
#else
pthread_t thread[NUM_THREADS];
pthread_attr_t attr;
int rc, t, status = 0;
// Initialize and set thread detached attribute
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for (t = 0; t < NUM_THREADS; t++)
{
/*Creating threads */
rc = pthread_create(&thread[t], &attr, ThreadFunc,(void *)argv[1]);
if (rc)
{
cout<<"Thread Creation Failed";
}
}
//Free attribute and wait for the other threads
pthread_attr_destroy(&attr);
/* Wait for the threads to terminate */
for(t=0;t<NUM_THREADS;t++){
rc = pthread_join(thread[t], (void **)&status);
if (rc)
{
cout<<"ERROR from pthread_join()"<<endl;
}
}
#endif
}catch(exception &e){
cout<< e.what();
}
cout<<endl<<"----------------------------------TEST COMPLETE--------------------------------"<<endl;
}
1.1 ws-axis/c/tests/auto_build/testcases/client/cpp/ManyTypeRefRoot_TTestClient.cpp
Index: ManyTypeRefRoot_TTestClient.cpp
===================================================================
/* This program will create 10 Threads and each thread will invoke ManyTypeRefRoot Service
@Author James
*/
#include "ManyTypeRefRoot.hpp"
#include <axis/AxisException.hpp>
#include <exception>
#include <ctype.h>
#include <iostream>
#include <stdlib.h>
#include <axis/Axis.hpp>
/* Defining platform specific constants */
#ifdef WIN32
#include <windows.h>
#define RETTYPE DWORD WINAPI
#define ARGTYPE LPVOID
#else
#include <pthread.h>
#include <unistd.h>
#define RETTYPE void*
#define ARGTYPE void*
#endif
//#define MACRO_NUM_THREADS 10
//int NUM_THREADS = MACRO_NUM_THREADS;
#define NUM_THREADS 10
/* In windows the entry point function return type is DWORD WINAPI
In linux it is void * */
RETTYPE ThreadFunc(ARGTYPE Param)
{
/*Type casting the url to char * */
char *p=(char *)Param;
char endpoint[256];
const char* url="http://puppet.in.ibm.com:9060/ManyTypeRefRoot/services/sampleWS";
if(p!=NULL)
url=p;
try
{
sprintf(endpoint, "%s", url);
ManyTypeRefRoot *ws=new ManyTypeRefRoot(endpoint, APTHTTP1_1);
Type1_Array input;
Type1_Array result;
Type1 types[10];
Type1* current;
int i;
for ( i = 0; i < 10; i++ ) {
current = new Type1 ();
current->kind = "Test type";
current->index = i;
types[i] = *current;
}
input.m_Array = types;
input.m_Size = 10;
result = ws->getInput(input);
Type1 *arrayResult = result.m_Array;
//for ( i = 0; i < 10; i++, arrayResult++ ) {
cout << arrayResult->index << " : " << arrayResult->kind << endl;
//}
}catch(AxisException& e)
{
cout << "Exception : " << e.what() << endl;
}
catch(exception& e)
{
cout << "Unknown exception has occured" << endl;
}
catch(...)
{
cout << "Unknown exception has occured" << endl;
}
#ifndef WIN32
pthread_exit(0);
#endif
return 0;
}
int main(int argc, char *argv[])
{
Axis::initialize(false);
try{
int i;
#ifdef WIN32
/*Windows specific code comes here */
HANDLE hThread[NUM_THREADS];
for(i=0;i<NUM_THREADS;i++){
DWORD dwThreadId;
//LPVOID dwThrdParam = LPVOID(argv[1]);
hThread[i] = CreateThread(
NULL, // no security attributes
0, // use default stack size
ThreadFunc, // thread function
LPVOID(argv[1]), // argument to thread function
0,
&dwThreadId); // returns the thread identifier
if (hThread[i] == NULL)
{
cout<<"Thread creation Failed";
}
}
/* Waiting for threads to terminate */
WaitForMultipleObjects(NUM_THREADS,hThread,true, INFINITE);
for(i=0;i<NUM_THREADS;i++)
CloseHandle( hThread[i] );
#else
pthread_t thread[NUM_THREADS];
pthread_attr_t attr;
int rc, t, status = 0;
// Initialize and set thread detached attribute
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for (t = 0; t < NUM_THREADS; t++)
{
/*Creating threads */
rc = pthread_create(&thread[t], &attr, ThreadFunc,(void *)argv[1]);
if (rc)
{
cout<<"Thread Creation Failed";
}
}
//Free attribute and wait for the other threads
pthread_attr_destroy(&attr);
/* Wait for the threads to terminate */
for(t=0;t<NUM_THREADS;t++){
rc = pthread_join(thread[t], (void **)&status);
if (rc)
{
cout<<"ERROR from pthread_join()"<<endl;
}
}
#endif
}catch(exception &e){
cout<< e.what();
}
cout<<"----------------------------------TEST COMPLETE--------------------------------"<<endl;
}
1.1 ws-axis/c/tests/auto_build/testcases/client/cpp/SimpleArrayDoc_TTestClient.cpp
Index: SimpleArrayDoc_TTestClient.cpp
===================================================================
/* This program will create 10 Threads and each thread will invoke SimpleArrayDoc Service
@Author James
*/
#include "ArrayTestPortType.hpp"
#include <axis/AxisException.hpp>
#include <exception>
#include <ctype.h>
#include <iostream>
#include <stdlib.h>
#include <axis/Axis.hpp>
/* Defining platform specific constants */
#ifdef WIN32
#include <windows.h>
#define RETTYPE DWORD WINAPI
#define ARGTYPE LPVOID
#else
#include <pthread.h>
#include <unistd.h>
#define RETTYPE void*
#define ARGTYPE void*
#endif
//#define MACRO_NUM_THREADS 10
//int NUM_THREADS = MACRO_NUM_THREADS;
#define NUM_THREADS 10
#define ARRAYSIZE 2
/* In windows the entry point function return type is DWORD WINAPI
In linux it is void * */
RETTYPE ThreadFunc(ARGTYPE Param)
{
/*Type casting the url to char * */
char *p=(char *)Param;
char endpoint[256];
int x;
const char* url="http://puppet.in.ibm.com:9060/Calculator/services/Calculator";
if(p!=NULL)
url=p;
try
{
sprintf(endpoint, "%s", url);
ArrayTestPortType ws(endpoint);
//testing echoIntArray
IntArrayType arrin;
arrin.intItem.m_Array = new int[ARRAYSIZE];
arrin.intItem.m_Size = ARRAYSIZE;
for (x=0;x<ARRAYSIZE;x++)
{
arrin.intItem.m_Array[x] = x;
}
if (ws.echoIntArray(&arrin)->intItem.m_Array != NULL)
cout << "successful "<<endl;
else
cout << "failed "<<endl;
}catch(AxisException& e)
{
cout << "Exception : " << e.what() << endl;
}
catch(exception& e)
{
cout << "Unknown exception has occured" << endl;
}
catch(...)
{
cout << "Unknown exception has occured" << endl;
}
#ifndef WIN32
pthread_exit(0);
#endif
return 0;
}
int main(int argc, char *argv[])
{
Axis::initialize(false);
try{
int i;
#ifdef WIN32
/*Windows specific code comes here */
HANDLE hThread[NUM_THREADS];
for(i=0;i<NUM_THREADS;i++){
DWORD dwThreadId;
//LPVOID dwThrdParam = LPVOID(argv[1]);
hThread[i] = CreateThread(
NULL, // no security attributes
0, // use default stack size
ThreadFunc, // thread function
LPVOID(argv[1]), // argument to thread function
0,
&dwThreadId); // returns the thread identifier
if (hThread[i] == NULL)
{
cout<<"Thread creation Failed";
}
}
/* Waiting for threads to terminate */
WaitForMultipleObjects(NUM_THREADS,hThread,true, INFINITE);
for(i=0;i<NUM_THREADS;i++)
CloseHandle( hThread[i] );
#else
pthread_t thread[NUM_THREADS];
pthread_attr_t attr;
int rc, t, status = 0;
// Initialize and set thread detached attribute
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for (t = 0; t < NUM_THREADS; t++)
{
/*Creating threads */
rc = pthread_create(&thread[t], &attr, ThreadFunc,(void *)argv[1]);
if (rc)
{
cout<<"Thread Creation Failed";
}
}
//Free attribute and wait for the other threads
pthread_attr_destroy(&attr);
/* Wait for the threads to terminate */
for(t=0;t<NUM_THREADS;t++){
rc = pthread_join(thread[t], (void **)&status);
if (rc)
{
cout<<"ERROR from pthread_join()"<<endl;
}
}
#endif
}catch(exception &e){
cout<< e.what();
}
cout<<"----------------------------------TEST COMPLETE--------------------------------"<<endl;
}
1.1 ws-axis/c/tests/auto_build/testcases/client/cpp/LargeReturningString_TTestClient.cpp
Index: LargeReturningString_TTestClient.cpp
===================================================================
/* This program will create 10 Threads and each thread will invoke Large Returning String Service
@Author James
*/
#include "LargeReturningString.hpp"
#include <axis/AxisException.hpp>
//#include <exception>
#include <ctype.h>
#include <iostream>
#include <stdlib.h>
#include <axis/Axis.hpp>
/* Defining platform specific constants */
#ifdef WIN32
#include <windows.h>
#define RETTYPE DWORD WINAPI
//#define IFWIN32 WINAPI
#define ARGTYPE LPVOID
#else
#include <pthread.h>
#include <unistd.h>
#define IFWIN32
#define RETTYPE void*
#define ARGTYPE void*
#endif
//#define MACRO_NUM_THREADS 10
//int NUM_THREADS = MACRO_NUM_THREADS;
#define NUM_THREADS 10
/* In windows the entry point function return type is DWORD WINAPI
In linux it is void * */
RETTYPE ThreadFunc(ARGTYPE Param)
{
/*Type casting the url to char * */
char endpoint[256];
const char* url="http://localhost:LargeReturningString/services/LargeReturningString";
url=(char *)Param;
try {
sprintf(endpoint, "%s", url);
LargeReturningString *ws = new LargeReturningString(endpoint, APTHTTP1_1);
int input = 2*1024*1024;
xsd__string result = "";
result = ws->getLargeString(input);
if ( result == NULL ) {
cout << "NULL" << endl;
} else {
cout << strlen(result) << endl;
}
}catch(AxisException& e)
{
cout << "AxisException: " << e.what() << endl;
}
catch(exception& e)
{
cout << "Unknown Exception: " << endl;
}
catch(...)
{
cout << "Unspecified Exception: " << endl;
}
#ifndef WIN32
pthread_exit(0);
#endif
return 0;
}
int main(int argc, char *argv[])
{
Axis::initialize(false);
try{
int i;
#ifdef WIN32
/*Windows specific code comes here */
HANDLE hThread[NUM_THREADS];
for(i=0;i<NUM_THREADS;i++){
DWORD dwThreadId;
//LPVOID dwThrdParam = LPVOID(argv[1]);
hThread[i] = CreateThread(
NULL, // no security attributes
0, // use default stack size
ThreadFunc, // thread function
LPVOID(argv[1]), // argument to thread function
0,
&dwThreadId); // returns the thread identifier
if (hThread[i] == NULL)
{
cout<<"Thread creation Failed";
}
}
/* Waiting for threads to terminate */
WaitForMultipleObjects(NUM_THREADS,hThread,true, INFINITE);
for(i=0;i<NUM_THREADS;i++)
CloseHandle( hThread[i] );
#else
pthread_t thread[NUM_THREADS];
pthread_attr_t attr;
int rc, t, status = 0;
// Initialize and set thread detached attribute
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for (t = 0; t < NUM_THREADS; t++)
{
/*Creating threads */
rc = pthread_create(&thread[t], &attr, ThreadFunc,(void *)argv[1]);
if (rc)
{
cout<<"Thread Creation Failed";
}
}
//Free attribute and wait for the other threads
pthread_attr_destroy(&attr);
/* Wait for the threads to terminate */
for(t=0;t<NUM_THREADS;t++){
rc = pthread_join(thread[t], (void **)&status);
if (rc)
{
cout<<"ERROR from pthread_join()"<<endl;
}
}
#endif
}catch(exception &e){
cout<< e.what();
}
cout<<"----------------------------------TEST COMPLETE--------------------------------"<<endl;
}
1.1 ws-axis/c/tests/auto_build/testcases/client/cpp/FaultMappingDoc_TTestClient.cpp
Index: FaultMappingDoc_TTestClient.cpp
===================================================================
/* This program will create 10 Threads and each thread will invoke FaultMapping Service
@Author James
*/
#include "MathOps.hpp"
#include <axis/AxisException.hpp>
//#include <exception>
#include <ctype.h>
#include <iostream>
#include <stdlib.h>
#include <axis/Axis.hpp>
#include <signal.h>
/* Defining platform specific constants */
#ifdef WIN32
#include <windows.h>
#define RETTYPE DWORD WINAPI
#define ARGTYPE LPVOID
#else
#include <pthread.h>
#include <unistd.h>
#define RETTYPE void*
#define ARGTYPE void*
#endif
//#define MACRO_NUM_THREADS 10
//int NUM_THREADS = MACRO_NUM_THREADS;
#define NUM_THREADS 10
void sig_handler(int);
/* In windows the entry point function return type is DWORD WINAPI
In linux it is void * */
RETTYPE ThreadFunc(ARGTYPE Param)
{
/*Type casting the url to char * */
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);
url = (char *)Param;
sprintf(endpoint, "%s", url);
op = "div";
if (strcmp(op, "div") == 0)
{
for(int i = 0; i < 4; i++)
{
// cout << i << endl;
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;
}
try
{
MathOps ws(endpoint);
//cout << "Trying to " << op << " " << i1 << " by " << i2 << endl;
iResult = ws.div(i1, i2);
//cout << "Result is " << iResult << endl;
}
catch(DivByZeroStruct& dbzs)
{
/*cout << "DivByZeroStruct Fault: \""
<< dbzs.varString
<< "\", "
<< dbzs.varInt
<< ", "
<< dbzs.varFloat
<< endl; */
}
catch(SpecialDetailStruct& sds)
{
/*cout << "SpecialDetailStruct Fault: \""
<< sds.varString
<< "\""
<< endl;*/
}
catch(OutOfBoundStruct& oobs)
{
/*cout << "OutOfBoundStruct Fault: \""
<< oobs.varString
<< "\", "
<< oobs.varInt
<< ", \""
<< oobs.specialDetail->varString
<< "\""
<< endl;*/
if(i==3)
cout<<"Success"<<endl;
}
catch(SoapFaultException& sfe)
{
cout << "SoapFaultException: " << sfe.what() << endl;
}
catch(AxisException& e)
{
cout << "AxisException: " << e.what() << endl;
}
catch(exception& e)
{
cout << "Unknown Exception: " << endl;
}
catch(...)
{
cout << "Unspecified Exception: " << endl;
}
}
}
else
{
cout << "Invalid operation " << op << endl;
}
#ifndef WIN32
pthread_exit(0);
#endif
return 0;
}
int main(int argc, char *argv[])
{
Axis::initialize(false);
try{
int i;
#ifdef WIN32
/*Windows specific code comes here */
HANDLE hThread[NUM_THREADS];
for(i=0;i<NUM_THREADS;i++){
DWORD dwThreadId;
//LPVOID dwThrdParam = LPVOID(argv[1]);
hThread[i] = CreateThread(
NULL, // no security attributes
0, // use default stack size
ThreadFunc, // thread function
LPVOID(argv[1]), // argument to thread function
0,
&dwThreadId); // returns the thread identifier
if (hThread[i] == NULL)
{
cout<<"Thread creation Failed";
}
}
/* Waiting for threads to terminate */
WaitForMultipleObjects(NUM_THREADS,hThread,true, INFINITE);
for(i=0;i<NUM_THREADS;i++)
CloseHandle( hThread[i] );
#else
pthread_t thread[NUM_THREADS];
pthread_attr_t attr;
int rc, t, status = 0;
// Initialize and set thread detached attribute
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for (t = 0; t < NUM_THREADS; t++)
{
/*Creating threads */
rc = pthread_create(&thread[t], &attr, ThreadFunc,(void *)argv[1]);
if (rc)
{
cout<<"Thread Creation Failed";
}
}
//Free attribute and wait for the other threads
pthread_attr_destroy(&attr);
/* Wait for the threads to terminate */
for(t=0;t<NUM_THREADS;t++){
rc = pthread_join(thread[t], (void **)&status);
if (rc)
{
cout<<"ERROR from pthread_join()"<<endl;
}
}
#endif
}catch(exception &e){
cout<< e.what();
}
cout<<"----------------------------------TEST COMPLETE--------------------------------"<<endl;
}
void sig_handler(int sig) {
signal(sig, sig_handler);
cout << "SIGNAL RECEIVED " << sig << endl;
exit(1);
}