TranslatedString tests added 49/218449/4 accepted/tizen/unified/20191126.124659 submit/tizen/20191125.210615
authorOskar Chodowicz <o.chodowicz@partner.samsung.com>
Fri, 22 Nov 2019 09:43:52 +0000 (10:43 +0100)
committerLukasz Oleksak <l.oleksak@samsung.com>
Fri, 22 Nov 2019 15:28:39 +0000 (15:28 +0000)
Change-Id: I15f2bc8be7895a20859fd6d8f86d3e46d57f1cef

tests/no-ui-scenarios/TranslatedStringTests.cpp [new file with mode: 0644]

diff --git a/tests/no-ui-scenarios/TranslatedStringTests.cpp b/tests/no-ui-scenarios/TranslatedStringTests.cpp
new file mode 100644 (file)
index 0000000..3d7cac7
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2017  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "TranslatedString.hpp"
+
+#include <gtest/gtest.h>
+
+TEST(TranslatedString, translationExistingKey)
+{
+       EXPECT_TRUE(setlocale(LC_ALL, "C"));
+       EXPECT_EQ(TranslatedString{"IDS_MSG_ACBUTTON_DONE_ABB"}.str(), std::string{"IDS_MSG_ACBUTTON_DONE_ABB"});
+       EXPECT_TRUE(setlocale(LC_ALL, "en_US.UTF-8"));
+       EXPECT_EQ(TranslatedString{"IDS_MSG_ACBUTTON_DONE_ABB"}.str(), std::string{"DONE"});
+}
+
+TEST(TranslatedString, translationNotExistingKey)
+{
+       EXPECT_TRUE(setlocale(LC_ALL, "C"));
+       EXPECT_EQ(TranslatedString{"IDS_ACCESSIBILITY_TEST_KEY"}.str(), std::string{"IDS_ACCESSIBILITY_TEST_KEY"});
+       EXPECT_TRUE(setlocale(LC_ALL, "en_US.UTF-8"));
+       EXPECT_EQ(TranslatedString{"IDS_ACCESSIBILITY_TEST_KEY"}.str(), std::string{"IDS_ACCESSIBILITY_TEST_KEY"});
+}
+
+TEST(TranslatedString, createFormatedStringDouble)
+{
+       EXPECT_TRUE(setlocale(LC_ALL, "C"));
+       EXPECT_EQ(TranslatedString::create("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS", 0.11).str(), std::string{"IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"});
+       EXPECT_TRUE(setlocale(LC_ALL, "en_GB.UTF-8"));
+       EXPECT_EQ(TranslatedString::create("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS", 0.11).str(), std::string{"0.1 seconds"});
+}
+
+TEST(TranslatedString, createFormatedStringInt)
+{
+       EXPECT_TRUE(setlocale(LC_ALL, "C"));
+       EXPECT_EQ(TranslatedString::create("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SWITCHES", 5).str(), std::string{"IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SWITCHES"});
+       EXPECT_TRUE(setlocale(LC_ALL, "en_GB.UTF-8"));
+       EXPECT_EQ(TranslatedString::create("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SWITCHES", 5).str(), std::string{"5 Switches"});
+}
+
+TEST(TranslatedString, addTranslatedString)
+{
+       EXPECT_TRUE(setlocale(LC_ALL, "C"));
+       auto sum_1 = TranslatedString{"IDS_MSG_ACBUTTON_DONE_ABB"} + TranslatedString{"IDS_MSG_ACBUTTON_DONE_ABB"};
+       sum_1 += TranslatedString{"IDS_MSG_ACBUTTON_DONE_ABB"};
+       EXPECT_EQ(sum_1.str(), std::string{"IDS_MSG_ACBUTTON_DONE_ABBIDS_MSG_ACBUTTON_DONE_ABBIDS_MSG_ACBUTTON_DONE_ABB"});
+       EXPECT_TRUE(setlocale(LC_ALL, "en_GB.UTF-8"));
+       auto sum_2 = TranslatedString{"IDS_MSG_ACBUTTON_DONE_ABB"} + TranslatedString{"IDS_MSG_ACBUTTON_DONE_ABB"};
+       sum_2 += TranslatedString{"IDS_MSG_ACBUTTON_DONE_ABB"};
+       EXPECT_EQ(sum_2.str(), std::string{"DONEDONEDONE"});
+}
+
+int main(int argc, char *argv[])
+{
+       bindtextdomain(PACKAGE, LOCALEDIR);
+       textdomain(PACKAGE);
+       try {
+               ::testing::InitGoogleTest(&argc, argv);
+               return RUN_ALL_TESTS();
+       } catch (...) {
+               return 1;
+       }
+}