f67d88a4f7b3a040fd41e939aa591c59963a95a3
[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.getController()->GetTextModel()->GetNumberOfUnderlineRuns();
51
52   DALI_TEST_EQUALS( numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION );
53
54   Vector<GlyphRun> underlineRuns;
55   underlineRuns.Resize(numberOfUnderlineRuns);
56   textLabelImpl.getController()->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.getController()->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 }