summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStefan Vacek <stefan.vacek@intel.com>2015-08-28 16:59:52 +0200
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2015-10-07 10:36:13 +0200
commite5ffa017047525ed2e3ee41ea2294546ee64894c (patch)
treea3e431ffc19163ff8a54abae752e6063060789e3 /tests
parentcd35815e6870df9b8db0da807c4d4db3607539ba (diff)
downloadDLT-daemon-e5ffa017047525ed2e3ee41ea2294546ee64894c.tar.gz
Add C++ extension
- header only implementation, uses variadic templates from C++ 11 - Enable installation and building tests with -DWITH_DLT_CXX11_EXT - allow logging in the form of DLT_LOG_CXX(context, level, param1, param2, param3), e.g. - allow logging of user types (if a function logToDlt for the given user-type is present), e.g. - Added pkg-config file automotive-dlt-c++.pc - Sample code is provided in tests/dlt-test-cpp-extension.cpp Signed-off-by: Stefan Vacek <stefan.vacek@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt5
-rw-r--r--tests/dlt-test-cpp-extension.cpp118
2 files changed, 123 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6cc1006..5ce6945 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -21,3 +21,8 @@ target_link_libraries(dlt_test_receiver dlt)
target_link_libraries(dlt_env_ll_unit_test gtest gtest_main dlt)
target_link_libraries(dlt-test-preregister-context gtest gtest_main dlt)
+if(${WITH_DLT_CXX11_EXT})
+ add_executable(dlt-test-cpp-extension dlt-test-cpp-extension.cpp)
+ set_target_properties(dlt-test-cpp-extension PROPERTIES COMPILE_FLAGS "-std=c++11")
+ target_link_libraries(dlt-test-cpp-extension gtest gtest_main dlt)
+endif() \ No newline at end of file
diff --git a/tests/dlt-test-cpp-extension.cpp b/tests/dlt-test-cpp-extension.cpp
new file mode 100644
index 0000000..ce9f1db
--- /dev/null
+++ b/tests/dlt-test-cpp-extension.cpp
@@ -0,0 +1,118 @@
+/**
+ * @licence app begin@
+ * Copyright (C) 2015 Intel Corporation
+ *
+ * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
+ * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-test-cpp-extension.cpp
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+#include "dlt_cpp_extension.hpp"
+#include <stdio.h>
+#include <string.h>
+
+
+struct MyStruct
+{
+ int64_t uuid;
+ int32_t interfaceId;
+ int32_t registrationState;
+};
+
+
+template<>
+inline int logToDlt(DltContextData & log, MyStruct const & value)
+{
+ int result = 0;
+
+ result += dlt_user_log_write_string(&log, "(");
+ result += logToDlt(log, value.uuid);
+ result += dlt_user_log_write_string(&log, ",");
+ result += logToDlt(log, value.interfaceId);
+ result += dlt_user_log_write_string(&log, ",");
+ result += logToDlt(log, value.registrationState);
+ result += dlt_user_log_write_string(&log, ")");
+
+ if (result != 0)
+ {
+ result = -1;
+ }
+
+ return result;
+}
+
+
+/**
+ * Sample code to show usage of the cpp-extension
+ * mainly the variadic templates
+ */
+int main()
+{
+ if (dlt_register_app("TCPP", "Test cpp extension") < 0)
+ {
+ printf("Failed to register application\n");
+ return -1;
+ }
+
+ DltContext ctx;
+ if (dlt_register_context_ll_ts(&ctx, "TCPP", "Test cpp extension", DLT_LOG_INFO, DLT_TRACE_STATUS_OFF) < 0)
+ {
+ printf("Failed to register context\n");
+ return -1;
+ }
+
+ dlt_enable_local_print();
+ dlt_verbose_mode();
+
+ DLT_LOG(ctx, DLT_LOG_WARN, DLT_STRING("a message")); /* the classic way to go */
+
+ int an_int = 42;
+ float a_float = 22.7;
+ DLT_LOG_FCN_CXX(ctx, DLT_LOG_WARN, "Testing DLT_LOG_CXX_FCN", an_int, a_float);
+ DLT_LOG_CXX(ctx, DLT_LOG_WARN, 1.0, 65);
+
+ /* Example for logging user-defined types */
+ MyStruct myData = { 1u, 2u, 3u};
+ DLT_LOG_CXX(ctx, DLT_LOG_WARN, "MyStruct myData", myData);
+
+ char * non_const_string = (char *)malloc(17);
+ memcpy(non_const_string, "non_const_string", 16);
+ non_const_string[16] = 0;
+ DLT_LOG_CXX(ctx, DLT_LOG_WARN, "char *", non_const_string);
+
+ std::string aString = "std::string";
+ DLT_LOG_CXX(ctx, DLT_LOG_WARN, "std::string", aString);
+
+ std::vector<int> intVector;
+ intVector.push_back(0);
+ intVector.push_back(1);
+ intVector.push_back(2);
+ DLT_LOG_CXX(ctx, DLT_LOG_WARN, "vector", intVector);
+
+ std::vector<double> doubleList;
+ doubleList.push_back(10.);
+ doubleList.push_back(11.);
+ doubleList.push_back(12.);
+ DLT_LOG_CXX(ctx, DLT_LOG_WARN, "list", doubleList);
+
+ std::map<const char *, int> testMap;
+ testMap["apple"] = 100;
+ testMap["plum"] = 200;
+ testMap["orange"] = 300;
+ DLT_LOG_CXX(ctx, DLT_LOG_WARN, "map", testMap);
+
+ dlt_unregister_context(&ctx);
+ dlt_unregister_app();
+
+ return 0;
+}