summaryrefslogtreecommitdiff
path: root/cleopatre
diff options
context:
space:
mode:
authorBelkadi & Buret2011-06-27 18:47:15 +0200
committerBelkadi & Buret2011-06-30 15:16:40 +0200
commit657c32e0500e2e45760b4374137319dfdd9b2182 (patch)
treef6f385cff1469c215555190437172c474551e08a /cleopatre
parent12fb1433c73e569c99c7459613234161952a12f9 (diff)
cleo/devkit/test: add utest for libspid_hpav_info_read_file(), refs #2449
Add unit tests for the function libspid_hpav_info_read_file().
Diffstat (limited to 'cleopatre')
-rw-r--r--cleopatre/devkit/tests/libspid/utests/Makefile4
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/hpav_info_utests.c115
-rw-r--r--cleopatre/devkit/tests/libspid/utests/testfiles/hpav.info5
3 files changed, 122 insertions, 2 deletions
diff --git a/cleopatre/devkit/tests/libspid/utests/Makefile b/cleopatre/devkit/tests/libspid/utests/Makefile
index 39314c3700..aa41fdb300 100644
--- a/cleopatre/devkit/tests/libspid/utests/Makefile
+++ b/cleopatre/devkit/tests/libspid/utests/Makefile
@@ -1,6 +1,6 @@
PRJ_BASE = ../../../../application/libspid
-FILES = system network config_item config_line image
-OBJ_FILES = $(PRJ_OBJPATH)/config_line.o
+FILES = system network config_item config_line image hpav_info
+OBJ_FILES = $(PRJ_OBJPATH)/config_line.o $(PRJ_OBJPATH)/config_item.o
LIBSPID_DIR=../../../../application/libspid
LINUX_DIR=../../../../linux-2.6.25.10-spc300
diff --git a/cleopatre/devkit/tests/libspid/utests/src/hpav_info_utests.c b/cleopatre/devkit/tests/libspid/utests/src/hpav_info_utests.c
new file mode 100644
index 0000000000..506df36a2d
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/hpav_info_utests.c
@@ -0,0 +1,115 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2008-2011 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hpav_info_utests.c
+ * \brief Unitary tests for libspid - part related to hpav.info
+ * \ingroup Cleopatre - libspid
+ *
+ * This file contains tests for the libspid part related to handling the
+ * hpav.info.
+ */
+
+
+#include <check.h>
+#include <errno.h>
+#include <stdio.h>
+#include <sys/stat.h>
+
+#include "libspid.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf("LIBSPID_HPAV_INFO UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+#define HPAV_INFO "testfiles/hpav.info"
+
+/* fixtures - run before and after each unit test */
+void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ( (stat (UTESTS_TMP_DIR, &st) == 0) )
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+
+/* Tests */
+START_TEST (test_libspid_hpav_info_read_file)
+{
+ libspid_hpav_info_t hpav_info;
+ memset (&hpav_info, 0, sizeof (libspid_hpav_info_t));
+
+ system ("cp " HPAV_INFO " " LIBSPID_HPAV_INFO_PATH);
+
+ /* NULL param */
+ fail_if (libspid_hpav_info_read_file (NULL) != LIBSPID_ERROR_PARAM);
+
+ /* Nominal case */
+ fail_if (libspid_hpav_info_read_file (&hpav_info) != LIBSPID_SUCCESS);
+ fail_if (strcmp (LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED, hpav_info.status));
+ fail_if (strcmp (LIBSPID_HPAV_INFO_VALUE_CCO_MAIN, hpav_info.cco));
+ fail_if (hpav_info.is_backup_cco != LIBSPID_FALSE);
+ fail_if (hpav_info.is_sc != LIBSPID_TRUE);
+ fail_if (hpav_info.is_sc_button != LIBSPID_FALSE);
+}
+END_TEST
+
+Suite *
+libspid_hpav_info_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_HPAV_INFO");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test config_item */
+ tcase_add_test (tc_core, test_libspid_hpav_info_read_file);
+
+ suite_add_tcase (s, tc_core);
+ return s;
+}
+
+int
+main (void)
+{
+ Suite *s = libspid_hpav_info_suite ();
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ srunner_run_all (sr, CK_NORMAL);
+ int number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/testfiles/hpav.info b/cleopatre/devkit/tests/libspid/utests/testfiles/hpav.info
new file mode 100644
index 0000000000..7069563c2c
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/testfiles/hpav.info
@@ -0,0 +1,5 @@
+STATUS = unassociated
+CCO = main
+BACKUP_CCO = no
+SC = yes
+SC_BUTTON = no