Support Underline to Markup using underlined-character-run
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-TextLabel-internal.cpp
1 /*
2  * Copyright (c) 2020 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 }