summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBiastoch, Darian (ADITG/ESM) <dbiastoch@de.adit-jv.com>2021-04-08 06:36:18 +0000
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2021-06-30 10:54:59 +0900
commit57d981f9d765286a85e682f7bee0769d7349e7aa (patch)
tree3fbfef66707cff032da293b1e7ef249131845032 /tests
parent72dc5bb1fa7bd0823ef17269ab6e5c7dd76f90fd (diff)
downloadDLT-daemon-57d981f9d765286a85e682f7bee0769d7349e7aa.tar.gz
Alternative solutions for json-c dependency
json-c dependency was removed from libdlt ('dlt_common') and shifted into 'dlt-control-common'. By this only the command line tools have a dependency on json-c. dlt-control-common is now built as a static library, so that it can be linked against json-c. Command line tools that included only the .c file of dlt-control-common before, are now linked against this static libarary (see console/CMakeLists.txt). Signed-off-by: dbiastoch <dbiastoch@de.adit-jv.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt13
-rw-r--r--tests/gtest_dlt_common.cpp73
-rw-r--r--tests/gtest_dlt_json_filter.cpp78
3 files changed, 89 insertions, 75 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 9c1ab86..26edca4 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -2,8 +2,6 @@
add_compile_options(-isystem ${gtest_SOURCE_DIR}/include)
configure_file(${PROJECT_SOURCE_DIR}/tests/testfile.dlt ${PROJECT_BINARY_DIR}/tests COPYONLY)
-configure_file(${PROJECT_SOURCE_DIR}/tests/testfile_extended.dlt ${PROJECT_BINARY_DIR}/tests COPYONLY)
-configure_file(${PROJECT_SOURCE_DIR}/tests/testfilter.json ${PROJECT_BINARY_DIR}/tests COPYONLY)
configure_file(${PROJECT_SOURCE_DIR}/tests/testfilter.txt ${PROJECT_BINARY_DIR}/tests COPYONLY)
configure_file(${PROJECT_SOURCE_DIR}/tests/testfile_filetransfer.txt ${PROJECT_BINARY_DIR}/tests COPYONLY)
@@ -15,6 +13,7 @@ endif()
set(DLT_LIBRARIES ${LIBRARIES} dlt)
set(DLT_DAEMON_LIBRARIES ${LIBRARIES} dlt_daemon)
+set(DLT_CONTROL_LIBRARIES ${LIBRARIES} dlt dlt_control_common_lib)
if(WITH_SYSTEMD OR WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD_JOURNAL)
add_definitions( -DSD_EXPORT_SYMBOLS )
@@ -26,6 +25,16 @@ add_test(NAME gtest_dlt_common
COMMAND gtest_dlt_common
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+if(WITH_EXTENDED_FILTERING)
+ configure_file(${PROJECT_SOURCE_DIR}/tests/testfile_extended.dlt ${PROJECT_BINARY_DIR}/tests COPYONLY)
+ configure_file(${PROJECT_SOURCE_DIR}/tests/testfilter.json ${PROJECT_BINARY_DIR}/tests COPYONLY)
+ add_executable(gtest_dlt_json_filter gtest_dlt_json_filter.cpp)
+ target_link_libraries(gtest_dlt_json_filter ${DLT_CONTROL_LIBRARIES})
+ add_test(NAME gtest_dlt_json_filter
+ COMMAND gtest_dlt_json_filter
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+endif()
+
add_executable(gtest_dlt_user gtest_dlt_user.cpp)
target_link_libraries(gtest_dlt_user ${DLT_LIBRARIES})
add_test(NAME gtest_dlt_user
diff --git a/tests/gtest_dlt_common.cpp b/tests/gtest_dlt_common.cpp
index b6a6c48..9afb830 100644
--- a/tests/gtest_dlt_common.cpp
+++ b/tests/gtest_dlt_common.cpp
@@ -1827,79 +1827,6 @@ TEST(t_dlt_message_print_ascii_with_filter, nullpointer)
-#ifdef EXTENDED_FILTERING
-/* Begin Method: dlt_common::dlt_message_print_ascii with json filter*/
-TEST(t_dlt_message_print_ascii_with_json_filter, normal)
-{
- DltFile file;
- DltFilter filter;
- static char text[DLT_DAEMON_TEXTSIZE];
-
- /* Get PWD so file can be used*/
- char pwd[100];
- char openfile[114];
-
- /* ignore returned value from getcwd */
- if (getcwd(pwd, 100) == NULL) {}
-
- char openfilter[117];
- sprintf(openfile, "%s/testfile_extended.dlt", pwd);
- sprintf(openfilter, "%s/testfilter.json", pwd);
- /*---------------------------------------*/
-
- /* Normal Use-Case, expect 0 */
- EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0));
- EXPECT_LE(DLT_RETURN_OK, dlt_filter_init(&filter, 0));
- EXPECT_LE(DLT_RETURN_OK, dlt_json_filter_load(&filter, openfilter, 0));
- EXPECT_LE(DLT_RETURN_OK, dlt_file_set_filter(&file, &filter, 0));
- EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0));
-
- char tmp[DLT_ID_SIZE+1];
- strncpy(tmp, filter.apid[0], DLT_ID_SIZE);
- tmp[DLT_ID_SIZE] = {};
- EXPECT_STREQ("LOG",tmp);
- EXPECT_EQ(3,filter.log_level[0]);
- EXPECT_EQ(0,filter.payload_min[0]);
- EXPECT_EQ(INT32_MAX,filter.payload_max[0]);
-
-
- strncpy(tmp, filter.apid[1], DLT_ID_SIZE);
- EXPECT_STREQ("app",tmp);
- strncpy(tmp, filter.ctid[1], DLT_ID_SIZE);
- EXPECT_STREQ("",tmp);
-
- EXPECT_EQ(0,filter.log_level[2]);
- EXPECT_EQ(20,filter.payload_min[2]);
- EXPECT_EQ(50,filter.payload_max[2]);
-
- while (dlt_file_read(&file, 0) >= 0) {}
-
- for (int i = 0; i < file.counter; i++) {
- EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0));
- EXPECT_LE(DLT_RETURN_OK, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0));
- }
-
- for (int i = 0; i < file.counter; i++) {
- EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0));
- EXPECT_LE(DLT_RETURN_OK, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1));
- }
-
- EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0));
-}
-TEST(t_dlt_message_print_ascii_with_json_filter, abnormal)
-{
- /* equal with t_dlt_message_print_ascii */
-}
-TEST(t_dlt_message_print_ascii_with_json_filter, nullpointer)
-{
- /* equal with t_dlt_message_print_ascii */
-}
-/* End Method: dlt_common::dlt_message_print_ascii with json filter*/
-#endif
-
-
-
-
/* Begin Method: dlt_common::dlt_message_print_header */
TEST(t_dlt_message_print_header, normal)
{
diff --git a/tests/gtest_dlt_json_filter.cpp b/tests/gtest_dlt_json_filter.cpp
new file mode 100644
index 0000000..8cdd98a
--- /dev/null
+++ b/tests/gtest_dlt_json_filter.cpp
@@ -0,0 +1,78 @@
+#include <stdio.h>
+#include <gtest/gtest.h>
+#include <limits.h>
+#include <syslog.h>
+
+extern "C"
+{
+ #include "dlt-control-common.h"
+ #include "dlt-daemon.h"
+}
+
+/* Begin Method: dlt_common::dlt_message_print_ascii with json filter*/
+TEST(t_dlt_message_print_ascii_with_json_filter, normal)
+{
+ DltFile file;
+ DltFilter filter;
+ static char text[DLT_DAEMON_TEXTSIZE];
+
+ /* Get PWD so file can be used*/
+ char pwd[100];
+ char openfile[114];
+
+ /* ignore returned value from getcwd */
+ if (getcwd(pwd, 100) == NULL) {}
+
+ char openfilter[117];
+ sprintf(openfile, "%s/testfile_extended.dlt", pwd);
+ sprintf(openfilter, "%s/testfilter.json", pwd);
+ /*---------------------------------------*/
+
+ /* Normal Use-Case, expect 0 */
+ EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0));
+ EXPECT_LE(DLT_RETURN_OK, dlt_filter_init(&filter, 0));
+ EXPECT_LE(DLT_RETURN_OK, dlt_json_filter_load(&filter, openfilter, 0));
+ EXPECT_LE(DLT_RETURN_OK, dlt_file_set_filter(&file, &filter, 0));
+ EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0));
+
+ char tmp[DLT_ID_SIZE+1];
+ strncpy(tmp, filter.apid[0], DLT_ID_SIZE);
+ tmp[DLT_ID_SIZE] = {};
+ EXPECT_STREQ("LOG",tmp);
+ EXPECT_EQ(3,filter.log_level[0]);
+ EXPECT_EQ(0,filter.payload_min[0]);
+ EXPECT_EQ(INT32_MAX,filter.payload_max[0]);
+
+
+ strncpy(tmp, filter.apid[1], DLT_ID_SIZE);
+ EXPECT_STREQ("app",tmp);
+ strncpy(tmp, filter.ctid[1], DLT_ID_SIZE);
+ EXPECT_STREQ("",tmp);
+
+ EXPECT_EQ(0,filter.log_level[2]);
+ EXPECT_EQ(20,filter.payload_min[2]);
+ EXPECT_EQ(50,filter.payload_max[2]);
+
+ while (dlt_file_read(&file, 0) >= 0) {}
+
+ for (int i = 0; i < file.counter; i++) {
+ EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0));
+ EXPECT_LE(DLT_RETURN_OK, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 0));
+ }
+
+ for (int i = 0; i < file.counter; i++) {
+ EXPECT_LE(DLT_RETURN_OK, dlt_file_message(&file, i, 0));
+ EXPECT_LE(DLT_RETURN_OK, dlt_message_print_ascii(&file.msg, text, DLT_DAEMON_TEXTSIZE, 1));
+ }
+
+ EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0));
+}
+TEST(t_dlt_message_print_ascii_with_json_filter, abnormal)
+{
+ /* equal with t_dlt_message_print_ascii */
+}
+TEST(t_dlt_message_print_ascii_with_json_filter, nullpointer)
+{
+ /* equal with t_dlt_message_print_ascii */
+}
+/* End Method: dlt_common::dlt_message_print_ascii with json filter*/