From 3dca373d843213f03c95df56e36b16d6b83fd58f Mon Sep 17 00:00:00 2001 From: Bui Nguyen Quoc Thanh Date: Fri, 24 Apr 2020 15:35:49 +0700 Subject: Unittest for new api Add two new testcases in tests/gtest_dlt_common.cpp for dlt_file_quick_parsing() Signed-off-by: Bui Nguyen Quoc Thanh --- tests/gtest_dlt_common.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/gtest_dlt_common.cpp b/tests/gtest_dlt_common.cpp index 04fdbc6..adbc87d 100644 --- a/tests/gtest_dlt_common.cpp +++ b/tests/gtest_dlt_common.cpp @@ -1623,6 +1623,59 @@ TEST(t_dlt_file_open, nullpointer) +/* Begin Method: dlt_common::dlt_file_quick_parsing */ +TEST(t_dlt_file_quick_parsing, normal) +{ + DltFile file; + /* Get PWD so file can be used*/ + char pwd[100]; + char openfile[114]; + char output[128] = "/tmp/output_testfile.txt"; + + /* ignore returned value from getcwd */ + if (getcwd(pwd, 100) == NULL) {} + + sprintf(openfile, "%s/testfile.dlt", pwd); + /*---------------------------------------*/ + + /* Normal Use-Case, expected 0 */ + EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); + EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); + EXPECT_LE(DLT_RETURN_OK, dlt_file_quick_parsing(&file, output, DLT_OUTPUT_ASCII, 0)); + EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); + unlink(output); +} + +TEST(t_dlt_file_quick_parsing, abnormal) +{ + DltFile file; + /* Get PWD so file can be used*/ + char pwd[100]; + char openfile[114]; + char output[128] = "/tmp/output_testfile.txt"; + + /* ignore returned value from getcwd */ + if (getcwd(pwd, 100) == NULL) {} + + sprintf(openfile, "%s/testfile.dlt", pwd); + /*---------------------------------------*/ + + /* Abnormal Use-Case, expected DLT_RETURN_WRONG_PARAMETER (-5) */ + EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); + EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); + EXPECT_GE(DLT_RETURN_WRONG_PARAMETER, dlt_file_quick_parsing(&file, NULL, DLT_OUTPUT_ASCII, 0)); + EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); + + EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); + EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); + EXPECT_GE(DLT_RETURN_WRONG_PARAMETER, dlt_file_quick_parsing(NULL, output, DLT_OUTPUT_ASCII, 0)); + EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); +} +/* End Method: dlt_common::dlt_file_quick_parsing */ + + + + /* Begin Method: dlt_common::dlt_message_print_ascii*/ TEST(t_dlt_message_print_ascii, normal) { @@ -3129,7 +3182,8 @@ TEST(t_dlt_message_payload, abnormal) /* Get PWD so file and filter can be used*/ char pwd[100]; - getcwd(pwd, 100); + if (getcwd(pwd, 100) == NULL) {} + char openfile[114]; sprintf(openfile, "%s/testfile.dlt", pwd); /*---------------------------------------*/ -- cgit v1.2.1