From 3bb7eb24092ff771ccfd1119f8c1088f3f78f981 Mon Sep 17 00:00:00 2001 From: Martin Willers Date: Mon, 31 May 2021 07:45:48 +0200 Subject: Add missing string functions (#309) Signed-off-by: Martin Willers --- tests/gtest_dlt_user.cpp | 209 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) (limited to 'tests') diff --git a/tests/gtest_dlt_user.cpp b/tests/gtest_dlt_user.cpp index a66f7a4..918af11 100644 --- a/tests/gtest_dlt_user.cpp +++ b/tests/gtest_dlt_user.cpp @@ -89,6 +89,10 @@ extern "C" { * int dlt_user_log_write_utf8_string_attr(DltContextData *log, const char *text, const char *name); * int dlt_user_log_write_sized_utf8_string(DltContextData *log, const char *text, uint16_t length); * int dlt_user_log_write_sized_utf8_string_attr(DltContextData *log, const char *text, uint16_t length, const char *name); + * int dlt_user_log_write_constant_utf8_string(DltContextData *log, const char *text); + * int dlt_user_log_write_constant_utf8_string_attr(DltContextData *log, const char *text, const char *name); + * int dlt_user_log_write_sized_constant_utf8_string(DltContextData *log, const char *text); + * int dlt_user_log_write_sized_constant_utf8_string_attr(DltContextData *log, const char *text, const char *name); * int dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length); * int dlt_user_log_write_raw_attr(DltContextData *log,void *data,uint16_t length, const char *name); * int dlt_user_log_write_raw_formatted(DltContextData *log,void *data,uint16_t length,DltFormatType type); @@ -3337,6 +3341,131 @@ TEST(t_dlt_user_log_write_sized_utf8_string, nullpointer) EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); } +/*/////////////////////////////////////// */ +/* t_dlt_user_log_write_constant_utf8_string*/ +TEST(t_dlt_user_log_write_constant_utf8_string, verbose) +{ + DltContext context; + DltContextData contextData; + + EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); + EXPECT_LE(DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string verbose")); + + const char *text1 = "test1"; + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(&contextData, text1)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); +} + +TEST(t_dlt_user_log_write_constant_utf8_string, nullpointer) +{ + DltContext context; + DltContextData contextData; + + EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); + EXPECT_LE(DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string nullpointer")); + + const char *text1 = "test1"; + EXPECT_LE(DLT_RETURN_TRUE, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(NULL, text1)); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(NULL, NULL)); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(&contextData, NULL)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); +} + +TEST(t_dlt_user_log_write_constant_utf8_string, nonverbose) +{ + dlt_nonverbose_mode(); + + DltContext context; + DltContextData contextData; + + EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); + EXPECT_LE(DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string nonverbose")); + + const char *text2 = "test2"; + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, 42)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string(&contextData, text2)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); + + dlt_verbose_mode(); +} + +/*/////////////////////////////////////// */ +/* t_dlt_user_log_write_sized_constant_utf8_string */ +TEST(t_dlt_user_log_write_sized_constant_utf8_string, verbose) +{ + DltContext context; + DltContextData contextData; + + EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); + EXPECT_LE(DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string verbose")); + + const char *text1 = "test1text"; + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(&contextData, text1, 5)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); +} + +TEST(t_dlt_user_log_write_sized_constant_utf8_string, nullpointer) +{ + DltContext context; + DltContextData contextData; + + EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); + EXPECT_LE(DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string nullpointer")); + + const char *text1 = "test1text"; + EXPECT_LE(DLT_RETURN_TRUE, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(NULL, text1, 5)); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(NULL, NULL, 5)); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(&contextData, NULL, 5)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); +} + +TEST(t_dlt_user_log_write_sized_constant_utf8_string, nonverbose) +{ + dlt_nonverbose_mode(); + + DltContext context; + DltContextData contextData; + + EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); + EXPECT_LE(DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string nonverbose")); + + const char *text2 = "test2text"; + size_t text2len = 5; // only use a (non-null-terminated) substring + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start_id(&context, &contextData, DLT_LOG_DEFAULT, 42)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string(&contextData, text2, text2len)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); + + dlt_verbose_mode(); +} + /*/////////////////////////////////////// */ /* t_dlt_user_log_write_string_attr */ TEST(t_dlt_user_log_write_string_attr, normal) @@ -3463,6 +3592,86 @@ TEST(t_dlt_user_log_write_sized_utf8_string_attr, normal) EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); } +/*/////////////////////////////////////// */ +/* t_dlt_user_log_write_constant_utf8_string_attr */ +TEST(t_dlt_user_log_write_constant_utf8_string_attr, normal) +{ + DltContext context; + DltContextData contextData; + + EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); + EXPECT_LE(DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string_attr normal")); + + const char *text1 = "test1"; + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string_attr(&contextData, text1, "name")); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); +} + +TEST(t_dlt_user_log_write_constant_utf8_string_attr, nullpointer) +{ + DltContext context; + DltContextData contextData; + + EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); + EXPECT_LE(DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_constant_utf8_string_attr nullpointer")); + + const char *text1 = "test1"; + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string_attr(NULL, text1, "name")); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string_attr(NULL, NULL, "name")); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_constant_utf8_string_attr(&contextData, NULL, "name")); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); +} + +/*/////////////////////////////////////// */ +/* t_dlt_user_log_write_sized_constant_utf8_string_attr */ +TEST(t_dlt_user_log_write_sized_constant_utf8_string_attr, normal) +{ + DltContext context; + DltContextData contextData; + + EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); + EXPECT_LE(DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string_attr normal")); + + const char *text1 = "test1text"; + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string_attr(&contextData, text1, 5, "name")); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); +} + +TEST(t_dlt_user_log_write_sized_constant_utf8_string_attr, nullpointer) +{ + DltContext context; + DltContextData contextData; + + EXPECT_LE(DLT_RETURN_OK, dlt_register_app("TUSR", "dlt_user.c tests")); + EXPECT_LE(DLT_RETURN_OK, + dlt_register_context(&context, "TEST", "dlt_user.c t_dlt_user_log_write_sized_constant_utf8_string_attr nullpointer")); + + const char *text1 = "test1text"; + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_start(&context, &contextData, DLT_LOG_DEFAULT)); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string_attr(NULL, text1, 5, "name")); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string_attr(NULL, NULL, 5, "name")); + EXPECT_GT(DLT_RETURN_OK, dlt_user_log_write_sized_constant_utf8_string_attr(&contextData, NULL, 5, "name")); + EXPECT_LE(DLT_RETURN_OK, dlt_user_log_write_finish(&contextData)); + + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context)); + EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app()); +} + /*/////////////////////////////////////// */ /* t_dlt_user_log_write_raw */ TEST(t_dlt_user_log_write_raw, normal) -- cgit v1.2.1