-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
695b08c
commit 0db75b1
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(qx_common_io) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
include(OB/Test) | ||
|
||
ob_add_basic_standard_test( | ||
TARGET_PREFIX "${TESTS_TARGET_PREFIX}" | ||
TARGET_VAR test_target | ||
LINKS | ||
${TESTS_COMMON_TARGET} | ||
Qx::Io | ||
) | ||
|
||
# Bundle test data | ||
file(GLOB_RECURSE text_data | ||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} | ||
"data/*.*" | ||
) | ||
|
||
qt_add_resources(${test_target} "tst_qx_common_io_data" | ||
PREFIX "/" | ||
FILES | ||
${text_data} | ||
) |
5 changes: 5 additions & 0 deletions
5
tests/io/qx_common_io/data/writeStringToFile/overwrite_expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
0123456789 | ||
01Jishy | ||
SaltSalivaMan | ||
test456789 | ||
0123456789 |
3 changes: 3 additions & 0 deletions
3
tests/io/qx_common_io/data/writeStringToFile/overwrite_input.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Jishy | ||
SaltSalivaMan | ||
test |
5 changes: 5 additions & 0 deletions
5
tests/io/qx_common_io/data/writeStringToFile/overwrite_original.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
0123456789 | ||
0123456789 | ||
0123456789 | ||
0123456789 | ||
0123456789 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Qt Includes | ||
#include <QtTest> | ||
|
||
// Qx Includes | ||
#include <qx/io/qx-common-io.h> | ||
|
||
// Test Includes | ||
//#include <qx_test_common.h> | ||
|
||
class tst_qx_common_io : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
private: | ||
QTemporaryDir mWriteDir; | ||
|
||
public: | ||
tst_qx_common_io(); | ||
|
||
private slots: | ||
// Init | ||
// void initTestCase(); | ||
// void initTestCase_data(); | ||
// void cleanupTestCase(); | ||
// void init() | ||
// void cleanup(); | ||
|
||
// Test cases | ||
void writeStringToFile_data(); | ||
void writeStringToFile(); | ||
}; | ||
|
||
// Setup | ||
tst_qx_common_io::tst_qx_common_io() | ||
{ | ||
QVERIFY(mWriteDir.isValid()); | ||
} | ||
|
||
// Cases | ||
void tst_qx_common_io::writeStringToFile_data() | ||
{ | ||
QTest::addColumn<QFile*>("file"); | ||
QTest::addColumn<QString>("input"); | ||
QTest::addColumn<QString>("expected"); | ||
|
||
// TODO: Make this more generic with helper functions once more test files are added | ||
|
||
// Overwrite | ||
QString overwritePath = mWriteDir.filePath("overwrite_file.txt"); | ||
QVERIFY(QFile::copy(u":/data/writeStringToFile/overwrite_original.txt"_s, overwritePath)); | ||
QFile::setPermissions(overwritePath, QFile::WriteOwner); // Required since copying from a file marked read-only | ||
|
||
QFile inputFile(u":/data/writeStringToFile/overwrite_input.txt"_s); | ||
QVERIFY(inputFile.open(QIODevice::ReadOnly | QIODevice::Text)); | ||
QString input = inputFile.readAll(); | ||
inputFile.close(); | ||
|
||
QFile expectedFile(u":/data/writeStringToFile/overwrite_expected.txt"_s); | ||
QVERIFY(expectedFile.open(QIODevice::ReadOnly | QIODevice::Text)); | ||
QString expected = expectedFile.readAll(); | ||
expectedFile.close(); | ||
|
||
QTest::newRow("Overwrite") << new QFile(overwritePath, this) << input << expected; | ||
} | ||
|
||
void tst_qx_common_io::writeStringToFile() | ||
{ | ||
// Fetch data from test table | ||
QFETCH(QFile*, file); | ||
QFETCH(QString, input); | ||
QFETCH(QString, expected); | ||
|
||
// Write to file | ||
// TODO: Handle different arguments for writeStringToFile in _data | ||
Qx::IoOpReport rp = Qx::writeStringToFile(*file, input, Qx::Overwrite, Qx::TextPos(1,2)); | ||
QVERIFY(!rp.isFailure()); | ||
|
||
// Get file's new contents and compare | ||
QVERIFY(file->open(QIODevice::ReadOnly | QIODevice::Text)); | ||
QTextStream ts(file); // Handles proper conversion of \r\n to \n | ||
QString newData = ts.readAll(); | ||
QCOMPARE(newData, expected); | ||
file->close(); | ||
} | ||
|
||
QTEST_APPLESS_MAIN(tst_qx_common_io) | ||
#include "tst_qx_common_io.moc" |