summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am42
-rw-r--r--test/locale/da.mobin0 -> 948 bytes
-rw-r--r--test/resource_test.cc5
-rw-r--r--test/translationtest.cc80
-rw-r--r--test/uitests/Makefile.am9
5 files changed, 132 insertions, 4 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index c9ece6e..372b57f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -10,11 +10,16 @@ TESTS = resource enginetest paintertest configfile audiocache \
dgxmlparsertest domloadertest configparsertest midimapparsertest \
eventsdstest powermaptest
+if WITH_NLS
+TESTS += translationtest
+endif
+
EXTRA_DIST = \
dgunit.h \
drumkit_creator.h \
lv2_test_host.h \
- scopedfile.h
+ scopedfile.h \
+ locale/da.mo
if ENABLE_LV2
TESTS += lv2
@@ -25,11 +30,13 @@ check_PROGRAMS = $(TESTS)
resource_CXXFLAGS = -DOUTPUT=\"resource\" $(SNDFILE_CFLAGS) \
$(DEBUG_FLAGS) \
-I$(top_srcdir)/src \
+ -I$(top_srcdir)/plugingui \
-I$(top_srcdir)/hugin
resource_LDFLAGS = $(SNDFILE_LIBS)
+nodist_resource_SOURCES = \
+ $(top_builddir)/plugingui/resource_data.cc
resource_SOURCES = \
$(top_srcdir)/plugingui/resource.cc \
- $(top_srcdir)/plugingui/resource_data.cc \
$(top_srcdir)/hugin/hugin.c \
$(top_srcdir)/src/random.cc \
dgtest.cc \
@@ -279,4 +286,35 @@ powermaptest_SOURCES = \
powermaptest.cc \
dgtest.cc
+RES = \
+ $(top_srcdir)/test/locale/da.mo
+
+rcgen_verbose = $(rcgen_verbose_@AM_V@)
+rcgen_verbose_ = $(rcgen_verbose_@AM_DEFAULT_V@)
+rcgen_verbose_0 = @echo " RCGEN "$@;
+
+translationtest_resource_data.cc: $(top_builddir)/plugingui/rcgen $(RES)
+ $(rcgen_verbose)$(top_builddir)/plugingui/rcgen$(EXEEXT) -s $(top_srcdir)/test/ -o $@ $(RES)
+
+translationtest_CXXFLAGS = \
+ -DOUTPUT=\"translationtest\" \
+ -I$(top_srcdir)/plugingui \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/hugin \
+ -DMO_SRC=\"$(top_srcdir)/test/locale/da.mo\" \
+ -Wno-invalid-source-encoding
+translationtest_LDFLAGS =
+nodist_translationtest_SOURCES = \
+ $(top_builddir)/test/translationtest_resource_data.cc
+translationtest_SOURCES = \
+ $(top_srcdir)/hugin/hugin.c \
+ $(top_srcdir)/plugingui/resource.cc \
+ $(top_srcdir)/src/translation.cc \
+ $(top_srcdir)/plugingui/uitranslation.cc \
+ translationtest.cc \
+ dgtest.cc
+
+BUILT_SOURCES = translationtest_resource_data.cc
+CLEANFILES = translationtest_resource_data.cc
+
endif
diff --git a/test/locale/da.mo b/test/locale/da.mo
new file mode 100644
index 0000000..13eeaca
--- /dev/null
+++ b/test/locale/da.mo
Binary files differ
diff --git a/test/resource_test.cc b/test/resource_test.cc
index 28a244e..1beae94 100644
--- a/test/resource_test.cc
+++ b/test/resource_test.cc
@@ -86,6 +86,11 @@ public:
ResourceTester rc("no_such_file");
DGUNIT_ASSERT(!rc.valid());
}
+
+ {
+ ResourceTester rc(":no_such_file");
+ DGUNIT_ASSERT(!rc.valid());
+ }
}
};
diff --git a/test/translationtest.cc b/test/translationtest.cc
new file mode 100644
index 0000000..f64e1f3
--- /dev/null
+++ b/test/translationtest.cc
@@ -0,0 +1,80 @@
+/* -*- Mode: c++ -*- */
+/***************************************************************************
+ * translationtest.cc
+ *
+ * Sun Sep 8 14:51:08 CEST 2019
+ * Copyright 2019 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "dgunit.h"
+
+#include <locale>
+
+#include <translation.h>
+#include <uitranslation.h>
+#include <stdlib.h>
+
+class TranslationTest
+ : public DGUnit
+{
+public:
+ TranslationTest()
+ {
+ DGUNIT_TEST(TranslationTest::testFromFile);
+ DGUNIT_TEST(TranslationTest::testFromLocale);
+ }
+
+ void testFromFile()
+ {
+ Translation t;
+ char buf[100000];
+ FILE* fp = fopen(MO_SRC, "r");
+ DGUNIT_ASSERT(fp != nullptr);
+ auto sz = fread(buf, 1, sizeof(buf), fp);
+ fclose(fp);
+ DGUNIT_ASSERT(t.load(buf, sz));
+
+ // Look up translation from .mo file
+ DGUNIT_ASSERT_EQUAL(std::string("Trommesæt"),
+ std::string(_("Drumkit")));
+
+ // No translation, return key
+ DGUNIT_ASSERT_EQUAL(std::string("No translation"),
+ std::string(_("No translation")));
+ }
+
+ void testFromLocale()
+ {
+ setenv("LANG", "da_DK.UTF-8", 1);
+ UITranslation t;
+
+ // Look up translation from .mo file
+ DGUNIT_ASSERT_EQUAL(std::string("Trommesæt"),
+ std::string(_("Drumkit")));
+
+ // No translation, return key
+ DGUNIT_ASSERT_EQUAL(std::string("No translation"),
+ std::string(_("No translation")));
+ }
+};
+
+// Registers the fixture into the 'registry'
+static TranslationTest test;
diff --git a/test/uitests/Makefile.am b/test/uitests/Makefile.am
index a5e6d01..b28682f 100644
--- a/test/uitests/Makefile.am
+++ b/test/uitests/Makefile.am
@@ -55,7 +55,7 @@ rcgen_verbose = $(rcgen_verbose_@AM_V@)
rcgen_verbose_ = $(rcgen_verbose_@AM_DEFAULT_V@)
rcgen_verbose_0 = @echo " RCGEN "$@;
-$(top_builddir)/test/uitests/benchmarktest_resource_data.cc: $(top_builddir)/plugingui/rcgen $(RES)
+benchmarktest_resource_data.cc: $(top_builddir)/plugingui/rcgen $(RES)
$(rcgen_verbose)$(top_builddir)/plugingui/rcgen$(EXEEXT) -d $(top_srcdir)/test/uitests -o $@ $(RES)
benchmarktest_LDADD = \
@@ -65,11 +65,16 @@ benchmarktest_CXXFLAGS = \
-I$(top_srcdir)/plugingui \
-I$(top_srcdir)/src \
-I$(top_srcdir)/hugin
+nodist_benchmarktest_SOURCES = \
+ benchmarktest_resource_data.cc
benchmarktest_SOURCES = \
benchmarktest.cc \
- $(top_builddir)/test/uitests/benchmarktest_resource_data.cc \
$(top_srcdir)/hugin/hugin.c
+BUILT_SOURCES = benchmarktest_resource_data.cc
+CLEANFILES = benchmarktest_resource_data.cc
+
+
powerwidgettest_LDADD = \
$(top_builddir)/plugingui/libdggui.la \
$(top_builddir)/src/libdg.la