cwFileSys,cwLex,cwVectOps,cwObject,cwTime : Updated to use cwTest to manage test() function.

This commit is contained in:
kevin 2024-05-29 12:37:53 -04:00
parent 91fad53d33
commit 24f9b937a6
12 changed files with 213 additions and 44 deletions

View File

@ -4,8 +4,8 @@ libcwSRC =
libcwHDR += src/libcw/cwCommon.h src/libcw/cwCommonImpl.h src/libcw/cwMem.h src/libcw/cwLog.h src/libcw/cwUtility.h
libcwSRC += src/libcw/cwCommonImpl.cpp src/libcw/cwMem.cpp src/libcw/cwLog.cpp src/libcw/cwUtility.cpp
libcwHDR += src/libcw/cwString.h src/libcw/cwMath.h src/libcw/cwVectOps.h src/libcw/cwMtx.h src/libcw/cwVariant.h
libcwSRC += src/libcw/cwString.cpp src/libcw/cwMath.cpp src/libcw/cwMtx.cpp src/libcw/cwVariant.cpp
libcwHDR += src/libcw/cwString.h src/libcw/cwMath.h src/libcw/cwVectOps.h src/libcw/cwMtx.h src/libcw/cwVariant.h
libcwSRC += src/libcw/cwString.cpp src/libcw/cwMath.cpp src/libcw/cwVectOps.cpp src/libcw/cwMtx.cpp src/libcw/cwVariant.cpp
libcwHDR += src/libcw/cwB23Tree.h
libcwSRC += src/libcw/cwB23Tree.cpp
@ -46,8 +46,8 @@ libcwSRC += src/libcw/cwUi.cpp src/libcw/cwUiTest.cpp
endif
libcwHDR += src/libcw/cwKeyboard.h
libcwSRC += src/libcw/cwKeyboard.cpp
libcwHDR += src/libcw/cwKeyboard.h src/libcw/cwTest.h
libcwSRC += src/libcw/cwKeyboard.cpp src/libcw/cwTest.cpp
libcwHDR += src/libcw/cwSerialPortDecls.h src/libcw/cwSerialPort.h src/libcw/cwSerialPortSrv.h
libcwSRC += src/libcw/cwSerialPort.cpp src/libcw/cwSerialPortSrv.cpp

View File

@ -1,8 +1,12 @@
#include "cwCommon.h"
#include "cwLog.h"
#include "cwCommonImpl.h"
#include "cwTest.h"
#include "cwObject.h"
#include "cwFileSys.h"
#include "cwCommonImpl.h"
#include "cwMem.h"
#include "cwString.h"
#include "cwText.h"
@ -893,3 +897,33 @@ cw::rc_t cw::filesys::makeDir( const char* dirStr )
return kOkRC;
}
cw::rc_t cw::filesys::test( const test::test_args_t& args )
{
rc_t rc = kOkRC;
filesys::pathPart_t* pp = filesys::pathParts(__FILE__);
cwLogPrint("dir:%s",pp->dirStr);
cwLogPrint("fn: %s",pp->fnStr);
cwLogPrint("ext:%s",pp->extStr);
char* fn = filesys::makeFn( pp->dirStr, pp->fnStr, pp->extStr, nullptr );
cwLogPrint("fn: %s",fn);
mem::release(pp);
mem::release(fn);
const char myPath[] = "~/src/foo";
char* expPath = filesys::expandPath(myPath);
cwLogPrint("%s %s",myPath,expPath);
mem::release(expPath);
return rc;
}

View File

@ -90,6 +90,8 @@ namespace cw
char* makeVersionedDirectory(const char* recordDir, const char* recordFolder );
rc_t makeDir( const char* dirStr );
rc_t test( const test::test_args_t& args );
}
}

View File

@ -4,6 +4,6 @@ namespace cw
namespace flow
{
rc_t test( const object_t* cfg, int argc, const char* argv[] );
rc_t test( const test::test_args_t& args );
}
}

View File

