From 4c8d43322e89b87288fb5ba12e523237e620481b Mon Sep 17 00:00:00 2001 From: Lutz Helwing Date: Tue, 22 Sep 2015 10:49:29 +0200 Subject: Fixed whitespace and formatting of new code Fixed licence headers Signed-off-by: Alexander Wenzel --- tests/dlt-test-cpp-extension.cpp | 180 +++---- tests/dlt-test-preregister-context.c | 48 +- tests/dlt_env_ll_unit_test.cpp | 933 ++++++++++++++++++----------------- tests/gtest_dlt_common.cpp | 2 - 4 files changed, 596 insertions(+), 567 deletions(-) (limited to 'tests') diff --git a/tests/dlt-test-cpp-extension.cpp b/tests/dlt-test-cpp-extension.cpp index ce9f1db..c4cf70c 100644 --- a/tests/dlt-test-cpp-extension.cpp +++ b/tests/dlt-test-cpp-extension.cpp @@ -1,118 +1,122 @@ -/** +/* * @licence app begin@ - * Copyright (C) 2015 Intel Corporation + * SPDX license identifier: MPL-2.0 * - * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps. + * Copyright (C) 2015 Intel Corporation * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. * - * \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/. + * Mozilla Public License (MPL), 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@ */ +/*! + * \author Stefan Vacek Intel Corporation + * + * \copyright Copyright © 2015 Intel Corporation. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt-test-cpp-extension.cpp +*/ + #include "dlt_cpp_extension.hpp" #include #include - struct MyStruct { - int64_t uuid; - int32_t interfaceId; - int32_t registrationState; + 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; + 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 intVector; - intVector.push_back(0); - intVector.push_back(1); - intVector.push_back(2); - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "vector", intVector); - - std::vector doubleList; - doubleList.push_back(10.); - doubleList.push_back(11.); - doubleList.push_back(12.); - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "list", doubleList); - - std::map 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; + 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 intVector; + intVector.push_back(0); + intVector.push_back(1); + intVector.push_back(2); + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "vector", intVector); + + std::vector doubleList; + doubleList.push_back(10.); + doubleList.push_back(11.); + doubleList.push_back(12.); + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "list", doubleList); + + std::map 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; } diff --git a/tests/dlt-test-preregister-context.c b/tests/dlt-test-preregister-context.c index ad10d6f..2f66347 100644 --- a/tests/dlt-test-preregister-context.c +++ b/tests/dlt-test-preregister-context.c @@ -1,8 +1,29 @@ -/** - * Copyright (C) 2015 Intel Corporation +/* + * @licence app begin@ + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2015 Intel Corporation + * + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. + * + * This Source Code Form is subject to the terms of the + * Mozilla Public License (MPL), 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/. * + * For further information see http://www.genivi.org/. + * @licence end@ */ +/*! + * \author Stefan Vacek Intel Corporation + * + * \copyright Copyright © 2015 Intel Corporation. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt-test-preregister-context.c +*/ + #include /* for fork() */ #include "dlt.h" @@ -12,21 +33,22 @@ */ int main() { - DltContext mainContext; - DLT_REGISTER_CONTEXT(mainContext, "CTXP", "main context"); + DltContext mainContext; + DLT_REGISTER_CONTEXT(mainContext, "CTXP", "main context"); - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before app registered")); - usleep(200000); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before app registered")); + usleep(200000); - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Second message before app registered")); - usleep(200000); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Second message before app registered")); + usleep(200000); - DLT_REGISTER_APP("PRNT", "Sample pre-register application"); + DLT_REGISTER_APP("PRNT", "Sample pre-register application"); - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message after app registered")); - usleep(200000); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message after app registered")); + usleep(200000); - DLT_UNREGISTER_APP(); + DLT_UNREGISTER_APP() + ; - return 0; + return 0; } diff --git a/tests/dlt_env_ll_unit_test.cpp b/tests/dlt_env_ll_unit_test.cpp index f50e603..10c8907 100644 --- a/tests/dlt_env_ll_unit_test.cpp +++ b/tests/dlt_env_ll_unit_test.cpp @@ -1,10 +1,28 @@ /* -@COPYRIGHT_TAG@ - */ -/** - * @file + * @licence app begin@ + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2015 Intel Corporation + * + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. + * + * This Source Code Form is subject to the terms of the + * Mozilla Public License (MPL), 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/. + * + * For further information see http://www.genivi.org/. + * @licence end@ */ +/*! + * \author Stefan Vacek Intel Corporation + * + * \copyright Copyright © 2015 Intel Corporation. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt_env_ll_unit_test.cpp +*/ #include "gtest/gtest.h" #include "dlt_user.h" @@ -13,528 +31,515 @@ /* simply include the whole file to allow testing it */ #include "src/lib/dlt_env_ll.c" - int main(int argc, char* argv[]) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } - TEST(DltExtensionTests, extract_id) { - /* testing valid input */ - char id[4u]; - - char env0[] = "abcd:1234:3"; - char *tmp = &env0[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env0[0], 4); // moved 4 bytes - ASSERT_EQ(id[0], 'a'); - ASSERT_EQ(id[1], 'b'); - ASSERT_EQ(id[2], 'c'); - ASSERT_EQ(id[3], 'd'); - - char env1[] = "abc:1234:3"; - tmp = &env1[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env1[0], 3); // moved 3 bytes - ASSERT_EQ(id[0], 'a'); - ASSERT_EQ(id[1], 'b'); - ASSERT_EQ(id[2], 'c'); - ASSERT_EQ(id[3], 0); - - char env2[] = "ab:1234:3"; - tmp = &env2[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env2[0], 2); // moved 2 bytes - ASSERT_EQ(id[0], 'a'); - ASSERT_EQ(id[1], 'b'); - ASSERT_EQ(id[2], 0); - ASSERT_EQ(id[3], 0); - - char env3[] = "a:1234:3"; - tmp = &env3[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env3[0], 1); // moved 1 byte - ASSERT_EQ(id[0], 'a'); - ASSERT_EQ(id[1], 0); - ASSERT_EQ(id[2], 0); - ASSERT_EQ(id[3], 0); - - char env4[] = ":1234:3"; - tmp = &env4[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env4[0], 0); // moved 1 byte - ASSERT_EQ(id[0], 0); - ASSERT_EQ(id[1], 0); - ASSERT_EQ(id[2], 0); - ASSERT_EQ(id[3], 0); - - char env5[] = "abcd:1234:3;"; - tmp = &env5[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env5[0], 4); // moved 4 bytes - ASSERT_EQ(id[0], 'a'); - ASSERT_EQ(id[1], 'b'); - ASSERT_EQ(id[2], 'c'); - ASSERT_EQ(id[3], 'd'); - - - /* testing invalid input */ - /* - string too long: abcde: - * - string too short/missing end: abc - * - NULL string: - */ - tmp = NULL; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); - - char env6[] = "abcd:1234:3"; - tmp = &env6[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, NULL), -1); - - char invalid0[] = ""; - tmp = &invalid0[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); - - char invalid1[] = "abcd"; /* missing delimiter */ - tmp = &invalid1[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); - - char invalid2[] = "abcde"; /* id too long */ - tmp = &invalid2[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); + /* testing valid input */ + char id[4u]; + + char env0[] = "abcd:1234:3"; + char *tmp = &env0[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env0[0], 4); // moved 4 bytes + ASSERT_EQ(id[0], 'a'); + ASSERT_EQ(id[1], 'b'); + ASSERT_EQ(id[2], 'c'); + ASSERT_EQ(id[3], 'd'); + + char env1[] = "abc:1234:3"; + tmp = &env1[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env1[0], 3); // moved 3 bytes + ASSERT_EQ(id[0], 'a'); + ASSERT_EQ(id[1], 'b'); + ASSERT_EQ(id[2], 'c'); + ASSERT_EQ(id[3], 0); + + char env2[] = "ab:1234:3"; + tmp = &env2[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env2[0], 2); // moved 2 bytes + ASSERT_EQ(id[0], 'a'); + ASSERT_EQ(id[1], 'b'); + ASSERT_EQ(id[2], 0); + ASSERT_EQ(id[3], 0); + + char env3[] = "a:1234:3"; + tmp = &env3[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env3[0], 1); // moved 1 byte + ASSERT_EQ(id[0], 'a'); + ASSERT_EQ(id[1], 0); + ASSERT_EQ(id[2], 0); + ASSERT_EQ(id[3], 0); + + char env4[] = ":1234:3"; + tmp = &env4[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env4[0], 0); // moved 1 byte + ASSERT_EQ(id[0], 0); + ASSERT_EQ(id[1], 0); + ASSERT_EQ(id[2], 0); + ASSERT_EQ(id[3], 0); + + char env5[] = "abcd:1234:3;"; + tmp = &env5[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env5[0], 4); // moved 4 bytes + ASSERT_EQ(id[0], 'a'); + ASSERT_EQ(id[1], 'b'); + ASSERT_EQ(id[2], 'c'); + ASSERT_EQ(id[3], 'd'); + + /* testing invalid input */ + /* - string too long: abcde: + * - string too short/missing end: abc + * - NULL string: + */ + tmp = NULL; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); + + char env6[] = "abcd:1234:3"; + tmp = &env6[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, NULL), -1); + + char invalid0[] = ""; + tmp = &invalid0[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); + + char invalid1[] = "abcd"; /* missing delimiter */ + tmp = &invalid1[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); + + char invalid2[] = "abcde"; /* id too long */ + tmp = &invalid2[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); } - TEST(DltExtensionTests, extract_ll) { - /* testing valid input */ - int8_t ll; - - char env_1[] = "-1"; - char *tmp = &env_1[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env_1[0], 2); // moved 2 bytes - ASSERT_EQ(ll, -1); - - char env0[] = "0;"; - tmp = &env0[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env0[0], 1); // moved 1 byte - ASSERT_EQ(ll, 0); - - char env1[] = "1;"; - tmp = &env1[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env1[0], 1); // moved 1 byte - ASSERT_EQ(ll, 1); - - char env2[] = "2;"; - tmp = &env2[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env2[0], 1); // moved 1 byte - ASSERT_EQ(ll, 2); - - char env3[] = "3;"; - tmp = &env3[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env3[0], 1); // moved 1 byte - ASSERT_EQ(ll, 3); - - char env4[] = "4;"; - tmp = &env4[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env4[0], 1); // moved 1 byte - ASSERT_EQ(ll, 4); - - char env5[] = "5;"; - tmp = &env5[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env5[0], 1); // moved 1 byte - ASSERT_EQ(ll, 5); - - char env6[] = "6;"; - tmp = &env6[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env6[0], 1); // moved 1 byte - ASSERT_EQ(ll, 6); - - /* testing invalid input */ - /* - number outside range, e.g. -2, 103 - * - missing delimiter - * - NULL string: - */ - tmp = NULL; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); - - char env7[] = "abcd:1234:3"; - tmp = &env7[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, NULL), -1); - - char invalid0[] = ""; - tmp = &invalid0[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); - - char invalid1[] = "-2"; /* outside range */ - tmp = &invalid1[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); - - char invalid2[] = "8"; /* outside range */ - tmp = &invalid2[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); - - char invalid3[] = "1e"; /* missing delimiter */ - tmp = &invalid3[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); + /* testing valid input */ + int8_t ll; + + char env_1[] = "-1"; + char *tmp = &env_1[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env_1[0], 2); // moved 2 bytes + ASSERT_EQ(ll, -1); + + char env0[] = "0;"; + tmp = &env0[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env0[0], 1); // moved 1 byte + ASSERT_EQ(ll, 0); + + char env1[] = "1;"; + tmp = &env1[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env1[0], 1); // moved 1 byte + ASSERT_EQ(ll, 1); + + char env2[] = "2;"; + tmp = &env2[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env2[0], 1); // moved 1 byte + ASSERT_EQ(ll, 2); + + char env3[] = "3;"; + tmp = &env3[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env3[0], 1); // moved 1 byte + ASSERT_EQ(ll, 3); + + char env4[] = "4;"; + tmp = &env4[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env4[0], 1); // moved 1 byte + ASSERT_EQ(ll, 4); + + char env5[] = "5;"; + tmp = &env5[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env5[0], 1); // moved 1 byte + ASSERT_EQ(ll, 5); + + char env6[] = "6;"; + tmp = &env6[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env6[0], 1); // moved 1 byte + ASSERT_EQ(ll, 6); + + /* testing invalid input */ + /* - number outside range, e.g. -2, 103 + * - missing delimiter + * - NULL string: + */ + tmp = NULL; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); + + char env7[] = "abcd:1234:3"; + tmp = &env7[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, NULL), -1); + + char invalid0[] = ""; + tmp = &invalid0[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); + + char invalid1[] = "-2"; /* outside range */ + tmp = &invalid1[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); + + char invalid2[] = "8"; /* outside range */ + tmp = &invalid2[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); + + char invalid3[] = "1e"; /* missing delimiter */ + tmp = &invalid3[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); } - TEST(DltExtensionTests, extract_ll_item) { - /* testing valid input */ - dlt_env_ll_item item; - - char env0[] = "abcd:1234:3"; - char *tmp = &env0[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), 0); - ASSERT_EQ(tmp - &env0[0], 11); // moved 11 bytes - ASSERT_EQ(item.appId[0], 'a'); - ASSERT_EQ(item.appId[1], 'b'); - ASSERT_EQ(item.appId[2], 'c'); - ASSERT_EQ(item.appId[3], 'd'); - ASSERT_EQ(item.ctxId[0], '1'); - ASSERT_EQ(item.ctxId[1], '2'); - ASSERT_EQ(item.ctxId[2], '3'); - ASSERT_EQ(item.ctxId[3], '4'); - ASSERT_EQ(item.ll, 3); - - char env1[] = "::-1;"; - tmp = &env1[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), 0); - ASSERT_EQ(tmp - &env1[0], 4); // moved 4 bytes - ASSERT_EQ(item.appId[0], 0); - ASSERT_EQ(item.appId[1], 0); - ASSERT_EQ(item.appId[2], 0); - ASSERT_EQ(item.appId[3], 0); - ASSERT_EQ(item.ctxId[0], 0); - ASSERT_EQ(item.ctxId[1], 0); - ASSERT_EQ(item.ctxId[2], 0); - ASSERT_EQ(item.ctxId[3], 0); - ASSERT_EQ(item.ll, -1); - - /* testing invalid input */ - /* - string too long: abcde: - * - string too short/missing end: abc - * - NULL string: - */ - tmp = NULL; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); - - char env2[] = "abcd:1234:3"; - tmp = &env2[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, NULL), -1); - - char invalid0[] = ""; - tmp = &invalid0[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); - - char invalid1[] = "abcd:1234:"; /* missing ll */ - tmp = &invalid1[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); - - char invalid2[] = "abcd:1234"; /* missing ll, missing delimiter in ctxId */ - tmp = &invalid2[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); - - char invalid3[] = "abcd:"; /* missing ll, missing delimiter in appId */ - tmp = &invalid3[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); - - char invalid4[] = "abcd"; /* missing ll, missing delimiter in appId */ - tmp = &invalid4[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + /* testing valid input */ + dlt_env_ll_item item; + + char env0[] = "abcd:1234:3"; + char *tmp = &env0[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), 0); + ASSERT_EQ(tmp - &env0[0], 11); // moved 11 bytes + ASSERT_EQ(item.appId[0], 'a'); + ASSERT_EQ(item.appId[1], 'b'); + ASSERT_EQ(item.appId[2], 'c'); + ASSERT_EQ(item.appId[3], 'd'); + ASSERT_EQ(item.ctxId[0], '1'); + ASSERT_EQ(item.ctxId[1], '2'); + ASSERT_EQ(item.ctxId[2], '3'); + ASSERT_EQ(item.ctxId[3], '4'); + ASSERT_EQ(item.ll, 3); + + char env1[] = "::-1;"; + tmp = &env1[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), 0); + ASSERT_EQ(tmp - &env1[0], 4); // moved 4 bytes + ASSERT_EQ(item.appId[0], 0); + ASSERT_EQ(item.appId[1], 0); + ASSERT_EQ(item.appId[2], 0); + ASSERT_EQ(item.appId[3], 0); + ASSERT_EQ(item.ctxId[0], 0); + ASSERT_EQ(item.ctxId[1], 0); + ASSERT_EQ(item.ctxId[2], 0); + ASSERT_EQ(item.ctxId[3], 0); + ASSERT_EQ(item.ll, -1); + + /* testing invalid input */ + /* - string too long: abcde: + * - string too short/missing end: abc + * - NULL string: + */ + tmp = NULL; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + + char env2[] = "abcd:1234:3"; + tmp = &env2[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, NULL), -1); + + char invalid0[] = ""; + tmp = &invalid0[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + + char invalid1[] = "abcd:1234:"; /* missing ll */ + tmp = &invalid1[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + + char invalid2[] = "abcd:1234"; /* missing ll, missing delimiter in ctxId */ + tmp = &invalid2[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + + char invalid3[] = "abcd:"; /* missing ll, missing delimiter in appId */ + tmp = &invalid3[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + + char invalid4[] = "abcd"; /* missing ll, missing delimiter in appId */ + tmp = &invalid4[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); } - TEST(DltExtensionTests, basic_ll_set_handling) { - dlt_env_init_ll_set(NULL); // must not crash - dlt_env_free_ll_set(NULL); // must not crash - dlt_env_increase_ll_set(NULL); // must not crash - - dlt_env_ll_set ll_set; - dlt_env_init_ll_set(&ll_set); - EXPECT_TRUE(NULL != ll_set.item); - EXPECT_EQ(DLT_ENV_LL_SET_INCREASE, ll_set.array_size); - EXPECT_EQ(0, ll_set.num_elem); - - dlt_env_free_ll_set(&ll_set); - EXPECT_TRUE(NULL == ll_set.item); - EXPECT_EQ(0, ll_set.array_size); - EXPECT_EQ(0, ll_set.num_elem); - - dlt_env_init_ll_set(&ll_set); - for (int i = 0; i