Browse Source

Added domain test to views testing

master
Artyom Beilis 8 years ago
parent
commit
91d5961597
9 changed files with 71 additions and 8 deletions
  1. +2
    -2
      CMakeLists.txt
  2. +1
    -0
      bin/cppcms_tmpl_cc
  3. BIN
      tests/en/LC_MESSAGES/main.mo
  4. +16
    -0
      tests/en/LC_MESSAGES/main.po
  5. BIN
      tests/en/LC_MESSAGES/plugin2.mo
  6. +16
    -0
      tests/en/LC_MESSAGES/plugin2.po
  7. +2
    -2
      tests/tc_plugin2.tmpl
  8. +1
    -1
      tests/tc_skin.tmpl
  9. +33
    -3
      tests/tc_test.cpp

+ 2
- 2
CMakeLists.txt View File

@@ -856,8 +856,8 @@ add_test(copy_filter_test copy_filter_test)
add_test(mount_point_test mount_point_test)
add_test(file_buffer_test file_buffer_test)
if(NOT DISABLE_SHARED)
add_test(tc_test_shared tc_test "--shared")
add_test(tc_test_separate tc_test "--separate")
add_test(tc_test_shared tc_test "--shared" "${CNF}")
add_test(tc_test_separate tc_test "--separate" "${CNF}")
add_test(plugin_test plugin_test "${CMAKE_CURRENT_BINARY_DIR}")
endif()



+ 1
- 0
bin/cppcms_tmpl_cc View File

@@ -142,6 +142,7 @@ class view_block:
self.gettext_domain = spec_gettext;
output_declaration( '\t\t_domain_id=cppcms::translation_domain_scope::domain_id(_s,"%s");' % self.gettext_domain)
else:
output_declaration( '\t\t_domain_id=booster::locale::ios_info::get(_s).domain_id();')
self.gettext_domain = None;
output_declaration("\t}")



BIN
tests/en/LC_MESSAGES/main.mo View File


+ 16
- 0
tests/en/LC_MESSAGES/main.po View File

@@ -0,0 +1,16 @@
# Copyright (C) 2016 Artyom Beilis
# This file is distributed under the same license as the CppCMS package.
#
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-18 23:10+0200\n"
"Language: \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?0:1;\n"

msgid "translate me"
msgstr "Main Translate Me"


BIN
tests/en/LC_MESSAGES/plugin2.mo View File


+ 16
- 0
tests/en/LC_MESSAGES/plugin2.po View File

@@ -0,0 +1,16 @@
# Copyright (C) 2016 Artyom Beilis
# This file is distributed under the same license as the CppCMS package.
#
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-18 23:10+0200\n"
"Language: \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?0:1;\n"

msgid "translate me"
msgstr "Plugin Translate Me"


+ 2
- 2
tests/tc_plugin2.tmpl View File

@@ -1,11 +1,11 @@
<% c++ #include "tc_sep_skin.h" %>
<% domain plugin %>
<% domain plugin2 %>
<% skin plugin2 %>
<% view master_plugin uses data::master extends tc_skin::master_api2 %>
<% template call() %>Plugin2: <% include f1() %><% end %>
<% end view %>

<% view msg uses data::helper extends tc_skin::message_base %>
<% view msg uses data::master extends tc_skin::message_base %>
<% template render() %><% include f1() %>; <% gt "translate me" %>; <% include f1() %><% end %>
<% end view %>



+ 1
- 1
tests/tc_skin.tmpl View File

@@ -241,7 +241,7 @@ TBD
<% template h1() %>skin::helper_plugin::h1 <%= x %><% end %>
<% end view %>

<% view message_base uses data::helper %>
<% view message_base uses data::master %>
<% template f1() %><% gt "translate me" %><% end %>
<% template render() %><% include f1() %><% end %>
<% end view %>


+ 33
- 3
tests/tc_test.cpp View File

@@ -512,6 +512,29 @@ public:
"plugin::helper_plugin::h1 13\n" //from skin1,name1 include h1()
"");
}
void test_domain()
{
std::cout <<"- Testing gettext domains" << std::endl;
response().out() << booster::locale::translate("translate me")<<";";
{
cppcms::translation_domain_scope scope(response().out(),"plugin2");
response().out() << booster::locale::translate("translate me")<<";";
}
response().out() << booster::locale::translate("translate me")<<";";
compare_strings(str(),"Main Translate Me;Plugin Translate Me;Main Translate Me;");

data::master c;
std::cout <<"-- main" << std::endl;
render("message_base",c);
compare_strings(str(),"Main Translate Me");
std::cout <<"-- plugin" << std::endl;
render("plugin2","msg",c);
compare_strings(str(),"Main Translate Me; Plugin Translate Me; Main Translate Me");
std::cout <<"-- undefined main" << std::endl;
response().out() << booster::locale::as::domain("plugin2");
render("plugin2","msg",c);
compare_strings(str(),"Plugin Translate Me; Plugin Translate Me; Plugin Translate Me");
}


private:
@@ -523,14 +546,19 @@ private:
int main(int argc,char **argv)
{
std::string type;
if(argc!=2 || ((type=argv[1])!="--separate" && type!="--shared")) {
std::cerr << "Usage (--separate|--shared)" << std::endl;
if(argc!=3 || ((type=argv[1])!="--separate" && type!="--shared")) {
std::cerr << "Usage (--separate|--shared) /path/to/tests/dir" << std::endl;
return 1;
}
bool separate = type == "--separate";
try {
cppcms::json::value cfg;
cfg["views"]["paths"][0]="./";
cfg["localization"]["locales"][0]="en_US.UTF-8";
cfg["localization"]["messages"]["paths"][0]=std::string(argv[2]);
cfg["localization"]["messages"]["domains"][0]="main";
cfg["localization"]["messages"]["domains"][1]="plugin2";

if(separate) {
std::cout << "Using separate header/body" << std::endl;
cfg["views"]["skins"][0]="tc_sep_skin_a";
@@ -567,8 +595,10 @@ int main(int argc,char **argv)
app.test_cache();
app.test_using_render();
app.test_gettext();
if(separate)
if(separate) {
app.test_using_from();
app.test_domain();
}
}
catch(std::exception const &e)
{


Loading…
Cancel
Save