@ -3,7 +3,8 @@
#include "cwCommonImpl.h"
#include "cwMem.h"
#include "cwFile.h"
#include "cwTest.h"
#include "cwObject.h"
#include "cwLex.h"
@ -853,7 +854,7 @@ namespace cw
//)
//(
rc_t test()
rc_t test( const test::test_args_t& args )
{
rc_t rc = kOkRC;
unsigned tid = kInvalidId;

View File

@ -129,7 +129,7 @@ namespace cw
const char* idToLabel( handle_t h, unsigned typeId );
// Lexer testing stub.
rc_t test( );
rc_t test( const test::test_args_t& args );
}
}

View File

@ -5,6 +5,7 @@
#include "cwCommonImpl.h"
#include "cwMem.h"
#include "cwFile.h"
#include "cwTest.h"
#include "cwLex.h"
#include "cwText.h"
#include "cwNumericConvert.h"
@ -152,37 +153,37 @@ namespace cw
void _objTypePrintIndent( const char* text, unsigned indent, const char* indentStr=" " )
{
for(unsigned i=0; i<indent; ++i)
printf("%s",indentStr);
printf("%s",text);
cwLogPrint("%s",indentStr);
cwLogPrint("%s",text);
}
void _objTypePrintChild( const object_t* o, print_ctx_t& c, const char* eolStr=",\n", const char* indentStr=" " )
{
_objTypePrintIndent(" ",c.indent,indentStr);
o->type->print(o,c);
printf("%s",eolStr);
cwLogPrint("%s",eolStr);
}
void _objTypePrintNull( const object_t* o, print_ctx_t& c ) { printf("NULL "); }
void _objTypePrintError( const object_t* o, print_ctx_t& c ) { printf("Error "); }
void _objTypePrintChar( const object_t* o, print_ctx_t& c ) { printf("%c",o->u.c); }
void _objTypePrintInt8( const object_t* o, print_ctx_t& c ) { printf("%i",o->u.i8); }
void _objTypePrintUInt8( const object_t* o, print_ctx_t& c ) { printf("%i",o->u.u8); }
void _objTypePrintInt16( const object_t* o, print_ctx_t& c ) { printf("%i",o->u.i16); }
void _objTypePrintUInt16( const object_t* o, print_ctx_t& c ) { printf("%i",o->u.u16); }
void _objTypePrintInt32( const object_t* o, print_ctx_t& c ) { printf("%i",o->u.i32); }
void _objTypePrintUInt32( const object_t* o, print_ctx_t& c ) { printf("%i",o->u.u32); }
void _objTypePrintInt64( const object_t* o, print_ctx_t& c ) { printf("%lli", o->u.i64); }
void _objTypePrintUInt64( const object_t* o, print_ctx_t& c ) { printf("%lli", o->u.u64); }
void _objTypePrintBool( const object_t* o, print_ctx_t& c ) { printf("%s",o->u.b ? "true" : "false"); }
void _objTypePrintFloat( const object_t* o, print_ctx_t& c ) { printf("%f",o->u.f); }
void _objTypePrintDouble( const object_t* o, print_ctx_t& c ) { printf("%f",o->u.d); }
void _objTypePrintString( const object_t* o, print_ctx_t& c ) { printf("%s",o->u.str); }
void _objTypePrintVect( const object_t* o, print_ctx_t& c ) { printf("<vect>"); }
void _objTypePrintNull( const object_t* o, print_ctx_t& c ) { cwLogPrint("NULL "); }
void _objTypePrintError( const object_t* o, print_ctx_t& c ) { cwLogPrint("Error "); }
void _objTypePrintChar( const object_t* o, print_ctx_t& c ) { cwLogPrint("%c",o->u.c); }
void _objTypePrintInt8( const object_t* o, print_ctx_t& c ) { cwLogPrint("%i",o->u.i8); }
void _objTypePrintUInt8( const object_t* o, print_ctx_t& c ) { cwLogPrint("%i",o->u.u8); }
void _objTypePrintInt16( const object_t* o, print_ctx_t& c ) { cwLogPrint("%i",o->u.i16); }
void _objTypePrintUInt16( const object_t* o, print_ctx_t& c ) { cwLogPrint("%i",o->u.u16); }
void _objTypePrintInt32( const object_t* o, print_ctx_t& c ) { cwLogPrint("%i",o->u.i32); }
void _objTypePrintUInt32( const object_t* o, print_ctx_t& c ) { cwLogPrint("%i",o->u.u32); }
void _objTypePrintInt64( const object_t* o, print_ctx_t& c ) { cwLogPrint("%lli", o->u.i64); }
void _objTypePrintUInt64( const object_t* o, print_ctx_t& c ) { cwLogPrint("%lli", o->u.u64); }
void _objTypePrintBool( const object_t* o, print_ctx_t& c ) { cwLogPrint("%s",o->u.b ? "true" : "false"); }
void _objTypePrintFloat( const object_t* o, print_ctx_t& c ) { cwLogPrint("%f",o->u.f); }
void _objTypePrintDouble( const object_t* o, print_ctx_t& c ) { cwLogPrint("%f",o->u.d); }
void _objTypePrintString( const object_t* o, print_ctx_t& c ) { cwLogPrint("%s",o->u.str); }
void _objTypePrintVect( const object_t* o, print_ctx_t& c ) { cwLogPrint("<vect>"); }
void _objTypePrintPair( const object_t* o, print_ctx_t& c )
{
o->u.children->type->print(o->u.children,c);
printf(": ");
cwLogPrint(": ");
o->u.children->sibling->type->print(o->u.children->sibling,c);
}
@ -1013,4 +1014,118 @@ cw::rc_t cw::objectToFile( const char* fn, const object_t* obj )
return rc;
}
namespace cw
{
rc_t _object_test_basic( const test::test_args_t& args )
{
rc_t rc = kOkRC;
cw::object_t* o = nullptr;
const char s [] = "{ a:1, b:2, c:[ 1.23, 4.56 ], d:true, e:false, f:true }";
int a = 0;
int b = 0;
const cw::object_t* c = nullptr;
bool d,e,f;
const unsigned bufN = 128;
char buf[bufN];
unsigned i = 0;
cw::object_t* oo = nullptr;
if((rc = cw::objectFromString(s,o)) != kOkRC )
goto errLabel;
int v;
if((rc = o->get("b",v)) != kOkRC )
goto errLabel;
cwLogPrint("value:%i\n",v);
o->print();
if((rc = o->getv("a",a,"b",b)) != kOkRC )
goto errLabel;
cwLogPrint("G: %i %i\n",a,b);
if((rc = o->readv("a",0,a,
"b",0,b,
"c",cw::kOptFl | cw::kListTId,c,
"d",0,d,
"e",0,e,
"f",0,f)) != kOkRC )
{
goto errLabel;
}
cwLogPrint("R: %i %i : %i %i %i\n",a,b,d,e,f);
i = o->to_string(buf,bufN);
cwLogPrint("%i : %s\n",i, buf);
oo = o->duplicate();
oo->print();
oo->free();
o->free();
errLabel:
return rc;
}
rc_t _object_test_to_json( const test::test_args_t& args )
{
double v0[] = {1.23,2.34,3.45};
unsigned v0N = sizeof(v0)/sizeof(v0[0]);
int v1[] = {-1,0,1,2,3,4};
unsigned v1N = sizeof(v1)/sizeof(v1[0]);
cw::object_t* d = cw::newDictObject();
d->putv("A","Abc","B",1.234);
d->put_numeric_list("v0",v0,v0N);
d->put_numeric_list("v1",v1,v1N);
char* s = d->to_string();
cwLogPrint("%s\n",s);
cw::mem::release(s);
d->free();
return kOkRC;
}
}
cw::rc_t cw::object_test( const test::test_args_t& args )
{
rc_t rc = kOkRC;
if( textIsEqual(args.test_label,"basic") )
{
rc = _object_test_basic(args);
goto errLabel;
}
if( textIsEqual(args.test_label,"to_json") )
{
rc = _object_test_to_json(args);
goto errLabel;
}
rc = cwLogError(kInvalidArgRC,"Unknown test case module:%s test:%s.",args.module_label,args.test_label);
errLabel:
return cw::kOkRC;
}

