Merge "Makes the LTR/RTL alignment of text follow the system language by default...
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-TextLabel-internal.cpp
1 /*
2  * Copyright (c) 2021 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 <stdlib.h>
20
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23
24 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
25 #include <dali-toolkit/internal/text/text-controller.h>
26 #include <dali-toolkit/internal/text/text-controller-impl.h>
27
28 using namespace Dali;
29 using namespace Toolkit;
30 using namespace Text;
31
32 int UtcDaliTextLabelMarkupUnderline(void)
33 {
34   ToolkitTestApplication application;
35   tet_infoline(" UtcDaliTextLabelMarkupUnderline ");
36
37   TextLabel textLabel = TextLabel::New();
38
39   application.GetScene().Add( textLabel );
40
41   textLabel.SetProperty( TextLabel::Property::TEXT, "<u>ABC</u>EF<u>GH</u>" );
42   textLabel.SetProperty( TextLabel ::Property::ENABLE_MARKUP,  true );
43
44   application.SendNotification();
45   application.Render();
46
47   uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
48
49   Toolkit::Internal::TextLabel& textLabelImpl = GetImpl( textLabel );
50   const Text::Length numberOfUnderlineRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
51
52   DALI_TEST_EQUALS( numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION );
53
54   Vector<GlyphRun> underlineRuns;
55   underlineRuns.Resize(numberOfUnderlineRuns);
56   textLabelImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
57
58   //ABC are underlined
59   DALI_TEST_EQUALS( underlineRuns[0u].glyphIndex, 0u, TEST_LOCATION);
60   DALI_TEST_EQUALS( underlineRuns[1u].glyphIndex, 1u, TEST_LOCATION);
61   DALI_TEST_EQUALS( underlineRuns[2u].glyphIndex, 2u, TEST_LOCATION);
62
63   //GH are underlined
64   DALI_TEST_EQUALS( underlineRuns[3u].glyphIndex, 5u, TEST_LOCATION);
65   DALI_TEST_EQUALS( underlineRuns[4u].glyphIndex, 6u, TEST_LOCATION);
66
67   END_TEST;
68
69 }
70
71 int UtcDaliTextLabelBackgroundTag(void)
72 {
73   ToolkitTestApplication application;
74   tet_infoline("UtcDaliTextLabelBackgroundTag\n");
75
76   TextLabel label = TextLabel::New();
77   DALI_TEST_CHECK( label );
78
79   label.SetProperty( TextLabel ::Property::ENABLE_MARKUP,  true );
80   label.SetProperty( TextLabel::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>" );
81   application.GetScene().Add( label );
82   application.SendNotification();
83   application.Render();
84
85   Toolkit::Internal::TextLabel& labelImpl = GetImpl( label );
86   const ColorIndex* const backgroundColorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
87
88   DALI_TEST_CHECK( backgroundColorIndicesBuffer );
89
90   //default color
91   DALI_TEST_EQUALS( backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
92
93   //red color
94   DALI_TEST_EQUALS( backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
95
96   //yellow color
97   DALI_TEST_EQUALS( backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
98
99   END_TEST;
100 }
101
102 int UtcDaliTextLabelTextWithSpan(void)
103 {
104   ToolkitTestApplication application;
105   tet_infoline("UtcDaliTextLabelTextWithSpan\n");
106
107   TextLabel label = TextLabel::New();
108   DALI_TEST_CHECK( label );
109
110   label.SetProperty( TextLabel ::Property::ENABLE_MARKUP,  true );
111   label.SetProperty( TextLabel::Property::TEXT, "Hello Span" );
112   application.GetScene().Add( label );
113
114   application.SendNotification();
115   application.Render();
116
117   Vector3 originalSize = label.GetNaturalSize();
118   label.SetProperty( TextLabel::Property::TEXT, "H<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ello</span> Span" );
119
120   application.SendNotification();
121   application.Render();
122
123   Vector3 spanSize = label.GetNaturalSize();
124
125   DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
126
127   Toolkit::Internal::TextLabel& labelImpl = GetImpl( label );
128   const ColorIndex* const colorIndicesBuffer1 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
129
130   DALI_TEST_CHECK( colorIndicesBuffer1 );
131
132   //default color
133   DALI_TEST_EQUALS( colorIndicesBuffer1[0], 0u, TEST_LOCATION);
134
135   //span color
136   DALI_TEST_EQUALS( colorIndicesBuffer1[1], 1u, TEST_LOCATION);
137
138   //default color
139   DALI_TEST_EQUALS( colorIndicesBuffer1[6], 0u, TEST_LOCATION);
140
141
142   label.SetProperty( TextLabel::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan" );
143
144   application.SendNotification();
145   application.Render();
146
147   const ColorIndex* const colorIndicesBuffer2 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
148
149   DALI_TEST_CHECK( colorIndicesBuffer2 );
150
151   //default color
152   DALI_TEST_EQUALS( colorIndicesBuffer2[0], 0u, TEST_LOCATION);
153
154   //default color
155   DALI_TEST_EQUALS( colorIndicesBuffer2[1], 0u, TEST_LOCATION);
156
157   //span color
158   DALI_TEST_EQUALS( colorIndicesBuffer2[6], 1u, TEST_LOCATION);
159
160   //default color
161   DALI_TEST_EQUALS( colorIndicesBuffer2[7], 0u, TEST_LOCATION);
162
163   END_TEST;
164 }