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