Import LinuxCNC source tree
This commit is contained in:
82
tests/inifile/ini_api_c/expected
Normal file
82
tests/inifile/ini_api_c/expected
Normal file
@@ -0,0 +1,82 @@
|
||||
+++ Running test program for 'initest' +++
|
||||
--- test integer/unsigned value
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:7: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
42
|
||||
-42
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:8: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
42
|
||||
-42
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:9: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
42
|
||||
-42
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:10: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
42
|
||||
-42
|
||||
--- test real value
|
||||
42
|
||||
-42
|
||||
--- test boolean value
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
--- test bad integer/unsigned value
|
||||
xtest.ini:14: error: Invalid signed integer [SECTION]VARBadNum='BadInt42'
|
||||
iniFindSInt: Entry not found
|
||||
xtest.ini:14: error: Invalid unsigned integer [SECTION]VARBadNum='BadInt42'
|
||||
iniFindUInt: Entry not found
|
||||
xtest.ini:14: error: Invalid floating point [SECTION]VARBadNum='BadInt42'
|
||||
iniFindDouble: Entry not found
|
||||
--- test warn integer/unsigned trailing context
|
||||
xtest.ini:15: warning: Trailing character(s) in signed integer conversion ([SECTION]VARWarnNum='42Warn')
|
||||
42
|
||||
xtest.ini:15: warning: Trailing character(s) in unsigned integer conversion ([SECTION]VARWarnNum='42Warn')
|
||||
42
|
||||
xtest.ini:15: warning: Trailing character(s) in floating point conversion ([SECTION]VARWarnNum='42Warn')
|
||||
42
|
||||
--- test bad boolean value
|
||||
xtest.ini:13: error: Invalid boolean value [SECTION]VARBadBool='BadBool'
|
||||
iniFindBool: Entry not found
|
||||
--- test string value
|
||||
BadInt42
|
||||
42Warn
|
||||
--- test missing value
|
||||
iniFindString: Entry not found
|
||||
iniFindSInt: Entry not found
|
||||
iniFindUInt: Entry not found
|
||||
iniFindBool: Entry not found
|
||||
iniFindInt: Entry not found
|
||||
--- test missing section
|
||||
value to check the rest is missing
|
||||
iniFindString: Entry not found
|
||||
iniFindSInt: Entry not found
|
||||
iniFindUInt: Entry not found
|
||||
iniFindBool: Entry not found
|
||||
iniFindInt: Entry not found
|
||||
+++ all done +++
|
||||
136
tests/inifile/ini_api_c/initest.c
Normal file
136
tests/inifile/ini_api_c/initest.c
Normal file
@@ -0,0 +1,136 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <inifile.h>
|
||||
|
||||
void myerror(const char *pfx, int err)
|
||||
{
|
||||
fprintf(stderr, "%s: ", pfx);
|
||||
switch(err) {
|
||||
case -EINVAL: fprintf(stderr, "Invalid argument or ini-file"); break;
|
||||
case -ENOSPC: fprintf(stderr, "Buffer too small"); break;
|
||||
case -ENOENT: fprintf(stderr, "Entry not found"); break;
|
||||
default: fprintf(stderr, "Unknown error: %d", err); break;
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int lose = 0;
|
||||
int optc;
|
||||
const char *var = NULL;
|
||||
const char *sec = NULL;
|
||||
char typ = 's';
|
||||
|
||||
while(-1 != (optc = getopt(argc, argv, "v:s:t:"))) {
|
||||
switch(optc) {
|
||||
case 'v':
|
||||
var = strdup(optarg);
|
||||
break;
|
||||
case 's':
|
||||
sec = strdup(optarg);
|
||||
break;
|
||||
case 't':
|
||||
switch(*optarg) {
|
||||
case 'b':
|
||||
case 'i':
|
||||
case 'n':
|
||||
case 'u':
|
||||
case 'r':
|
||||
case 's':
|
||||
typ = *optarg;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Invalid type specifier '%c'\n", isprint(*optarg & 0xff) ? *optarg : '?');
|
||||
lose++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lose++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(optind >= argc) {
|
||||
fprintf(stderr, "Missing ini file\n");
|
||||
lose++;
|
||||
}
|
||||
|
||||
if(lose)
|
||||
return 1;
|
||||
|
||||
int rv;
|
||||
char buf[PATH_MAX];
|
||||
double r;
|
||||
int n;
|
||||
rtapi_s64 i;
|
||||
rtapi_u64 u;
|
||||
bool b;
|
||||
|
||||
switch(typ) {
|
||||
case 'b':
|
||||
rv = iniFindBool(argv[optind], var, sec, &b);
|
||||
if(!rv) {
|
||||
printf("%s\n", b ? "true" : "false");
|
||||
} else {
|
||||
myerror("iniFindBool", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
rv = iniFindInt(argv[optind], var, sec, &n);
|
||||
if(!rv) {
|
||||
printf("%d\n", n);
|
||||
} else {
|
||||
myerror("iniFindInt", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
rv = iniFindSInt(argv[optind], var, sec, &i);
|
||||
if(!rv) {
|
||||
printf("%ld\n", i);
|
||||
} else {
|
||||
myerror("iniFindSInt", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
rv = iniFindUInt(argv[optind], var, sec, &u);
|
||||
if(!rv) {
|
||||
printf("%lu\n", u);
|
||||
} else {
|
||||
myerror("iniFindUInt", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
rv = iniFindDouble(argv[optind], var, sec, &r);
|
||||
if(!rv) {
|
||||
printf("%.15lg\n", r);
|
||||
} else {
|
||||
myerror("iniFindDouble", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
rv = iniFindString(argv[optind], var, sec, buf, sizeof(buf));
|
||||
if(!rv) {
|
||||
printf("%s\n", buf);
|
||||
} else {
|
||||
myerror("iniFindString", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// vim: ts=4 sw=4
|
||||
95
tests/inifile/ini_api_c/test.sh
Executable file
95
tests/inifile/ini_api_c/test.sh
Executable file
@@ -0,0 +1,95 @@
|
||||
#!/bin/bash
|
||||
FLGS=( -O2 -Wall -Wextra -Werror -I"${HEADERS}" -DULAPI -L"${LIBDIR}" )
|
||||
gcc "${FLGS[@]}" -o initest initest.c -llinuxcncini || { echo "Failed compile"; exit 1; }
|
||||
|
||||
[ -x ./initest ] || { echo "initest program not present or executable"; exit 1; }
|
||||
|
||||
r() { echo "$@" >> result; }
|
||||
f() { echo "***" "$@" "failed" >> result; }
|
||||
t() { echo "***" "$@" "did not fail" >> result; }
|
||||
tst() { ./initest "$@" xtest.ini >> result 2>&1; }
|
||||
|
||||
true > result
|
||||
r "+++ Running test program for 'initest' +++"
|
||||
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=value to check the rest is missing"
|
||||
echo "VARdp=42"
|
||||
echo "VARxp=0x2a"
|
||||
echo "VARop=0o52"
|
||||
echo "VARbp=0b101010"
|
||||
echo "VARdm=-42"
|
||||
echo "VARxm=-0x2a"
|
||||
echo "VARom=-0o52"
|
||||
echo "VARbm=-0b101010"
|
||||
echo "VARrp=+4.2e1"
|
||||
echo "VARrm=-4.2e1"
|
||||
echo "VARBadBool=BadBool"
|
||||
echo "VARBadNum=BadInt42"
|
||||
echo "VARWarnNum=42Warn"
|
||||
echo "VARBt1=TRUE"
|
||||
echo "VARBt2=true"
|
||||
echo "VARBt3=True"
|
||||
echo "VARBt4=yes"
|
||||
echo "VARBt5=YeS"
|
||||
echo "VARBt6=1"
|
||||
echo "VARBt7=oN"
|
||||
echo "VARBf1=FALSE"
|
||||
echo "VARBf2=false"
|
||||
echo "VARBf3=FalSe"
|
||||
echo "VARBf4=no"
|
||||
echo "VARBf5=nO"
|
||||
echo "VARBf6=0"
|
||||
echo "VARBf7=oFf" ) > xtest.ini
|
||||
r "--- test integer/unsigned value"
|
||||
for i in d x o b; do
|
||||
tst -v"VAR${i}p" -ti || f "Integer VAR${i}p variable"
|
||||
tst -v"VAR${i}m" -ti || f "Integer VAR${i}m variable"
|
||||
tst -v"VAR${i}p" -tu || f "Unsigned VAR${i}p variable"
|
||||
tst -v"VAR${i}m" -tu || f "Unsigned VAR${i}m variable"
|
||||
tst -v"VAR${i}p" -tn || f "Integer VAR${i}p variable"
|
||||
tst -v"VAR${i}m" -tn || f "Integer VAR${i}m variable"
|
||||
done
|
||||
r "--- test real value"
|
||||
tst -vVARrp -tr || f "Real variable"
|
||||
tst -vVARrm -tr || f "Real variable"
|
||||
r "--- test boolean value"
|
||||
for i in 1 2 3 4 5 6 7; do
|
||||
tst -v"VARBt${i}" -tb || f "Boolean variable VARBt${i}"
|
||||
tst -v"VARBf${i}" -tb || f "Boolean variable VARBf${i}"
|
||||
done
|
||||
|
||||
r "--- test bad integer/unsigned value"
|
||||
tst -v"VARBadNum" -ti && t "Bad integer VARBadNum"
|
||||
tst -v"VARBadNum" -tu && t "Bad unsigned VARBadNum"
|
||||
tst -v"VARBadNum" -tr && t "Bad real VARBadNum"
|
||||
r "--- test warn integer/unsigned trailing context"
|
||||
tst -v"VARWarnNum" -ti || f "Bad integer VARWarnNum"
|
||||
tst -v"VARWarnNum" -tu || f "Bad unsigned VARWarnNum"
|
||||
tst -v"VARWarnNum" -tr || f "Bad real VARWarnNum"
|
||||
r "--- test bad boolean value"
|
||||
tst -v"VARBadBool" -tb && t "Bad boolean VARBadBool"
|
||||
|
||||
r "--- test string value"
|
||||
tst -v"VARBadNum" -ts || f "String VARBadNum"
|
||||
tst -v"VARWarnNum" -ts || f "String VARWarnNum"
|
||||
|
||||
r "--- test missing value"
|
||||
tst -v"MissingVAR" -ts && t "MissingVAR string"
|
||||
tst -v"MissingVAR" -ti && t "MissingVAR sint"
|
||||
tst -v"MissingVAR" -tu && t "MissingVAR uint"
|
||||
tst -v"MissingVAR" -tb && t "MissingVAR bool"
|
||||
tst -v"MissingVAR" -tn && t "MissingVAR int"
|
||||
|
||||
r "--- test missing section"
|
||||
tst -v"VAR" -s"SECTION" -ts || f "Section string"
|
||||
tst -v"VAR" -s"MISSING" -ts && t "Missing section string"
|
||||
tst -v"VAR" -s"MISSING" -ti && t "Missing section sint"
|
||||
tst -v"VAR" -s"MISSING" -tu && t "Missing section uint"
|
||||
tst -v"VAR" -s"MISSING" -tb && t "Missing section bool"
|
||||
tst -v"VAR" -s"MISSING" -tn && t "Missing section int"
|
||||
|
||||
r "+++ all done +++"
|
||||
|
||||
rm -f initest xtest.ini
|
||||
exit 0
|
||||
Reference in New Issue
Block a user