View File

@ -460,6 +460,8 @@ namespace cw
rc_t objectToFile( const char* fn, const object_t* obj );
rc_t object_test( const test::test_args_t& args );
}

View File

@ -1,6 +1,7 @@
#include "cwCommon.h"
#include "cwLog.h"
#include "cwCommonImpl.h"
#include "cwTest.h"
#include "cwTime.h"
#ifdef OS_OSX
@ -399,7 +400,7 @@ unsigned cw::time::formatDateTime( char* buffer, unsigned bufN, bool includeDate
return (unsigned)n;
}
cw::rc_t cw::time::test()
cw::rc_t cw::time::test(const test::test_args_t& test )
{
spec_t t0,t1;
@ -410,15 +411,15 @@ cw::rc_t cw::time::test()
unsigned dMs = elapsedMs(t0,t1);
printf("dMs:%i : GTE:%i LTE:%i\n",dMs, isGTE(t0,t1), isLTE(t0,t1) );
cwLogPrint("dMs:%i : GTE:%i LTE:%i\n",dMs, isGTE(t0,t1), isLTE(t0,t1) );
microsecondsToSpec( t0, 2500000 ); // 2.5 seconds
printf("%li %li\n",t0.tv_sec,t0.tv_nsec);
cwLogPrint("%li %li\n",t0.tv_sec,t0.tv_nsec);
subtractMicros( t0, 750000 ); // subtract .75 seconds
printf("%li %li\n",t0.tv_sec,t0.tv_nsec);
cwLogPrint("%li %li\n",t0.tv_sec,t0.tv_nsec);
subtractMicros( t0, 500000 ); // subtract .5 seconds
printf("%li %li\n",t0.tv_sec,t0.tv_nsec);
cwLogPrint("%li %li\n",t0.tv_sec,t0.tv_nsec);
time::get(t0);
@ -429,11 +430,11 @@ cw::rc_t cw::time::test()
int usec = time::elapsedMicros(t0,t1);
printf("usec:%i\n",usec);
cwLogPrint("usec:%i\n",usec);
t0 = current_time();
sleepMs(1000);
printf("sleep %i ms\n",elapsedMs(t0));
cwLogPrint("sleep %i ms\n",elapsedMs(t0));
return kOkRC;

View File

@ -85,7 +85,7 @@ namespace cw
// Return count of bytes in in buf[]
unsigned formatDateTime( char* buf, unsigned bufN, bool includeDateFl=false );
rc_t test();
rc_t test( const test::test_args_t& test );
//)

15
cwVectOps.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "cwCommon.h"
#include "cwLog.h"
#include "cwCommonImpl.h"
#include "cwTest.h"
#include "cwVectOps.h"
cw::rc_t cw::vop::test( const test::test_args_t& args )
{
int v1[] = { 1,2,1,2,1,2,1,2,1,2 };
int v0[ 10 ];
cw::vop::deinterleave( v0, v1, 5, 2 );
cw::vop::print(v0,10,"%i ");
return cw::kOkRC;
}

View File

@ -17,10 +17,10 @@ namespace cw
if( label != nullptr )
{
printf("%s : ",label);
cwLogPrint("%s : ",label);
if( colN && n > colN )
{
printf("\n");
cwLogPrint("\n");
newline_fl = true;
}
}
@ -30,19 +30,19 @@ namespace cw
for(unsigned i=0; i<n; ++i)
{
printf(fmt,v0[i]);
cwLogPrint(fmt,v0[i]);
newline_fl = false;
if( (n+1) % colN == 0 )
{
printf("\n");
cwLogPrint("\n");
newline_fl = true;
}
}
if( !newline_fl )
printf("\n");
cwLogPrint("\n");
}
@ -545,8 +545,7 @@ namespace cw
}
rc_t test( const test::test_args_t& args );
}
}