chore: add test for TranslatorStorage

This commit is contained in:
AlexSP0 2023-04-11 14:15:20 +04:00 committed by GitHub
parent 46ab925906
commit 0ae9861008
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 132 additions and 0 deletions

View File

@ -26,6 +26,7 @@ BuildRequires: libuuid-devel
BuildRequires: glib2-devel
BuildRequires: libpcre-devel
BuildRequires: libkrb5-devel
BuildRequires: libgtest-devel
BuildRequires: qt5-base-common
BuildRequires: doxygen

View File

@ -41,6 +41,7 @@ RUN apt-get update \
libpcre-devel \
libkrb5-devel \
libxerces-c-devel \
libgtest-devel \
xsd \
boost-devel-headers \
desktop-file-utils \

View File

@ -1,3 +1,4 @@
add_subdirectory(core)
add_subdirectory(gui)
add_subdirectory(io)
add_subdirectory(model)

View File

@ -0,0 +1,4 @@
find_package(GPUI COMPONENTS gui core REQUIRED)
include_directories(${GPUI_INCLUDE_DIRS})
add_subdirectory(translatorstorage)

View File

@ -0,0 +1,28 @@
find_package(GTest)
find_package(Qt5 COMPONENTS Core Gui Test LinguistTools REQUIRED)
set(TS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/i18n/test_ru.ts
${CMAKE_CURRENT_SOURCE_DIR}/i18n/test_en.ts
)
add_translation(QM_FILES "${TS_FILES}")
add_translation_resource(RESOURCES_SRC translatorstorage-tests "${QM_FILES}")
qt5_add_resources(LIB_RESOURCES ${RESOURCES_SRC})
add_executable(translatorstorage-test
translatorstorage-test.cpp
translatorstorageshadow.h
translatorstorageshadow.cpp
${LIB_RESOURCES}
)
target_link_libraries(translatorstorage-test gpui-core Qt5::Core Qt5::Gui Qt5::Test
gtest gtest_main)
add_gpui_test(core.translatorstorage-test translatorstorage-test)

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="ru_RU">
<context>
<name>QObject</name>
<message>
<location filename="../translatorstorage-test.cpp" line="13"/>
<source>test</source>
<translation>тест</translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
<name>QObject</name>
<message>
<location filename="../translatorstorage-test.cpp" line="13"/>
<source>test</source>
<translation>test</translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,33 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <memory.h>
#include <QApplication>
#include <QObject>
#include <QTest>
#include "../../../../src/core/translatorstorage.h"
#include "translatorstorageshadow.h"
TEST(TranslatorStorage, loadTranslators)
{
QObject::tr("test");
TranslatorStorage translatorStorage;
translatorStorage.loadTranslators("en");
void *ptr = &translatorStorage;
tests::TranslatorStorageShadow *shadowPtr = static_cast<tests::TranslatorStorageShadow *>(ptr);
auto loadedTranslations = shadowPtr->d.get()->translators.size();
EXPECT_EQ(loadedTranslations, 1);
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -0,0 +1,13 @@
#include "translatorstorageshadow.h"
#include <memory>
namespace tests
{
TranslatorStorageShadow::TranslatorStorageShadow()
: d(new TranslatorStorageShadowPrivate)
{}
TranslatorStorageShadow::~TranslatorStorageShadow() {}
} // namespace tests

View File

@ -0,0 +1,27 @@
#ifndef GPUI_TRANSLATOR_STORAGE_SHADOW_H
#define GPUI_TRANSLATOR_STORAGE_SHADOW_H
#include "../../../../src/core/translatorstorage.h"
namespace tests
{
class TranslatorStorageShadowPrivate;
class TranslatorStorageShadow
{
public:
TranslatorStorageShadow();
~TranslatorStorageShadow();
public:
std::unique_ptr<TranslatorStorageShadowPrivate> d;
};
class TranslatorStorageShadowPrivate
{
public:
std::vector<std::unique_ptr<QTranslator>> translators = {};
QString m_errorString = {};
};
} // namespace tests
#endif