[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextSelectionPopupMirroringRTL.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
18 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
21 #include <libintl.h>
22 #include <locale.h>
23 #include <stdlib.h>
24 #include <fstream>
25 #include <iostream>
26
27 using namespace Dali;
28 using namespace Toolkit;
29
30 namespace
31 {
32 const char*        DEFAULT_LOCALE_DIR = "/tmp/locale/";
33 static std::string gLocaleLang;
34 static std::string gLocaleLanguage;
35
36 } // namespace
37
38 void dali_textselectionpopupmirroringrtl_startup(void)
39 {
40   // Keep the current locale environment.
41   char* langPtr = getenv("LANG");
42   gLocaleLang   = std::string(langPtr);
43
44   char* languagePtr = getenv("LANGUAGE");
45   gLocaleLanguage   = std::string(languagePtr);
46
47   // Set the locale environment to Arabic.
48   setenv("LANG", "ar_AE.UTF-8", 1);
49   setenv("LANGUAGE", "ar_AE:ar", 1);
50
51   test_return_value = TET_UNDEF;
52 }
53
54 void dali_textselectionpopupmirroringrtl_cleanup(void)
55 {
56   // Restore the locale environment.
57   setenv("LANG", gLocaleLang.c_str(), 1);
58   setenv("LANGUAGE", gLocaleLanguage.c_str(), 1);
59
60   test_return_value = TET_PASS;
61 }
62
63 int UtcDaliToolkitTextSelectionPopupMirroringRTL(void)
64 {
65   // Test the popup mirroring.
66   const std::string CUT("optionCut");
67   const std::string COPY("optionCopy");
68   const std::string PASTE("optionPaste");
69
70   ToolkitTestApplication application;
71
72   setlocale(LC_ALL, "ar_AE.UTF-8");
73   textdomain("dali-toolkit");
74   bindtextdomain("dali-toolkit", DEFAULT_LOCALE_DIR);
75
76   TextSelectionPopup textSelectionPopup = TextSelectionPopup::New(NULL);
77
78   // Enable some buttons.
79   TextSelectionPopup::Buttons buttons = static_cast<TextSelectionPopup::Buttons>(TextSelectionPopup::COPY | TextSelectionPopup::CUT | TextSelectionPopup::PASTE);
80   textSelectionPopup.EnableButtons(buttons);
81
82   // Show the popup.
83   textSelectionPopup.ShowPopup();
84
85   Actor cutActor = textSelectionPopup.FindChildByName(CUT);
86   if(!cutActor)
87   {
88     tet_result(TET_FAIL);
89   }
90
91   Actor tableOfButtons = cutActor.GetParent();
92   if(!tableOfButtons)
93   {
94     tet_result(TET_FAIL);
95   }
96
97   // The order should be PASTE, CUT, COPY
98   DALI_TEST_EQUALS(PASTE, tableOfButtons.GetChildAt(0).GetProperty<std::string>(Dali::Actor::Property::NAME), TEST_LOCATION);
99   DALI_TEST_EQUALS(CUT, tableOfButtons.GetChildAt(2).GetProperty<std::string>(Dali::Actor::Property::NAME), TEST_LOCATION);
100   DALI_TEST_EQUALS(COPY, tableOfButtons.GetChildAt(4).GetProperty<std::string>(Dali::Actor::Property::NAME), TEST_LOCATION);
101
102   tet_result(TET_PASS);
103   END_TEST;
104 }