mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-04-03 20:47:37 +03:00
Better handle of parser status messages (critical/not critical)
Use of messageWidget for displaying parser status messages setRootGroup assigns the right label to the root db folder test uses portable QTemporaryFile instead of hardcoded file
This commit is contained in:
parent
a7e358c27d
commit
41f9c3d2a1
10 changed files with 150 additions and 124 deletions
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
|
||||
#include "TestCsvParser.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
QTEST_GUILESS_MAIN(TestCsvParser)
|
||||
|
@ -32,8 +33,8 @@ void TestCsvParser::cleanupTestCase()
|
|||
|
||||
void TestCsvParser::init()
|
||||
{
|
||||
file.setFileName("/tmp/keepassXn94do1x.csv");
|
||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate))
|
||||
file = new QTemporaryFile();
|
||||
if (not file->open())
|
||||
QFAIL("Cannot open file!");
|
||||
parser->setBackslashSyntax(false);
|
||||
parser->setComment('#');
|
||||
|
@ -43,26 +44,26 @@ void TestCsvParser::init()
|
|||
|
||||
void TestCsvParser::cleanup()
|
||||
{
|
||||
file.close();
|
||||
file->remove();
|
||||
}
|
||||
|
||||
/****************** TEST CASES ******************/
|
||||
void TestCsvParser::testMissingQuote() {
|
||||
parser->setTextQualifier(':');
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << "A,B\n:BM,1";
|
||||
QEXPECT_FAIL("", "Bad format", Continue);
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QWARN(parser->getStatus().toLatin1());
|
||||
}
|
||||
|
||||
void TestCsvParser::testMalformed() {
|
||||
parser->setTextQualifier(':');
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << "A,B,C\n:BM::,1,:2:";
|
||||
QEXPECT_FAIL("", "Bad format", Continue);
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QWARN(parser->getStatus().toLatin1());
|
||||
}
|
||||
|
@ -70,14 +71,14 @@ void TestCsvParser::testMalformed() {
|
|||
void TestCsvParser::testBackslashSyntax() {
|
||||
parser->setBackslashSyntax(true);
|
||||
parser->setTextQualifier(QChar('X'));
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
//attended result: one"\t\"wo
|
||||
out << "Xone\\\"\\\\t\\\\\\\"w\noX\n"
|
||||
<< "X13X,X2\\X,X,\"\"3\"X\r"
|
||||
<< "3,X\"4\"X,,\n"
|
||||
<< "XX\n"
|
||||
<< "\\";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.at(0).at(0) == "one\"\\t\\\"w\no");
|
||||
QVERIFY(t.at(1).at(0) == "13");
|
||||
|
@ -92,10 +93,10 @@ void TestCsvParser::testBackslashSyntax() {
|
|||
}
|
||||
|
||||
void TestCsvParser::testQuoted() {
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << "ro,w,\"end, of \"\"\"\"\"\"row\"\"\"\"\"\n"
|
||||
<< "2\n";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.at(0).at(0) == "ro");
|
||||
QVERIFY(t.at(0).at(1) == "w");
|
||||
|
@ -105,41 +106,41 @@ void TestCsvParser::testQuoted() {
|
|||
}
|
||||
|
||||
void TestCsvParser::testEmptySimple() {
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out <<"";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 0);
|
||||
}
|
||||
|
||||
void TestCsvParser::testEmptyQuoted() {
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out <<"\"\"";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 0);
|
||||
}
|
||||
|
||||
void TestCsvParser::testEmptyNewline() {
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out <<"\"\n\"";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 0);
|
||||
}
|
||||
|
||||
void TestCsvParser::testEmptyFile()
|
||||
{
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 0);
|
||||
}
|
||||
|
||||
void TestCsvParser::testNewline()
|
||||
{
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << "1,2\n\n\n";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 1);
|
||||
QVERIFY(t.at(0).at(0) == "1");
|
||||
|
@ -148,9 +149,9 @@ void TestCsvParser::testNewline()
|
|||
|
||||
void TestCsvParser::testCR()
|
||||
{
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << "1,2\r3,4";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 2);
|
||||
QVERIFY(t.at(0).at(0) == "1");
|
||||
|
@ -161,9 +162,9 @@ void TestCsvParser::testCR()
|
|||
|
||||
void TestCsvParser::testLF()
|
||||
{
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << "1,2\n3,4";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 2);
|
||||
QVERIFY(t.at(0).at(0) == "1");
|
||||
|
@ -174,9 +175,9 @@ void TestCsvParser::testLF()
|
|||
|
||||
void TestCsvParser::testCRLF()
|
||||
{
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << "1,2\r\n3,4";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 2);
|
||||
QVERIFY(t.at(0).at(0) == "1");
|
||||
|
@ -187,13 +188,13 @@ void TestCsvParser::testCRLF()
|
|||
|
||||
void TestCsvParser::testComments()
|
||||
{
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << " #one\n"
|
||||
<< " \t # two, three \r\n"
|
||||
<< " #, sing\t with\r"
|
||||
<< " #\t me!\n"
|
||||
<< "useful,text #1!";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 1);
|
||||
QVERIFY(t.at(0).at(0) == "useful");
|
||||
|
@ -201,21 +202,21 @@ void TestCsvParser::testComments()
|
|||
}
|
||||
|
||||
void TestCsvParser::testColumns() {
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << "1,2\n"
|
||||
<< ",,,,,,,,,a\n"
|
||||
<< "a,b,c,d\n";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(parser->getCsvCols() == 10);
|
||||
}
|
||||
|
||||
void TestCsvParser::testSimple() {
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << ",,2\r,2,3\n"
|
||||
<< "A,,B\"\n"
|
||||
<< " ,,\n";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 4);
|
||||
QVERIFY(t.at(0).at(0) == "");
|
||||
|
@ -234,11 +235,11 @@ void TestCsvParser::testSimple() {
|
|||
|
||||
void TestCsvParser::testSeparator() {
|
||||
parser->setFieldSeparator('\t');
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << "\t\t2\r\t2\t3\n"
|
||||
<< "A\t\tB\"\n"
|
||||
<< " \t\t\n";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 4);
|
||||
QVERIFY(t.at(0).at(0) == "");
|
||||
|
@ -258,10 +259,10 @@ void TestCsvParser::testSeparator() {
|
|||
void TestCsvParser::testMultiline()
|
||||
{
|
||||
parser->setTextQualifier(QChar(':'));
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << ":1\r\n2a::b:,:3\r4:\n"
|
||||
<< "2\n";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.at(0).at(0) == "1\n2a:b");
|
||||
QVERIFY(t.at(0).at(1) == "3\n4");
|
||||
|
@ -279,10 +280,10 @@ void TestCsvParser::testEmptyReparsing()
|
|||
|
||||
void TestCsvParser::testReparsing()
|
||||
{
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << ":te\r\nxt1:,:te\rxt2:,:end of \"this\n string\":\n"
|
||||
<< "2\n";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
|
||||
QEXPECT_FAIL("", "Wrong qualifier", Continue);
|
||||
|
@ -301,10 +302,10 @@ void TestCsvParser::testReparsing()
|
|||
|
||||
void TestCsvParser::testQualifier() {
|
||||
parser->setTextQualifier(QChar('X'));
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << "X1X,X2XX,X,\"\"3\"\"\"X\r"
|
||||
<< "3,X\"4\"X,,\n";
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 2);
|
||||
QVERIFY(t.at(0).at(0) == "1");
|
||||
|
@ -322,10 +323,10 @@ void TestCsvParser::testUnicode() {
|
|||
//CORRECT QChar g(0x20AC);
|
||||
//ERROR QChar g("\u20AC");
|
||||
parser->setFieldSeparator(QChar('A'));
|
||||
QTextStream out(&file);
|
||||
QTextStream out(file);
|
||||
out << QString("€1A2śA\"3śAż\"Ażac");
|
||||
|
||||
QVERIFY(parser->parse(&file));
|
||||
QVERIFY(parser->parse(file));
|
||||
t = parser->getCsvTable();
|
||||
QVERIFY(t.size() == 1);
|
||||
QVERIFY(t.at(0).at(0) == "€1");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue