diff --git a/src/variable.c b/src/variable.c index ddfbe48..f8bee82 100644 --- a/src/variable.c +++ b/src/variable.c @@ -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) diff --git a/tests/Makefile b/tests/Makefile index 5263503..55c6010 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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) diff --git a/tests/project.conf b/tests/project.conf index 9e3c3be..4955e88 100644 --- a/tests/project.conf +++ b/tests/project.conf @@ -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 diff --git a/tests/tests.sh b/tests/tests.sh index e2a28d7..5e0b5c9 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -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 diff --git a/tests/variable.c b/tests/variable.c new file mode 100644 index 0000000..4e05e61 --- /dev/null +++ b/tests/variable.c @@ -0,0 +1,66 @@ +/* $Id$ */ +/* Copyright (c) 2012 Pierre Pronchery */ +/* 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 . */ + + + +#include +#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;; +}