[Release] wrt-commons_0.2.113
[framework/web/wrt-commons.git] / tests / files_localization / test_suite01.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * This file contains the declaration of widget dao class.
18  *
19  * @file    test_suite01.cpp
20  * @author  Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
21  * @version 1.0
22  * @brief
23  */
24
25 #include <dpl/log/log.h>
26 #include <dpl/test/test_runner.h>
27 #include <dpl/static_block.h>
28 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
29 #include <dpl/localization/w3c_file_localization.h>
30 #include <LanguageTagsProvider.h>
31
32 namespace {
33
34 STATIC_BLOCK
35 {
36     WrtDB::LanguageTagList tags;
37     tags.push_back(L"pl-pl");
38     tags.push_back(L"en-en");
39     tags.push_back(L"pl-en");
40     LanguageTagsProviderSingleton::Instance().setLanguageTags(tags);
41 }
42
43 static const DPL::String widget1Path =
44     L"/opt/share/widget/tests/localization/widget1/";
45 static const DPL::String widget2Path =
46     L"/opt/share/widget/tests/localization/widget2/";
47 } // anonymous namespace
48
49 RUNNER_TEST(test01_getFilePathInWidgetPackageFromUrl){
50     WrtDB::TizenAppId name = L"tizenid201"; //no difference if it is valid or invalid appId/pkgId, we fill database which has no intergrity constrainst
51     WrtDB::WidgetDAOReadOnly dao(name);
52
53     DPL::Optional<DPL::String> result = W3CFileLocalization::getFilePathInWidgetPackageFromUrl(
54             name,
55             DPL::String(L"widget://one"));
56
57     RUNNER_ASSERT_MSG(!!result, "No result");
58     RUNNER_ASSERT(
59         *result ==
60         L"/opt/share/widget/tests/localization/widget1/res/wgt/locales/pl-en/one");
61 }
62
63 RUNNER_TEST(test02_getFilePathInWidgetPackageFromUrl){
64     WrtDB::TizenAppId name = L"tizenid202";
65     WrtDB::WidgetDAOReadOnly dao(name);
66
67     DPL::Optional<DPL::String> result = W3CFileLocalization::getFilePathInWidgetPackageFromUrl(
68             name,
69             DPL::String(L"widget://one"));
70
71     RUNNER_ASSERT_MSG(!!result, "No result");
72     RUNNER_ASSERT(
73         *result ==
74         L"/opt/share/widget/tests/localization/widget2/res/wgt/locales/pl-en/one");
75 }
76
77 RUNNER_TEST(test03_getFilePathInWidgetPackageFromUrl){
78     WrtDB::TizenAppId name = L"tizenid202";
79     WrtDB::WidgetDAOReadOnly dao(name);
80
81     DPL::Optional<DPL::String> result = W3CFileLocalization::getFilePathInWidgetPackageFromUrl(
82             name,
83             DPL::String(L"widget://two"));
84
85     RUNNER_ASSERT_MSG(!!result, "No result");
86     RUNNER_ASSERT(
87         *result ==
88         L"/opt/share/widget/tests/localization/widget2/res/wgt/locales/en-en/two");
89 }
90
91 RUNNER_TEST(test04_getFilePathInWidgetPackage){
92     WrtDB::TizenAppId name = L"tizenid201";
93     WrtDB::WidgetDAOReadOnly dao(name);
94
95     DPL::Optional<DPL::String> result = W3CFileLocalization::getFilePathInWidgetPackage(
96             name,
97             DPL::String(L"one"));
98
99     RUNNER_ASSERT_MSG(!!result, "No result");
100     RUNNER_ASSERT(*result == L"locales/pl-en/one");
101 }
102
103 RUNNER_TEST(test05_getFilePathInWidgetPackage){
104     WrtDB::TizenAppId name = L"tizenid202";
105     WrtDB::WidgetDAOReadOnly dao(name);
106
107     DPL::Optional<DPL::String> result = W3CFileLocalization::getFilePathInWidgetPackage(
108             name,
109             DPL::String(L"two"));
110
111     RUNNER_ASSERT_MSG(!!result, "No result");
112     RUNNER_ASSERT(*result == L"locales/en-en/two");
113 }
114