diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 67efb6494..595b70f93 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -1,16 +1,17 @@ find_package(Qt5 REQUIRED COMPONENTS Test) include_directories(${CMAKE_SOURCE_DIR} "${CMAKE_BINARY_DIR}/src/core/") set(CORE_TEST_LIBRARIES gcompris_core Qt5::Core Qt5::Test ) ecm_add_tests(ActivityInfoTest.cpp ApplicationSettingsTest.cpp DirectoryTest.cpp + FileTest.cpp # add new test file here NAME_PREFIX Core LINK_LIBRARIES ${CORE_TEST_LIBRARIES}) diff --git a/tests/core/FileTest.cpp b/tests/core/FileTest.cpp new file mode 100644 index 000000000..1d7aed82f --- /dev/null +++ b/tests/core/FileTest.cpp @@ -0,0 +1,71 @@ +/* GCompris - FileTest.cpp + * + * Copyright (C) 2018 Himanshu Vishwakarma + * GCompris (C) 2018 GCompris Developers + * + * Authors: + * Himanshu Vishwakarma + * + * This program 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. + * + * This program 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 this program; if not, see . + */ + +/* This file is used for the unit tests */ + +#include +#include + +#include "src/core/File.h" + +class CoreFileTest : public QObject +{ + Q_OBJECT +private slots: + void FileTest(); + void ReadWriteTest(); +}; + +void CoreFileTest::FileTest() +{ + File file; + QSignalSpy spyName(&file, &File::nameChanged); + + QVERIFY(spyName.count() == 0); + + QString name = QStringLiteral("./dummy_test_files.txt"); + file.setName(name); + QVERIFY(File::exists(name)); + QVERIFY(File::mkpath(QStringLiteral("./make/dummy/path"))); + QVERIFY(spyName.count() == 1); + QCOMPARE(file.write(QStringLiteral("How are you??")), true); + QCOMPARE(file.read(), QStringLiteral("How are you??")); +} + +void CoreFileTest::ReadWriteTest() +{ + File file; + + QString fileContaint = QStringLiteral("this is going to test the class File in the core"); + QSignalSpy spyError(&file, &File::error); + QVERIFY(spyError.count() == 0); + // File object does not having file name + QVERIFY(!file.write(fileContaint)); + QVERIFY(spyError.count() == 1); + QVERIFY(file.write(fileContaint, "./dummy_test_files.txt")); + QCOMPARE(file.read(), fileContaint); + QVERIFY(file.exists("./dummy_test_files.txt")); + +} + +QTEST_MAIN(CoreFileTest) +#include "FileTest.moc" \ No newline at end of file