/*====================================================================*\ FILE : TestGeneRandom.c PURPOSE : pro_toolkit appdata random access testing functions. HISTORY.. 25-Sep-96 H-01-11 DXU $$1 Created. 09-Oct-96 H-01-12 mgs $$2 Removed MSGFIL macro. 19-Oct-96 H-01-14 amin $$3 ProAppData -> ProExtdata 19-Oct-96 H-01-14 amin $$4 PROAPP -> PROEXT 15-Sep-97 H-03-22 Pavel $$5 Replace Pro/D on Pro/E 05-Oct-97 H-03-25 Pavel $$6 More includes & type cast 04-Nov-97 H-03-29 Pavel $$7 Corrected TEST_CALL_REPORTs 16-Dec-98 I-01-29 agsh $$8 Corrected TEST_CALL_REPORT \*====================================================================*/ /*--------------------------------------------------------------------*\ Pro/DEVELOP includes \*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*\ Pro/TOOLKIT includes \*--------------------------------------------------------------------*/ #include "ProToolkit.h" #include "ProExtdata.h" #include "ProUtil.h" #include "UtilMessage.h" #include "UtilFiles.h" #include "TestError.h" #include "TestGenedata.h" /*--------------------------------------------------------------------*\ C System includes \*--------------------------------------------------------------------*/ #include #include /*--------------------------------------------------------------------*\ Application macros \*--------------------------------------------------------------------*/ #define USER_MAX_STRING 120 #define USER_MAX_STREAM 120 /*--------------------------------------------------------------------*\ Application data types \*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*\ Application global/external data \*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*\ Application static data/function \*--------------------------------------------------------------------*/ static int ProTestRdmSlotName( ProExtdataClass *p_class, int maxsize, ProName name, int *format, char **data); static int ProTestRdmInt( ); static char ProTestRdmAlpha( ); static char ProTestRdmAlphaNum( ); static int ProTestRdmName( char *name, int maxlen); static double ProTestRdmDouble( ); static int ProTestRdmFmt( ); static int ProTestRdmStr( int maxsize, char *str); static unsigned char ProTestRdmByte( ); static int ProTestRdmStream( int maxsize, unsigned char **p_stream); static int ProTestRdmKeyType( ); /*====================================================================*\ Function : ProTestRdmSlotName Purpose : Generate random slot name, data type and data \*====================================================================*/ static int ProTestRdmSlotName( ProExtdataClass *p_class, int maxsize, ProName name, int *format, char **data) { char s_name[PRO_NAME_SIZE]; int *p_int; double *p_double; wchar_t *wstr; char str[USER_MAX_STRING], dummy[PRO_NAME_SIZE]; ProWstringToString(dummy, p_class->class_name); ProTestRdmName(s_name, (PRO_NAME_SIZE-strlen(dummy)-1)); ProStringToWstring(name, s_name); *format = ProTestRdmFmt(); switch(*format) { case PRO_INTEGER_TYPE : p_int = (int*)calloc(1,sizeof(int)); *p_int = ProTestRdmInt(); (*data)=(char*)p_int; return(sizeof(int)); break; case PRO_DOUBLE_TYPE : p_double = (double*)calloc(1,sizeof(double)); *p_double = ProTestRdmDouble(); (*data)=(char*)p_double; return(sizeof(double)); break; case PRO_WIDE_STRING_TYPE : ProTestRdmStr(PRO_LINE_SIZE,str); wstr = (wchar_t*)calloc(strlen(str)+1,sizeof(wchar_t)); ProStringToWstring(wstr,str); (*data)=(char*)wstr; return((strlen(str)+1) * sizeof(wchar_t)); break; case PRO_STREAM_TYPE : return(ProTestRdmStream(maxsize,(unsigned char **)data)); break; default : return(1); } } /*====================================================================*\ Function : ProTestRdmInt Purpose : Generate random int \*====================================================================*/ static int ProTestRdmInt() { unsigned int i=0; int b; for(b=0;b 1.0) d = d/10.0; if(rand() % 2) return(i+d); else return(-i-d); } /*====================================================================*\ Function : ProTestRdmFmt Purpose : Generate random data format \*====================================================================*/ static int ProTestRdmFmt() { static int a[] = { PRO_INTEGER_TYPE, PRO_DOUBLE_TYPE, PRO_WIDE_STRING_TYPE, PRO_STREAM_TYPE}; return(a[rand() % 4]); } /*====================================================================*\ Function : ProTestRdmStr Purpose : Generate random string \*====================================================================*/ static int ProTestRdmStr( int maxsize, char *str) { int len,i; do{ len = rand() % USER_MAX_STRING; } while (len==0 || len > maxsize); for(i=0;i maxsize); *p_stream = (unsigned char*)calloc(len,1); for(i=0;i