Skip to content

Commit

Permalink
Added domain test to views testing
Browse files Browse the repository at this point in the history
  • Loading branch information
artyom-beilis committed Jan 18, 2016
1 parent 7dc0736 commit 91d5961
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions bin/cppcms_tmpl_cc
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
Binary file added tests/en/LC_MESSAGES/main.mo
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/en/LC_MESSAGES/main.po
Original file line number Diff line number Diff line change
@@ -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"

Binary file added tests/en/LC_MESSAGES/plugin2.mo
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/en/LC_MESSAGES/plugin2.po
Original file line number Diff line number Diff line change
@@ -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"

4 changes: 2 additions & 2 deletions tests/tc_plugin2.tmpl
Original file line number Diff line number Diff line change
@@ -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 %>

Expand Down
2 changes: 1 addition & 1 deletion tests/tc_skin.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
36 changes: 33 additions & 3 deletions tests/tc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,29 @@ class test_app : public cppcms::application {
"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:
Expand All @@ -523,14 +546,19 @@ class test_app : public cppcms::application {
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";
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 91d5961

Please sign in to comment.