Text's selection popup mirroring.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextSelectionPopupMirroringRTL.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 const std::string DEFAULT_EN_LOCALE_DIR = "/tmp/locale/en/LC_MESSAGES/";
35
36 }
37
38 void dali_textselectionpopupmirroringrtl_startup(void)
39 {
40   // Cheat! Copy the .mo file
41   std::ifstream  src( std::string( DEFAULT_EN_LOCALE_DIR + "dali-toolkit.mo.ar" ).c_str(), std::ifstream::binary );
42   std::ofstream  dst( std::string( DEFAULT_EN_LOCALE_DIR + "dali-toolkit.mo" ).c_str(), std::ofstream::binary );
43   dst << src.rdbuf();
44
45   test_return_value = TET_UNDEF;
46 }
47
48 void dali_textselectionpopupmirroringrtl_cleanup(void)
49 {
50   test_return_value = TET_PASS;
51 }
52
53 int UtcDaliToolkitTextSelectionPopupMirroringRTL(void)
54 {
55   // Test the popup mirroring.
56   const std::string CUT( "optionCut" );
57   const std::string COPY( "optionCopy" );
58   const std::string PASTE( "optionPaste" );
59
60   ToolkitTestApplication application;
61
62   setlocale( LC_ALL, "en_GB.UTF-8" );
63   textdomain("dali-toolkit");
64   bindtextdomain("dali-toolkit", DEFAULT_LOCALE_DIR );
65
66   TextSelectionPopup textSelectionPopup = TextSelectionPopup::New( NULL );
67
68   // Enable some buttons.
69   TextSelectionPopup::Buttons buttons = static_cast<TextSelectionPopup::Buttons>( TextSelectionPopup::COPY | TextSelectionPopup::CUT | TextSelectionPopup::PASTE );
70   textSelectionPopup.EnableButtons( buttons );
71
72   // Show the popup.
73   textSelectionPopup.ShowPopup();
74
75   Actor cutActor = textSelectionPopup.FindChildByName( CUT );
76   if( !cutActor )
77   {
78     tet_result(TET_FAIL);
79   }
80
81   Actor tableOfButtons = cutActor.GetParent();
82   if( !tableOfButtons )
83   {
84     tet_result(TET_FAIL);
85   }
86
87   // The order should be PASTE, CUT, COPY
88   DALI_TEST_EQUALS( PASTE, tableOfButtons.GetChildAt( 0 ).GetName(), TEST_LOCATION );
89   DALI_TEST_EQUALS( CUT, tableOfButtons.GetChildAt( 2 ).GetName(), TEST_LOCATION );
90   DALI_TEST_EQUALS( COPY, tableOfButtons.GetChildAt( 4 ).GetName(), TEST_LOCATION );
91
92   tet_result(TET_PASS);
93   END_TEST;
94 }