2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/glyph-set.h>
24 #include <dali-test-suite-utils.h>
26 // Internal headers are allowed here
28 #include <dali/internal/event/text/font-impl.h>
29 #include <dali/internal/event/resources/resource-ticket.h>
30 #include <dali/internal/event/common/thread-local-storage.h>
34 // Called only once before first test is run.
35 void utc_dali_internal_font_startup()
37 test_return_value = TET_UNDEF;
40 // Called only once after last test is run
41 void utc_dali_internal_font_cleanup()
43 test_return_value = TET_PASS;
50 static const char* TestText = "Some text";
53 Integration::GlyphMetrics characters[] =
55 {' ', 1, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f},
56 {'S', 1, 10.0f, 20.0f, 0.0f, 1.0f, 12.0f},
57 {'o', 1, 11.0f, 20.0f, 0.0f, 1.0f, 13.0f},
58 {'m', 1, 12.0f, 20.0f, 0.0f, 1.0f, 14.0f},
59 {'e', 1, 13.0f, 20.0f, 0.0f, 1.0f, 15.0f},
60 {'t', 1, 14.0f, 20.0f, 0.0f, 1.0f, 16.0f},
61 {'x', 1, 15.0f, 20.0f, 0.0f, 1.0f, 17.0f} };
63 static Integration::GlyphSet* BuildGlyphSet()
65 Integration::GlyphSet* set = new Integration::GlyphSet();
66 Integration::BitmapPtr bitmapData;
68 for (unsigned int index = 0; index < sizeof(characters)/sizeof(characters[0]); index++)
70 set->AddCharacter(bitmapData, characters[index]);
73 set->mLineHeight = 20.0f;
74 set->mUnitsPerEM = 2048.0f/64.0f;
79 static Font CreateFont(TestApplication& application)
81 Integration::GlyphSet* glyphSet = BuildGlyphSet();
82 Integration::ResourcePointer resourcePtr(glyphSet); // reference it
84 // Don't use a font which could be cached otherwise cached values will be used making measure text test to fail.
85 Font font = Font::New(FontParameters("TET-FreeSans", "Book", PointSize(8)));
86 application.SendNotification(); // Send to update thread
87 application.Render(16); // Process request
88 application.Render(16); // Resource complete
89 application.SendNotification(); // Update event objects
90 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
94 } //anonymous namespace
97 int UtcDaliFontMeasureTextWidth(void)
99 TestApplication application;
101 tet_infoline("Testing Dali::Font::MeasureTextWidth()");
103 Font testFont = CreateFont(application);
104 float width = testFont.MeasureTextWidth(TestText, 30.0f);
106 DALI_TEST_EQUALS(width, 270.0f, 0.001f, TEST_LOCATION);
110 int UtcDaliFontMeasureTextWidthNegative(void)
112 TestApplication application;
114 tet_infoline("Testing Dali::Font::MeasureTextWidth() with negative height");
116 Font testFont = CreateFont(application);
117 float width = testFont.MeasureTextWidth(TestText, -30.0f);
119 DALI_TEST_EQUALS(width, 0.0f, TEST_LOCATION);
123 int UtcDaliFontMeasureTextHeight(void)
125 TestApplication application;
127 tet_infoline("Testing Dali::Font::MeasureTextHeight()");
129 Font testFont = CreateFont(application);
130 float height = testFont.MeasureTextHeight(TestText, 200.0f);
132 DALI_TEST_EQUALS(height, 22.2222f, 0.001f, TEST_LOCATION);
136 int UtcDaliFontMeasureTextHeightNegative(void)
138 TestApplication application;
140 tet_infoline("Testing Dali::Font::MeasureTextHeight() with negative width");
142 Font testFont = CreateFont(application);
143 float height = testFont.MeasureTextHeight(TestText, -200.0f);
145 DALI_TEST_EQUALS(height, 0.0f, TEST_LOCATION);