i18n
Loading...
Searching...
No Matches
TestCXX20.cpp
#include "gtest/gtest.h"
#include "I18n.hpp"
#include "SystemCode.hpp"
#if defined(__APPLE__)
#include <CoreFoundation/CoreFoundation.h>
#elif defined(__unix__) || defined(__linux__)
#include <locale>
#endif
// Test 1: Take systemLocale (ci use FR) + (variadic_locales)
TEST(I18nTest, DefaultLocaleSystem_1) {
i18n.setSupportedLocales<LocaleFr, LocaleEn>();
DefaultLocale* current = i18n.getLocale();
ASSERT_NE(current, nullptr) << "Current locale must be set after injection.";
EXPECT_EQ(current->languageCode(), getSystemCode()) << "Default locale should be the first injected ('en').";
}
// Test 2: If no systemLocale take 'en' + (variadic_locales)
TEST(I18nTest, DefautLocaleEn_2) {
i18n.setSupportedLocales<LocaleEs, LocaleEn>();
DefaultLocale* current = i18n.getLocale();
ASSERT_NE(current, nullptr) << "Current locale must be set after injection.";
EXPECT_EQ(current->languageCode(), "en") << "Default locale should be the first injected ('en').";
}
// Test 3: If no systemLocale & No 'en' take first found (variadic_locales)
TEST(I18nTest, DefaultLocaleFirst_3) {
// Inject the locales using the compile-time tuple method
i18n.setSupportedLocales<LocaleEs>();
// Check if the current locale pointer is set
DefaultLocale* current = i18n.getLocale();
ASSERT_NE(current, nullptr) << "Current locale must be set after injection.";
EXPECT_EQ(current->getButtonCancel(), "Cancelar");
}
// Test 4: Set with tuples Locale to 'fr' and usage. + (tuple)
TEST(I18nTest, SetupLocaleFr_4) {
// Inject the locales using the compile-time tuple method
i18n.setSupportedLocales<SupportedLocales>();
// Check if the current locale pointer is set
EXPECT_EQ(i18n.setLocale("fr"), true);
DefaultLocale* current = i18n.getLocale();
ASSERT_NE(current, nullptr) << "Current locale must be set after injection.";
EXPECT_EQ(current->languageCode(), "fr");
EXPECT_EQ(current->getButtonCancel(), "Annuler");
EXPECT_EQ(current->getButtonSubmit(), "Valider");
EXPECT_EQ(current->getLoginSubTitle(), "Bienvenue !");
EXPECT_EQ(current->getSignInTitle(), "Connexion");
EXPECT_EQ(current->getSignUpTitle(), "Inscription");
}
std::tuple< LocaleEn, LocaleEs, LocaleFr, LocaleIt > SupportedLocales
Definition SupportedLocales.hpp:23
std::string getSystemCode()
Definition SystemCode.hpp:23
TEST(I18nTest, DefaultLocaleSystem_1)
Definition TestCXX20.cpp:23
static I18n< T > & getInstance()
Get the I18n singleton instance.
Definition I18n.hpp:46