Added tests for the Variable class
This commit is contained in:
parent
1f71b021d1
commit
34f155ebdc
|
@ -248,6 +248,14 @@ void variable_delete(Variable * variable)
|
|||
}
|
||||
|
||||
|
||||
/* variable_get_as */
|
||||
int variable_get_as(Variable * variable, VariableType type, void * result)
|
||||
{
|
||||
/* FIXME implement */
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* useful */
|
||||
/* variable_serialize */
|
||||
int variable_serialize(Variable * variable, Buffer * buffer, int type)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
TARGETS = string tests.log
|
||||
TARGETS = string variable tests.log
|
||||
PREFIX = /usr/local
|
||||
DESTDIR =
|
||||
BINDIR = $(PREFIX)/bin
|
||||
|
@ -25,14 +25,24 @@ string_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
|||
string: $(string_OBJS)
|
||||
$(CC) -o string $(string_OBJS) $(string_LDFLAGS)
|
||||
|
||||
tests.log: string
|
||||
variable_OBJS = variable.o
|
||||
variable_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
variable_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
|
||||
variable: $(variable_OBJS)
|
||||
$(CC) -o variable $(variable_OBJS) $(variable_LDFLAGS)
|
||||
|
||||
tests.log: string variable
|
||||
./tests.sh -P "$(PREFIX)" -- "tests.log"
|
||||
|
||||
string.o: string.c ../src/string.c
|
||||
$(CC) $(string_CFLAGS) -c string.c
|
||||
|
||||
variable.o: variable.c ../src/variable.c
|
||||
$(CC) $(variable_CFLAGS) -c variable.c
|
||||
|
||||
clean:
|
||||
$(RM) -- $(string_OBJS) $(tests.log_OBJS)
|
||||
$(RM) -- $(string_OBJS) $(variable_OBJS) $(tests.log_OBJS)
|
||||
|
||||
distclean: clean
|
||||
$(RM) -- $(TARGETS)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
targets=string,tests.log
|
||||
targets=string,variable,tests.log
|
||||
cppflags_force=-I ../include
|
||||
cflags_force=-W
|
||||
cflags=-Wall -g -O2
|
||||
|
@ -16,4 +16,11 @@ depends=../src/string.c
|
|||
[tests.log]
|
||||
type=script
|
||||
script=./tests.sh
|
||||
depends=string
|
||||
depends=string,variable
|
||||
|
||||
[variable]
|
||||
type=binary
|
||||
sources=variable.c
|
||||
|
||||
[variable.c]
|
||||
depends=../src/variable.c
|
||||
|
|
|
@ -46,6 +46,7 @@ target="$1"
|
|||
> "$target"
|
||||
FAILED=
|
||||
./string >> "$target" || FAILED="$FAILED string"
|
||||
./variable >> "$target" || FAILED="$FAILED variable"
|
||||
[ -z "$FAILED" ] && exit 0
|
||||
echo "Failed tests:$FAILED" 1>&2
|
||||
exit 2
|
||||
|
|
66
tests/variable.c
Normal file
66
tests/variable.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS System libSystem */
|
||||
/* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "System/variable.h"
|
||||
|
||||
|
||||
/* variable */
|
||||
static int _variable(char const * progname)
|
||||
{
|
||||
int ret = 0;
|
||||
Variable * variable;
|
||||
const int samples[] = { 0, -1, 1, -127, -128, 126, 127 };
|
||||
size_t i;
|
||||
int32_t j;
|
||||
int8_t i8;
|
||||
size_t s;
|
||||
void * p;
|
||||
|
||||
/* variable_new */
|
||||
for(i = 0; i < sizeof(samples) / sizeof(*samples); i++)
|
||||
{
|
||||
printf("%s: Testing variable_new_deserialize_type(): %d\n",
|
||||
progname, samples[i]);
|
||||
i8 = samples[i];
|
||||
s = sizeof(i8);
|
||||
p = &i8;
|
||||
if((variable = variable_new_deserialize_type(VT_INT8, &s, p))
|
||||
== NULL)
|
||||
{
|
||||
printf("%s: %d: Test failed\n", progname, samples[i]);
|
||||
ret += 1;
|
||||
continue;
|
||||
}
|
||||
p = &j;
|
||||
if(variable_get_as(variable, VT_INT32, p) != 0
|
||||
|| j != samples[i])
|
||||
{
|
||||
printf("%s: %d: Test failed\n", progname, samples[i]);
|
||||
ret += 1;
|
||||
}
|
||||
variable_delete(variable);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* main */
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
return (_variable(argv[0]) == 0) ? 0 : 2;;
|
||||
}
|
Loading…
Reference in New Issue
Block a user