forked from Outerra/crashrpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLangFileTests.cpp
176 lines (134 loc) · 5.54 KB
/
LangFileTests.cpp
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*************************************************************************************
This file is a part of CrashRpt library.
Copyright (c) 2003-2013 The CrashRpt project authors. All Rights Reserved.
Use of this source code is governed by a BSD-style license
that can be found in the License.txt file in the root of the source
tree. All contributing project authors may
be found in the Authors.txt file in the root of the source tree.
***************************************************************************************/
#include "stdafx.h"
#include "Tests.h"
#include "CrashRpt.h"
#include "Utility.h"
#include "strconv.h"
#include "TestUtils.h"
#define MIN(a,b) (a<=b?a:b)
class LangFileTests : public CTestSuite
{
BEGIN_TEST_MAP(LangFileTests, "CrashRpt language file tests")
REGISTER_TEST(Test_lang_file_versions);
REGISTER_TEST(Test_lang_file_strings);
END_TEST_MAP()
public:
void SetUp();
void TearDown();
void Test_lang_file_versions();
void Test_lang_file_strings();
private:
std::vector<CString> m_asLangAbbr; // The list of lang file abbreviations
};
REGISTER_TEST_SUITE( LangFileTests );
void LangFileTests::SetUp()
{
m_asLangAbbr.push_back(_T("DE"));
m_asLangAbbr.push_back(_T("EN"));
m_asLangAbbr.push_back(_T("ES"));
m_asLangAbbr.push_back(_T("FR"));
m_asLangAbbr.push_back(_T("HI"));
m_asLangAbbr.push_back(_T("IT"));
m_asLangAbbr.push_back(_T("PT"));
m_asLangAbbr.push_back(_T("RU"));
m_asLangAbbr.push_back(_T("ZH-CN"));
}
void LangFileTests::TearDown()
{
}
void LangFileTests::Test_lang_file_versions()
{
// This test ensures that CrashRptVersion field of all CrashRpt language files
// equals to CRASHRPT_VER constant value
if(g_bRunningFromUNICODEFolder)
return; // Skip this test if running from another process
const int BUFF_SIZE = 1024;
TCHAR szBuffer[BUFF_SIZE]=_T("");
UINT i;
for(i=0; i<m_asLangAbbr.size(); i++)
{
CString sExePath = Utility::GetModulePath(NULL);
CString sFileName;
#ifndef WIN64
sFileName.Format(_T("%s\\..\\lang_files\\crashrpt_lang_%s.ini"),
sExePath.GetBuffer(0), m_asLangAbbr[i].GetBuffer(0));
#else
sFileName.Format(_T("%s\\..\\..\\lang_files\\crashrpt_lang_%s.ini"),
sExePath.GetBuffer(0), m_asLangAbbr[i].GetBuffer(0));
#endif //!WIN64
GetPrivateProfileString(_T("Settings"), _T("CrashRptVersion"), _T(""), szBuffer, BUFF_SIZE, sFileName);
int nActualVer = _ttoi(szBuffer);
TEST_ASSERT(nActualVer==CRASHRPT_VER);
}
__TEST_CLEANUP__;
}
void LangFileTests::Test_lang_file_strings()
{
// This test ensures that all lang files have the same count of
// sections and the same count of strings in each section.
if(g_bRunningFromUNICODEFolder)
return; // Skip this test if running from another process
strconv_t strconv;
CString sExePath = Utility::GetModulePath(NULL);
// Use EN lang file as template for comparison
CString sTemplateFileName;
#ifndef WIN64
sTemplateFileName.Format(_T("%s\\..\\lang_files\\crashrpt_lang_EN.ini"),
sExePath.GetBuffer(0));
#else
sTemplateFileName.Format(_T("%s\\..\\..\\lang_files\\crashrpt_lang_EN.ini"),
sExePath.GetBuffer(0));
#endif //!WIN64
UINT i;
for(i=0; i<m_asLangAbbr.size(); i++)
{
if(m_asLangAbbr[i]==_T("EN"))
continue; // Skip EN file
// Format i-th file name
CString sFileName;
#ifndef WIN64
sFileName.Format(_T("%s\\..\\lang_files\\crashrpt_lang_%s.ini"),
sExePath.GetBuffer(0), m_asLangAbbr[i].GetBuffer(0));
#else
sFileName.Format(_T("%s\\..\\..\\lang_files\\crashrpt_lang_%s.ini"),
sExePath.GetBuffer(0), m_asLangAbbr[i].GetBuffer(0));
#endif //!WIN64
// Get count of sections in EN file
std::vector<CString> asTemplateSections;
int nTemplateSectionCount = TestUtils::EnumINIFileSections(sTemplateFileName, asTemplateSections);
// Get count of sections in i-th file
std::vector<CString> asSections;
int nSectionCount = TestUtils::EnumINIFileSections(sFileName, asSections);
// Ensure section count is the same
TEST_ASSERT_MSG(nTemplateSectionCount==nSectionCount, "Count of INI sections is different in lang files EN and %s", strconv.t2a(m_asLangAbbr[i]));
// Now compare strings in each section
int nSection = 0;
for(nSection = 0; nSection<nTemplateSectionCount; nSection++)
{
// Get count of strings in n-th section in EN file
std::vector<CString> asTemplateStrings;
int nTemplateStringCount = TestUtils::EnumINIFileStrings(sTemplateFileName, asTemplateSections[nSection], asTemplateStrings);
// Get count of strings in n-th section in i-th file
std::vector<CString> asStrings;
int nStringCount = TestUtils::EnumINIFileStrings(sFileName, asTemplateSections[nSection], asStrings);
// Compare string names
size_t nStr;
for(nStr=0; nStr<MIN(asTemplateStrings.size(), asStrings.size()); nStr++)
{
// Ensure string names are the same
TEST_ASSERT_MSG(asTemplateStrings[nStr]==asStrings[nStr], "Names of INI strings #%d in section %s are different in lang files EN and %s : %s and %s",
nStr, strconv.t2a(asTemplateSections[nSection]), strconv.t2a(m_asLangAbbr[i]), strconv.t2a(asTemplateStrings[nStr]), strconv.t2a(asStrings[nStr]));
}
// Ensure string count is the same
TEST_ASSERT_MSG(nTemplateStringCount==nStringCount, "Count of INI strings in section %s is different in lang files EN and %s", strconv.t2a(asTemplateSections[nSection]), strconv.t2a(m_asLangAbbr[i]));
}
}
__TEST_CLEANUP__;
}