summaryrefslogtreecommitdiff
path: root/src/components/config_profile/test/ini_file_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/config_profile/test/ini_file_test.cc')
-rw-r--r--src/components/config_profile/test/ini_file_test.cc200
1 files changed, 101 insertions, 99 deletions
diff --git a/src/components/config_profile/test/ini_file_test.cc b/src/components/config_profile/test/ini_file_test.cc
index cd124c9ed3..2f256c8b51 100644
--- a/src/components/config_profile/test/ini_file_test.cc
+++ b/src/components/config_profile/test/ini_file_test.cc
@@ -42,16 +42,16 @@ using namespace ::profile;
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);
+ 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;
+ const char* res = search_value;
EXPECT_TRUE(read_result);
EXPECT_STREQ(res, value);
@@ -60,18 +60,19 @@ TEST(IniFileTest, WriteItemReadItem) {
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);
+ 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;
+ 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);
@@ -80,30 +81,31 @@ TEST(IniFileTest, WriteItemWithoutValueReadItem) {
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);
+ 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;
+ 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 char* chapter2 = "Chapter2";
- const bool write_result2 = ini_write_value(fname, chapter2, test_item, value,
- INI_FLAG_ITEM_UP_CREA);
+ 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;
+ const char* res2 = value2;
EXPECT_TRUE(read_result2);
EXPECT_STREQ(res2, res);
EXPECT_TRUE(file_system::DeleteFile("./test_ini_file.ini"));
@@ -111,29 +113,29 @@ TEST(IniFileTest, WriteSameItemInDifferentChapters) {
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);
+ 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;
+ 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);
+ 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;
+ 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"));
@@ -141,92 +143,92 @@ TEST(IniFileTest, RewriteItem) {
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";
+ 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);
+ 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";
+ const char* item2 = "Test_item2";
+ const char* value2 = "test_value2";
- write_result = ini_write_value(fname, chapter, item2, value2,
- INI_FLAG_ITEM_UP_CREA);
+ 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;
+ 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;
+ 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);
+ 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);
+ 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);
+ 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) {
+TEST(IniFileTest, ParseEmptyLine) {
char line[INI_LINE_LEN] = {0};
char val[INI_LINE_LEN] = {0};
- const char * tag = "HMI";
+ 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]";
+TEST(IniFileTest, ParseChapter) {
+ const char* line = "[HMI]";
char val[INI_LINE_LEN] = {0};
- const char * tag = "HMI";
+ 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]";
+TEST(IniFileTest, ParseChapterTagEmpty) {
+ const char* line = "[HMI]";
char val[INI_LINE_LEN] = {0};
char tag[INI_LINE_LEN] = {0};
@@ -235,37 +237,37 @@ TEST(IniFileTest,ParseChapterTagEmpty) {
EXPECT_EQ(INI_WRONG_CHAPTER, result);
}
-TEST(IniFileTest,ParseChapterWithUppercaseTag) {
- const char * line = "[Security Manager]";
+TEST(IniFileTest, ParseChapterWithUppercaseTag) {
+ const char* line = "[Security Manager]";
char val[INI_LINE_LEN] = {0};
- const char * tag = "SECURITY MANAGER";
+ 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]";
+TEST(IniFileTest, ParseChapterWithLowcaseTag) {
+ const char* line = "[Security Manager]";
char val[INI_LINE_LEN] = {0};
- const char * tag = "Security Manager";
+ 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]";
+TEST(IniFileTest, ParseWithWrongChapter) {
+ const char* line = "[HMI]";
char val[INI_LINE_LEN] = {0};
- const char * tag = "MAIN";
+ const char* tag = "MAIN";
Ini_search_id result;
result = ini_parse_line(line, tag, val);
EXPECT_EQ(INI_WRONG_CHAPTER, result);
}
-TEST(IniFileTest,ParseLineWithItem) {
+TEST(IniFileTest, ParseLineWithItem) {
char line[INI_LINE_LEN] = "LaunchHMI = true";
char val[INI_LINE_LEN] = "";
char tag[INI_LINE_LEN] = "LAUNCHHMI";
@@ -278,21 +280,21 @@ TEST(IniFileTest,ParseLineWithItem) {
EXPECT_EQ(*check_val, *val);
}
-TEST(IniFileTest,ParseLineWithoutItem) {
- const char * line = "LaunchHMI = ";
+TEST(IniFileTest, ParseLineWithoutItem) {
+ const char* line = "LaunchHMI = ";
char val[INI_LINE_LEN] = {0};
- const char * tag = "LAUNCHHMI";
+ const char* tag = "LAUNCHHMI";
Ini_search_id result;
result = ini_parse_line(line, tag, val);
- const char *res = val;
- const char *check_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";
+TEST(IniFileTest, ParseLineWithEmptytag) {
+ const char* line = "LaunchHMI = true";
char val[INI_LINE_LEN] = {0};
char tag[INI_LINE_LEN] = {0};
@@ -301,24 +303,24 @@ TEST(IniFileTest,ParseLineWithEmptytag) {
EXPECT_EQ(INI_WRONG_ITEM, result);
}
-TEST(IniFileTest,ParseLineWithLowcaseTag) {
- const char * line = "LaunchHMI = true";
+TEST(IniFileTest, ParseLineWithLowcaseTag) {
+ const char* line = "LaunchHMI = true";
char val[INI_LINE_LEN] = {0};
- const char * tag = "LaunchHmi";
+ 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]";
+TEST(IniFileTest, ParseLineWithComment) {
+ const char* line = "; [HMI]";
char val[INI_LINE_LEN] = {0};
- const char * tag = "HMI";
+ const char* tag = "HMI";
Ini_search_id result;
result = ini_parse_line(line, tag, val);
- const char *res = val;
+ const char* res = val;
EXPECT_EQ(INI_REMARK, result);
EXPECT_STREQ(line, res);
}