Add unit tests for wxTranslations language lookup
This commit is contained in:
parent
1f658ff729
commit
6d48acb5f3
8 changed files with 108 additions and 10 deletions
|
|
@ -106,6 +106,8 @@ if(wxUSE_XML)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(TEST_DATA
|
set(TEST_DATA
|
||||||
|
intl/en_GB/internat.mo
|
||||||
|
intl/en_GB/internat.po
|
||||||
intl/fr/internat.mo
|
intl/fr/internat.mo
|
||||||
intl/fr/internat.po
|
intl/fr/internat.po
|
||||||
intl/ja/internat.mo
|
intl/ja/internat.mo
|
||||||
|
|
|
||||||
|
|
@ -463,7 +463,7 @@ COND_MONOLITHIC_1___WXLIB_MONO_p = \
|
||||||
|
|
||||||
### Targets: ###
|
### Targets: ###
|
||||||
|
|
||||||
all: test$(EXEEXT) $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_gui_bundle___depname) $(__test_allheaders___depname) $(__test_allheaders_bundle___depname) data data-image-sample data-images fr ja
|
all: test$(EXEEXT) $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_gui_bundle___depname) $(__test_allheaders___depname) $(__test_allheaders_bundle___depname) data data-image-sample data-images en_GB fr ja
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
|
||||||
|
|
@ -602,6 +602,18 @@ data-images:
|
||||||
esac; \
|
esac; \
|
||||||
done
|
done
|
||||||
|
|
||||||
|
en_GB:
|
||||||
|
@mkdir -p ./intl/en_GB
|
||||||
|
@for f in internat.po internat.mo; do \
|
||||||
|
if test ! -f ./intl/en_GB/$$f -a ! -d ./intl/en_GB/$$f ; \
|
||||||
|
then x=yep ; \
|
||||||
|
else x=`find $(srcdir)/intl/en_GB/$$f -newer ./intl/en_GB/$$f -print` ; \
|
||||||
|
fi; \
|
||||||
|
case "$$x" in ?*) \
|
||||||
|
cp -pRf $(srcdir)/intl/en_GB/$$f ./intl/en_GB ;; \
|
||||||
|
esac; \
|
||||||
|
done
|
||||||
|
|
||||||
fr:
|
fr:
|
||||||
@mkdir -p ./intl/fr
|
@mkdir -p ./intl/fr
|
||||||
@for f in internat.po internat.mo; do \
|
@for f in internat.po internat.mo; do \
|
||||||
|
|
@ -1278,4 +1290,4 @@ failtest_allheaders:
|
||||||
@IF_GNU_MAKE@-include ./.deps/*.d
|
@IF_GNU_MAKE@-include ./.deps/*.d
|
||||||
|
|
||||||
.PHONY: all install uninstall clean distclean test_gui_bundle \
|
.PHONY: all install uninstall clean distclean test_gui_bundle \
|
||||||
test_allheaders_bundle data data-image-sample data-images fr ja
|
test_allheaders_bundle data data-image-sample data-images en_GB fr ja
|
||||||
|
|
|
||||||
BIN
tests/intl/en_GB/internat.mo
Normal file
BIN
tests/intl/en_GB/internat.mo
Normal file
Binary file not shown.
18
tests/intl/en_GB/internat.po
Normal file
18
tests/intl/en_GB/internat.po
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# SOME DESCRIPTIVE TITLE.
|
||||||
|
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||||
|
# This file is distributed under the same license as the PACKAGE package.
|
||||||
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||||
|
#
|
||||||
|
#, fuzzy
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: \n"
|
||||||
|
"POT-Creation-Date: 2003-10-04 23:10+0200\n"
|
||||||
|
"PO-Revision-Date: 2024-02-13 13:25+0100\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"Language: en_GB\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/uilocale.h"
|
#include "wx/uilocale.h"
|
||||||
|
#include "wx/scopeguard.h"
|
||||||
|
|
||||||
#include "wx/private/glibc.h"
|
#include "wx/private/glibc.h"
|
||||||
|
|
||||||
|
|
@ -241,8 +242,9 @@ void IntlTestCase::IsAvailable()
|
||||||
|
|
||||||
TEST_CASE("wxTranslations::AddCatalog", "[translations]")
|
TEST_CASE("wxTranslations::AddCatalog", "[translations]")
|
||||||
{
|
{
|
||||||
// We currently have translations for French and Japanese in this test
|
// We currently have translations for British English, French and Japanese
|
||||||
// directory, check that loading those succeeds but loading others doesn't.
|
// in this test directory, check that loading those succeeds but loading
|
||||||
|
// others doesn't.
|
||||||
wxFileTranslationsLoader::AddCatalogLookupPathPrefix("./intl");
|
wxFileTranslationsLoader::AddCatalogLookupPathPrefix("./intl");
|
||||||
|
|
||||||
const wxString domain("internat");
|
const wxString domain("internat");
|
||||||
|
|
@ -252,11 +254,12 @@ TEST_CASE("wxTranslations::AddCatalog", "[translations]")
|
||||||
SECTION("All")
|
SECTION("All")
|
||||||
{
|
{
|
||||||
auto available = trans.GetAvailableTranslations(domain);
|
auto available = trans.GetAvailableTranslations(domain);
|
||||||
REQUIRE( available.size() == 2 );
|
REQUIRE( available.size() == 3 );
|
||||||
|
|
||||||
available.Sort();
|
available.Sort();
|
||||||
CHECK( available[0] == "fr" );
|
CHECK( available[0] == "en_GB" );
|
||||||
CHECK( available[1] == "ja" );
|
CHECK( available[1] == "fr" );
|
||||||
|
CHECK( available[2] == "ja" );
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("French")
|
SECTION("French")
|
||||||
|
|
@ -287,6 +290,60 @@ TEST_CASE("wxTranslations::AddCatalog", "[translations]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("wxTranslations::GetBestTranslation", "[translations]")
|
||||||
|
{
|
||||||
|
wxFileTranslationsLoader::AddCatalogLookupPathPrefix("./intl");
|
||||||
|
|
||||||
|
const wxString domain("internat");
|
||||||
|
|
||||||
|
wxTranslations trans;
|
||||||
|
wxON_BLOCK_EXIT1( wxUnsetEnv, "WXLANGUAGE" );
|
||||||
|
|
||||||
|
SECTION("ChooseLanguage")
|
||||||
|
{
|
||||||
|
// Simple case.
|
||||||
|
wxSetEnv("WXLANGUAGE", "fr:en");
|
||||||
|
CHECK( trans.GetBestTranslation(domain) == "fr" );
|
||||||
|
CHECK( trans.GetBestAvailableTranslation(domain) == "fr" );
|
||||||
|
|
||||||
|
// Choose 2nd language _and_ its base form.
|
||||||
|
wxSetEnv("WXLANGUAGE", "cs:fr_CA:en");
|
||||||
|
CHECK( trans.GetBestTranslation(domain) == "fr" );
|
||||||
|
CHECK( trans.GetBestAvailableTranslation(domain) == "fr" );
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("EnglishHandling")
|
||||||
|
{
|
||||||
|
// Check that existing en_GB file isn't used for msgid language.
|
||||||
|
wxSetEnv("WXLANGUAGE", "en_US");
|
||||||
|
|
||||||
|
CHECK( trans.GetBestTranslation(domain) == "en" );
|
||||||
|
// GetBestAvailableTranslation() will wrongly return "en_GB", don't test that.
|
||||||
|
|
||||||
|
wxSetEnv("WXLANGUAGE", "es:en");
|
||||||
|
CHECK( trans.GetBestTranslation(domain) == "en" );
|
||||||
|
// GetBestAvailableTranslation() will wrongly return "en_GB", don't test that.
|
||||||
|
|
||||||
|
// And that it is used when it should be
|
||||||
|
wxSetEnv("WXLANGUAGE", "en_GB");
|
||||||
|
CHECK( trans.GetBestTranslation(domain) == "en_GB" );
|
||||||
|
CHECK( trans.GetBestAvailableTranslation(domain) == "en_GB" );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("DontSkipMsgidLanguage")
|
||||||
|
{
|
||||||
|
// Check that msgid language will be used if it's the best match.
|
||||||
|
wxSetEnv("WXLANGUAGE", "cs:en:fr");
|
||||||
|
CHECK( trans.GetBestTranslation(domain) == "en" );
|
||||||
|
|
||||||
|
// ...But won't be used if there's a suitable translation file.
|
||||||
|
wxSetEnv("WXLANGUAGE", "fr:en:cs");
|
||||||
|
CHECK( trans.GetBestTranslation(domain) == "fr" );
|
||||||
|
CHECK( trans.GetBestAvailableTranslation(domain) == "fr" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("wxLocale::Default", "[locale]")
|
TEST_CASE("wxLocale::Default", "[locale]")
|
||||||
{
|
{
|
||||||
const int langDef = wxUILocale::GetSystemLanguage();
|
const int langDef = wxUILocale::GetSystemLanguage();
|
||||||
|
|
|
||||||
|
|
@ -512,7 +512,7 @@ $(OBJS):
|
||||||
|
|
||||||
### Targets: ###
|
### Targets: ###
|
||||||
|
|
||||||
all: $(OBJS)\test.exe $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_allheaders___depname) data data-image-sample data-images fr ja
|
all: $(OBJS)\test.exe $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_allheaders___depname) data data-image-sample data-images en_GB fr ja
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-if exist $(OBJS)\*.o del $(OBJS)\*.o
|
-if exist $(OBJS)\*.o del $(OBJS)\*.o
|
||||||
|
|
@ -572,6 +572,10 @@ data-images:
|
||||||
if not exist image mkdir image
|
if not exist image mkdir image
|
||||||
for %%f in (bitfields.bmp bitfields-alpha.bmp 8bpp-colorsused-large.bmp 8bpp-colorsused-negative.bmp rle4-delta-320x240.bmp rle8-delta-320x240.bmp rle8-delta-320x240-expected.bmp horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png wx.png toucan.png toucan_hue_0.538.png toucan_sat_-0.41.png toucan_bright_-0.259.png toucan_hsv_0.538_-0.41_-0.259.png toucan_light_46.png toucan_dis_240.png toucan_grey.png toucan_mono_255_255_255.png width-times-height-overflow.bmp width_height_32_bit_overflow.pgm bad_truncated.gif) do if not exist image\%%f copy .\image\%%f image
|
for %%f in (bitfields.bmp bitfields-alpha.bmp 8bpp-colorsused-large.bmp 8bpp-colorsused-negative.bmp rle4-delta-320x240.bmp rle8-delta-320x240.bmp rle8-delta-320x240-expected.bmp horse_grey.bmp horse_grey_flipped.bmp horse_rle4.bmp horse_rle4_flipped.bmp horse_rle8.bmp horse_rle8_flipped.bmp horse_bicubic_50x50.png horse_bicubic_100x100.png horse_bicubic_150x150.png horse_bicubic_300x300.png horse_bilinear_50x50.png horse_bilinear_100x100.png horse_bilinear_150x150.png horse_bilinear_300x300.png horse_box_average_50x50.png horse_box_average_100x100.png horse_box_average_150x150.png horse_box_average_300x300.png cross_bicubic_256x256.png cross_bilinear_256x256.png cross_box_average_256x256.png cross_nearest_neighb_256x256.png paste_input_background.png paste_input_black.png paste_input_overlay_transparent_border_opaque_square.png paste_input_overlay_transparent_border_semitransparent_circle.png paste_input_overlay_transparent_border_semitransparent_square.png paste_result_background_plus_circle_plus_square.png paste_result_background_plus_overlay_transparent_border_opaque_square.png paste_result_background_plus_overlay_transparent_border_semitransparent_square.png paste_result_no_background_square_over_circle.png wx.png toucan.png toucan_hue_0.538.png toucan_sat_-0.41.png toucan_bright_-0.259.png toucan_hsv_0.538_-0.41_-0.259.png toucan_light_46.png toucan_dis_240.png toucan_grey.png toucan_mono_255_255_255.png width-times-height-overflow.bmp width_height_32_bit_overflow.pgm bad_truncated.gif) do if not exist image\%%f copy .\image\%%f image
|
||||||
|
|
||||||
|
en_GB:
|
||||||
|
if not exist $(OBJS)\intl\en_GB mkdir $(OBJS)\intl\en_GB
|
||||||
|
for %%f in (internat.po internat.mo) do if not exist $(OBJS)\intl\en_GB\%%f copy .\intl\en_GB\%%f $(OBJS)\intl\en_GB
|
||||||
|
|
||||||
fr:
|
fr:
|
||||||
if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr
|
if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr
|
||||||
for %%f in (internat.po internat.mo) do if not exist $(OBJS)\intl\fr\%%f copy .\intl\fr\%%f $(OBJS)\intl\fr
|
for %%f in (internat.po internat.mo) do if not exist $(OBJS)\intl\fr\%%f copy .\intl\fr\%%f $(OBJS)\intl\fr
|
||||||
|
|
@ -1201,7 +1205,7 @@ $(OBJS)\test_allheaders_allheaders.o: ./allheaders.cpp
|
||||||
$(OBJS)\test_allheaders_testableframe.o: ./testableframe.cpp
|
$(OBJS)\test_allheaders_testableframe.o: ./testableframe.cpp
|
||||||
$(CXX) -c -o $@ $(TEST_ALLHEADERS_CXXFLAGS) $(CPPDEPS) $<
|
$(CXX) -c -o $@ $(TEST_ALLHEADERS_CXXFLAGS) $(CPPDEPS) $<
|
||||||
|
|
||||||
.PHONY: all clean data data-image-sample data-images fr ja
|
.PHONY: all clean data data-image-sample data-images en_GB fr ja
|
||||||
|
|
||||||
|
|
||||||
SHELL := $(COMSPEC)
|
SHELL := $(COMSPEC)
|
||||||
|
|
|
||||||
|
|
@ -792,7 +792,7 @@ $(OBJS):
|
||||||
|
|
||||||
### Targets: ###
|
### Targets: ###
|
||||||
|
|
||||||
all: $(OBJS)\test.exe $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_allheaders___depname) data data-image-sample data-images fr ja
|
all: $(OBJS)\test.exe $(__test_drawing___depname) $(__test_drawingplugin___depname) $(__test_gui___depname) $(__test_allheaders___depname) data data-image-sample data-images en_GB fr ja
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-if exist $(OBJS)\*.obj del $(OBJS)\*.obj
|
-if exist $(OBJS)\*.obj del $(OBJS)\*.obj
|
||||||
|
|
@ -863,6 +863,10 @@ fr:
|
||||||
if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr
|
if not exist $(OBJS)\intl\fr mkdir $(OBJS)\intl\fr
|
||||||
for %f in (internat.po internat.mo) do if not exist $(OBJS)\intl\fr\%f copy .\intl\fr\%f $(OBJS)\intl\fr
|
for %f in (internat.po internat.mo) do if not exist $(OBJS)\intl\fr\%f copy .\intl\fr\%f $(OBJS)\intl\fr
|
||||||
|
|
||||||
|
en_GB:
|
||||||
|
if not exist $(OBJS)\intl\en_GB mkdir $(OBJS)\intl\en_GB
|
||||||
|
for %f in (internat.po internat.mo) do if not exist $(OBJS)\intl\en_GB\%f copy .\intl\en_GB\%f $(OBJS)\intl\en_GB
|
||||||
|
|
||||||
ja:
|
ja:
|
||||||
if not exist $(OBJS)\intl\ja mkdir $(OBJS)\intl\ja
|
if not exist $(OBJS)\intl\ja mkdir $(OBJS)\intl\ja
|
||||||
for %f in (internat.po internat.mo) do if not exist $(OBJS)\intl\ja\%f copy .\intl\ja\%f $(OBJS)\intl\ja
|
for %f in (internat.po internat.mo) do if not exist $(OBJS)\intl\ja\%f copy .\intl\ja\%f $(OBJS)\intl\ja
|
||||||
|
|
|
||||||
|
|
@ -429,6 +429,7 @@
|
||||||
<files>internat.po internat.mo</files>
|
<files>internat.po internat.mo</files>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<wx-data id="en_GB" template="catalog"/>
|
||||||
<wx-data id="fr" template="catalog"/>
|
<wx-data id="fr" template="catalog"/>
|
||||||
<wx-data id="ja" template="catalog"/>
|
<wx-data id="ja" template="catalog"/>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue