added test of the psensor_type_to_unit_str function
authorJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 16 Jul 2012 21:08:19 +0000 (21:08 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 16 Jul 2012 21:08:19 +0000 (21:08 +0000)
tests/Makefile.am
tests/test_psensor_type_to_unit_str.c [new file with mode: 0644]

index c7b7e8c..575e0e8 100644 (file)
@@ -2,23 +2,37 @@ check-local: checkpatch.pl
        find $(top_srcdir)/src -name \*.c -exec $(srcdir)/checkpatch.pl --ignore SPLIT_STRING --show-types -q --no-tree  -emacs -f {} \;
        find $(top_srcdir)/src -name \*.h -exec $(srcdir)/checkpatch.pl --ignore SPLIT_STRING --show-types -q --no-tree  -emacs -f {} \;
 
+DEFS = -DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" -DLOCALEDIR=\"$(localedir)\" @DEFS@
+
 EXTRA_DIST = checkpatch.pl data test-io-dir-list.sh
 
 check_PROGRAMS = test-io-dir-list \
+       test-psensor-type-to-unit-str \
        test-url-encode \
        test-url-normalize
 
 AM_CPPFLAGS = -pedantic -Werror
 
+LIBS += ../src/lib/libpsensor.a \
+       $(SENSORS_LIBS)
+
+if ATASMART
+LIBS += $(ATASMART_LIBS)
+endif
+
+if GTOP
+LIBS += $(GTOP_LIBS)
+endif
+
+test_psensor_type_to_unit_str_SOURCES = test_psensor_type_to_unit_str.c
+
 test_url_encode_SOURCES = test_url_encode.c
-test_url_encode_LDADD = ../src/lib/libpsensor.a
 
 test_url_normalize_SOURCES = test_url_normalize.c
-test_url_normalize_LDADD = ../src/lib/libpsensor.a
 
 test_io_dir_list_SOURCES = test_io_dir_list.c
-test_io_dir_list_LDADD = ../src/lib/libpsensor.a
 
-TESTS = test-url-encode \
+TESTS = test-psensor-type-to-unit-str \
+       test-url-encode \
        test-url-normalize \
        test-io-dir-list.sh
\ No newline at end of file
diff --git a/tests/test_psensor_type_to_unit_str.c b/tests/test_psensor_type_to_unit_str.c
new file mode 100644 (file)
index 0000000..f3eb7f4
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#include <locale.h>
+#include <libintl.h>
+#define _(str) gettext(str)
+
+#include "../src/lib/psensor.h"
+
+static int test_psensor_type_to_unit_str()
+{
+       const char *u;
+       int failures;
+
+       u = psensor_type_to_unit_str(SENSOR_TYPE_TEMP, 1);
+       if (strcmp("\302\260C", u))
+           failures++;
+
+       u = psensor_type_to_unit_str(SENSOR_TYPE_TEMP, 0);
+       if (strcmp("\302\260F", u))
+           failures++;
+
+       u = psensor_type_to_unit_str(SENSOR_TYPE_LMSENSOR_TEMP, 1);
+       if (strcmp("\302\260C", u))
+           failures++;
+
+       u = psensor_type_to_unit_str(SENSOR_TYPE_LMSENSOR_TEMP, 0);
+       if (strcmp("\302\260F", u))
+           failures++;
+
+       u = psensor_type_to_unit_str(SENSOR_TYPE_FAN, 0);
+       if (strcmp(_("RPM"), u))
+           failures++;
+
+       return failures;
+}
+
+int main(int argc, char **argv)
+{
+       int failures;
+
+       setlocale(LC_ALL, "");
+       bindtextdomain(PACKAGE, LOCALEDIR);
+       textdomain(PACKAGE);
+
+       failures = 0;
+
+       failures += test_psensor_type_to_unit_str();
+
+       if (failures) 
+               exit(EXIT_FAILURE);
+       else
+               exit(EXIT_SUCCESS);
+}