Mercurial > pub > dyncall > dyncall
diff test/ellipsis/main.cc @ 410:7608e34098b0
- cleanups, simplifications, some api clarification, ...
- test cases consistency:
* return status code depending on test results (for actual conformance tests, not stuff that is not an example or hack to check something, ..)
* platform init helper added for some
author | Tassilo Philipp |
---|---|
date | Tue, 05 Oct 2021 21:53:04 +0200 |
parents | f5577f6bf97a |
children | 85b7a117b807 |
line wrap: on
line diff
--- a/test/ellipsis/main.cc Sun Oct 03 19:41:41 2021 +0200 +++ b/test/ellipsis/main.cc Tue Oct 05 21:53:04 2021 +0200 @@ -6,7 +6,7 @@ Description: call (...) functions via dyncall library, targets are auto-generated License: - Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>, + Copyright (c) 2007-2021 Daniel Adler <dadler@uni-goettingen.de>, Tassilo Philipp <tphilipp@potion-studios.com> Permission to use, copy, modify, and distribute this software for any @@ -58,18 +58,18 @@ void init() { - for (int i = 0 ; i < NARGS ; ++i ) + for (int i = 0 ; i < NARGS ; ++i ) { valueInt [i] = DCint (i); valueLongLong[i] = DClonglong(i); valueDouble [i] = DCdouble (i); valuePointer [i] = DCpointer (i); - } + } } void arg(DCCallVM* pCall, int select, int pos) { - switch(select) + switch(select) { case 0: dcArgInt ( pCall, valueInt [pos] ); break; case 1: dcArgLongLong( pCall, valueLongLong[pos] ); break; @@ -78,7 +78,7 @@ } } -#define assert(x) if (!(x)) return false +#define test(x) if (!(x)) return false bool test_ellipsis_case(int x) { @@ -86,19 +86,19 @@ DCCallVM* pCall = dcNewCallVM(4096); - assert( dcGetError(pCall) == DC_ERROR_NONE ); - + test( dcGetError(pCall) == DC_ERROR_NONE ); + dcMode(pCall, DC_CALL_C_ELLIPSIS); dcReset(pCall); - - assert( dcGetError(pCall) == DC_ERROR_NONE ); - + + test( dcGetError(pCall) == DC_ERROR_NONE ); + int y = x; int selects[NARGS] = { 0 }; int pos = 0; - if (y > 0) + if (y > 0) { - int select = (y-1) % NTYPES; + int select = (y-1) % NTYPES; selects[pos] = select; arg(pCall,select,pos); y = (y-1) / NTYPES; @@ -107,21 +107,21 @@ dcMode(pCall, DC_CALL_C_ELLIPSIS_VARARGS); - for(; y>0; ++pos) + for(; y>0; ++pos) { - int select = (y-1) % NTYPES; + int select = (y-1) % NTYPES; selects[pos] = select; arg(pCall,select,pos); y = (y-1) / NTYPES; } dcCallVoid(pCall,getFunc(x)); - - assert( getId() == x ); - + + test( getId() == x ); + for(int i=0; i<pos; ++i) { - assert( equals( selects[i], i, getArg(i) ) ); + test( equals( selects[i], i, getArg(i) ) ); } - + dcFree(pCall); return true; } @@ -157,7 +157,7 @@ init(); if (argc == 2) { int index = atoi(argv[1]); - success = run_range( index, index+1 ); + success = run_range( index, index+1 ); } else if (argc == 3) { int from = atoi(argv[1]); int to = atoi(argv[2])+1; @@ -167,11 +167,11 @@ success = run_range(0,ncalls); } - printf("result: ellipsis: %s\n", success ? "1" : "0"); + printf("result: ellipsis: %d\n", success); dcTest_deInitPlatform(); - return (success) ? 0 : -1; + return !success; } } // extern "C"