forked from FashionFreedom/Seamly2D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtst_qmuparsererrormsg.cpp
237 lines (206 loc) · 8.96 KB
/
tst_qmuparsererrormsg.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/***************************************************************************
* *
* Copyright (C) 2017 Seamly, LLC *
* *
* https://github.com/fashionfreedom/seamly2d *
* *
***************************************************************************
**
** Seamly2D is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Seamly2D is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************
************************************************************************
**
** @file tst_qmuparsererrormsg.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 16 10, 2015
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2015 Seamly2D project
** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
**
** Seamly2D is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Seamly2D is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "tst_qmuparsererrormsg.h"
#include "../vmisc/def.h"
#include "../vmisc/logging.h"
#include <QtTest>
//---------------------------------------------------------------------------------------------------------------------
TST_QmuParserErrorMsg::TST_QmuParserErrorMsg(const QString &locale, QObject *parent)
: AbstractTest(parent),
m_locale(locale),
appTranslator(nullptr),
msg(nullptr)
{
}
//---------------------------------------------------------------------------------------------------------------------
TST_QmuParserErrorMsg::~TST_QmuParserErrorMsg()
{
delete appTranslator;
delete msg;
}
//---------------------------------------------------------------------------------------------------------------------
void TST_QmuParserErrorMsg::initTestCase()
{
if (m_locale.isEmpty())
{
QFAIL("Empty locale code.");
}
const QStringList locales = SupportedLocales();
if (not locales.contains(m_locale))
{
QFAIL("Unsupported locale code.");
}
QDir dir(TranslationsPath());
const QStringList fileNames = dir.entryList(QStringList("seamly2d_*.qm"));
QVERIFY2(locales.size() == fileNames.size(), "Unexpected count of files.");
if (loadTranslations(m_locale) != NoError)
{
const QString message = QString("Couldn't load variables. Locale = %1").arg(m_locale);
QSKIP(qUtf8Printable(message));
}
}
//---------------------------------------------------------------------------------------------------------------------
void TST_QmuParserErrorMsg::TestEErrorCodes_data()
{
QTest::addColumn<int>("code");
QTest::addColumn<bool>("tok");
QTest::addColumn<bool>("pos");
AddCase(qmu::ecUNASSIGNABLE_TOKEN, true, true);
AddCase(qmu::ecINTERNAL_ERROR, false, false);
AddCase(qmu::ecINVALID_NAME, true, false);
AddCase(qmu::ecINVALID_BINOP_IDENT, true, false);
AddCase(qmu::ecINVALID_INFIX_IDENT, true, false);
AddCase(qmu::ecINVALID_POSTFIX_IDENT, true, false);
AddCase(qmu::ecINVALID_FUN_PTR, false, false);
AddCase(qmu::ecEMPTY_EXPRESSION, false, false);
AddCase(qmu::ecINVALID_VAR_PTR, false, false);
AddCase(qmu::ecUNEXPECTED_OPERATOR, true, true);
AddCase(qmu::ecUNEXPECTED_EOF, false, true);
AddCase(qmu::ecUNEXPECTED_ARG_SEP, false, true);
AddCase(qmu::ecUNEXPECTED_PARENS, true, true);
AddCase(qmu::ecUNEXPECTED_FUN, true, true);
AddCase(qmu::ecUNEXPECTED_VAL, true, true);
AddCase(qmu::ecUNEXPECTED_VAR, true, true);
AddCase(qmu::ecUNEXPECTED_ARG, false, true);
AddCase(qmu::ecMISSING_PARENS, false, false);
AddCase(qmu::ecTOO_MANY_PARAMS, true, true);
AddCase(qmu::ecTOO_FEW_PARAMS, true, true);
AddCase(qmu::ecDIV_BY_ZERO, false, false);
AddCase(qmu::ecDOMAIN_ERROR, false, false);
AddCase(qmu::ecNAME_CONFLICT, false, false);
AddCase(qmu::ecOPT_PRI, false, false);
AddCase(qmu::ecBUILTIN_OVERLOAD, true, false);
AddCase(qmu::ecUNEXPECTED_STR, false, true);
AddCase(qmu::ecUNTERMINATED_STRING, false, true);
AddCase(qmu::ecSTRING_EXPECTED, false, false);
AddCase(qmu::ecVAL_EXPECTED, false, false);
AddCase(qmu::ecOPRT_TYPE_CONFLICT, true, true);
AddCase(qmu::ecSTR_RESULT, false, false);
AddCase(qmu::ecGENERIC, false, false);
AddCase(qmu::ecLOCALE, false, false);
AddCase(qmu::ecUNEXPECTED_CONDITIONAL, true, false);
AddCase(qmu::ecMISSING_ELSE_CLAUSE, false, false);
AddCase(qmu::ecMISPLACED_COLON, false, true);
}
//---------------------------------------------------------------------------------------------------------------------
void TST_QmuParserErrorMsg::TestEErrorCodes()
{
QFETCH(int, code);
QFETCH(bool, tok);
QFETCH(bool, pos);
const QString translated = (*msg)[code];
const QString message = QString("String: '%1'.").arg(translated);
QVERIFY2((translated.indexOf(QLatin1String("$TOK$")) != -1) == tok, qUtf8Printable(message));
QVERIFY2((translated.indexOf(QLatin1String("$POS$")) != -1) == pos, qUtf8Printable(message));
}
//---------------------------------------------------------------------------------------------------------------------
void TST_QmuParserErrorMsg::cleanupTestCase()
{
RemoveTranslation();
}
//---------------------------------------------------------------------------------------------------------------------
void TST_QmuParserErrorMsg::AddCase(int code, bool tok, bool pos)
{
const QString tag = QString("Check translation code=%1 in file seamly2d_%2.qm").arg(code).arg(m_locale);
QTest::newRow(qUtf8Printable(tag)) << code << tok << pos;
}
//---------------------------------------------------------------------------------------------------------------------
int TST_QmuParserErrorMsg::loadTranslations(const QString &checkedLocale)
{
const QString path = TranslationsPath();
const QString file = QString("seamly2d_%1.qm").arg(checkedLocale);
if (QFileInfo(path+QLatin1String("/")+file).size() <= 34)
{
const QString message = QString("Translation for locale = %1 is empty. \nFull path: %2/%3")
.arg(checkedLocale)
.arg(path)
.arg(file);
QWARN(qUtf8Printable(message));
return ErrorSize;
}
appTranslator = new QTranslator(this);
if (not appTranslator->load(file, path))
{
const QString message = QString("Can't load translation for locale = %1. \nFull path: %2/%3")
.arg(checkedLocale)
.arg(path)
.arg(file);
QWARN(qUtf8Printable(message));
delete appTranslator;
return ErrorLoad;
}
if (not QCoreApplication::installTranslator(appTranslator))
{
const QString message = QString("Can't install translation for locale = %1. \nFull path: %2/%3")
.arg(checkedLocale)
.arg(path)
.arg(file);
QWARN(qUtf8Printable(message));
delete appTranslator;
return ErrorInstall;
}
delete msg;
msg = new qmu::QmuParserErrorMsg();//Very important do it after load QM file.
return NoError;
}
//---------------------------------------------------------------------------------------------------------------------
void TST_QmuParserErrorMsg::RemoveTranslation()
{
if (not appTranslator.isNull())
{
const bool result = QCoreApplication::removeTranslator(appTranslator);
if (result == false)
{
const QString message = QString("Can't remove translation for locale = %1").arg(m_locale);
QWARN(qUtf8Printable(message));
}
delete appTranslator;
}
}