aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2017-11-23 18:09:45 +0100
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2017-11-23 18:09:45 +0100
commit0328742a8378421ebe27668fc16eb4fc63dfe9c6 (patch)
tree1b53873b171df16e5e17442c5aa6d1f630ca6f4b
parent5c999a8e1240e01b917f15ae6fd60d3d32611f11 (diff)
downloadembedlog-0328742a8378421ebe27668fc16eb4fc63dfe9c6.tar.gz
embedlog-0328742a8378421ebe27668fc16eb4fc63dfe9c6.tar.bz2
embedlog-0328742a8378421ebe27668fc16eb4fc63dfe9c6.zip
Added some tests for print module
-rw-r--r--man/el_print.312
-rw-r--r--src/el-options.c2
-rw-r--r--src/el-print.c1
-rw-r--r--tst/el-options.c11
-rw-r--r--tst/el-print.c105
5 files changed, 119 insertions, 12 deletions
diff --git a/man/el_print.3 b/man/el_print.3
index 11b59f5..03894c3 100644
--- a/man/el_print.3
+++ b/man/el_print.3
@@ -197,6 +197,18 @@ Any of the input parameters is invalid.
Loggig to file is enabled and filename was not set with \fBEL_OPT_FNAME\fR
option
+.TP
+.B EBADF
+Logging to file is enabled, file was opened sucessfuly, but log cannot be stored
+into file. This usually happen that file was unlinked from the file system and
+\fBembedlog\fR couldn't create new file again (no access to directory or
+directory doesn't exist at all). Log is lost, but \fBembedlog\fR will try to
+recreate log file everytime \fIel_print\fR is called.
+
+.TP
+.B ENOMEDIUM
+All possible outputs are disabled
+
.RE
\fBel_print\fR(), \fBel_vprint\fR(), \fBel_perror\fR() \fBel_pmemory\fR
may also return
diff --git a/src/el-options.c b/src/el-options.c
index 3b08cdc..c61f39a 100644
--- a/src/el-options.c
+++ b/src/el-options.c
@@ -498,7 +498,7 @@ int el_log_allowed
enum el_level level /* log level to check */
)
{
- return options->level >= level && options->outputs;
+ return options->level >= level;
}
diff --git a/src/el-print.c b/src/el-print.c
index 9d79bba..5bf26e3 100644
--- a/src/el-print.c
+++ b/src/el-print.c
@@ -528,6 +528,7 @@ int el_ovprint
VALID(EINVAL, fmt);
VALID(ECHRNG, el_log_allowed(options, level));
+ VALID(ENOMEDIUM, options->outputs);
e = 0;
diff --git a/tst/el-options.c b/tst/el-options.c
index 994d39a..1953fc6 100644
--- a/tst/el-options.c
+++ b/tst/el-options.c
@@ -346,17 +346,6 @@ static void options_log_allowed(void)
mt_fail(el_log_allowed(&g_options, EL_INFO) == 0);
mt_fail(el_log_allowed(&g_options, EL_DBG) == 0);
- g_options.outputs = 0;
-
- mt_fail(el_log_allowed(&g_options, EL_FATAL) == 0);
- mt_fail(el_log_allowed(&g_options, EL_ALERT) == 0);
- mt_fail(el_log_allowed(&g_options, EL_CRIT) == 0);
- mt_fail(el_log_allowed(&g_options, EL_ERROR) == 0);
- mt_fail(el_log_allowed(&g_options, EL_WARN) == 0);
- mt_fail(el_log_allowed(&g_options, EL_NOTICE) == 0);
- mt_fail(el_log_allowed(&g_options, EL_INFO) == 0);
- mt_fail(el_log_allowed(&g_options, EL_DBG) == 0);
-
mt_fail(el_cleanup() == 0);
}
diff --git a/tst/el-print.c b/tst/el-print.c
index 13e91df..718aa0f 100644
--- a/tst/el-print.c
+++ b/tst/el-print.c
@@ -16,6 +16,7 @@
#include <rb.h>
#include <string.h>
#include <ctype.h>
+#include <errno.h>
#include "mtest.h"
#include "stdlib.h"
@@ -622,6 +623,106 @@ static void print_mix_of_everything(void)
/* ==========================================================================
+ ========================================================================== */
+
+
+static void print_too_long_print_truncate(void)
+{
+ char msg[EL_LOG_MAX + 3];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ memset(msg, 'a', sizeof(msg));
+ msg[sizeof(msg) - 1] = '\0';
+ msg[sizeof(msg) - 2] = '3';
+ msg[sizeof(msg) - 3] = '2';
+ msg[sizeof(msg) - 4] = '1';
+ msg[sizeof(msg) - 4] = '0';
+
+ add_log(ELI, "not truncated");
+ add_log(ELI, msg);
+
+ /*
+ * while el_print will make copy of msg, our test print_check function
+ * will just use pointer to our msg here, and since we expect message to
+ * be truncated, we truncate it here and print_check will take this
+ * truncated message as expected one.
+ */
+
+ msg[sizeof(msg) - 3] = '\0';
+
+ mt_fok(print_check());
+}
+
+
+/* ==========================================================================
+ ========================================================================== */
+
+
+static void print_truncate_with_date(void)
+{
+ char msg[EL_LOG_MAX + 3];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ el_option(EL_OPT_TS, EL_OPT_TS_LONG);
+ memset(msg, 'a', sizeof(msg));
+ msg[sizeof(msg) - 1] = '\0';
+ msg[sizeof(msg) - 2] = '3';
+ msg[sizeof(msg) - 3] = '2';
+ msg[sizeof(msg) - 4] = '1';
+ msg[sizeof(msg) - 4] = '0';
+
+ add_log(ELI, "not truncated");
+ add_log(ELI, msg);
+
+ msg[sizeof(msg) - 3] = '\0';
+
+ mt_fok(print_check());
+}
+
+
+/* ==========================================================================
+ ========================================================================== */
+
+
+static void print_truncate_with_all_options(void)
+{
+ char msg[EL_LOG_MAX + 3];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ el_option(EL_OPT_TS, EL_OPT_TS_LONG);
+ el_option(EL_OPT_FINFO, 1);
+ el_option(EL_OPT_PRINT_LEVEL, 1);
+ memset(msg, 'a', sizeof(msg));
+ msg[sizeof(msg) - 1] = '\0';
+ msg[sizeof(msg) - 2] = '3';
+ msg[sizeof(msg) - 3] = '2';
+ msg[sizeof(msg) - 4] = '1';
+ msg[sizeof(msg) - 4] = '0';
+
+ add_log(ELI, "not truncated");
+ add_log(ELI, msg);
+
+ msg[sizeof(msg) - 3] = '\0';
+
+ mt_fok(print_check());
+}
+
+
+/* ==========================================================================
+ ========================================================================== */
+
+
+static void print_with_no_output_available(void)
+{
+ el_output_disable(EL_OUT_ALL);
+ mt_ferr(el_print(ELI, "i'll be back"), ENOMEDIUM);
+}
+
+
+/* ==========================================================================
__ __
/ /_ ___ _____ / /_ ____ _ _____ ____ __ __ ____
/ __// _ \ / ___// __/ / __ `// ___// __ \ / / / // __ \
@@ -645,4 +746,8 @@ void el_print_test_group(void)
mt_run(print_timestamp_long);
mt_run(print_finfo);
mt_run(print_mix_of_everything);
+ mt_run(print_too_long_print_truncate);
+ mt_run(print_truncate_with_date);
+ mt_run(print_truncate_with_all_options);
+ mt_run(print_with_no_output_available);
}