summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCollin <iCollin@users.noreply.github.com>2021-06-30 13:16:44 -0400
committerGitHub <noreply@github.com>2021-06-30 13:16:44 -0400
commit5ecfd16ff038fc8c964183e4e26231e3803a05ff (patch)
tree2c19a78be21e5607679240068fd6d897088ada59
parentb15ee865d68a0c719df1908321a65569a401e7e0 (diff)
downloadsdl_core-5ecfd16ff038fc8c964183e4e26231e3803a05ff.tar.gz
remove deprecated/unused ini files (#3731)
-rw-r--r--src/components/config_profile/include/config_profile/ini_file.h145
-rw-r--r--src/components/config_profile/src/ini_file.cc424
-rw-r--r--src/components/config_profile/test/ini_file_test.cc335
3 files changed, 0 insertions, 904 deletions
diff --git a/src/components/config_profile/include/config_profile/ini_file.h b/src/components/config_profile/include/config_profile/ini_file.h
deleted file mode 100644
index f489872533..0000000000
--- a/src/components/config_profile/include/config_profile/ini_file.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (c) 2013, Ford Motor Company
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the Ford Motor Company nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef SRC_COMPONENTS_CONFIG_PROFILE_INCLUDE_CONFIG_PROFILE_INI_FILE_H_
-#define SRC_COMPONENTS_CONFIG_PROFILE_INCLUDE_CONFIG_PROFILE_INI_FILE_H_
-
-#include <stdint.h>
-#include "utils/macro.h"
-
-namespace profile {
-
-#define INI_FILE_VER 1000
-
-#if !defined TRUE
-#define TRUE 1
-#endif
-#if !defined True
-#define True 1
-#endif
-
-#if !defined FALSE
-#define FALSE 0
-#endif
-#if !defined False
-#define False 0
-#endif
-
-/*
- * @brief Global defines
- */
-#define INI_LINE_LEN 1024
-#define INI_FILE_TEMP_NAME "ini.tmp"
-
-#define INI_FLAG_UPDATE 0x00
-#define INI_FLAG_ITEM_UP_CREA 0x01
-#define INI_FLAG_FILE_UP_CREA 0x10
-
-/*
- * @brief Global typedefs
- */
-typedef enum Ini_search_id_e {
- INI_NOTHING,
- INI_RIGHT_CHAPTER,
- INI_WRONG_CHAPTER,
- INI_RIGHT_ITEM,
- INI_WRONG_ITEM,
- INI_REMARK,
-
- INI_SEARCH_MAX
-} Ini_search_id;
-
-/*
- * @brief Prototypes of functions
- */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * @brief Write usage instructions to the end of the file
- * @param
- *
- * \deprecated This method will be removed in the next major release
- * See Profile::ParseConfiguration for the new ini parsing code
- *
- * @return NULL if file or desired entry not found, otherwise pointer to fname
- */
-DEPRECATED extern char* ini_write_inst(const char* fname, uint8_t flag);
-
-/*
- * @brief Read a certain item of the specified chapter of a ini-file
- *
- * \deprecated This method will be removed in the next major release
- * See Profile::ParseConfiguration for the new ini parsing code
- *
- * @return NULL if file or desired entry not found, otherwise pointer to value
- */
-DEPRECATED extern char* ini_read_value(const char* fname,
- const char* chapter,
- const char* item,
- char* value);
-
-/*
- * @brief Write a certain item of the specified chapter of a ini-file
- *
- * \deprecated This method will be removed in the next major release
- * See Profile::ParseConfiguration for the new ini parsing code
- *
- * @return NULL if file not found, otherwise pointer to value
- */
-DEPRECATED extern char ini_write_value(const char* fname,
- const char* chapter,
- const char* item,
- const char* value,
- uint8_t flag);
-
-/*
- * @brief Parse the given line for the item and returns the value if
- * there is one otherwise NULL
- *
- * \deprecated This method will be removed in the next major release
- * See Profile::ParseConfiguration for the new ini parsing code
- *
- * @return NULL if desired entry not found, otherwise pointer to value
- */
-DEPRECATED extern Ini_search_id ini_parse_line(const char* line,
- const char* tag,
- char* value);
-
-#ifdef __cplusplus
-}
-#endif
-
-} // namespace profile
-
-#endif // SRC_COMPONENTS_CONFIG_PROFILE_INCLUDE_CONFIG_PROFILE_INI_FILE_H_
diff --git a/src/components/config_profile/src/ini_file.cc b/src/components/config_profile/src/ini_file.cc
deleted file mode 100644
index 615100d9a7..0000000000
--- a/src/components/config_profile/src/ini_file.cc
+++ /dev/null
@@ -1,424 +0,0 @@
-/*
- * Copyright (c) 2013, Ford Motor Company
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the Ford Motor Company nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config_profile/ini_file.h"
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "utils/logger.h"
-
-#ifndef _WIN32
-#include <unistd.h>
-#else
-#define PATH_MAX _MAX_PATH
-#endif
-
-#ifdef __linux__
-#define USE_MKSTEMP 1
-#endif
-
-#include <string>
-
-namespace profile {
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-
-SDL_CREATE_LOG_VARIABLE("Profile")
-
-char* ini_write_inst(const char* fname, uint8_t flag) {
- FILE* fp = 0;
-
- if (NULL == fname)
- return NULL;
- if ('\0' == *fname)
- return NULL;
-
- if ((fp = fopen(fname, "a")) == 0)
- if (flag & INI_FLAG_FILE_UP_CREA)
- if ((fp = fopen(fname, "w")) == 0)
- return NULL;
- if (0 == fp) {
- return NULL;
- }
- fprintf(fp, "\n");
- fprintf(fp, "; The INI-file consists of different chapters.\n");
- fprintf(fp, "; Each chapter begins with the line containing\n");
- fprintf(fp, "; the name in square brackets. Syntax:\n");
- fprintf(fp, "; [chapter]\n");
- fprintf(fp, "; The chapters consists of a set of items with a\n");
- fprintf(fp, "; assinged value. The syntax is:\n");
- fprintf(fp, "; item=value\n");
- fprintf(fp, "; All white spaces an second encounters of chapters\n");
- fprintf(fp, "; or items will be ignored.\n");
- fprintf(fp, "; Remarks start with semicolon or star as first character.\n");
- fprintf(fp, "; It is alowed for names of chapters and items to\n");
- fprintf(fp, "; contain semicolon and star. Possible syntax is:\n");
- fprintf(fp, "; [ chapter ] ;Remark\n");
- fprintf(fp, "; item = value\n");
- fprintf(fp, "\n");
-
- fclose(fp);
- return const_cast<char*>(fname);
-}
-
-char* ini_read_value(const char* fname,
- const char* chapter,
- const char* item,
- char* value) {
- FILE* fp = 0;
- bool chapter_found = false;
- char line[INI_LINE_LEN] = "";
- char val[INI_LINE_LEN] = "";
- char tag[INI_LINE_LEN] = "";
-
- Ini_search_id result;
- *line = '\0';
- *val = '\0';
- *tag = '\0';
- if ((NULL == fname) || (NULL == chapter) || (NULL == item) || (NULL == value))
- return NULL;
-
- *value = '\0';
- if (('\0' == *fname) || ('\0' == *chapter) || ('\0' == *item))
- return NULL;
-
- if ((fp = fopen(fname, "r")) == 0)
- return NULL;
-
- snprintf(tag, INI_LINE_LEN, "%s", chapter);
- for (uint32_t i = 0; i < strlen(tag); ++i) {
- tag[i] = toupper(tag[i]);
- }
-
- while (NULL != fgets(line, INI_LINE_LEN, fp)) {
- // Now start the line parsing
- result = ini_parse_line(line, tag, val);
- if (!chapter_found) {
- if (INI_RIGHT_CHAPTER == result) {
- chapter_found = true;
-
- snprintf(tag, INI_LINE_LEN, "%s", item);
- for (uint32_t i = 0; i < strlen(tag); ++i)
- tag[i] = toupper(tag[i]);
- }
- } else {
- // FIXME (dchmerev): Unnecessary condition
- if ((INI_RIGHT_CHAPTER == result) || (INI_WRONG_CHAPTER == result)) {
- fclose(fp);
- return NULL;
- }
- if (INI_RIGHT_ITEM == result) {
- fclose(fp);
- snprintf(value, INI_LINE_LEN, "%s", val);
- return value;
- }
- }
- }
-
- fclose(fp);
-
- return NULL;
-}
-
-#ifdef BUILD_TESTS
-// cppcheck-suppress unusedFunction //Used in unit tests
-char ini_write_value(const char* fname,
- const char* chapter,
- const char* item,
- const char* value,
- uint8_t flag) {
- FILE *rd_fp, *wr_fp = 0;
- uint16_t cr_count;
- int32_t wr_result;
- bool chapter_found = false;
- bool value_written = false;
- char line[INI_LINE_LEN] = "";
- char val[INI_LINE_LEN] = "";
- char tag[INI_LINE_LEN] = "";
- char temp_fname[PATH_MAX] = "";
- Ini_search_id result;
- *line = '\0';
- *val = '\0';
- *tag = '\0';
- *temp_fname = '\0';
-
- if ((NULL == fname) || (NULL == chapter) || (NULL == item) || (NULL == value))
- return FALSE;
- if (('\0' == *fname) || ('\0' == *chapter) || ('\0' == *item))
- return FALSE;
-
- if (0 == (rd_fp = fopen(fname, "r"))) {
- ini_write_inst(fname, flag);
- if (0 == (rd_fp = fopen(fname, "r")))
- return FALSE;
- }
-
-#if USE_MKSTEMP
- {
- const char* temp_str = "./";
- if (temp_str) {
- snprintf(temp_fname, PATH_MAX, "%s/ini.XXXXXX", temp_str);
- int32_t fd = mkstemp(temp_fname);
- if (-1 == fd) {
- fclose(rd_fp);
- return FALSE;
- }
- wr_fp = fdopen(fd, "w");
- if (NULL == wr_fp) {
- unlink(temp_fname);
- close(fd);
- fclose(rd_fp);
- return FALSE;
- }
- } else {
- fclose(rd_fp);
- return FALSE;
- }
- }
-#else // #if USE_MKSTEMP
- tmpnam(temp_fname);
- if (0 == (wr_fp = fopen(temp_fname, "w"))) {
- fclose(rd_fp);
- return FALSE;
- }
-#endif // #else #if USE_MKSTEMP
-
- snprintf(tag, INI_LINE_LEN, "%s", chapter);
- for (uint32_t i = 0; i < strlen(tag); ++i)
- tag[i] = toupper(tag[i]);
-
- wr_result = 1;
- cr_count = 0;
- while ((NULL != fgets(line, INI_LINE_LEN, rd_fp)) && (0 < wr_result)) {
- // Now start the line parsing
- result = ini_parse_line(line, tag, val);
-
- if (!value_written) {
- if (!chapter_found) {
- if (INI_RIGHT_CHAPTER == result) {
- chapter_found = true;
- // coding style
- snprintf(tag, INI_LINE_LEN, "%s", item);
- for (uint32_t i = 0; i < strlen(tag); ++i)
- tag[i] = toupper(tag[i]);
- }
- } else {
- if ((INI_RIGHT_CHAPTER == result) || (INI_WRONG_CHAPTER == result)) {
- /* item not found but new capture */
- if (flag & INI_FLAG_ITEM_UP_CREA)
- fprintf(wr_fp, "%s=%s\n", item, value);
- /* The item must not update in an other chapter
- even it has the right name because only the
- first chapter is significant */
- value_written = true;
- } else if (result == INI_RIGHT_ITEM) {
- for (uint16_t i = 0; i < cr_count; ++i)
- fprintf(wr_fp, "\n");
- cr_count = 0;
- wr_result = fprintf(wr_fp, "%s=%s\n", item, value);
- value_written = true;
- continue;
- }
- }
- } /* if (!value_written) */
-
- if (0 == strcmp(val, "\n")) {
- ++cr_count;
- } else {
- for (uint32_t i = 0; i < cr_count; ++i)
- fprintf(wr_fp, "\n");
- cr_count = 0;
- wr_result = fprintf(wr_fp, "%s", line);
- }
- }
- if (0 < (wr_result) && (!value_written)) {
- if (flag & INI_FLAG_ITEM_UP_CREA) {
- if (!chapter_found)
- fprintf(wr_fp, "\n[%s]\n", chapter);
- fprintf(wr_fp, "%s=%s\n", item, value);
- value_written = true;
- }
- }
- fprintf(wr_fp, "\n");
-
- fclose(wr_fp);
- fclose(rd_fp);
-
- if (0 != rename(temp_fname, fname)) {
- if (0 != remove(temp_fname)) {
- SDL_LOG_WARN_WITH_ERRNO(
- "Unable to remove temp file: " << std::string(temp_fname));
- }
- return FALSE;
- }
-
- return (value_written);
-}
-#endif // BUILD_TESTS
-
-Ini_search_id ini_parse_line(const char* line, const char* tag, char* value) {
- const char* line_ptr;
- char temp_str[INI_LINE_LEN] = "";
- *temp_str = '\0';
-
- snprintf(value, INI_LINE_LEN, "%s", line);
-
- /* cut leading spaces */
- line_ptr = line;
- for (uint32_t i = 0; i < strlen(line); ++i) {
- if ((line[i] == ' ') || (line[i] == 9) || // TAB
- (line[i] == 10) || // LF
- (line[i] == 13)) { // CR
- ++line_ptr;
- } else {
- break;
- }
- }
- if ('\0' == *line_ptr) {
- snprintf(value, INI_LINE_LEN, "\n");
- return INI_NOTHING;
- }
-
- if ((*line_ptr == ';') || (*line_ptr == '*')) /* remark */
- return INI_REMARK;
-
- if (*line_ptr == '[' && strrchr(line_ptr, ']') != NULL) {
- ++line_ptr;
-
- /* cut leading stuff */
- uint16_t len = strlen(line_ptr);
- for (int32_t i = 0; i < len; ++i) {
- if ((*line_ptr == ' ') || (*line_ptr == 9) || // TAB
- (*line_ptr == 10) || // LF
- (*line_ptr == 13)) { // CR
- ++line_ptr;
- } else {
- break;
- }
- }
- if (*line_ptr == '\0')
- return INI_NOTHING;
-
- snprintf(temp_str, INI_LINE_LEN, "%s", line_ptr);
- char* temp_ptr = strrchr(temp_str, ']');
- if (NULL == temp_ptr) {
- return INI_NOTHING;
- } else {
- *temp_ptr = '\0';
- }
-
- /* cut trailing stuff */
- for (int32_t i = strlen(temp_str) - 1; i > 0; --i) {
- if ((temp_str[i] == ' ') || (temp_str[i] == 9) || // TAB
- (temp_str[i] == 10) || // LF
- (temp_str[i] == 13)) { // CR
- temp_str[i] = '\0';
- } else {
- break;
- }
- }
-
- snprintf(value, INI_LINE_LEN, "%s", temp_str);
-
- for (uint32_t i = 0; i < strlen(temp_str); ++i)
- temp_str[i] = toupper(temp_str[i]);
- if (strcmp(temp_str, tag) == 0)
- return INI_RIGHT_CHAPTER;
- else
- return INI_WRONG_CHAPTER;
- }
-
- if (NULL != strchr(line_ptr, '=')) {
- strncpy(temp_str, line_ptr, (strchr(line_ptr, '=') - line_ptr));
- /* cut trailing stuff */
- for (int32_t i = strlen(temp_str) - 1; i > 0; --i) {
- if ((temp_str[i] == '=') || (temp_str[i] == ' ') ||
- (temp_str[i] == 9) || // TAB
- (temp_str[i] == 10) || // LF
- (temp_str[i] == 13)) { // CR
- temp_str[i] = '\0';
- } else {
- break;
- }
- }
-
- snprintf(value, INI_LINE_LEN, "%s", temp_str);
-
- for (uint32_t i = 0; i < strlen(temp_str); ++i)
- temp_str[i] = toupper(temp_str[i]);
- if (strcmp(temp_str, tag) == 0) {
- line_ptr = strchr(line_ptr, '=') + 1;
- uint16_t len = strlen(line_ptr);
- /* cut trailing stuff */
- for (uint32_t i = 0; i < len; ++i) {
- if ((*line_ptr == ' ') || (*line_ptr == 9) || // TAB
- (*line_ptr == 10) || // LF
- (*line_ptr == 13)) { // CR
- ++line_ptr;
- } else {
- break;
- }
- }
-
- snprintf(value, INI_LINE_LEN, "%s", line_ptr);
-
- if (value[0] != '\0') {
- /* cut trailing stuff */
- for (int32_t i = strlen(value) - 1; i > 0; --i) {
- if ((value[i] == ' ') || (value[i] == ';') ||
- (value[i] == 9) || // TAB
- (value[i] == 10) || // LF
- (value[i] == 13)) { // CR
- value[i] = '\0';
- } else {
- break;
- }
- }
- }
- return INI_RIGHT_ITEM;
- } else {
- return INI_WRONG_ITEM;
- }
- }
-
- return INI_NOTHING;
-}
-
-#pragma GCC diagnostic pop
-
-} // namespace profile
diff --git a/src/components/config_profile/test/ini_file_test.cc b/src/components/config_profile/test/ini_file_test.cc
deleted file mode 100644
index c1a2b83120..0000000000
--- a/src/components/config_profile/test/ini_file_test.cc
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * Copyright (c) 2015, Ford Motor Company
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of the Ford Motor Company nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config_profile/ini_file.h"
-#include "gtest/gtest.h"
-#include "utils/file_system.h"
-
-namespace test {
-namespace components {
-namespace profile_test {
-
-using namespace ::profile;
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-
-TEST(IniFileTest, WriteItemReadItem) {
- // Write line in chapter
- const char* fname = "./test_ini_file.ini";
- const char* chapter = "Chapter";
- const char* item = "Test_item";
- const char* value = "test_value";
- const bool write_result =
- ini_write_value(fname, chapter, item, value, INI_FLAG_ITEM_UP_CREA);
- EXPECT_TRUE(write_result);
- char search_value[INI_LINE_LEN] = {0};
- const bool read_result = ini_read_value(fname, chapter, item, search_value);
- const char* res = search_value;
-
- EXPECT_TRUE(read_result);
- EXPECT_STREQ(res, value);
- EXPECT_TRUE(file_system::DeleteFile("./test_ini_file.ini"));
-}
-
-TEST(IniFileTest, WriteItemWithoutValueReadItem) {
- // Write line in chapter
- const char* fname = "./test_ini_file.ini";
- const char* chapter = "Chapter";
- const char* test_item = "Test_item";
- const char* value = "";
- const bool write_result =
- ini_write_value(fname, chapter, test_item, value, INI_FLAG_ITEM_UP_CREA);
- EXPECT_TRUE(write_result);
-
- // Read value from file
- char search_value[INI_LINE_LEN] = {0};
- const bool read_result =
- ini_read_value(fname, chapter, test_item, search_value);
- const char* res = search_value;
- EXPECT_TRUE(read_result);
- EXPECT_STREQ(res, value);
-
- EXPECT_TRUE(file_system::DeleteFile("./test_ini_file.ini"));
-}
-
-TEST(IniFileTest, WriteSameItemInDifferentChapters) {
- // Write line in chapter
- const char* fname = "./test_ini_file.ini";
- const char* chapter1 = "Chapter1";
- const char* test_item = "Test_item";
- const char* value = "test_value";
- const bool write_result =
- ini_write_value(fname, chapter1, test_item, value, INI_FLAG_ITEM_UP_CREA);
- EXPECT_TRUE(write_result);
- char search_value[INI_LINE_LEN] = {0};
- const bool read_result =
- ini_read_value(fname, chapter1, test_item, search_value);
- const char* res = search_value;
- EXPECT_TRUE(read_result);
- EXPECT_STREQ(res, value);
-
- // Create new chapter and write the same value
- const char* chapter2 = "Chapter2";
-
- const bool write_result2 =
- ini_write_value(fname, chapter2, test_item, value, INI_FLAG_ITEM_UP_CREA);
-
- EXPECT_TRUE(write_result2);
-
- char value2[INI_LINE_LEN] = "test_value";
- const bool read_result2 = ini_read_value(fname, chapter2, test_item, value2);
- const char* res2 = value2;
- EXPECT_TRUE(read_result2);
- EXPECT_STREQ(res2, res);
- EXPECT_TRUE(file_system::DeleteFile("./test_ini_file.ini"));
-}
-
-TEST(IniFileTest, RewriteItem) {
- // Write line in chapter
- const char* fname = "./test_ini_file.ini";
- const char* chapter = "Chapter";
- const char* item = "Test_item";
- const char* value = "test_value";
- bool write_result =
- ini_write_value(fname, chapter, item, value, INI_FLAG_ITEM_UP_CREA);
-
- EXPECT_TRUE(write_result);
- char search_value[INI_LINE_LEN] = {0};
- bool read_result = ini_read_value(fname, chapter, item, search_value);
- const char* res = search_value;
- EXPECT_TRUE(read_result);
- EXPECT_STREQ(res, value);
-
- // Write item again
- const char* newvalue = "new_test_value";
- write_result =
- ini_write_value(fname, chapter, item, newvalue, INI_FLAG_ITEM_UP_CREA);
-
- EXPECT_TRUE(write_result);
- char new_search_value[INI_LINE_LEN] = {0};
- read_result = ini_read_value(fname, chapter, item, new_search_value);
- const char* new_res = new_search_value;
- EXPECT_TRUE(read_result);
- EXPECT_STREQ(new_res, newvalue);
- EXPECT_TRUE(file_system::DeleteFile("./test_ini_file.ini"));
-}
-
-TEST(IniFileTest, WriteTwoItemsInOneChapter) {
- // Write line in chapter
- const char* fname = "./test_ini_file.ini";
- const char* chapter = "Chapter";
- const char* item = "Test_item";
- const char* value1 = "test_value";
-
- bool write_result =
- ini_write_value(fname, chapter, item, value1, INI_FLAG_ITEM_UP_CREA);
- EXPECT_TRUE(write_result);
-
- // Write another line in the same chapter
- const char* item2 = "Test_item2";
- const char* value2 = "test_value2";
-
- write_result =
- ini_write_value(fname, chapter, item2, value2, INI_FLAG_ITEM_UP_CREA);
- EXPECT_TRUE(write_result);
-
- // Search both values
- char search_value[INI_LINE_LEN] = {0};
- bool read_result = ini_read_value(fname, chapter, item, search_value);
- const char* res = search_value;
- EXPECT_TRUE(read_result);
- EXPECT_STREQ(res, value1);
-
- char search_value2[INI_LINE_LEN] = {0};
- read_result = ini_read_value(fname, chapter, item2, search_value2);
- const char* res2 = search_value2;
- EXPECT_TRUE(read_result);
- EXPECT_STREQ(res2, value2);
- EXPECT_TRUE(file_system::DeleteFile("./test_ini_file.ini"));
-}
-
-TEST(IniFileTest, WriteEmptyItemWithValueReadItem) {
- const char* fname = "./test_ini_file.ini";
- const char* chapter = "Chapter";
- const char* test_item = "";
- const char* value = "test_value";
- bool result =
- ini_write_value(fname, chapter, test_item, value, INI_FLAG_ITEM_UP_CREA);
- EXPECT_FALSE(result);
-}
-
-TEST(IniFileTest, WriteEmptyItemWithEmptyValue_ExpectFalse) {
- // Write empty line in chapter
- const char* fname = "./test_ini_file.ini";
- const char* chapter = "Chapter";
- const char* test_item = "";
- const char* value = "";
- bool result =
- ini_write_value(fname, chapter, test_item, value, INI_FLAG_ITEM_UP_CREA);
- EXPECT_FALSE(result);
-}
-
-TEST(IniFileTest, WriteItemInEmptyChapter_ExpectFalse) {
- // Write line in empty chapter
- const char* fname = "./test_ini_file.ini";
- const char* chapter = "";
- const char* test_item = "Test_item";
- const char* value = "test_value";
- bool result =
- ini_write_value(fname, chapter, test_item, value, INI_FLAG_ITEM_UP_CREA);
- EXPECT_FALSE(result);
-}
-
-TEST(IniFileTest, ParseEmptyLine) {
- char line[INI_LINE_LEN] = {0};
- char val[INI_LINE_LEN] = {0};
- const char* tag = "HMI";
-
- Ini_search_id result;
- result = ini_parse_line(line, tag, val);
- EXPECT_EQ(INI_NOTHING, result);
-}
-
-TEST(IniFileTest, ParseChapter) {
- const char* line = "[HMI]";
- char val[INI_LINE_LEN] = {0};
- const char* tag = "HMI";
-
- Ini_search_id result;
- result = ini_parse_line(line, tag, val);
- EXPECT_EQ(INI_RIGHT_CHAPTER, result);
-}
-
-TEST(IniFileTest, ParseChapterTagEmpty) {
- const char* line = "[HMI]";
- char val[INI_LINE_LEN] = {0};
- char tag[INI_LINE_LEN] = {0};
-
- Ini_search_id result;
- result = ini_parse_line(line, tag, val);
- EXPECT_EQ(INI_WRONG_CHAPTER, result);
-}
-
-TEST(IniFileTest, ParseChapterWithUppercaseTag) {
- const char* line = "[Security Manager]";
- char val[INI_LINE_LEN] = {0};
- const char* tag = "SECURITY MANAGER";
-
- Ini_search_id result;
- result = ini_parse_line(line, tag, val);
- EXPECT_EQ(INI_RIGHT_CHAPTER, result);
-}
-
-TEST(IniFileTest, ParseChapterWithLowcaseTag) {
- const char* line = "[Security Manager]";
- char val[INI_LINE_LEN] = {0};
- const char* tag = "Security Manager";
-
- Ini_search_id result;
- result = ini_parse_line(line, tag, val);
- EXPECT_EQ(INI_WRONG_CHAPTER, result);
-}
-
-TEST(IniFileTest, ParseWithWrongChapter) {
- const char* line = "[HMI]";
- char val[INI_LINE_LEN] = {0};
- const char* tag = "MAIN";
-
- Ini_search_id result;
- result = ini_parse_line(line, tag, val);
- EXPECT_EQ(INI_WRONG_CHAPTER, result);
-}
-
-TEST(IniFileTest, ParseLineWithItem) {
- char line[INI_LINE_LEN] = "LaunchHMI = true";
- char val[INI_LINE_LEN] = "";
- char tag[INI_LINE_LEN] = "LAUNCHHMI";
-
- Ini_search_id result;
- result = ini_parse_line(line, tag, val);
- EXPECT_EQ(INI_RIGHT_ITEM, result);
-
- char check_val[INI_LINE_LEN] = "true";
- EXPECT_EQ(*check_val, *val);
-}
-
-TEST(IniFileTest, ParseLineWithoutItem) {
- const char* line = "LaunchHMI = ";
- char val[INI_LINE_LEN] = {0};
- const char* tag = "LAUNCHHMI";
-
- Ini_search_id result;
- result = ini_parse_line(line, tag, val);
- const char* res = val;
- const char* check_val = "";
- EXPECT_EQ(INI_RIGHT_ITEM, result);
- EXPECT_STREQ(check_val, res);
-}
-
-TEST(IniFileTest, ParseLineWithEmptytag) {
- const char* line = "LaunchHMI = true";
- char val[INI_LINE_LEN] = {0};
- char tag[INI_LINE_LEN] = {0};
-
- Ini_search_id result;
- result = ini_parse_line(line, tag, val);
- EXPECT_EQ(INI_WRONG_ITEM, result);
-}
-
-TEST(IniFileTest, ParseLineWithLowcaseTag) {
- const char* line = "LaunchHMI = true";
- char val[INI_LINE_LEN] = {0};
- const char* tag = "LaunchHmi";
-
- Ini_search_id result;
- result = ini_parse_line(line, tag, val);
- EXPECT_EQ(INI_WRONG_ITEM, result);
-}
-
-TEST(IniFileTest, ParseLineWithComment) {
- const char* line = "; [HMI]";
- char val[INI_LINE_LEN] = {0};
- const char* tag = "HMI";
-
- Ini_search_id result;
- result = ini_parse_line(line, tag, val);
- const char* res = val;
- EXPECT_EQ(INI_REMARK, result);
- EXPECT_STREQ(line, res);
-}
-
-#pragma GCC diagnostic pop
-
-} // namespace profile_test
-} // namespace components
-} // namespace test