summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordbiastoch <dbiastoch@de.adit-jv.com>2021-01-20 15:12:15 +0100
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2021-06-30 10:54:59 +0900
commit445c2ec41eef9076a80cfc435b4d75a102e0adcb (patch)
tree74f233dea8aac0d08c54d4ea11069741e8dfd326
parent442688504260bb2bfcfb08a9865f223d2ab2d19a (diff)
downloadDLT-daemon-445c2ec41eef9076a80cfc435b4d75a102e0adcb.tar.gz
dlt-receive: Implemented gtest for extended filtering
-Added 'testfile_extended.dlt', which extends the default 'testfile.dlt' by messages with very different lenghts, log levels, ContextIDs and AppIDs -Added 'testfilter.json', which contains a valide json filter file -Implemented gtest 't_dlt_message_print_ascii_with_json_filter' in 'gtest_dlt_common.cpp' to test the correct behavior of extended filtering and the json filter file parsing Signed-off-by: dbiastoch <dbiastoch@de.adit-jv.com>
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/gtest_dlt_common.cpp73
-rw-r--r--tests/testfile_extended.dltbin0 -> 5012 bytes
-rw-r--r--tests/testfilter.json17
4 files changed, 92 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 3b7bbe4..9c1ab86 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -2,6 +2,8 @@
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)
diff --git a/tests/gtest_dlt_common.cpp b/tests/gtest_dlt_common.cpp
index 9afb830..b6a6c48 100644
--- a/tests/gtest_dlt_common.cpp
+++ b/tests/gtest_dlt_common.cpp
@@ -1827,6 +1827,79 @@ 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/testfile_extended.dlt b/tests/testfile_extended.dlt
new file mode 100644
index 0000000..6afa2aa
--- /dev/null
+++ b/tests/testfile_extended.dlt
Binary files differ
diff --git a/tests/testfilter.json b/tests/testfilter.json
new file mode 100644
index 0000000..c4ba61f
--- /dev/null
+++ b/tests/testfilter.json
@@ -0,0 +1,17 @@
+{
+"filter1": {
+ "AppId": "LOG",
+ "ContextId": "TEST",
+ "LogLevel": "3"
+ },
+"filter2": {
+ "AppId": "app",
+ "LogLevel": "4"
+ },
+"filter3": {
+ "AppId": "app2",
+ "ContextId": "con2",
+ "PayloadMin": "20",
+ "PayloadMax": "50"
+ }
+}