Skip to content

Commit

Permalink
Fix CheckFile(): check suffix of the file
Browse files Browse the repository at this point in the history
  • Loading branch information
iamantony committed Sep 27, 2016
1 parent d967dab commit adf07ce
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/sources/filechecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace QtCSV
inline bool CheckFile(const QString& filePath)
{
QFileInfo fileInfo(filePath);
if ( fileInfo.isAbsolute() && "csv" == fileInfo.completeSuffix() )
if ( fileInfo.isAbsolute() && "csv" == fileInfo.suffix() )
{
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/data/test.file.dots.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
one,two,three
one_element
23 changes: 23 additions & 0 deletions tests/testreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ void TestReader::testReadFileWithCommas()
}
}

void TestReader::testReadFileWithDotsInName()
{
const QString path = getPathToFileTestDotsInName();
QList<QStringList> data = QtCSV::Reader::readToList(path);

QVERIFY2(false == data.isEmpty(), "Failed to read file content");

QList<QStringList> expected;
expected << (QStringList() << "one" << "two" << "three");
expected << (QStringList() << "one_element");

QVERIFY2(expected.size() == data.size(), "Wrong number of rows");
for (int i = 0; i < data.size(); ++i)
{
QVERIFY2(expected.at(i) == data.at(i), "Wrong row data");
}
}

void TestReader::testReadFileWithCommasToStringData()
{
const QString path = getPathToFileTestComma();
Expand Down Expand Up @@ -321,6 +339,11 @@ QString TestReader::getPathToFileTestComma() const
return getPathToFolderWithTestFiles() + "test-comma.csv";
}

QString TestReader::getPathToFileTestDotsInName() const
{
return getPathToFolderWithTestFiles() + "test.file.dots.csv";
}

QString TestReader::getPathToFileTestSemicolon() const
{
return getPathToFolderWithTestFiles() + "test-semicolon.csv";
Expand Down
2 changes: 2 additions & 0 deletions tests/testreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private Q_SLOTS:
void testReadToListInvalidArgs();
void testReadToDataInvalidArgs();
void testReadFileWithCommas();
void testReadFileWithDotsInName();
void testReadFileWithCommasToStringData();
void testReadFileWithCommasToVariantData();
void testReadFileWithSemicolons();
Expand All @@ -31,6 +32,7 @@ private Q_SLOTS:
private:
QString getPathToFolderWithTestFiles() const;
QString getPathToFileTestComma() const;
QString getPathToFileTestDotsInName() const;
QString getPathToFileTestSemicolon() const;
QString getPathToFileTestDataTextDelimDQuotes() const;
QString getPathToFileTestDataTextDelimQuotes() const;
Expand Down
33 changes: 32 additions & 1 deletion tests/testwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,29 @@ TestWriter::TestWriter()

void TestWriter::cleanup()
{
if ( false == QFile::remove(getFilePath()) )
if ( QFile::exists(getFilePath()) &&
false == QFile::remove(getFilePath()) )
{
qDebug() << "Can't remove file:" << getFilePath();
}

if ( QFile::exists(getFilePathWithDotsInName()) &&
false == QFile::remove(getFilePathWithDotsInName()) )
{
qDebug() << "Can't remove file:" << getFilePathWithDotsInName();
}
}

QString TestWriter::getFilePath() const
{
return QDir::currentPath() + "/test-file.csv";
}

QString TestWriter::getFilePathWithDotsInName() const
{
return QDir::currentPath() + "/test.file.dots.csv";
}

void TestWriter::testWriteInvalidArgs()
{
QVERIFY2(false == QtCSV::Writer::write(QString(), QtCSV::StringData()),
Expand Down Expand Up @@ -101,6 +113,25 @@ void TestWriter::testWriteFromVariantData()
"Wrong values in third row");
}

void TestWriter::testWriteToFileWithDotsInName()
{
QStringList strList;
strList << "one" << "two" << "three";

QtCSV::StringData strData;
strData.addRow(strList);

bool writeResult =
QtCSV::Writer::write(getFilePathWithDotsInName(), strData);
QVERIFY2(true == writeResult, "Failed to write to file");

QList<QStringList> data =
QtCSV::Reader::readToList(getFilePathWithDotsInName());
QVERIFY2(false == data.isEmpty(), "Failed to read file content");
QVERIFY2(1 == data.size(), "Wrong number of rows");
QVERIFY2(strList == data.at(0), "Wrong data");
}

void TestWriter::testWriteAppendMode()
{
QStringList strFirstList;
Expand Down
2 changes: 2 additions & 0 deletions tests/testwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private Q_SLOTS:
void testWriteInvalidArgs();
void testWriteFromStringData();
void testWriteFromVariantData();
void testWriteToFileWithDotsInName();
void testWriteAppendMode();
void testWriteWithNotDefaultSeparator();
void testWriteWithHeader();
Expand All @@ -29,6 +30,7 @@ private Q_SLOTS:

private:
QString getFilePath() const;
QString getFilePathWithDotsInName() const;
QtCSV::StringData getTestStringData(const int &symbolsInRow,
const int &rowsNumber);
};
Expand Down

0 comments on commit adf07ce

Please sign in to comment.