celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject celix git commit: CELIX-339: add functionality to show celix_log_mock log output
Date Mon, 11 Jan 2016 09:03:03 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 3b82dc866 -> 099fc6b8e


CELIX-339: add functionality to show celix_log_mock log output


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/099fc6b8
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/099fc6b8
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/099fc6b8

Branch: refs/heads/develop
Commit: 099fc6b8e9af8b0609ffaadbe1cc349116ad761e
Parents: 3b82dc8
Author: Bjoern Petri <bpetri@apache.org>
Authored: Mon Jan 11 10:02:11 2016 +0100
Committer: Bjoern Petri <bpetri@apache.org>
Committed: Mon Jan 11 10:02:11 2016 +0100

----------------------------------------------------------------------
 framework/private/mock/celix_log_mock.c | 54 ++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/099fc6b8/framework/private/mock/celix_log_mock.c
----------------------------------------------------------------------
diff --git a/framework/private/mock/celix_log_mock.c b/framework/private/mock/celix_log_mock.c
index 066077d..7904553 100644
--- a/framework/private/mock/celix_log_mock.c
+++ b/framework/private/mock/celix_log_mock.c
@@ -25,17 +25,71 @@
  */
 #include "CppUTestExt/MockSupport_c.h"
 
+#include <stdarg.h>
+
+#include "celix_errno.h"
 #include "celix_log.h"
 
+static void test_logger_log(framework_logger_pt logger, framework_log_level_t level, const
char *func, const char *file, int line, char *fmsg, ...);
+static void test_logger_print(framework_log_level_t level, const char *func, const char *file,
int line, char *msg);
+
 void framework_log(framework_logger_pt logger, framework_log_level_t level, const char *func,
const char *file, int line, char *fmsg, ...) {
 	mock_c()->actualCall("framework_log");
+
+    test_logger_log(logger, level, func, file, line, "%s", fmsg);
 }
 
 void framework_logCode(framework_logger_pt logger, framework_log_level_t level, const char
*func, const char *file, int line, celix_status_t code, char *fmsg, ...) {
 	mock_c()->actualCall("framework_logCode")->withIntParameters("code", code);
+    char message[256];
+    celix_strerror(code, message, 256);
+    char msg[512];
+    va_list listPointer;
+    va_start(listPointer, fmsg);
+    vsprintf(msg, fmsg, listPointer);
+
+    test_logger_log(logger, level, func, file, line, "%s [%d]: %s", message, code, msg);
 }
 
 celix_status_t frameworkLogger_log(framework_log_level_t level, const char *func, const char
*file, int line, char *msg) {
 	mock_c()->actualCall("frameworkLogger_log");
+
+	test_logger_print(level, func, file, line, msg);
+
 	return mock_c()->returnValue().value.intValue;
 }
+
+//test logger functions, let you read the logged errors
+static void test_logger_log(framework_logger_pt logger, framework_log_level_t level, const
char *func, const char *file, int line, char *fmsg, ...) {
+    char msg[512];
+    va_list listPointer;
+    va_start(listPointer, fmsg);
+    vsprintf(msg, fmsg, listPointer);
+
+    test_logger_print(level, func, file, line, msg);
+}
+
+static void test_logger_print(framework_log_level_t level, const char *func, const char *file,
int line, char *msg) {
+    char *levelStr = NULL;
+    switch (level) {
+        case OSGI_FRAMEWORK_LOG_ERROR:
+            levelStr = "ERROR";
+            break;
+        case OSGI_FRAMEWORK_LOG_WARNING:
+            levelStr = "WARNING";
+            break;
+        case OSGI_FRAMEWORK_LOG_INFO:
+            levelStr = "INFO";
+            break;
+        case OSGI_FRAMEWORK_LOG_DEBUG:
+        default:
+            levelStr = "DEBUG";
+            break;
+    }
+
+    if (level == OSGI_FRAMEWORK_LOG_ERROR) {
+        printf("Code says: %s: %s\n\tat %s(%s:%d)\n", levelStr, msg, func, file, line);
+    } else {
+        printf("Code says: %s: %s\n", levelStr, msg);
+    }
+}


Mime
View raw message