summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThierry Carré2013-03-20 17:49:59 +0100
committerThierry Carré2013-04-26 17:03:14 +0200
commit35dd512c6ba54bf1dc33dba4450ac096d5a09388 (patch)
treeaaacb615e5aacdb526950c818f79f0cfe1e4b421
parentcb479e440ebeea36c76dd575186cc3ccce8e221d (diff)
cleo/devkit/tests/plcd: add utests for plcd_files, refs #3789
Add coverage for plcd sources only.
-rw-r--r--cleopatre/devkit/tests/libspid/stubs/libspid_stub.c63
-rw-r--r--cleopatre/devkit/tests/plcd/.gitignore1
-rw-r--r--cleopatre/devkit/tests/plcd/Makefile30
-rw-r--r--cleopatre/devkit/tests/plcd/inc/utest_plcd_files_read.h31
-rw-r--r--cleopatre/devkit/tests/plcd/inc/utest_plcd_files_write.h30
-rw-r--r--cleopatre/devkit/tests/plcd/src/utest_plcd_files.c63
-rw-r--r--cleopatre/devkit/tests/plcd/src/utest_plcd_files_read.c232
-rw-r--r--cleopatre/devkit/tests/plcd/src/utest_plcd_files_write.c55
-rw-r--r--common/tests/tests1
9 files changed, 499 insertions, 7 deletions
diff --git a/cleopatre/devkit/tests/libspid/stubs/libspid_stub.c b/cleopatre/devkit/tests/libspid/stubs/libspid_stub.c
index cc24d7021a..f85d9e07b3 100644
--- a/cleopatre/devkit/tests/libspid/stubs/libspid_stub.c
+++ b/cleopatre/devkit/tests/libspid/stubs/libspid_stub.c
@@ -37,3 +37,66 @@ libspid_image_update_current_index (
return LIBSPID_SUCCESS;
}
+libspid_error_t
+libspid_config_read_item (
+ const char *filename,
+ const char *label,
+ char *value,
+ int buffer_len) __attribute__((weak));
+libspid_error_t
+libspid_config_read_item (
+ const char *filename,
+ const char *label,
+ char *value,
+ int buffer_len)
+{
+ return LIBSPID_SUCCESS;
+}
+
+libspid_error_t
+libspid_config_read_items (
+ const char *filename,
+ const char * const labels[],
+ char *values[],
+ const int buffers_len[],
+ unsigned int count) __attribute__((weak));
+libspid_error_t
+libspid_config_read_items (
+ const char *filename,
+ const char * const labels[],
+ char *values[],
+ const int buffers_len[],
+ unsigned int count)
+{
+ return LIBSPID_SUCCESS;
+}
+
+libspid_error_t
+libspid_config_write_item (
+ const char *filename,
+ const char *label,
+ const char *value) __attribute__((weak));
+libspid_error_t
+libspid_config_write_item (
+ const char *filename,
+ const char *label,
+ const char *value)
+{
+ return LIBSPID_SUCCESS;
+}
+
+libspid_error_t
+libspid_config_write_items (
+ const char *filename,
+ const char * const labels[],
+ const char * const values[],
+ unsigned int count) __attribute__((weak));
+libspid_error_t
+libspid_config_write_items (
+ const char *filename,
+ const char * const labels[],
+ const char * const values[],
+ unsigned int count)
+{
+ return LIBSPID_SUCCESS;
+}
diff --git a/cleopatre/devkit/tests/plcd/.gitignore b/cleopatre/devkit/tests/plcd/.gitignore
index 2416a678e7..616af52e7e 100644
--- a/cleopatre/devkit/tests/plcd/.gitignore
+++ b/cleopatre/devkit/tests/plcd/.gitignore
@@ -1 +1,2 @@
obj/
+mmtypes.h
diff --git a/cleopatre/devkit/tests/plcd/Makefile b/cleopatre/devkit/tests/plcd/Makefile
index df88704db0..3d1692d662 100644
--- a/cleopatre/devkit/tests/plcd/Makefile
+++ b/cleopatre/devkit/tests/plcd/Makefile
@@ -14,6 +14,9 @@ PLCD_SRC_DIR := $(PLCD_DIR)/src
GIT_DIR := $(CLEO_DIR)/..
COMMON_INC := $(GIT_DIR)/common/include
+MMTYPES=$(INCPATH)/mmtypes.h
+MMTCGEN=$(CLEO_DIR)/../common/lib/mmtcgen
+
INCLUDES := -I$(INCPATH) \
-I$(OVERRIDE) \
-I$(PLCD_DIR)/inc \
@@ -21,7 +24,8 @@ INCLUDES := -I$(INCPATH) \
$(shell $(LIBSPID_DIR)/libspid-config --I_opts)
CC := gcc
-CFLAGS := $(INCLUDES) -MMD -Wall -g -fprofile-arcs -ftest-coverage
+CFLAGS := $(INCLUDES) -MMD -Wall -g
+CFLAGS_WITH_COV := $(CFLAGS) -fprofile-arcs -ftest-coverage
LFLAGS := -lcheck -fprofile-arcs
UTEST_BASE := utest_launcher.o libspid_stub.o
@@ -35,23 +39,33 @@ COVS := $(patsubst %o,%gcno,$(OBJS)) $(patsubst %o,%gcda,$(OBJS))
UTEST_AUTOSWITCH_BIN := $(OBJPATH)/utest_plcd_autoswitch
+UTEST_FILES_BIN := $(OBJPATH)/utest_plcd_files
+
+COVS := $(COVS) $(UTEST_AUTOSWITCH_BIN).info \
+ $(UTEST_FILES_BIN).info
-COVS := $(COVS) $(UTEST_AUTOSWITCH_BIN).info
UTEST_PLCD_AUTOSWITCH_OBJ := $(UTEST_BASE_OBJ) \
$(addprefix $(OBJPATH)/, utest_plcd_autoswitch.o \
plcd_autoswitch.o )
+UTEST_PLCD_FILES_OBJ := $(UTEST_BASE_OBJ) \
+ $(addprefix $(OBJPATH)/, plcd_files.o \
+ utest_plcd_files_write.o utest_plcd_files_read.o utest_plcd_files.o)
+
+all: $(UTEST_FILES_BIN) $(UTEST_AUTOSWITCH_BIN)
+
$(UTEST_AUTOSWITCH_BIN): $(UTEST_PLCD_AUTOSWITCH_OBJ)
$(CC) -o $@ $(UTEST_PLCD_AUTOSWITCH_OBJ) $(LFLAGS)
+$(UTEST_FILES_BIN): $(UTEST_PLCD_FILES_OBJ)
+ $(CC) -o $@ $(UTEST_PLCD_FILES_OBJ) $(LFLAGS)
-all: $(UTEST_AUTOSWITCH_BIN)
-$(OBJPATH)/%.o: $(PLCD_SRC_DIR)/%.c
- $(CC) $(CFLAGS) -o $@ -c $<
+$(OBJPATH)/%.o: $(PLCD_SRC_DIR)/%.c $(MMTYPES)
+ $(CC) $(CFLAGS_WITH_COV) -o $@ -c $<
-$(OBJPATH)/%.o: $(SRCPATH)/%.c
+$(OBJPATH)/%.o: $(SRCPATH)/%.c $(MMTYPES)
$(CC) $(CFLAGS) -o $@ -c $<
$(OBJPATH)/%.o: $(LIBSPID_STUBS_DIR)/%.c
@@ -63,12 +77,14 @@ $(OBJPATH):
mkdir $(OBJPATH)
-include $(DEPS)
+-include $(MMTCGEN)/Makefile
.PHONY: all clean
clean:
- rm -f $(OBJPATH)/utest_plcd_autoswitch
+ rm -f $(UTEST_AUTOSWITCH_BIN) $(UTEST_FILES_BIN)
rm -f $(OBJS)
rm -f $(DEPS)
rm -f $(COVS)
rmdir $(OBJPATH)
+ rm -f $(MMTYPES)
diff --git a/cleopatre/devkit/tests/plcd/inc/utest_plcd_files_read.h b/cleopatre/devkit/tests/plcd/inc/utest_plcd_files_read.h
new file mode 100644
index 0000000000..c091998b14
--- /dev/null
+++ b/cleopatre/devkit/tests/plcd/inc/utest_plcd_files_read.h
@@ -0,0 +1,31 @@
+#ifndef DEVKIT_TESTS_PLCD_INC_UTEST_PLCD_FILES_READ_H
+#define DEVKIT_TESTS_PLCD_INC_UTEST_PLCD_FILES_READ_H
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2013 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/tests/plcd/inc/utest_plcd_files_read.h
+ * \ingroup devkit_tests_plcd
+ */
+#include "plcd_ctx.h"
+
+typedef enum {
+ UTEST_READ_EMPTY,
+ UTEST_READ_NMK_ONLY,
+ UTEST_READ_PARTIAL,
+ UTEST_READ_FULL,
+ UTEST_READ_ERROR,
+ UTEST_READ_NB,
+} utest_read_t;
+
+extern utest_read_t utest_read;
+
+void
+check_hpav_conf_context (
+ plcd_hpav_conf_t *out, int r);
+
+#endif /* DEVKIT_TESTS_PLCD_INC_UTEST_PLCD_FILES_READ_H */
diff --git a/cleopatre/devkit/tests/plcd/inc/utest_plcd_files_write.h b/cleopatre/devkit/tests/plcd/inc/utest_plcd_files_write.h
new file mode 100644
index 0000000000..e4a60288cd
--- /dev/null
+++ b/cleopatre/devkit/tests/plcd/inc/utest_plcd_files_write.h
@@ -0,0 +1,30 @@
+#ifndef DEVKIT_TESTS_PLCD_INC_UTEST_PLCD_FILES_WRITE_H
+#define DEVKIT_TESTS_PLCD_INC_UTEST_PLCD_FILES_WRITE_H
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2013 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/tests/plcd/inc/utest_plcd_files_write.h
+ * \ingroup devkit_tests_plcd
+ */
+#include "plcd_ctx.h"
+
+typedef enum {
+ UTEST_WRITE_EMPTY,
+ UTEST_WRITE_PARTIAL,
+ UTEST_WRITE_FULL,
+ UTEST_WRITE_ERROR,
+ UTEST_WRITE_NB,
+} utest_write_t;
+
+extern utest_write_t utest_write;
+
+void
+check_hpav_info_context (
+ plcd_hpav_info_t *out, int r);
+
+#endif /* DEVKIT_TESTS_PLCD_INC_UTEST_PLCD_FILES_WRITE_H */
diff --git a/cleopatre/devkit/tests/plcd/src/utest_plcd_files.c b/cleopatre/devkit/tests/plcd/src/utest_plcd_files.c
new file mode 100644
index 0000000000..3746e70637
--- /dev/null
+++ b/cleopatre/devkit/tests/plcd/src/utest_plcd_files.c
@@ -0,0 +1,63 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2013 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/tests/plcd/src/utest_plcd_files.c
+ * \ingroup devkit_tests_plcd
+ */
+#include "inc/utest_launcher.h"
+#include "inc/utest_plcd_files_read.h"
+#include "inc/utest_plcd_files_write.h"
+#include "plcd_files.h"
+#include "plcd_ctx.h"
+#include "libspid.h"
+#include <check.h>
+
+utest_read_t utest_read;
+
+START_TEST (read_hpav_conf)
+{
+ plcd_ctx_t plcd_ctx;
+ char fake_path[] = "./I_m_a_fake_path";
+ int r;
+
+ memset (&plcd_ctx, 0, sizeof (plcd_ctx));
+ plcd_ctx.hpav_conf_path = fake_path;
+ utest_read = _i;
+
+ r = plcd_files_read_hpavconf (&plcd_ctx);
+ check_hpav_conf_context (&plcd_ctx.hpav_conf, r);
+}
+END_TEST
+
+START_TEST (write_hpav_info)
+{
+ plcd_ctx_t plcd_ctx;
+ char fake_path[] = "./I_m_a_fake_path";
+ int r;
+
+ memset (&plcd_ctx, 0, sizeof (plcd_ctx));
+ plcd_ctx.hpav_info_path = fake_path;
+
+ r = plcd_files_write_default_hpavinfo (&plcd_ctx);
+ check_hpav_info_context (&plcd_ctx.hpav_info, r);
+}
+END_TEST
+
+Suite *
+utest_suite (void)
+{
+ Suite *s = suite_create ("utest_plcd_files");
+ TCase *core = tcase_create ("core");
+
+ tcase_add_loop_test (core, read_hpav_conf,
+ 0, UTEST_READ_NB);
+ tcase_add_test (core, write_hpav_info);
+
+ suite_add_tcase(s, core);
+ return s;
+}
diff --git a/cleopatre/devkit/tests/plcd/src/utest_plcd_files_read.c b/cleopatre/devkit/tests/plcd/src/utest_plcd_files_read.c
new file mode 100644
index 0000000000..3e8ea347ac
--- /dev/null
+++ b/cleopatre/devkit/tests/plcd/src/utest_plcd_files_read.c
@@ -0,0 +1,232 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2013 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/tests/plcd/src/utest_plcd_files.c
+ * \ingroup devkit_tests_plcd
+ */
+#include "inc/utest_plcd_files_read.h"
+#include "plcd_files.h"
+#include "plcd_ctx.h"
+#include "libspid.h"
+#include <check.h>
+
+#define FAKE_NMK_READ "time is money"
+#define FAKE_CCO_PREF_READ "why not"
+#define FAKE_WAS_CCO_READ "maybe"
+#define FAKE_NID_READ "money isn't a goal"
+#define FAKE_HFID_READ "no sun today"
+
+libspid_error_t
+libspid_config_read_item (
+ const char *filename,
+ const char *label,
+ char *value,
+ int buffer_len)
+{
+ fail_if (filename == NULL);
+ fail_if (label == NULL);
+ fail_if (value == NULL);
+ fail_if (buffer_len == 0);
+
+ if (utest_read == UTEST_READ_ERROR
+ || utest_read == UTEST_READ_NB)
+ return LIBSPID_ERROR_SYSTEM;
+
+ if (!strcmp (LIBSPID_HPAV_CONF_LABEL_NMK, label))
+ {
+ if (utest_read == UTEST_READ_NMK_ONLY
+ || utest_read == UTEST_READ_PARTIAL
+ || utest_read == UTEST_READ_FULL)
+ {
+ strncpy (value, FAKE_NMK_READ, buffer_len);
+ return LIBSPID_SUCCESS;
+ }
+ }
+ else if (!strcmp (
+ LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED, label))
+ {
+ if (utest_read == UTEST_READ_PARTIAL
+ || utest_read == UTEST_READ_FULL)
+ {
+ strncpy (value, FAKE_CCO_PREF_READ, buffer_len);
+ return LIBSPID_SUCCESS;
+ }
+ }
+ else if (!strcmp (
+ LIBSPID_HPAV_CONF_LABEL_WAS_CCO, label))
+ {
+ if (utest_read == UTEST_READ_PARTIAL
+ || utest_read == UTEST_READ_FULL)
+ {
+ strncpy (value, FAKE_WAS_CCO_READ, buffer_len);
+ return LIBSPID_SUCCESS;
+ }
+ }
+ else if (!strcmp (
+ LIBSPID_HPAV_CONF_LABEL_NID, label))
+ {
+ if (utest_read == UTEST_READ_FULL)
+ {
+ strncpy (value, FAKE_NID_READ, buffer_len);
+ return LIBSPID_SUCCESS;
+ }
+ }
+ else if (!strcmp (
+ LIBSPID_HPAV_CONF_LABEL_SL, label))
+ {
+ if (utest_read == UTEST_READ_FULL)
+ {
+ strncpy (value, LIBSPID_HPAV_CONF_VALUE_SL_HS,
+ buffer_len);
+ return LIBSPID_SUCCESS;
+ }
+ }
+ else if (!strcmp (
+ LIBSPID_HPAV_CONF_LABEL_USER_HFID, label))
+ {
+ if (utest_read == UTEST_READ_FULL)
+ {
+ strncpy (value, FAKE_HFID_READ, buffer_len);
+ return LIBSPID_SUCCESS;
+ }
+ }
+ else if (!strcmp (
+ LIBSPID_HPAV_CONF_LABEL_AVLN_HFID, label))
+ {
+ if (utest_read == UTEST_READ_FULL)
+ {
+ strncpy (value, FAKE_HFID_READ, buffer_len);
+ return LIBSPID_SUCCESS;
+ }
+ }
+ else if (!strcmp (
+ LIBSPID_HPAV_CONF_LABEL_FORCE_ROLE, label))
+ {
+ if (utest_read == UTEST_READ_PARTIAL)
+ {
+ strncpy (value,
+ LIBSPID_HPAV_CONF_VALUE_FORCE_ROLE_STA,
+ buffer_len);
+ return LIBSPID_SUCCESS;
+ }
+ else if (utest_read == UTEST_READ_FULL)
+ {
+ strncpy (value,
+ LIBSPID_HPAV_CONF_VALUE_FORCE_ROLE_CCO,
+ buffer_len);
+ return LIBSPID_SUCCESS;
+ }
+ }
+
+ return LIBSPID_ERROR_NOT_FOUND;
+}
+
+libspid_error_t
+libspid_config_read_items (
+ const char *filename,
+ const char * const labels[],
+ char *values[],
+ const int buffers_len[],
+ unsigned int count)
+{
+ libspid_error_t r1, r2;
+ int i;
+
+ fail_if (filename == NULL);
+ fail_if (labels == NULL);
+ fail_if (values == NULL);
+ fail_if (buffers_len == NULL);
+ fail_if (count == 0);
+
+ for (i=0; i<count; i++)
+ {
+ /* Pointers will be check in
+ * libspid_config_read_item. */
+ switch (r1 = libspid_config_read_item (
+ filename,
+ labels[i],
+ values[i],
+ buffers_len[i]))
+ {
+ case LIBSPID_SUCCESS:
+ case LIBSPID_ERROR_NOT_FOUND:
+ if (i == 0
+ || r1 == LIBSPID_ERROR_NOT_FOUND)
+ {
+ r2 = r1;
+ }
+ break;
+
+ default:
+ return r1;
+ }
+ }
+
+ return r2;
+}
+
+void
+check_hpav_conf_context (
+ plcd_hpav_conf_t *out, int r)
+{
+ switch (utest_read)
+ {
+ case UTEST_READ_EMPTY:
+ case UTEST_READ_ERROR:
+ fail_unless (r == -1);
+ fail_if (out->is_cco_preferred != LIBSPID_FALSE);
+ fail_if (out->was_cco != LIBSPID_FALSE);
+ fail_if (strlen (out->nmk_str));
+ fail_if (strlen (out->nid_str));
+ fail_if (strlen (out->sl_str));
+ fail_if (strlen (out->user_hfid));
+ fail_if (strlen (out->avln_hfid));
+ fail_if (out->force_role != PLCD_FORCE_ROLE_NONE);
+ break;
+
+ case UTEST_READ_NMK_ONLY:
+ fail_unless (r == 0);
+ fail_if (out->is_cco_preferred != LIBSPID_FALSE);
+ fail_if (out->was_cco != LIBSPID_FALSE);
+ fail_if (strcmp (out->nmk_str, FAKE_NMK_READ));
+ fail_if (strcmp (out->nid_str, LIBSPID_VALUE_NONE));
+ fail_if (strcmp (out->sl_str, LIBSPID_HPAV_CONF_VALUE_SL_SC));
+ fail_if (strlen (out->user_hfid));
+ fail_if (strlen (out->avln_hfid));
+ fail_if (out->force_role != PLCD_FORCE_ROLE_NONE);
+ break;
+
+ case UTEST_READ_PARTIAL:
+ fail_unless (r == 0);
+ fail_if (out->is_cco_preferred != LIBSPID_FALSE);
+ fail_if (out->was_cco != LIBSPID_FALSE);
+ fail_if (strcmp (out->nmk_str, FAKE_NMK_READ));
+ fail_if (strcmp (out->nid_str, LIBSPID_VALUE_NONE));
+ fail_if (strcmp (out->sl_str, LIBSPID_HPAV_CONF_VALUE_SL_SC));
+ fail_if (strlen (out->user_hfid));
+ fail_if (strlen (out->avln_hfid));
+ fail_if (out->force_role != PLCD_FORCE_ROLE_STA);
+ break;
+
+ case UTEST_READ_FULL:
+ fail_unless (r == 0);
+ fail_if (out->is_cco_preferred != LIBSPID_FALSE);
+ fail_if (out->was_cco != LIBSPID_FALSE);
+ fail_if (strcmp (out->nmk_str, FAKE_NMK_READ));
+ fail_if (strcmp (out->nid_str, FAKE_NID_READ));
+ fail_if (strcmp (out->sl_str, LIBSPID_HPAV_CONF_VALUE_SL_HS));
+ fail_if (strcmp (out->user_hfid, FAKE_HFID_READ));
+ fail_if (strcmp (out->avln_hfid, FAKE_HFID_READ));
+ fail_if (out->force_role != PLCD_FORCE_ROLE_CCO);
+ break;
+
+ case UTEST_READ_NB:
+ fail ("Last enum shouldn't be called");
+ break;
+ }
+}
diff --git a/cleopatre/devkit/tests/plcd/src/utest_plcd_files_write.c b/cleopatre/devkit/tests/plcd/src/utest_plcd_files_write.c
new file mode 100644
index 0000000000..4246e87d9e
--- /dev/null
+++ b/cleopatre/devkit/tests/plcd/src/utest_plcd_files_write.c
@@ -0,0 +1,55 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2013 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/tests/plcd/src/utest_plcd_files_write.c
+ * \ingroup devkit_tests_plcd
+ */
+#include "inc/utest_plcd_files_write.h"
+#include "plcd_files.h"
+#include "plcd_ctx.h"
+#include "libspid.h"
+#include <check.h>
+
+libspid_error_t
+libspid_config_write_items (
+ const char *filename,
+ const char * const labels[],
+ const char * const values[],
+ unsigned int count)
+{
+ int i;
+
+ fail_if (filename == NULL);
+ fail_if (labels == NULL);
+ fail_if (values == NULL);
+ fail_if (count == 0);
+
+ for (i=0; i<count; i++)
+ {
+ fail_if (labels[i] == NULL);
+ fail_if (values[i] == NULL);
+ }
+
+ return LIBSPID_SUCCESS;
+}
+
+void
+check_hpav_info_context (
+ plcd_hpav_info_t *out, int r)
+{
+ fail_unless (r == 0);
+ fail_if (strcmp (
+ LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED,
+ out->status));
+ fail_if (strcmp (
+ LIBSPID_HPAV_INFO_VALUE_CCO_STATION,
+ out->cco));
+ fail_if (LIBSPID_FALSE != out->is_backup_cco);
+ fail_if (LIBSPID_FALSE != out->is_sc);
+ fail_if (LIBSPID_FALSE != out->is_sc_button);
+}
diff --git a/common/tests/tests b/common/tests/tests
index 714990bf52..0124a69a82 100644
--- a/common/tests/tests
+++ b/common/tests/tests
@@ -46,6 +46,7 @@ valgrind vs_mme: ./obj/vs_mme_utests
cleopatre/devkit/tests/plcd:
make: make
cov plcd_autoswitch: ./obj/utest_plcd_autoswitch
+cov plcd_files: ./obj/utest_plcd_files
cleopatre/devkit/tests/busybox:
busybox-applet-order: python busybox_applets_order.py