Localization tests move
authorKarol Pawlowski <k.pawlowski@samsung.com>
Thu, 14 Feb 2013 11:22:23 +0000 (12:22 +0100)
committerKarol Pawlowski <k.pawlowski@samsung.com>
Thu, 14 Feb 2013 13:02:48 +0000 (14:02 +0100)
[Issue#] LINUXWRT-102
[Problem] Localization tests should be in wrt-commons, no wrt-extra
[Cause] N/A
[Solution] N/A
[Verification] Build wrt-commons repository

Change-Id: Id45acc35305b41c49aca69840ecefe81ff441972

tests/CMakeLists.txt
tests/unit_tests/CMakeLists.txt [new file with mode: 0644]
tests/unit_tests/misc_unit/CMakeLists.txt [new file with mode: 0644]
tests/unit_tests/misc_unit/Localization_testcases.cpp [new file with mode: 0644]
tests/unit_tests/misc_unit/README [new file with mode: 0644]
tests/unit_tests/misc_unit/tests_miscunit.cpp [new file with mode: 0644]

index 40112fe..9a9007c 100644 (file)
@@ -13,6 +13,7 @@ WRT_ADD_INTERNAL_DEPENDENCIES(
 
 ADD_SUBDIRECTORY(dao)
 ADD_SUBDIRECTORY(dpl)
+ADD_SUBDIRECTORY(unit_tests)
 
 # Rollback CXX flags
 #SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_BACKUP})
\ No newline at end of file
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9dfb50f
--- /dev/null
@@ -0,0 +1,19 @@
+# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    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.
+#
+# @file        CMakeLists.txt
+# @author      Lukasz Marek (l.marek@samsung.com)
+#
+
+ADD_SUBDIRECTORY(misc_unit)
diff --git a/tests/unit_tests/misc_unit/CMakeLists.txt b/tests/unit_tests/misc_unit/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8429573
--- /dev/null
@@ -0,0 +1,43 @@
+# Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    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.
+#
+# @file        CMakeLists.txt
+# @author      Marcin Kaminski (marcin.ka@samsung.com)
+# @author      Karol Pawlowski (k.pawlowski@samsung.com)
+# @version     1.0
+# @brief
+#
+
+SET(MISCUNIT_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+
+PKG_CHECK_MODULES(TEST_PKGS
+    vconf
+    REQUIRED
+    )
+
+WRT_INCLUDE_DIRECTORIES(
+    ${TEST_PKGS_INCLUDE_DIRS}
+    ${PROJECT_SOURCE_DIR}/modules/localization/include
+    )
+
+WRT_LINK_DIRECTORIES(${TEST_PKGS_LIBRARY_DIRS})
+WRT_TARGET_LINK_LIBRARIES(${TEST_PKGS_LIBRARIES})
+
+FILE(GLOB MISCUNIT_TESTS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*testcases.cpp")
+
+# target wrt-test-miscunit
+SET(TARGET_MISCUNIT_TEST "wrt-tests-localization")
+WRT_TEST_BUILD(${TARGET_MISCUNIT_TEST} ${MISCUNIT_TESTS_SOURCES} tests_miscunit.cpp)
+WRT_TEST_INSTALL(${TARGET_MISCUNIT_TEST})
+
diff --git a/tests/unit_tests/misc_unit/Localization_testcases.cpp b/tests/unit_tests/misc_unit/Localization_testcases.cpp
new file mode 100644 (file)
index 0000000..bd4b003
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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.
+ */
+/**
+ * @file    Localization_testcases.cpp
+ * @author  Marcin Kaminski (marcin.ka@samsung.com)
+ * @version 1.0
+ * @brief   This file contains tests for localization related code.
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/test/test_runner.h>
+#include <vconf.h>
+
+#include <LanguageTagsProvider.h>
+
+RUNNER_TEST_GROUP_INIT(LanguageTagsProvider)
+
+RUNNER_TEST(tagsFromSystemLocales)
+{
+    LogInfo("Generating tags from system locales");
+
+    char* currlocals = vconf_get_str(VCONFKEY_LANGSET);
+    LogDebug("Locales fetched from system settings: " << currlocals);
+    RUNNER_ASSERT_MSG(!!currlocals, "NULL locales received from system");
+    int result = vconf_set_str(VCONFKEY_LANGSET, "en_US.UTF-8");
+    LogDebug("Returned vconf set execution status: " << result);
+    RUNNER_ASSERT_MSG(result == 0, "Invalid value returned by vconf_set_str on setting locales");
+
+    /* Ensure that system locales where fetched */
+    LanguageTagsProviderSingleton::Instance().resetLanguageTags();
+    LogDebug("Language tags set based on current system locales");
+
+    LanguageTags ltlist = LanguageTagsProviderSingleton::Instance().getLanguageTags();
+    RUNNER_ASSERT_MSG(!ltlist.empty(), "Empty tag list returned");
+
+    /* Correct list generated from given locales should contain: "en-US", "en" and "" */
+    LanguageTags correct;
+    correct.push_back(L"en-US");
+    correct.push_back(L"en");
+    correct.push_back(L"");
+
+    RUNNER_ASSERT_MSG( correct==ltlist, "Received and expected language tags lists differ");
+
+    /* Restore system locales */
+    result = vconf_set_str(VCONFKEY_LANGSET, currlocals);
+    RUNNER_ASSERT_MSG(result == 0, "Invalid value returned by vconf_set_str on restoring locales");
+    LogDebug("System locales restored");
+}
+
+RUNNER_TEST(tagsFromGivenLocales)
+{
+    LogInfo("Generating tags from given locales");
+
+    const char *locales1 = "it_IT.UTF-8", *locales2="en_GB";
+
+    LogDebug("Using locales with codepage: " << locales1);
+    LanguageTagsProviderSingleton::Instance().setLanguageTagsFromLocales(locales1);
+    LanguageTags ltlist = LanguageTagsProviderSingleton::Instance().getLanguageTags();
+    /* Correct list generated from given locales should contain: "it-IT", "it" and
+     * two default values: "en" and "" */
+    LanguageTags correct;
+    correct.push_back(L"it-IT");
+    correct.push_back(L"it");
+    correct.push_back(L"");
+    RUNNER_ASSERT_MSG(correct==ltlist, "Received and expected language tags lists differ");
+
+    LogDebug("Using locales without codepage: " << locales2);
+    LanguageTagsProviderSingleton::Instance().setLanguageTagsFromLocales(locales2);
+    ltlist = LanguageTagsProviderSingleton::Instance().getLanguageTags();
+    correct.clear();
+    correct.push_back(L"en-GB");
+    correct.push_back(L"en");
+    correct.push_back(L"");
+    RUNNER_ASSERT_MSG(correct==ltlist, "Received and expected language tags lists differ");
+}
+
+RUNNER_TEST(tagsFromNullLocales)
+{
+    LogInfo("Generating tags when NULL locales given");
+
+    LanguageTagsProviderSingleton::Instance().setLanguageTagsFromLocales(NULL);
+    LanguageTags ltlist = LanguageTagsProviderSingleton::Instance().getLanguageTags();
+    /* List with two values "en" and "" should be returned */
+    LanguageTags correct;
+    correct.push_back(L"");
+    RUNNER_ASSERT_MSG(correct==ltlist, "Received and expected language tags lists differ");
+}
+
+
+RUNNER_TEST(tagsFromGivenTagList)
+{
+    LogInfo("Copying given tags list");
+
+    LogDebug("Correct full list (with default values)");
+    LanguageTags correct;
+    correct.push_back(L"de-DE");
+    correct.push_back(L"de");
+    correct.push_back(L"");
+    LanguageTagsProviderSingleton::Instance().setLanguageTags(correct);
+    LanguageTags result = LanguageTagsProviderSingleton::Instance().getLanguageTags();
+    RUNNER_ASSERT_MSG(correct==result, "Received and expected language tags lists differ");
+
+    LogDebug("Tags list without default values)");
+    LanguageTags nondef;
+    nondef.push_back(L"de-DE");
+    nondef.push_back(L"de");
+    LanguageTagsProviderSingleton::Instance().setLanguageTags(correct);
+    result = LanguageTagsProviderSingleton::Instance().getLanguageTags();
+
+    /* Received list should contains elements from input list with default
+     * values added (as "correct" list has) */
+    RUNNER_ASSERT_MSG(!result.empty(), "Empty tags list should never be returned");
+    RUNNER_ASSERT_MSG(nondef!=result, "Received list is same as given incomplete one");
+    RUNNER_ASSERT_MSG(correct==result, "Received and expected language tags lists differ");
+}
+
+RUNNER_TEST(tagsFromEmptyList)
+{
+    LogInfo("Generating tags when empty tag list given");
+
+    LanguageTags input;
+    LanguageTagsProviderSingleton::Instance().setLanguageTags(input);
+    LanguageTags result = LanguageTagsProviderSingleton::Instance().getLanguageTags();
+    RUNNER_ASSERT_MSG(!result.empty(), "Empty tags list should never be returned");
+}
+
+RUNNER_TEST(defaultWidgetLocale)
+{
+    LogInfo("Adding default widget locales to language tags list");
+
+    LanguageTags input;
+    input.push_back(L"de-DE");
+    input.push_back(L"de");
+    input.push_back(L"");
+    LanguageTagsProviderSingleton::Instance().setLanguageTags(input);
+    LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(L"it");
+    LanguageTags result = LanguageTagsProviderSingleton::Instance().getLanguageTags();
+    RUNNER_ASSERT_MSG(result.size() == 4, "4 different language tags expected");
+    LanguageTags reference;
+    reference.push_back(L"de-DE");
+    reference.push_back(L"de");
+    reference.push_back(L"it");
+    reference.push_back(L"");
+    RUNNER_ASSERT_MSG(result == reference, "Received and expected language tags lists differ");
+    LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(L"it");
+    LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(L"de-DE");
+    result = LanguageTagsProviderSingleton::Instance().getLanguageTags();
+    RUNNER_ASSERT_MSG(result == reference, "Adding already included tag should not change tags list");
+}
diff --git a/tests/unit_tests/misc_unit/README b/tests/unit_tests/misc_unit/README
new file mode 100644 (file)
index 0000000..366e961
--- /dev/null
@@ -0,0 +1,13 @@
+Miscellaneous test suite
+Unit tests (manifest files, wrt-api). Internal tests for new features in wrt.
+
+Binary file: wrt-tests-misc. Uses our test framework. Allows to use different
+types of output. Text output shows results on console - green passed.
+To run:
+1. Install wrt-extra on target
+2. Run wrt-tests-localization --output=text
+
+Automatic: YES
+Included in Daily Build: NO
+Included in Gerrit Builds: NO
+Number of test cases: 75
\ No newline at end of file
diff --git a/tests/unit_tests/misc_unit/tests_miscunit.cpp b/tests/unit_tests/misc_unit/tests_miscunit.cpp
new file mode 100644 (file)
index 0000000..ba7a1d8
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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.
+ */
+/**
+ * @file    tests_miscunit.cpp
+ * @author  Marcin Kaminski (marcin.ka@samsung.com)
+ * @version 1.0
+ * @brief   This is main file for miscellaneous unit tests (tests of different
+ *          classes, namespaces and functions).
+ */
+
+#include <dpl/test/test_runner.h>
+#include <dpl/log/log.h>
+
+int main (int argc, char *argv[])
+{
+    LogInfo("Starting miscellaneous unit tests");
+    int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
+
+    return status;
+}