Skip to content

Commit

Permalink
add another small unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-w committed Feb 1, 2024
1 parent 11a8cbd commit cda718f
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,18 @@ IF(ENABLE_TESTING)
ADD_TEST(testStelFileMgr testStelFileMgr)
SET_TARGET_PROPERTIES(testStelFileMgr PROPERTIES FOLDER "src/tests")

SET(tests_testStelTranslator_SRCS
tests/testStelTranslator.hpp
tests/testStelTranslator.cpp
)
ADD_EXECUTABLE(testStelTranslator ${tests_testStelTranslator_SRCS})
TARGET_LINK_LIBRARIES(testStelTranslator ${TESTS_LIBRARIES})
ADD_DEPENDENCIES(buildTests testStelTranslator)
ADD_TEST(testStelTranslator testStelTranslator)
SET_TARGET_PROPERTIES(testStelTranslator PROPERTIES FOLDER "src/tests")
SET_TESTS_PROPERTIES(testStelTranslator PROPERTIES
ENVIRONMENT "STELLARIUM_DATA_ROOT=${PROJECT_SOURCE_DIR}")

SET(tests_testStelSphereGeometry_SRCS
tests/testStelSphereGeometry.hpp
tests/testStelSphereGeometry.cpp
Expand Down
53 changes: 53 additions & 0 deletions src/tests/testStelTranslator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Stellarium
* Copyright (C) 2024 Alexander Wolf
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/

#include "tests/testStelTranslator.hpp"

#include <QObject>
#include <QFileInfo>
#include <QFile>
#include <QDir>
#include <QString>
#include <QStringList>
#include <QDebug>
#include <QRegularExpression>

#include "StelTranslator.hpp"
#include "StelFileMgr.hpp"

QTEST_GUILESS_MAIN(TestStelTranslator)

void TestStelTranslator::initTestCase()
{
StelTranslator* testTranslator = new StelTranslator("stellarium", "en");
QVERIFY(testTranslator->getTrueLocaleName()=="en");
QVERIFY(testTranslator->qtranslate("Month")=="Month");
QVERIFY(testTranslator->qtranslate("km/s", "speed")=="km/s");

StelTranslator* testTranslatorRu = new StelTranslator("stellarium", "ru");
QVERIFY(testTranslatorRu->getTrueLocaleName()=="ru");
QVERIFY(testTranslatorRu->qtranslate("Month")=="Месяц");
QVERIFY(testTranslatorRu->qtranslate("km/s", "speed")=="км/с");

StelTranslator* testTranslatorPtBr = new StelTranslator("stellarium", "pt_BR");
QVERIFY(testTranslatorPtBr->getTrueLocaleName()=="pt_BR");
QVERIFY(testTranslatorPtBr->qtranslate("Month")=="Mês");
QVERIFY(testTranslatorPtBr->qtranslate("km/s", "speed")=="km/s");
}

42 changes: 42 additions & 0 deletions src/tests/testStelTranslator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Stellarium
* Copyright (C) 2024 Alexander Wolf
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/

#ifndef TESTSTELTRANSLATOR_HPP
#define TESTSTELTRANSLATOR_HPP

#include <QObject>
#include <QString>
#include <QStringList>
#include <QtTest>
#include <QTemporaryDir>

class StelTranslator;

class TestStelTranslator : public QObject
{
Q_OBJECT
private slots:
void initTestCase();

//private:
// StelTranslator* testTranslator;
};

#endif // _TESTSTELTRANSLATOR_HPP

0 comments on commit cda718f

Please sign in to comment.