Loading files
/*
* LibrePCB - Professional EDA for everyone!
* Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
* https://librepcb.org/
*
* 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 <http://www.gnu.org/licenses/>.
*/
/*******************************************************************************
* Includes
******************************************************************************/
#include <gtest/gtest.h>
#include <librepcb/core/application.h>
#include <librepcb/core/fileio/filepath.h>
#include <librepcb/core/fileio/fileutils.h>
#include <librepcb/core/types/version.h>
#include <QtCore>
/*******************************************************************************
* Namespace
******************************************************************************/
namespace librepcb {
namespace tests {
/*******************************************************************************
* Test Class
******************************************************************************/
class ApplicationTest : public ::testing::Test {
public:
ApplicationTest() {}
~ApplicationTest() override { Application::setTranslationLocale(QLocale()); }
std::string getTranslatedString() {
return QCoreApplication::translate("ui::MainMenuBar", "File").toStdString();
}
};
/*******************************************************************************
* Test Methods
******************************************************************************/
TEST_F(ApplicationTest, testGetVersion) {
EXPECT_FALSE(Application::getVersion().isEmpty());
}
TEST_F(ApplicationTest, testGetFileFormatVersion) {
EXPECT_GE(Application::getFileFormatVersion(), Version::fromString("0.1"));
}
TEST_F(ApplicationTest, testBuildFullVersionDetails) {
const QString s = Application::buildFullVersionDetails();
EXPECT_FALSE(s.trimmed().isEmpty());
EXPECT_GE(s.split("\n").count(), 5);
}
TEST_F(ApplicationTest, testGetTempDir) {
const FilePath fp = Application::getTempDir();
std::cout << qPrintable(fp.toStr()) << std::endl;
EXPECT_TRUE(fp.isValid());
}
TEST_F(ApplicationTest, testGetRandomTempPath) {
const FilePath fp = Application::getRandomTempPath();
EXPECT_TRUE(fp.isLocatedInDir(Application::getTempDir()));
// Test if we can create a file.
FileUtils::writeFile(fp, "test");
FileUtils::removeFile(fp);
// Test if we can create a folder.
FileUtils::makePath(fp);
FileUtils::removeDirRecursively(fp);
}
TEST_F(ApplicationTest, testGetCacheDir) {
// Check if the resources directory is valid and writable.
EXPECT_TRUE(Application::getCacheDir().isValid());
const FilePath tmpFp = Application::getCacheDir().getPathTo("test.txt");
FileUtils::writeFile(tmpFp, "test");
EXPECT_EQ("test", FileUtils::readFile(tmpFp));
FileUtils::removeFile(tmpFp);
}
TEST_F(ApplicationTest, testGetResourcesDir) {
// check if the resources directory is valid, exists and is not empty
EXPECT_TRUE(Application::getResourcesDir().isValid());
EXPECT_TRUE(Application::getResourcesDir().isExistingDir());
EXPECT_FALSE(Application::getResourcesDir().isEmptyDir());
// as the tests can't be installed, the resources must be located in the
// repository root
FilePath repoRoot =
Application::getResourcesDir().getParentDir().getParentDir();
EXPECT_TRUE(repoRoot.getPathTo("LICENSE.txt").isExistingFile());
EXPECT_TRUE(repoRoot.getPathTo("CMakeLists.txt").isExistingFile());
}
TEST_F(ApplicationTest, testExistenceOfResourceFiles) {
EXPECT_TRUE(Application::getResourcesDir().isExistingDir());
EXPECT_TRUE(
Application::getResourcesDir().getPathTo("README.md").isExistingFile());
}
TEST_F(ApplicationTest, testSetTranslationLocale_en) {
Application::setTranslationLocale(QLocale("en"));
EXPECT_EQ("File", getTranslatedString());
}
TEST_F(ApplicationTest, testSetTranslationLocale_en_US) {
Application::setTranslationLocale(QLocale("en_US"));
EXPECT_EQ("File", getTranslatedString());
}
TEST_F(ApplicationTest, testSetTranslationLocale_de) {
Application::setTranslationLocale(QLocale("de"));
EXPECT_EQ("Datei", getTranslatedString());
}
TEST_F(ApplicationTest, testSetTranslationLocale_de_DE) {
Application::setTranslationLocale(QLocale("de_DE"));
EXPECT_EQ("Datei", getTranslatedString());
}
TEST_F(ApplicationTest, testSetTranslationLocale_de_CH) {
Application::setTranslationLocale(QLocale("de_CH"));
EXPECT_EQ("Datei", getTranslatedString());
}
/*******************************************************************************
* End of File
******************************************************************************/
} // namespace tests
} // namespace librepcb
9ea812f0aThis file is pinned to the selected release. Download the original to open it in your design tool.