File: ts-generic.cpp

package info (click to toggle)
libsimpleini 4.25%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 724 kB
  • sloc: cpp: 4,599; makefile: 75; sh: 3
file content (137 lines) | stat: -rw-r--r-- 3,937 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "../SimpleIni.h"
#include "gtest/gtest.h"

// Test SI_CONVERT_GENERIC with char interface
class TestGenericChar : public ::testing::Test {
protected:
	void SetUp() override;
protected:
	CSimpleIniA ini;
};

void TestGenericChar::SetUp() {
	ini.SetUnicode();
	SI_Error err = ini.LoadFile("tests.ini");
	ASSERT_EQ(err, SI_OK);
}

TEST_F(TestGenericChar, TestSectionAKeyAValA) {
	const char* result = ini.GetValue("section1", "key1");
	ASSERT_STREQ(result, "value1");
}

TEST_F(TestGenericChar, TestSectionAKeyAValU) {
	const char tesuto2[] = u8"テスト2";
	const char* result = ini.GetValue("section2", "test2");
	ASSERT_STREQ(result, tesuto2);
}

TEST_F(TestGenericChar, TestSectionAKeyUValA) {
	const char tesuto[] = u8"テスト";
	const char* result = ini.GetValue("section2", tesuto);
	ASSERT_STREQ(result, "test");
}

TEST_F(TestGenericChar, TestSectionAKeyUValU) {
	const char tesuto2[] = u8"テスト2";
	const char tesutoni[] = u8"テスト二";
	const char* result = ini.GetValue("section2", tesuto2);
	ASSERT_STREQ(result, tesutoni);
}

TEST_F(TestGenericChar, TestSectionUKeyAValA) {
	const char kensa[] = u8"検査";
	const char* result = ini.GetValue(kensa, "key2");
	ASSERT_STREQ(result, "value2");
}

TEST_F(TestGenericChar, TestSectionUKeyAValU) {
	const char kensa[] = u8"検査";
	const char tesuto2[] = u8"テスト2";
	const char* result = ini.GetValue(kensa, "test2");
	ASSERT_STREQ(result, tesuto2);
}

TEST_F(TestGenericChar, TestSectionUKeyUValA) {
	const char kensa[] = u8"検査";
	const char tesuto[] = u8"テスト";
	const char* result = ini.GetValue(kensa, tesuto);
	ASSERT_STREQ(result, "test");
}

TEST_F(TestGenericChar, TestSectionUKeyUValU) {
	const char kensa[] = u8"検査";
	const char tesuto2[] = u8"テスト2";
	const char tesutoni[] = u8"テスト二";
	const char* result = ini.GetValue(kensa, tesuto2);
	ASSERT_STREQ(result, tesutoni);
}

#ifdef _WIN32
// Test SI_CONVERT_GENERIC with wchar_t interface (Windows only)
// On non-Windows platforms, wchar_t support with SI_CONVERT_GENERIC doesn't work the same way
class TestGenericWide : public ::testing::Test {
protected:
	void SetUp() override;
protected:
	CSimpleIniW ini;
};

void TestGenericWide::SetUp() {
	ini.SetUnicode();
	SI_Error err = ini.LoadFile("tests.ini");
	ASSERT_EQ(err, SI_OK);
}

TEST_F(TestGenericWide, TestSectionAKeyAValA) {
	const wchar_t* result = ini.GetValue(L"section1", L"key1");
	ASSERT_STREQ(result, L"value1");
}

TEST_F(TestGenericWide, TestSectionAKeyAValU) {
	const wchar_t tesuto2[] = L"テスト2";
	const wchar_t* result = ini.GetValue(L"section2", L"test2");
	ASSERT_STREQ(result, tesuto2);
}

TEST_F(TestGenericWide, TestSectionAKeyUValA) {
	const wchar_t tesuto[] = L"テスト";
	const wchar_t* result = ini.GetValue(L"section2", tesuto);
	ASSERT_STREQ(result, L"test");
}

TEST_F(TestGenericWide, TestSectionAKeyUValU) {
	const wchar_t tesuto2[] = L"テスト2";
	const wchar_t tesutoni[] = L"テスト二";
	const wchar_t* result = ini.GetValue(L"section2", tesuto2);
	ASSERT_STREQ(result, tesutoni);
}

TEST_F(TestGenericWide, TestSectionUKeyAValA) {
	const wchar_t kensa[] = L"検査";
	const wchar_t* result = ini.GetValue(kensa, L"key2");
	ASSERT_STREQ(result, L"value2");
}

TEST_F(TestGenericWide, TestSectionUKeyAValU) {
	const wchar_t kensa[] = L"検査";
	const wchar_t tesuto2[] = L"テスト2";
	const wchar_t* result = ini.GetValue(kensa, L"test2");
	ASSERT_STREQ(result, tesuto2);
}

TEST_F(TestGenericWide, TestSectionUKeyUValA) {
	const wchar_t kensa[] = L"検査";
	const wchar_t tesuto[] = L"テスト";
	const wchar_t* result = ini.GetValue(kensa, tesuto);
	ASSERT_STREQ(result, L"test");
}

TEST_F(TestGenericWide, TestSectionUKeyUValU) {
	const wchar_t kensa[] = L"検査";
	const wchar_t tesuto2[] = L"テスト2";
	const wchar_t tesutoni[] = L"テスト二";
	const wchar_t* result = ini.GetValue(kensa, tesuto2);
	ASSERT_STREQ(result, tesutoni);
}
#endif // _WIN32