From: Jean-Philippe Orsini Date: Mon, 16 Jul 2012 23:09:13 +0000 (+0000) Subject: added test X-Git-Tag: v0.8.0.5~296 X-Git-Url: https://git.wpitchoune.net/gitweb/?p=psensor.git;a=commitdiff_plain;h=4919f502f0e04ad8b63e40d59c0ed42a9583b268 added test --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 575e0e8..aefec3f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -8,6 +8,7 @@ EXTRA_DIST = checkpatch.pl data test-io-dir-list.sh check_PROGRAMS = test-io-dir-list \ test-psensor-type-to-unit-str \ + test-psensor-value-to-str \ test-url-encode \ test-url-normalize @@ -24,15 +25,14 @@ if GTOP LIBS += $(GTOP_LIBS) endif +test_io_dir_list_SOURCES = test_io_dir_list.c test_psensor_type_to_unit_str_SOURCES = test_psensor_type_to_unit_str.c - +test_psensor_value_to_str_SOURCES = test_psensor_value_to_str.c test_url_encode_SOURCES = test_url_encode.c - test_url_normalize_SOURCES = test_url_normalize.c -test_io_dir_list_SOURCES = test_io_dir_list.c - -TESTS = test-psensor-type-to-unit-str \ +TESTS = test-io-dir-list.sh \ + test-psensor-type-to-unit-str \ + test-psensor-value-to-str \ test-url-encode \ - test-url-normalize \ - test-io-dir-list.sh \ No newline at end of file + test-url-normalize diff --git a/tests/Makefile.in b/tests/Makefile.in index a22dcb9..284b279 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -35,12 +35,13 @@ build_triplet = @build@ host_triplet = @host@ check_PROGRAMS = test-io-dir-list$(EXEEXT) \ test-psensor-type-to-unit-str$(EXEEXT) \ - test-url-encode$(EXEEXT) test-url-normalize$(EXEEXT) + test-psensor-value-to-str$(EXEEXT) test-url-encode$(EXEEXT) \ + test-url-normalize$(EXEEXT) @ATASMART_TRUE@am__append_1 = $(ATASMART_LIBS) @GTOP_TRUE@am__append_2 = $(GTOP_LIBS) -TESTS = test-psensor-type-to-unit-str$(EXEEXT) \ - test-url-encode$(EXEEXT) test-url-normalize$(EXEEXT) \ - test-io-dir-list.sh +TESTS = test-io-dir-list.sh test-psensor-type-to-unit-str$(EXEEXT) \ + test-psensor-value-to-str$(EXEEXT) test-url-encode$(EXEEXT) \ + test-url-normalize$(EXEEXT) subdir = tests DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -59,6 +60,11 @@ am_test_psensor_type_to_unit_str_OBJECTS = \ test_psensor_type_to_unit_str_OBJECTS = \ $(am_test_psensor_type_to_unit_str_OBJECTS) test_psensor_type_to_unit_str_LDADD = $(LDADD) +am_test_psensor_value_to_str_OBJECTS = \ + test_psensor_value_to_str.$(OBJEXT) +test_psensor_value_to_str_OBJECTS = \ + $(am_test_psensor_value_to_str_OBJECTS) +test_psensor_value_to_str_LDADD = $(LDADD) am_test_url_encode_OBJECTS = test_url_encode.$(OBJEXT) test_url_encode_OBJECTS = $(am_test_url_encode_OBJECTS) test_url_encode_LDADD = $(LDADD) @@ -75,9 +81,11 @@ CCLD = $(CC) LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ SOURCES = $(test_io_dir_list_SOURCES) \ $(test_psensor_type_to_unit_str_SOURCES) \ + $(test_psensor_value_to_str_SOURCES) \ $(test_url_encode_SOURCES) $(test_url_normalize_SOURCES) DIST_SOURCES = $(test_io_dir_list_SOURCES) \ $(test_psensor_type_to_unit_str_SOURCES) \ + $(test_psensor_value_to_str_SOURCES) \ $(test_url_encode_SOURCES) $(test_url_normalize_SOURCES) ETAGS = etags CTAGS = ctags @@ -233,10 +241,11 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ EXTRA_DIST = checkpatch.pl data test-io-dir-list.sh AM_CPPFLAGS = -pedantic -Werror +test_io_dir_list_SOURCES = test_io_dir_list.c test_psensor_type_to_unit_str_SOURCES = test_psensor_type_to_unit_str.c +test_psensor_value_to_str_SOURCES = test_psensor_value_to_str.c test_url_encode_SOURCES = test_url_encode.c test_url_normalize_SOURCES = test_url_normalize.c -test_io_dir_list_SOURCES = test_io_dir_list.c all: all-am .SUFFIXES: @@ -280,6 +289,9 @@ test-io-dir-list$(EXEEXT): $(test_io_dir_list_OBJECTS) $(test_io_dir_list_DEPEND test-psensor-type-to-unit-str$(EXEEXT): $(test_psensor_type_to_unit_str_OBJECTS) $(test_psensor_type_to_unit_str_DEPENDENCIES) $(EXTRA_test_psensor_type_to_unit_str_DEPENDENCIES) @rm -f test-psensor-type-to-unit-str$(EXEEXT) $(LINK) $(test_psensor_type_to_unit_str_OBJECTS) $(test_psensor_type_to_unit_str_LDADD) $(LIBS) +test-psensor-value-to-str$(EXEEXT): $(test_psensor_value_to_str_OBJECTS) $(test_psensor_value_to_str_DEPENDENCIES) $(EXTRA_test_psensor_value_to_str_DEPENDENCIES) + @rm -f test-psensor-value-to-str$(EXEEXT) + $(LINK) $(test_psensor_value_to_str_OBJECTS) $(test_psensor_value_to_str_LDADD) $(LIBS) test-url-encode$(EXEEXT): $(test_url_encode_OBJECTS) $(test_url_encode_DEPENDENCIES) $(EXTRA_test_url_encode_DEPENDENCIES) @rm -f test-url-encode$(EXEEXT) $(LINK) $(test_url_encode_OBJECTS) $(test_url_encode_LDADD) $(LIBS) @@ -295,6 +307,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_io_dir_list.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_psensor_type_to_unit_str.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_psensor_value_to_str.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_url_encode.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_url_normalize.Po@am__quote@ diff --git a/tests/test_psensor_value_to_str.c b/tests/test_psensor_value_to_str.c new file mode 100644 index 0000000..2d237ea --- /dev/null +++ b/tests/test_psensor_value_to_str.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010-2011 jeanfi@gmail.com + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include +#include +#include +#include + +#include "../src/lib/psensor.h" + +#define CELCIUS "\302\260C" +#define FAHRENHEIT "\302\260F" + +static int +test_psensor_value_to_str(unsigned int type, + double value, + int celcius, + const char *ref) +{ + char *str; + + str = psensor_value_to_str(type, value, celcius); + if (strcmp(ref, str)) + return 1; + else + return 0; +} + +int main(int argc, char **argv) +{ + int errs; + + errs = test_psensor_value_to_str(SENSOR_TYPE_TEMP, 13, 1, + "13"CELCIUS); + errs += test_psensor_value_to_str(SENSOR_TYPE_TEMP, 13, 0, + "13"FAHRENHEIT); + errs += test_psensor_value_to_str(SENSOR_TYPE_TEMP, 13.4, 1, + "13"CELCIUS); + errs += test_psensor_value_to_str(SENSOR_TYPE_TEMP, 13.5, 0, + "14"FAHRENHEIT); + + if (errs) + exit(EXIT_FAILURE); + else + exit(EXIT_SUCCESS); +}