1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include <stdio.h> 29*cdf0e10cSrcweir #include <rtl/tres.h> 30*cdf0e10cSrcweir #include <osl/diagnose.h> 31*cdf0e10cSrcweir #include <osl/time.h> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir /* force an assertion on false state */ 34*cdf0e10cSrcweir #define TST_BOOM(c, m) OSL_ENSURE(c, m) 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir typedef struct _rtl_CmpState 38*cdf0e10cSrcweir { 39*cdf0e10cSrcweir struct _rtl_CmpState* m_next; 40*cdf0e10cSrcweir struct _rtl_CmpState* m_prev; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir sal_Bool m_stat; 43*cdf0e10cSrcweir rtl_String* m_msg; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir } rtl_CmpState; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir typedef struct _rtl_FuncState 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir struct _rtl_FuncState* m_next; 50*cdf0e10cSrcweir struct _rtl_FuncState* m_prev; 51*cdf0e10cSrcweir rtl_String* m_name; 52*cdf0e10cSrcweir sal_uInt32 m_flags; 53*cdf0e10cSrcweir sal_uInt32 m_start; 54*cdf0e10cSrcweir sal_uInt32 m_stop; 55*cdf0e10cSrcweir struct _rtl_CmpState* m_cmp; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir } rtl_FuncState; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir typedef struct _rtl_TestResult_Data 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir rtl_TestResult_vtable* m_funcs; 64*cdf0e10cSrcweir void* m_externaldata; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir rtl_FuncState* m_state; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir } rtl_TestResult_Data; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir /** 72*cdf0e10cSrcweir * internal helper functions 73*cdf0e10cSrcweir */ 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir /* ...to create, link, unlink and destroy allocated memory */ 76*cdf0e10cSrcweir rtl_FuncState* SAL_CALL rtl_tres_create_funcstate( const sal_Char* meth ); 77*cdf0e10cSrcweir rtl_FuncState* SAL_CALL rtl_tres_link_funcstate( rtl_FuncState* ptr, 78*cdf0e10cSrcweir rtl_FuncState* plink ); 79*cdf0e10cSrcweir rtl_FuncState* SAL_CALL rtl_tres_unlink_funcstate( rtl_FuncState* plink ); 80*cdf0e10cSrcweir rtl_CmpState* SAL_CALL rtl_tres_create_cmpstate( 81*cdf0e10cSrcweir sal_Bool state, 82*cdf0e10cSrcweir const sal_Char* msg 83*cdf0e10cSrcweir ); 84*cdf0e10cSrcweir rtl_CmpState* SAL_CALL rtl_tres_link_cmpstate( rtl_CmpState* ptr, 85*cdf0e10cSrcweir rtl_CmpState* plink ); 86*cdf0e10cSrcweir rtl_CmpState* SAL_CALL rtl_tres_unlink_cmpstate( rtl_CmpState* plink ); 87*cdf0e10cSrcweir sal_uInt32 SAL_CALL rtl_tres_timer(); 88*cdf0e10cSrcweir void SAL_CALL rtl_tres_destroy_funcstate( rtl_FuncState* pState_ ); 89*cdf0e10cSrcweir void SAL_CALL rtl_tres_destroy_funcstates( rtl_FuncState* pState_ ); 90*cdf0e10cSrcweir void SAL_CALL rtl_tres_destroy_cmpstates( rtl_CmpState* pState_ ); 91*cdf0e10cSrcweir void SAL_CALL rtl_tres_destroy_cmpstate( rtl_CmpState* pState_ ); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir /* set and clear single bits */ 95*cdf0e10cSrcweir static void SAL_CALL rtl_tres_setbit( rtl_FuncState* pState_, 96*cdf0e10cSrcweir sal_uInt32 flag ); 97*cdf0e10cSrcweir static void SAL_CALL rtl_tres_clearbit( rtl_FuncState* pState_, 98*cdf0e10cSrcweir sal_uInt32 flag ); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir /** 101*cdf0e10cSrcweir * forward declarations of concrete function implementations overloadable 102*cdf0e10cSrcweir * and accessible via vtable 103*cdf0e10cSrcweir */ 104*cdf0e10cSrcweir static sal_Bool SAL_CALL rtl_tres_state( 105*cdf0e10cSrcweir rtl_TestResult* pThis_, 106*cdf0e10cSrcweir sal_Bool state, 107*cdf0e10cSrcweir const sal_Char* msg, 108*cdf0e10cSrcweir const sal_Char* sub, 109*cdf0e10cSrcweir sal_Bool v 110*cdf0e10cSrcweir ); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir static void SAL_CALL rtl_tres_end( rtl_TestResult* pThis_, 113*cdf0e10cSrcweir const sal_Char* msg ); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir static rtl_funcstate SAL_CALL rtl_tres_funcstate( rtl_TestResult* pThis_ ); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir static sal_Bool SAL_CALL rtl_tres_ispassed( rtl_TestResult* pThis_ ); 118*cdf0e10cSrcweir static sal_Bool SAL_CALL rtl_tres_isok( rtl_TestResult* pThis_ ); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir static sal_Bool SAL_CALL rtl_tres_isbit( rtl_TestResult* pThis_, 121*cdf0e10cSrcweir sal_uInt32 flag ); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir static rtl_funcstate SAL_CALL rtl_tres_getnextfuncstate( rtl_funcstate ); 124*cdf0e10cSrcweir static rtl_funcstate SAL_CALL rtl_tres_getprevfuncstate( rtl_funcstate ); 125*cdf0e10cSrcweir static sal_uInt32 SAL_CALL rtl_tres_getflags( rtl_funcstate ); 126*cdf0e10cSrcweir sal_uInt32 SAL_CALL rtl_tres_getstarttime( rtl_funcstate ); 127*cdf0e10cSrcweir sal_uInt32 SAL_CALL rtl_tres_getstoptime( rtl_funcstate ); 128*cdf0e10cSrcweir static rtl_cmpstate SAL_CALL rtl_tres_getcmpstate( rtl_funcstate ); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir static sal_Bool SAL_CALL rtl_tres_getstat( rtl_cmpstate ); 131*cdf0e10cSrcweir rtl_String* SAL_CALL rtl_tres_getname( rtl_funcstate ); 132*cdf0e10cSrcweir rtl_String* SAL_CALL rtl_tres_getmsg( rtl_cmpstate ); 133*cdf0e10cSrcweir static rtl_cmpstate SAL_CALL rtl_tres_getnextcmpstate( rtl_cmpstate ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir /** 137*cdf0e10cSrcweir * initialize vtable with function pointers 138*cdf0e10cSrcweir */ 139*cdf0e10cSrcweir static rtl_TestResult_vtable trVTable = 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir sizeof(rtl_TestResult_vtable), 142*cdf0e10cSrcweir rtl_tres_state, 143*cdf0e10cSrcweir rtl_tres_end, 144*cdf0e10cSrcweir rtl_tres_ispassed, 145*cdf0e10cSrcweir rtl_tres_isok, 146*cdf0e10cSrcweir rtl_tres_funcstate, 147*cdf0e10cSrcweir rtl_tres_isbit, 148*cdf0e10cSrcweir rtl_tres_getnextfuncstate, 149*cdf0e10cSrcweir rtl_tres_getprevfuncstate, 150*cdf0e10cSrcweir rtl_tres_getflags, 151*cdf0e10cSrcweir rtl_tres_getname, 152*cdf0e10cSrcweir rtl_tres_getstarttime, 153*cdf0e10cSrcweir rtl_tres_getstoptime, 154*cdf0e10cSrcweir rtl_tres_getcmpstate, 155*cdf0e10cSrcweir rtl_tres_getstat, 156*cdf0e10cSrcweir rtl_tres_getmsg, 157*cdf0e10cSrcweir rtl_tres_getnextcmpstate 158*cdf0e10cSrcweir }; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir /** 161*cdf0e10cSrcweir * rtl_tres_create 162*cdf0e10cSrcweir * create and initialize data struct for TestResult 163*cdf0e10cSrcweir * 164*cdf0e10cSrcweir * @param const sal_Char* meth = name of the method (entryname) 165*cdf0e10cSrcweir * @param sal_uInt32 flags = bitmap of comandline and status flags 166*cdf0e10cSrcweir * 167*cdf0e10cSrcweir * @return rtl_TestResult* = pointer to a new allocated testresult struct 168*cdf0e10cSrcweir */ 169*cdf0e10cSrcweir rtl_TestResult* rtl_tres_create( const sal_Char* meth, sal_uInt32 flags ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir /* allocate memory for testresult data structure */ 172*cdf0e10cSrcweir rtl_TestResult_Data* pData = (rtl_TestResult_Data*) malloc( sizeof( 173*cdf0e10cSrcweir rtl_TestResult_Data ) ); 174*cdf0e10cSrcweir /* initialize members... */ 175*cdf0e10cSrcweir pData->m_funcs = &trVTable; /* ...vtableptr to vtbladr */ 176*cdf0e10cSrcweir pData->m_externaldata = 0; /* ...external data pointer */ 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir /* allocate memory for state structure and initialize members */ 179*cdf0e10cSrcweir pData->m_state = rtl_tres_create_funcstate( meth ); 180*cdf0e10cSrcweir pData->m_state->m_flags = flags; /* ...option Bitmap */ 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir /* set OK flag initial */ 183*cdf0e10cSrcweir rtl_tres_setbit( pData->m_state, rtl_tres_Flag_OK ); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir return (rtl_TestResult*)pData ; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir /** 189*cdf0e10cSrcweir * rtl_tres_create_funcstate 190*cdf0e10cSrcweir * allocates and initializes a structure to represent the status of a test 191*cdf0e10cSrcweir * entry or its substates 192*cdf0e10cSrcweir * 193*cdf0e10cSrcweir * @param const sal_Char* meth = the name of the method (entry or sub entry) 194*cdf0e10cSrcweir * 195*cdf0e10cSrcweir * @return rtl_FuncState* = pointer to a new allocated funcstate struct 196*cdf0e10cSrcweir */ 197*cdf0e10cSrcweir rtl_FuncState* SAL_CALL rtl_tres_create_funcstate( const sal_Char* meth ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir rtl_FuncState* pStat = 0; /* status structure */ 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir /* allocate memory for status structure */ 202*cdf0e10cSrcweir pStat = (rtl_FuncState*) malloc( sizeof( struct _rtl_FuncState ) ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir if ( pStat ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir pStat->m_next = pStat; /* init ptr to next struct */ 207*cdf0e10cSrcweir pStat->m_prev = pStat; /* init ptr to prev struct */ 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir pStat->m_name = 0; /* init name */ 210*cdf0e10cSrcweir pStat->m_flags = 0; /* init flags */ 211*cdf0e10cSrcweir pStat->m_start = rtl_tres_timer(); /* init start milliseconds */ 212*cdf0e10cSrcweir pStat->m_stop = 0; /* init stop milliseconds */ 213*cdf0e10cSrcweir pStat->m_cmp = 0; /* init ptr to msg struct */ 214*cdf0e10cSrcweir rtl_string_newFromStr( &pStat->m_name, meth );/* copy meth to name */ 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir /* set ok flag initially */ 217*cdf0e10cSrcweir rtl_tres_setbit(pStat, rtl_tres_Flag_OK); 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir return ( pStat ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir /** 223*cdf0e10cSrcweir * rtl_tres_link_funcstate 224*cdf0e10cSrcweir * link initialized funcstate structure to a circular double linked list 225*cdf0e10cSrcweir * 226*cdf0e10cSrcweir * @param rtl_FuncState* ptr = pointer to a funcstate where to link in new 227*cdf0e10cSrcweir * @param rtl_FuncState* plink = pointer to a funcstate to link in list 228*cdf0e10cSrcweir * 229*cdf0e10cSrcweir * @return rtl_FuncState* = pointer to structure linked in new 230*cdf0e10cSrcweir */ 231*cdf0e10cSrcweir rtl_FuncState* SAL_CALL rtl_tres_link_funcstate( rtl_FuncState* ptr, 232*cdf0e10cSrcweir rtl_FuncState* plink ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir ptr->m_next->m_prev = plink; 235*cdf0e10cSrcweir ptr->m_next->m_prev->m_next = ptr->m_next; 236*cdf0e10cSrcweir ptr->m_next->m_prev->m_prev = ptr; 237*cdf0e10cSrcweir ptr->m_next = plink; 238*cdf0e10cSrcweir return ( plink ); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir /** 242*cdf0e10cSrcweir * rtl_tres_unlink_funcstate 243*cdf0e10cSrcweir * unlink funcstate structure from a circular double linked list 244*cdf0e10cSrcweir * 245*cdf0e10cSrcweir * @param rtl_FuncState* plink = pointer to a funcstate to unlink from list 246*cdf0e10cSrcweir * 247*cdf0e10cSrcweir * @return rtl_FuncState* = pointer to funcstate struct unlinked from 248*cdf0e10cSrcweir * list 249*cdf0e10cSrcweir */ 250*cdf0e10cSrcweir rtl_FuncState* SAL_CALL rtl_tres_unlink_funcstate( rtl_FuncState* plink ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir plink->m_next->m_prev = plink->m_prev; 253*cdf0e10cSrcweir plink->m_prev->m_next = plink->m_next; 254*cdf0e10cSrcweir plink->m_next = plink; 255*cdf0e10cSrcweir plink->m_prev = plink; 256*cdf0e10cSrcweir return ( plink ); 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir /** 260*cdf0e10cSrcweir * rtl_tres_link_cmpstate 261*cdf0e10cSrcweir * link initialized cmpstate structure to a circular double linked list 262*cdf0e10cSrcweir * 263*cdf0e10cSrcweir * @param rtl_CmpState* ptr = pointer to a cmpstate where to link in new 264*cdf0e10cSrcweir * @param rtl_CmpState* plink = pointer to a cmpstate to link in list 265*cdf0e10cSrcweir * 266*cdf0e10cSrcweir * @return rtl_CmpState* = pointer to cmpstate struct linked in new 267*cdf0e10cSrcweir */ 268*cdf0e10cSrcweir rtl_CmpState* SAL_CALL rtl_tres_link_cmpstate( rtl_CmpState* ptr, 269*cdf0e10cSrcweir rtl_CmpState* plink ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir ptr->m_next->m_prev = plink; 272*cdf0e10cSrcweir ptr->m_next->m_prev->m_next = ptr->m_next; 273*cdf0e10cSrcweir ptr->m_next->m_prev->m_prev = ptr; 274*cdf0e10cSrcweir ptr->m_next = plink; 275*cdf0e10cSrcweir return ( plink ); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir /** 278*cdf0e10cSrcweir * rtl_tres_unlink_cmpstate 279*cdf0e10cSrcweir * unlink cmpstate structure from a circular double linked list 280*cdf0e10cSrcweir * 281*cdf0e10cSrcweir * @param rtl_CmpState* plink = pointer to a cmpstate to unlink from list 282*cdf0e10cSrcweir * 283*cdf0e10cSrcweir * @return rtl_CmpState* = pointer to cmpstate struct unlinked from list 284*cdf0e10cSrcweir */ 285*cdf0e10cSrcweir rtl_CmpState* SAL_CALL rtl_tres_unlink_cmpstate( rtl_CmpState* plink ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir plink->m_next->m_prev = plink->m_prev; 288*cdf0e10cSrcweir plink->m_prev->m_next = plink->m_next; 289*cdf0e10cSrcweir plink->m_next = plink; 290*cdf0e10cSrcweir plink->m_prev = plink; 291*cdf0e10cSrcweir return ( plink ); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir /** 295*cdf0e10cSrcweir * rtl_tres_create_cmpstate 296*cdf0e10cSrcweir * allocates and initializes a structure to represent the status of a test 297*cdf0e10cSrcweir * comparison 298*cdf0e10cSrcweir * 299*cdf0e10cSrcweir * @param sal_Bool state = compare state 300*cdf0e10cSrcweir * @param sal_Char* msg = message for logging and debug purposes 301*cdf0e10cSrcweir * 302*cdf0e10cSrcweir * @return rtl_CmpState* = pointer to the new allocated struct 303*cdf0e10cSrcweir */ 304*cdf0e10cSrcweir rtl_CmpState* SAL_CALL rtl_tres_create_cmpstate( 305*cdf0e10cSrcweir sal_Bool state, 306*cdf0e10cSrcweir const sal_Char* msg 307*cdf0e10cSrcweir ) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir /* allocate memory for cmpstate struct */ 310*cdf0e10cSrcweir rtl_CmpState* pStat = (rtl_CmpState*) malloc( sizeof( rtl_CmpState ) ); 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir /* initialize if memory could be allocated */ 313*cdf0e10cSrcweir if ( pStat ) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir pStat->m_next = pStat; /* init next with this */ 316*cdf0e10cSrcweir pStat->m_prev = pStat; /* init prev with this */ 317*cdf0e10cSrcweir pStat->m_msg = 0; 318*cdf0e10cSrcweir pStat->m_stat = state; /* boolean state */ 319*cdf0e10cSrcweir rtl_string_newFromStr( &pStat->m_msg, msg ); /* copy message */ 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir return ( pStat ); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir /** 325*cdf0e10cSrcweir * rtl_tres_destroy 326*cdf0e10cSrcweir * free allocated memory of testresult data struct 327*cdf0e10cSrcweir * 328*cdf0e10cSrcweir * @param rtl_TestResult* pThis_ = ponter to a valid testresult struct 329*cdf0e10cSrcweir */ 330*cdf0e10cSrcweir void SAL_CALL rtl_tres_destroy( rtl_TestResult* pThis_ ) 331*cdf0e10cSrcweir { 332*cdf0e10cSrcweir /* cast to implementation representation structure */ 333*cdf0e10cSrcweir rtl_TestResult_Data* pData = (rtl_TestResult_Data*) pThis_; 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir /* destroy all funcstates */ 336*cdf0e10cSrcweir if ( pData->m_state ) 337*cdf0e10cSrcweir rtl_tres_destroy_funcstates( pData->m_state ); 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir /* free allocted memory and reinitialize to zero */ 340*cdf0e10cSrcweir /* to be able to prevent dangling pointer access*/ 341*cdf0e10cSrcweir free( pData ); pData = 0; 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir /** 345*cdf0e10cSrcweir * rtl_tres_destroy_funcstates 346*cdf0e10cSrcweir * free allocated memory occupied by the list of funcstate data structs 347*cdf0e10cSrcweir * (iterates through next pointers) 348*cdf0e10cSrcweir * 349*cdf0e10cSrcweir * @param rtl_FuncState* pState_ = pointer to a valid funcstate struct 350*cdf0e10cSrcweir */ 351*cdf0e10cSrcweir void SAL_CALL rtl_tres_destroy_funcstates( rtl_FuncState* pState_ ) 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir rtl_FuncState* plink = pState_->m_next; 354*cdf0e10cSrcweir while ( plink != plink->m_next ) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir rtl_tres_destroy_funcstate( rtl_tres_unlink_funcstate( plink ) ); 357*cdf0e10cSrcweir plink = pState_->m_next; 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir rtl_tres_destroy_funcstate( plink ); 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir /** 363*cdf0e10cSrcweir * rtl_tres_destroy_cmpstates 364*cdf0e10cSrcweir * free allocated memory occupied by the list of cmpstate data structs 365*cdf0e10cSrcweir * (iterates through next pointers) 366*cdf0e10cSrcweir * 367*cdf0e10cSrcweir * @param rtl_CmpState* pState_ = pointer to a valid cmpstate struct 368*cdf0e10cSrcweir */ 369*cdf0e10cSrcweir void SAL_CALL rtl_tres_destroy_cmpstates( rtl_CmpState* pState_ ) 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir rtl_CmpState* plink = pState_->m_next; 372*cdf0e10cSrcweir while ( plink != plink->m_next ) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir rtl_tres_destroy_cmpstate( rtl_tres_unlink_cmpstate( plink ) ); 375*cdf0e10cSrcweir plink = pState_->m_next; 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir rtl_tres_destroy_cmpstate( plink ); 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir /** 382*cdf0e10cSrcweir * rtl_tres_destroy_funcstate 383*cdf0e10cSrcweir * free allocated memory occupied by one funcstate and it's list 384*cdf0e10cSrcweir * of cmpstate data structs 385*cdf0e10cSrcweir * 386*cdf0e10cSrcweir * @param rtl_FuncState* pState_ = pointer to a valid funcstate struct 387*cdf0e10cSrcweir */ 388*cdf0e10cSrcweir void SAL_CALL rtl_tres_destroy_funcstate( rtl_FuncState* pState_ ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir rtl_FuncState* plink = pState_; 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir if ( plink->m_cmp ) 393*cdf0e10cSrcweir rtl_tres_destroy_cmpstates( plink->m_cmp ); 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir if ( plink->m_name ) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir rtl_string_release( plink->m_name ); 398*cdf0e10cSrcweir plink->m_name = 0; 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir plink->m_flags = 0; 401*cdf0e10cSrcweir free( plink ); 402*cdf0e10cSrcweir plink = 0; 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir /** 406*cdf0e10cSrcweir * rtl_tres_destroy_cmpstate 407*cdf0e10cSrcweir * free allocated memory of a cmpstate data struct 408*cdf0e10cSrcweir * 409*cdf0e10cSrcweir * @param rtl_CmpState* pState_ = pointer to cmpstate struct to destroy 410*cdf0e10cSrcweir */ 411*cdf0e10cSrcweir void SAL_CALL rtl_tres_destroy_cmpstate( rtl_CmpState* pState_ ) 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir rtl_CmpState* plink = pState_; 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir if ( plink->m_msg ) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir rtl_string_release( plink->m_msg ); 419*cdf0e10cSrcweir plink->m_msg = 0; 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir free( plink ); 422*cdf0e10cSrcweir plink = 0; 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir /** 425*cdf0e10cSrcweir * central function to call in tests 426*cdf0e10cSrcweir * 427*cdf0e10cSrcweir * @param rtl_TestResult* pThis_ = self pointer to TestResult structure 428*cdf0e10cSrcweir * @param sal_Bool state = boolean result of statement comparison 429*cdf0e10cSrcweir * @param const sal_Char* msg = message for actual statementcomparison 430*cdf0e10cSrcweir * @param const sal_Char* sub = name of sub testfunction 431*cdf0e10cSrcweir * @param sal_Bool v = boolean verbose parameter 432*cdf0e10cSrcweir * 433*cdf0e10cSrcweir * @return sal_Bool = determines if statement comparison 434*cdf0e10cSrcweir * was positive or not 435*cdf0e10cSrcweir */ 436*cdf0e10cSrcweir static sal_Bool SAL_CALL rtl_tres_state( 437*cdf0e10cSrcweir rtl_TestResult* pThis_, 438*cdf0e10cSrcweir sal_Bool state, 439*cdf0e10cSrcweir const sal_Char* msg, 440*cdf0e10cSrcweir const sal_Char* sub, 441*cdf0e10cSrcweir sal_Bool v 442*cdf0e10cSrcweir ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir /* cast pointer to testresult data implementation struct*/ 446*cdf0e10cSrcweir rtl_TestResult_Data* pData = (rtl_TestResult_Data*)pThis_; 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir /* initialize funcstate pointer with masterstate */ 449*cdf0e10cSrcweir rtl_FuncState* pFunc = pData->m_state; 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir /* if substate required */ 452*cdf0e10cSrcweir if ( sub ) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir /* link new created function state to last item */ 455*cdf0e10cSrcweir pFunc = rtl_tres_link_funcstate( pFunc->m_prev, 456*cdf0e10cSrcweir rtl_tres_create_funcstate( sub ) ); 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir /* indicate this state as substate */ 459*cdf0e10cSrcweir rtl_tres_setbit( pFunc, rtl_tres_Flag_SUB ); 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir /* indicate prvious state as passed if no masterstate */ 462*cdf0e10cSrcweir if ( pFunc->m_prev != pData->m_state ) 463*cdf0e10cSrcweir rtl_tres_setbit( pFunc->m_prev, rtl_tres_Flag_PASSED ); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir /* test failed */ 468*cdf0e10cSrcweir if( ! state ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir /* determine if assertion should be thrown */ 471*cdf0e10cSrcweir if ( rtl_tres_isbit( pThis_, rtl_tres_Flag_BOOM ) ) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir /* if message available */ 474*cdf0e10cSrcweir if ( msg ) 475*cdf0e10cSrcweir TST_BOOM( state, msg ); 476*cdf0e10cSrcweir else 477*cdf0e10cSrcweir TST_BOOM( state, "no msg available" ); 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir /* clear this state ok flag and masterstate ok flag */ 481*cdf0e10cSrcweir rtl_tres_clearbit( pFunc, rtl_tres_Flag_OK ); 482*cdf0e10cSrcweir rtl_tres_clearbit( pData->m_state, rtl_tres_Flag_OK ); 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir /* message available */ 485*cdf0e10cSrcweir if( msg ) 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir /* append a new comparison state */ 488*cdf0e10cSrcweir if (! pFunc->m_cmp ) 489*cdf0e10cSrcweir pFunc->m_cmp = rtl_tres_create_cmpstate( state, msg ); 490*cdf0e10cSrcweir else 491*cdf0e10cSrcweir rtl_tres_link_cmpstate( pFunc->m_cmp, 492*cdf0e10cSrcweir rtl_tres_create_cmpstate(state, msg ) ); 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir /* message to stderr required ? */ 495*cdf0e10cSrcweir if ( v || ( pFunc->m_next->m_flags & rtl_tres_Flag_VERBOSE ) ) 496*cdf0e10cSrcweir fprintf( stderr, "%s\n", msg ); 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir pFunc->m_stop = rtl_tres_timer(); 500*cdf0e10cSrcweir return ( state ); 501*cdf0e10cSrcweir } 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir /** 504*cdf0e10cSrcweir * rtl_tres_timer 505*cdf0e10cSrcweir * function to get actual timevalue 506*cdf0e10cSrcweir * this has to be replaced by a high resolution timer 507*cdf0e10cSrcweir */ 508*cdf0e10cSrcweir sal_uInt32 SAL_CALL rtl_tres_timer() 509*cdf0e10cSrcweir { 510*cdf0e10cSrcweir sal_uInt32 val = 0; 511*cdf0e10cSrcweir TimeValue* tmv = (TimeValue*)malloc( sizeof( TimeValue ) ); 512*cdf0e10cSrcweir osl_getSystemTime( tmv ); 513*cdf0e10cSrcweir val = tmv->Nanosec/1000L; 514*cdf0e10cSrcweir free( tmv ); 515*cdf0e10cSrcweir return ( val ); 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir static void SAL_CALL rtl_tres_end( rtl_TestResult* pThis_, 520*cdf0e10cSrcweir const sal_Char* msg ) 521*cdf0e10cSrcweir { 522*cdf0e10cSrcweir rtl_TestResult_Data* pData = (rtl_TestResult_Data*) pThis_; 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir if( msg ) 525*cdf0e10cSrcweir { 526*cdf0e10cSrcweir if (! pData->m_state->m_cmp ) 527*cdf0e10cSrcweir pData->m_state->m_cmp = rtl_tres_create_cmpstate( sal_True, msg ); 528*cdf0e10cSrcweir else 529*cdf0e10cSrcweir rtl_tres_link_cmpstate( pData->m_state->m_cmp, 530*cdf0e10cSrcweir rtl_tres_create_cmpstate( sal_True, msg ) ); 531*cdf0e10cSrcweir } 532*cdf0e10cSrcweir pData->m_state->m_prev->m_flags |= rtl_tres_Flag_PASSED; 533*cdf0e10cSrcweir pData->m_state->m_flags |= rtl_tres_Flag_PASSED; 534*cdf0e10cSrcweir pData->m_state->m_stop = rtl_tres_timer(); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir static sal_Bool SAL_CALL rtl_tres_ispassed( rtl_TestResult* pThis_ ) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir return rtl_tres_isbit( pThis_, rtl_tres_Flag_PASSED ); 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir static sal_Bool SAL_CALL rtl_tres_isok( rtl_TestResult* pThis_ ) 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir return rtl_tres_isbit( pThis_, rtl_tres_Flag_OK ); 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir /** 548*cdf0e10cSrcweir * return pointer to funcstate structure 549*cdf0e10cSrcweir */ 550*cdf0e10cSrcweir static rtl_funcstate SAL_CALL rtl_tres_funcstate( rtl_TestResult* pThis_ ) 551*cdf0e10cSrcweir { 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir rtl_TestResult_Data* pThis = (rtl_TestResult_Data*) pThis_; 554*cdf0e10cSrcweir return (rtl_funcstate)pThis->m_state; 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir /** 558*cdf0e10cSrcweir * determine if a flag is set or not 559*cdf0e10cSrcweir */ 560*cdf0e10cSrcweir static sal_Bool SAL_CALL rtl_tres_isbit( rtl_TestResult* pThis_, 561*cdf0e10cSrcweir sal_uInt32 flag ) 562*cdf0e10cSrcweir { 563*cdf0e10cSrcweir return (sal_Bool) 564*cdf0e10cSrcweir ((((rtl_TestResult_Data *) pThis_)->m_state->m_flags & flag) == flag); 565*cdf0e10cSrcweir } 566*cdf0e10cSrcweir /** 567*cdf0e10cSrcweir * set one single bit 568*cdf0e10cSrcweir */ 569*cdf0e10cSrcweir static void SAL_CALL rtl_tres_setbit( rtl_FuncState* pState_, 570*cdf0e10cSrcweir sal_uInt32 flag ) 571*cdf0e10cSrcweir { 572*cdf0e10cSrcweir pState_->m_flags |= flag; 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir /** 575*cdf0e10cSrcweir * clear one single bit 576*cdf0e10cSrcweir */ 577*cdf0e10cSrcweir static void SAL_CALL rtl_tres_clearbit( rtl_FuncState* pState_, 578*cdf0e10cSrcweir sal_uInt32 flag ) 579*cdf0e10cSrcweir { 580*cdf0e10cSrcweir pState_->m_flags = pState_->m_flags & ( ~flag ); 581*cdf0e10cSrcweir } 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir /** 584*cdf0e10cSrcweir * returns next pointer of passed funcstate structure 585*cdf0e10cSrcweir */ 586*cdf0e10cSrcweir rtl_funcstate SAL_CALL rtl_tres_getnextfuncstate( rtl_funcstate fstate ) 587*cdf0e10cSrcweir { 588*cdf0e10cSrcweir rtl_FuncState* fs = (rtl_FuncState*)fstate; 589*cdf0e10cSrcweir return( (rtl_funcstate)fs->m_next ); 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir } 592*cdf0e10cSrcweir /** 593*cdf0e10cSrcweir * returns previous pointer of passed funcstate structure 594*cdf0e10cSrcweir */ 595*cdf0e10cSrcweir rtl_funcstate SAL_CALL rtl_tres_getprevfuncstate( rtl_funcstate fstate ) 596*cdf0e10cSrcweir { 597*cdf0e10cSrcweir rtl_FuncState* fs = (rtl_FuncState*)fstate; 598*cdf0e10cSrcweir return( (rtl_funcstate)fs->m_prev ); 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir } 601*cdf0e10cSrcweir /** 602*cdf0e10cSrcweir * returns flag value of passed funcstate structure 603*cdf0e10cSrcweir */ 604*cdf0e10cSrcweir sal_uInt32 SAL_CALL rtl_tres_getflags( rtl_funcstate fstate ) 605*cdf0e10cSrcweir { 606*cdf0e10cSrcweir rtl_FuncState* fs = (rtl_FuncState*)fstate; 607*cdf0e10cSrcweir return( fs->m_flags ); 608*cdf0e10cSrcweir } 609*cdf0e10cSrcweir /** 610*cdf0e10cSrcweir * returns name of passed funcstate structure 611*cdf0e10cSrcweir */ 612*cdf0e10cSrcweir rtl_String* SAL_CALL rtl_tres_getname( rtl_funcstate fstate ) 613*cdf0e10cSrcweir { 614*cdf0e10cSrcweir rtl_FuncState* fs = (rtl_FuncState*)fstate; 615*cdf0e10cSrcweir return( fs->m_name ); 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir /** 618*cdf0e10cSrcweir * returns starttime of passed funcstate structure 619*cdf0e10cSrcweir */ 620*cdf0e10cSrcweir sal_uInt32 SAL_CALL rtl_tres_getstarttime( rtl_funcstate fstate ) 621*cdf0e10cSrcweir { 622*cdf0e10cSrcweir rtl_FuncState* fs = (rtl_FuncState*)fstate; 623*cdf0e10cSrcweir return( fs->m_start ); 624*cdf0e10cSrcweir } 625*cdf0e10cSrcweir 626*cdf0e10cSrcweir /** 627*cdf0e10cSrcweir * returns stoptime of passed funcstate structure 628*cdf0e10cSrcweir */ 629*cdf0e10cSrcweir sal_uInt32 SAL_CALL rtl_tres_getstoptime( rtl_funcstate fstate ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir rtl_FuncState* fs = (rtl_FuncState*)fstate; 632*cdf0e10cSrcweir return( fs->m_stop ); 633*cdf0e10cSrcweir } 634*cdf0e10cSrcweir 635*cdf0e10cSrcweir /** 636*cdf0e10cSrcweir * returns pointer to cmpstate of passed funcstate structure 637*cdf0e10cSrcweir */ 638*cdf0e10cSrcweir rtl_cmpstate SAL_CALL rtl_tres_getcmpstate( rtl_funcstate fstate) 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir rtl_FuncState* fs = (rtl_FuncState*)fstate; 641*cdf0e10cSrcweir return( (rtl_cmpstate)fs->m_cmp ); 642*cdf0e10cSrcweir 643*cdf0e10cSrcweir } 644*cdf0e10cSrcweir /** 645*cdf0e10cSrcweir * returns boolean state of passed cmpstate structure 646*cdf0e10cSrcweir */ 647*cdf0e10cSrcweir sal_Bool SAL_CALL rtl_tres_getstat( rtl_cmpstate cstate) 648*cdf0e10cSrcweir { 649*cdf0e10cSrcweir rtl_CmpState* cs = (rtl_CmpState*)cstate; 650*cdf0e10cSrcweir return( cs->m_stat ); 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir /** 653*cdf0e10cSrcweir * returns message of passed cmpstate structure 654*cdf0e10cSrcweir */ 655*cdf0e10cSrcweir rtl_String* SAL_CALL rtl_tres_getmsg( rtl_cmpstate cstate) 656*cdf0e10cSrcweir { 657*cdf0e10cSrcweir rtl_CmpState* cs = (rtl_CmpState*)cstate; 658*cdf0e10cSrcweir return( cs->m_msg ); 659*cdf0e10cSrcweir } 660*cdf0e10cSrcweir /** 661*cdf0e10cSrcweir * returns next pointer of passed cmpstate structure 662*cdf0e10cSrcweir */ 663*cdf0e10cSrcweir rtl_cmpstate SAL_CALL rtl_tres_getnextcmpstate( rtl_cmpstate cstate) 664*cdf0e10cSrcweir { 665*cdf0e10cSrcweir rtl_CmpState* cs = (rtl_CmpState*)cstate; 666*cdf0e10cSrcweir return( (rtl_cmpstate)cs->m_next ); 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir /* 670*cdf0e10cSrcweir // <method_logPrintf> 671*cdf0e10cSrcweir //inline void logPrintf ( const sal_Bool bTestCaseState, 672*cdf0e10cSrcweir // const char *pFormatStr, ... 673*cdf0e10cSrcweir // ) 674*cdf0e10cSrcweir //{ 675*cdf0e10cSrcweir // if( m_pFunctions && m_pFunctions->pLogPrintf ) 676*cdf0e10cSrcweir // { 677*cdf0e10cSrcweir // va_list vArgumentList; 678*cdf0e10cSrcweir // va_start ( vArgumentList, pFormatStr ); 679*cdf0e10cSrcweir 680*cdf0e10cSrcweir // m_pFunctions->pLogPrintf( this, bTestCaseState, pFormatStr, vArgumentList ); 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir // va_end ( vArgumentList ); 683*cdf0e10cSrcweir // } 684*cdf0e10cSrcweir //} // </method_logPrintf> 685*cdf0e10cSrcweir */ 686*cdf0e10cSrcweir 687