2 * Copyright (C) 2024 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "GUIInfoManager.h"
11 #include "guilib/GUIAction.h"
12 #include "guilib/GUIColorManager.h"
13 #include "guilib/GUIControlFactory.h"
14 #include "guilib/GUIFont.h"
15 #include "guilib/GUILabelControl.h"
16 #include "guilib/GUITexture.h"
17 #include "guilib/LocalizeStrings.h"
18 #include "guilib/guiinfo/GUIInfoLabel.h"
19 #include "utils/SystemInfo.h"
20 #include "utils/XBMCTinyXML.h"
25 #include <gtest/gtest.h>
29 class CGFTestable
: public CGUIControlFactory
32 static std::string
GetType(const TiXmlElement
* pControlNode
)
34 return CGUIControlFactory::GetType(pControlNode
);
37 static bool GetIntRange(const TiXmlNode
* pRootNode
,
43 return CGUIControlFactory::GetIntRange(pRootNode
, strTag
, iMinValue
, iMaxValue
, iIntervalValue
);
46 static bool GetFloatRange(const TiXmlNode
* pRootNode
,
50 float& fIntervalValue
)
52 return CGUIControlFactory::GetFloatRange(pRootNode
, strTag
, fMinValue
, fMaxValue
,
56 static bool GetPosition(const TiXmlNode
* node
,
58 const float parentSize
,
61 return CGUIControlFactory::GetPosition(node
, tag
, parentSize
, value
);
64 static bool GetDimension(
65 const TiXmlNode
* node
, const char* strTag
, const float parentSize
, float& value
, float& min
)
67 return CGUIControlFactory::GetDimension(node
, strTag
, parentSize
, value
, min
);
70 static bool GetDimensions(const TiXmlNode
* node
,
73 const char* centerLeftTag
,
74 const char* centerRightTag
,
76 const float parentSize
,
81 return CGUIControlFactory::GetDimensions(node
, leftTag
, rightTag
, centerLeftTag
, centerRightTag
,
82 widthTag
, parentSize
, left
, width
, min_width
);
85 static bool GetMovingSpeedConfig(const TiXmlNode
* pRootNode
,
87 UTILS::MOVING_SPEED::MapEventConfig
& movingSpeedCfg
)
89 return CGUIControlFactory::GetMovingSpeedConfig(pRootNode
, strTag
, movingSpeedCfg
);
92 static bool GetConditionalVisibility(const TiXmlNode
* control
,
93 std::string
& condition
,
94 std::string
& allowHiddenFocus
)
96 return CGUIControlFactory::GetConditionalVisibility(control
, condition
, allowHiddenFocus
);
99 static bool GetString(const TiXmlNode
* pRootNode
, const char* strTag
, std::string
& strString
)
101 return CGUIControlFactory::GetString(pRootNode
, strTag
, strString
);
108 using namespace std::string_literals
;
110 class CGUITestColorManager
: public CGUIColorManager
113 CGUITestColorManager()
116 xmlDoc
.Parse(R
"(<colors>
117 <color name="white
">ffffffff</color>
118 <color name="black
">00000000</color>
119 <color name="navy
">ff000080</color>
125 class CGUITestComponent
: public CGUIComponent
128 CGUITestComponent() : CGUIComponent(false)
130 m_guiColorManager
= std::make_unique
<CGUITestColorManager
>();
131 m_guiInfoManager
= std::make_unique
<CGUIInfoManager
>();
132 CServiceBroker::RegisterGUI(this);
139 std::vector
<CGUIAction::CExecutableAction
> actions
;
143 class TestGetActions
: public testing::WithParamInterface
<ActionsTest
>, public testing::Test
147 const auto ActionsTests
= std::array
{
148 ActionsTest
{R
"(<root>
149 <test condition="foo
">bar</test>
150 <test condition="bar
">foo</test>
152 {{"foo"s
, "bar"s
}, {"bar"s
, "foo"s
}}},
153 ActionsTest
{R
"(<root><test>bar</test></root>)"s
, {{""s
, "bar"s
}}},
154 ActionsTest
{R
"(<root><test/></root>)"s
, {}, false},
155 ActionsTest
{R
"(<root/>)"s
, {}, false},
165 class TestGetAlignment
: public testing::WithParamInterface
<AlignmentTest
>, public testing::Test
169 const auto AlignmentTests
= std::array
{
170 AlignmentTest
{R
"(<root><test>right</test></root>)"s
, XBFONT_RIGHT
},
171 AlignmentTest
{R
"(<root><test>bottom</test></root>)"s
, XBFONT_RIGHT
},
172 AlignmentTest
{R
"(<root><test>center</test></root>)"s
, XBFONT_CENTER_X
},
173 AlignmentTest
{R
"(<root><test>justify</test></root>)"s
, XBFONT_JUSTIFIED
},
174 AlignmentTest
{R
"(<root><test>left</test></root>)"s
, XBFONT_LEFT
},
175 AlignmentTest
{R
"(<root><test>foo</test></root>)"s
, XBFONT_LEFT
},
176 AlignmentTest
{R
"(<root><test/></root>)"s
, 0, false},
177 AlignmentTest
{R
"(<root/>)"s
, 0, false},
180 class TestGetAlignmentY
: public testing::WithParamInterface
<AlignmentTest
>, public testing::Test
184 const auto AlignmentYTests
= std::array
{
185 AlignmentTest
{R
"(<root><test>center</test></root>)"s
, XBFONT_CENTER_Y
},
186 AlignmentTest
{R
"(<root><test>bottom</test></root>)"s
, 0},
187 AlignmentTest
{R
"(<root><test/></root>)"s
, std::numeric_limits
<uint32_t>::max(), false},
188 AlignmentTest
{R
"(<root/>)"s
, std::numeric_limits
<uint32_t>::max(), false},
191 struct AspectRatioTest
198 class TestAspectRatio
: public testing::WithParamInterface
<AspectRatioTest
>, public testing::Test
202 const auto AspectRatioTests
= std::array
{
203 AspectRatioTest
{R
"(<root><test align="center
">keep</test></root>)"s
,
204 {CAspectRatio::AR_KEEP
, ASPECT_ALIGN_CENTER
, true}},
205 AspectRatioTest
{R
"(<root><test align="right
">scale</test></root>)"s
,
206 {CAspectRatio::AR_SCALE
, ASPECT_ALIGN_RIGHT
, true}},
207 AspectRatioTest
{R
"(<root><test align="left
">center</test></root>)"s
,
208 {CAspectRatio::AR_CENTER
, ASPECT_ALIGN_LEFT
, true}},
209 AspectRatioTest
{R
"(<root><test align="center
">stretch</test></root>)"s
,
210 {CAspectRatio::AR_STRETCH
, ASPECT_ALIGN_CENTER
, true}},
211 AspectRatioTest
{R
"(<root><test aligny="center
" scalediffuse="true">keep</test></root>)"s
,
212 {CAspectRatio::AR_KEEP
, ASPECT_ALIGNY_CENTER
, true}},
213 AspectRatioTest
{R
"(<root><test aligny="bottom
" scalediffuse="yes
">keep</test></root>)"s
,
214 {CAspectRatio::AR_KEEP
, ASPECT_ALIGNY_BOTTOM
, true}},
216 R
"(<root><test align="right
" aligny="top
" scalediffuse="no
">keep</test></root>)"s
,
217 {CAspectRatio::AR_KEEP
, ASPECT_ALIGN_RIGHT
| ASPECT_ALIGNY_TOP
, false}},
218 AspectRatioTest
{R
"(<root><test scalediffuse="false">keep</test></root>)"s
,
219 {CAspectRatio::AR_KEEP
, ASPECT_ALIGN_CENTER
, false}},
221 R
"(<root><test/></root>)"s
, {CAspectRatio::AR_STRETCH
, ASPECT_ALIGN_CENTER
, true}, false},
222 AspectRatioTest
{R
"(<root/>)"s
, {CAspectRatio::AR_STRETCH
, ASPECT_ALIGN_CENTER
, true}, false},
228 UTILS::COLOR::Color value
;
232 class TestGetColor
: public testing::WithParamInterface
<ColorTest
>, public testing::Test
236 const auto ColorTests
= std::array
{
237 ColorTest
{R
"(<root><test>white</test></root>)"s
, 0xFFFFFFFF},
238 ColorTest
{R
"(<root><test>navy</test></root>)"s
, 0xFF000080},
239 ColorTest
{R
"(<root><test>black</test></root>)"s
, 0x00000000},
240 ColorTest
{R
"(<root><test>0x12345678</test></root>)"s
, 0x12345678},
241 ColorTest
{R
"(<root><test/></root>)"s
, std::numeric_limits
<uint32_t>::max(), false},
242 ColorTest
{R
"(<root/>)"s
, std::numeric_limits
<uint32_t>::max(), false},
245 struct ConditionalVisibilityTest
248 std::string condition
;
253 class TestConditionalVisibility
: public testing::WithParamInterface
<ConditionalVisibilityTest
>,
258 const auto ConditionalVisibilityTests
= std::array
{
259 ConditionalVisibilityTest
{R
"(<root>
260 <visible>foo</visible>
263 ConditionalVisibilityTest
{R
"(<root>
264 <visible allowhiddenfocus="bar
">foo</visible>
267 ConditionalVisibilityTest
{R
"(<root>
268 <visible allowhiddenfocus="bar
">foo</visible>
269 <visible allowhiddenfocus="foobar
">bar</visible>
271 "[foo] + [bar]"s
, "foobar"s
},
272 ConditionalVisibilityTest
{R
"(<root/>)", ""s
, ""s
, false},
282 class TestGetDimension
: public testing::WithParamInterface
<DimensionTest
>, public testing::Test
286 const auto DimensionTests
= std::array
{
287 DimensionTest
{R
"(<root><test>0.1</test></root>)"s
, 0.f
, 0.1f
},
288 DimensionTest
{R
"(<root><test max="3.0">auto</test></root>)"s
, 1.f
, 3.f
},
289 DimensionTest
{R
"(<root><test max="3.0r
">auto</test></root>)"s
, 1.f
, -2.9f
},
290 DimensionTest
{R
"(<root><test max="3.0%">auto</test></root>)"s
, 1.f
, 3.f
* 0.1f
/ 100.f
},
291 DimensionTest
{R
"(<root><test min="2.0" max="3.0">auto</test></root>)"s
, 2.f
, 3.f
},
292 DimensionTest
{R
"(<root><test min="2.0r
" max="3.0">auto</test></root>)"s
, -1.9f
, 3.f
},
293 DimensionTest
{R
"(<root><test min="2.0%" max="3.0">auto</test></root>)"s
, 2.f
* 0.1f
/ 100.f
,
295 DimensionTest
{R
"(<root><test>something</test></root>)"s
, 0.f
, 0.f
},
296 DimensionTest
{R
"(<root><test/></root>)"s
, 0.f
, 0.f
, false},
297 DimensionTest
{R
"(<root/>)"s
, 0.f
, 0.f
, false},
300 struct DimensionsTest
303 float left
, width
, min_width
;
307 class TestGetDimensions
: public testing::WithParamInterface
<DimensionsTest
>, public testing::Test
311 const auto DimensionsTests
= std::array
{
312 DimensionsTest
{R
"(<root><left>0.1</left><width>0.2</width></root>)"s
, 0.1f
, 0.2f
, 0.f
},
313 DimensionsTest
{R
"(<root><left>0.01</left><right>50%</right></root>)"s
, 0.01f
,
314 0.1f
- 0.1f
* 50.f
/ 100.f
- 0.01f
, 0.f
},
315 DimensionsTest
{R
"(<root><center_left>0.025f</center_left><right>50%</right></root>)"s
, 0.f
,
316 (0.05f
- 0.025f
) * 2, 0.f
},
318 R
"(<root><center_right>0.025f</center_right><width min="0.5" max="0.2">auto</width></root>)"s
,
319 (0.1f
- 0.025f
) - 0.2f
/ 2, 0.2f
, 0.5f
},
326 T min
, max
, interval
;
330 class TestGetFloatRange
: public testing::WithParamInterface
<RangeTest
<float>>, public testing::Test
334 const auto FloatRangeTests
= std::array
{
335 RangeTest
<float>{R
"(<root><test>1.0,100.0,0.25</test></root>)"s
, 1.f
, 100.f
, 0.25f
},
336 RangeTest
<float>{R
"(<root><test>1.0,100.0</test></root>)"s
, 1.f
, 100.f
, 0.f
},
337 RangeTest
<float>{R
"(<root><test>,100.0,5.0</test></root>)"s
, 0.f
, 100.f
, 5.f
},
338 RangeTest
<float>{R
"(<root><test>1.0</test></root>)"s
, 1.f
, 0.f
, 0.f
},
339 RangeTest
<float>{R
"(<root><test/></root>)"s
, 0.f
, 0.f
, 0.f
, false},
340 RangeTest
<float>{R
"(<root/>)"s
, 0.f
, 0.f
, 0.f
, false},
350 class TestGetHitRect
: public testing::WithParamInterface
<HitRectTest
>, public testing::Test
354 const auto HitRectTests
= std::array
{
355 HitRectTest
{R
"(<root><hitrect x="1.0" y="2.0" w="3.0" h="4.0"/></root>)"s
,
356 CRect
{1.0, 2.0, 4.0, 6.0}},
357 HitRectTest
{R
"(<root><hitrect y="2.0" right="3.0" h="4.0"/></root>)"s
,
358 CRect
{0.0, 2.0, 0.0, 6.0}},
359 HitRectTest
{R
"(<root><hitrect x="1.0" y="2.0" w="3.0" bottom="4.0"/></root>)"s
,
360 CRect
{1.0, 2.0, 4.0, 2.0}},
361 HitRectTest
{R
"(<root/>)"s
, CRect
{0.0, 0.0, 0.0, 0.0}, false},
368 std::string fallback
;
372 class TestGetInfoLabel
: public testing::WithParamInterface
<InfoLabelTest
>, public testing::Test
376 const auto InfoLabelTests
= std::array
{
377 InfoLabelTest
{R
"(<root>Foo dat bar</root>)"s
, "Foo dat bar"s
, ""s
},
378 InfoLabelTest
{R
"(<root fallback="yo
">Foo dat bar</root>)"s
, "Foo dat bar"s
, "yo"s
},
379 InfoLabelTest
{R
"(<root fallback="yo
">1</root>)"s
, "Pictures"s
, "yo"s
},
380 InfoLabelTest
{R
"(<root fallback="1">Bar</root>)"s
, "Bar"s
, "Pictures"s
},
381 InfoLabelTest
{R
"(<root fallback="1"></root>)"s
, ""s
, ""s
, false},
382 InfoLabelTest
{R
"(<root/>)"s
, ""s
, ""s
, false},
385 struct InfoLabelsTest
388 std::vector
<std::array
<std::string
, 2>> labels
;
391 class TestGetInfoLabels
: public testing::WithParamInterface
<InfoLabelsTest
>, public testing::Test
395 const auto InfoLabelsTests
= std::array
{
396 InfoLabelsTest
{R
"(<root><number>1234</number></root>)"s
, {{"1234"s
, ""s
}}},
397 InfoLabelsTest
{R
"(<root><test>1</test><test fallback="1">foo</test></root>)"s
,
398 {{"Pictures"s
, ""s
}, {"foo"s
, "Pictures"s
}}},
399 InfoLabelsTest
{R
"(<root>
400 <test fallback="1">foo</test>
401 <info>System.BuildVersion</info>
402 <info>System.BuildVersionShort</info>
404 {{CSysInfo::GetVersion(), "foo"s
}, {CSysInfo::GetVersionShort(), "foo"s
}}},
405 InfoLabelsTest
{R
"(<root/)"s
, {}},
408 class TestGetIntRange
: public testing::WithParamInterface
<RangeTest
<int>>, public testing::Test
412 const auto IntRangeTests
= std::array
{
413 RangeTest
<int>{R
"(<root><test>1,100,5</test></root>)"s
, 1, 100, 5},
414 RangeTest
<int>{R
"(<root><test>1,100</test></root>)"s
, 1, 100, 0},
415 RangeTest
<int>{R
"(<root><test>,100,5</test></root>)"s
, 0, 100, 5},
416 RangeTest
<int>{R
"(<root><test>1</test></root>)"s
, 1, 0, 0},
417 RangeTest
<int>{R
"(<root><test/></root>)"s
, 0, 0, 0, false},
418 RangeTest
<int>{R
"(<root/>)"s
, 0, 0, 0, false},
421 struct MovingSpeedTest
424 UTILS::MOVING_SPEED::MapEventConfig config
;
428 class TestGetMovingSpeed
: public testing::WithParamInterface
<MovingSpeedTest
>, public testing::Test
432 const auto MovingSpeedTests
= std::array
{
434 R
"(<root><test acceleration="1.0" maxvelocity="2.0"
435 resettimeout="3" delta="4.0">
436 <eventconfig type="up
"/>
437 <eventconfig type="down
" acceleration="2.0"/>
438 <eventconfig type="left
" maxvelocity="3.0"/>
439 <eventconfig type="right
" resettimeout="4"/>
440 <eventconfig type="none
" delta="5"/>
443 {UTILS::MOVING_SPEED::EventType::UP
, UTILS::MOVING_SPEED::EventCfg
{1.0, 2.0, 3, 4.0}},
444 {UTILS::MOVING_SPEED::EventType::DOWN
, UTILS::MOVING_SPEED::EventCfg
{2.0, 2.0, 3, 4.0}},
445 {UTILS::MOVING_SPEED::EventType::LEFT
, UTILS::MOVING_SPEED::EventCfg
{1.0, 3.0, 3, 4.0}},
446 {UTILS::MOVING_SPEED::EventType::RIGHT
,
447 UTILS::MOVING_SPEED::EventCfg
{1.0, 2.0, 4, 4.0}},
448 {UTILS::MOVING_SPEED::EventType::NONE
, UTILS::MOVING_SPEED::EventCfg
{1.0, 2.0, 3, 5.0}},
452 <eventconfig type="up
"/>
453 <eventconfig type="down
" acceleration="2.0"/>
454 <eventconfig type="left
" maxvelocity="3.0"/>
455 <eventconfig type="right
" resettimeout="4"/>
456 <eventconfig type="none
" delta="5"/>
459 {UTILS::MOVING_SPEED::EventType::UP
, UTILS::MOVING_SPEED::EventCfg
{0.0, 0.0, 0, 0.0}},
460 {UTILS::MOVING_SPEED::EventType::DOWN
, UTILS::MOVING_SPEED::EventCfg
{2.0, 0.0, 0, 0.0}},
461 {UTILS::MOVING_SPEED::EventType::LEFT
, UTILS::MOVING_SPEED::EventCfg
{0.0, 3.0, 0, 0.0}},
462 {UTILS::MOVING_SPEED::EventType::RIGHT
,
463 UTILS::MOVING_SPEED::EventCfg
{0.0, 0.0, 4, 0.0}},
464 {UTILS::MOVING_SPEED::EventType::NONE
, UTILS::MOVING_SPEED::EventCfg
{0.0, 0.0, 0, 5.0}},
466 MovingSpeedTest
{R
"(<root><test/></root>)"s
, {}, true},
467 MovingSpeedTest
{R
"(<root/>)"s
, {}, false},
477 class TestGetPosition
: public testing::WithParamInterface
<PositionTest
>, public testing::Test
481 const auto PositionTests
= std::array
{
482 PositionTest
{R
"(<root><test>0.1</test></root>)"s
, 0.1f
},
483 PositionTest
{R
"(<root><test>0.2r</test></root>)"s
, -0.1f
},
484 PositionTest
{R
"(<root><test>0.2%</test></root>)"s
, 0.2f
* 0.1f
/ 100.f
},
485 PositionTest
{R
"(<root><test>something</test></root>)"s
, 0.f
},
486 PositionTest
{R
"(<root><test/></root>)"s
, 0.f
, false},
487 PositionTest
{R
"(<root/>)"s
, 0.f
, false},
494 std::vector
<std::pair
<int, float>> values
;
498 class TestGetScroller
: public testing::WithParamInterface
<ScrollerTest
>, public testing::Test
502 const auto ScrollerTests
= std::array
{
503 ScrollerTest
{R
"(<root><test>400</test></root>)"s
, 400, {{100, 24.75f
}, {200, 62.186874f
}}},
504 ScrollerTest
{R
"(<root><test tween="linear
">400</test></root>)"s
,
506 {{100, 24.75f
}, {200, 62.186874f
}}},
507 ScrollerTest
{R
"(<root><test tween="quadratic
">400</test></root>)"s
,
509 {{100, 43.374378f
}, {200, 85.701675f
}}},
510 ScrollerTest
{R
"(<root><test tween="cubic
">400</test></root>)"s
,
512 {{100, 57.389225f
}, {200, 94.593353f
}}},
513 ScrollerTest
{R
"(<root><test tween="sine
">400</test></root>)"s
,
515 {{100, 37.905243f
}, {200, 81.640106f
}}},
517 R
"(<root><test tween="back
">400</test></root>)"s
, 400, {{100, 81.236595f
}, {200, 101.63f
}}},
518 ScrollerTest
{R
"(<root><test tween="circle
">400</test></root>)"s
,
520 {{100, 65.85923f
}, {200, 95.376564f
}}},
521 ScrollerTest
{R
"(<root><test tween="bounce
">400</test></root>)"s
,
523 {{100, 46.325039f
}, {200, 87.514725f
}}},
524 ScrollerTest
{R
"(<root><test tween="elastic
">400</test></root>)"s
,
526 {{100, 91.834221f
}, {200, 100.14141f
}}},
527 ScrollerTest
{R
"(<root><test tween="linear
" easing="in
">400</test></root>)"s
,
529 {{100, 24.75f
}, {200, 62.186874f
}}},
530 ScrollerTest
{R
"(<root><test tween="linear
" easing="inout
">400</test></root>)"s
,
532 {{100, 24.75f
}, {200, 62.186874f
}}},
533 ScrollerTest
{R
"(<root><test tween="quadratic
" easing="in
">400</test></root>)"s
,
535 {{100, 6.1256237f
}, {200, 29.360115f
}}},
536 ScrollerTest
{R
"(<root><test tween="quadratic
" easing="inout
">400</test></root>)"s
,
538 {{100, 24.502501f
}, {200, 61.87281f
}}},
539 ScrollerTest
{R
"(<root><test tween="cubic
" easing="in
">400</test></root>)"s
,
541 {{100, 1.5160923f
}, {200, 13.642845f
}}},
542 ScrollerTest
{R
"(<root><test tween="cubic
" easing="inout
">400</test></root>)"s
,
544 {{100, 6.0643692f
}, {200, 88.081032f
}}},
545 ScrollerTest
{R
"(<root><test tween="sine
" easing="in
">400</test></root>)"s
,
547 {{100, 7.4624777f
}, {200, 34.309639f
}}},
548 ScrollerTest
{R
"(<root><test tween="sine
" easing="inout
">400</test></root>)"s
,
550 {{100, 14.368075f
}, {200, 74.68074f
}}},
551 ScrollerTest
{R
"(<root><test tween="back
" easing="in
">400</test></root>)"s
,
553 {{100, -6.3273964f
}, {200, -15.736771f
}}},
554 ScrollerTest
{R
"(<root><test tween="back
" easing="inout
">400</test></root>)"s
,
556 {{100, -9.9900274f
}, {200, 121.89823f
}}},
557 ScrollerTest
{R
"(<root><test tween="circle
" easing="in
">400</test></root>)"s
,
559 {{100, 3.1112075f
}, {200, 15.952465f
}}},
560 ScrollerTest
{R
"(<root><test tween="circle
" easing="inout
">400</test></root>)"s
,
562 {{100, 6.5553517f
}, {200, 87.345459f
}}},
563 ScrollerTest
{R
"(<root><test tween="bounce
" easing="in
">400</test></root>)"s
,
565 {{100, 2.9874623f
}, {200, 25.886932f
}}},
566 ScrollerTest
{R
"(<root><test tween="bounce
" easing="inout
">400</test></root>)"s
,
568 {{100, 11.881172f
}, {200, 79.502777f
}}},
569 ScrollerTest
{R
"(<root><test tween="elastic
" easing="in
">400</test></root>)"s
,
571 {{100, -0.5421927f
}, {200, -1.9441023f
}}},
572 ScrollerTest
{R
"(<root><test tween="elastic
" easing="inout
">400</test></root>)"s
,
574 {{100, 1.085682f
}, {200, 97.521629f
}}},
575 ScrollerTest
{R
"(<root><test/></root>)"s
, 200, {}, false},
576 ScrollerTest
{R
"(<root/>)"s
, 200, {}, false},
586 class TestGetString
: public testing::WithParamInterface
<StringTest
>, public testing::Test
590 const auto StringTests
= std::array
{
591 StringTest
{R
"(<root><test>foo</test></root>)"s
, "foo"s
},
592 StringTest
{R
"(<root><test>1</test></root>)"s
, "Pictures"s
},
593 StringTest
{R
"(<root><test>-1</test></root>)"s
, "-1"s
},
594 StringTest
{R
"(<root><test/></root>)"s
, ""s
, true},
595 StringTest
{R
"(<root/>)"s
, ""s
, false},
605 class TestGetTexture
: public testing::WithParamInterface
<TextureTest
>, public testing::Test
609 const auto TextureTests
= std::array
{
610 TextureTest
{R
"(<root><test>foo.png</test></root>)"s
,
611 {false, CRect
{0.0, 0.0, 0.0, 0.0}, true, 0, ""s
,
612 KODI::GUILIB::GUIINFO::CGUIInfoColor
{0, 0}, "foo.png"s
}},
613 TextureTest
{R
"(<root><test flipx="true">foo.png</test></root>)"s
,
614 {false, CRect
{0.0, 0.0, 0.0, 0.0}, true, 1, ""s
,
615 KODI::GUILIB::GUIINFO::CGUIInfoColor
{0, 0}, "foo.png"s
}},
616 TextureTest
{R
"(<root><test flipy="true">foo.png</test></root>)"s
,
617 {false, CRect
{0.0, 0.0, 0.0, 0.0}, true, 3, ""s
,
618 KODI::GUILIB::GUIINFO::CGUIInfoColor
{0, 0}, "foo.png"s
}},
619 TextureTest
{R
"(<root><test flipx="true" flipy="true">foo.png</test></root>)"s
,
620 {false, CRect
{0.0, 0.0, 0.0, 0.0}, true, 2, ""s
,
621 KODI::GUILIB::GUIINFO::CGUIInfoColor
{0, 0}, "foo.png"s
}},
622 TextureTest
{R
"(<root><test border="1,2,3,4">foo.png</test></root>)"s
,
623 {false, CRect
{1.0, 2.0, 3.0, 4.0}, true, 0, ""s
,
624 KODI::GUILIB::GUIINFO::CGUIInfoColor
{0, 0}, "foo.png"s
}},
625 TextureTest
{R
"(<root><test infill="false" border="1,2,3,4">foo.png</test></root>)"s
,
626 {false, CRect
{1.0, 2.0, 3.0, 4.0}, false, 0, ""s
,
627 KODI::GUILIB::GUIINFO::CGUIInfoColor
{0, 0}, "foo.png"s
}},
628 TextureTest
{R
"(<root><test diffuse="bar
.png
">foo.png</test></root>)"s
,
629 {false, CRect
{0.0, 0.0, 0.0, 0.0}, true, 0, "bar.png"s
,
630 KODI::GUILIB::GUIINFO::CGUIInfoColor
{0, 0}, "foo.png"s
}},
631 TextureTest
{R
"(<root><test colordiffuse="1">foo.png</test></root>)"s
,
632 {false, CRect
{0.0, 0.0, 0.0, 0.0}, true, 0, ""s
,
633 KODI::GUILIB::GUIINFO::CGUIInfoColor
{1, 0}, "foo.png"s
}},
634 TextureTest
{R
"(<root><test colordiffuse="white
">foo.png</test></root>)"s
,
635 {false, CRect
{0.0, 0.0, 0.0, 0.0}, true, 0, ""s
,
636 KODI::GUILIB::GUIINFO::CGUIInfoColor
{0xFFFFFFFF, 0}, "foo.png"s
}},
637 TextureTest
{R
"(<root><test background="true">foo.png</test></root>)"s
,
638 {true, CRect
{0.0, 0.0, 0.0, 0.0}, true, 0, ""s
,
639 KODI::GUILIB::GUIINFO::CGUIInfoColor
{0, 0}, "foo.png"s
}},
640 TextureTest
{R
"(<root><test/></root>)"s
,
641 {false, CRect
{0.0, 0.0, 0.0, 0.0}, true, 0, ""s
,
642 KODI::GUILIB::GUIINFO::CGUIInfoColor
{0, 0}, ""s
},
644 TextureTest
{R
"(<root/>)"s
,
645 {false, CRect
{0.0, 0.0, 0.0, 0.0}, true, 0, ""s
,
646 KODI::GUILIB::GUIINFO::CGUIInfoColor
{0, 0}, ""s
},
656 class TestGetType
: public testing::WithParamInterface
<TypeTest
>, public testing::Test
660 const auto TypeTests
= std::array
{
661 TypeTest
{R
"(<root type="foo
"/></root>)"s
, "foo"s
},
662 TypeTest
{R
"(<root><type>foo</type></root>)"s
, "foo"s
},
663 TypeTest
{R
"(<root/>)"s
, ""s
},
668 TEST_P(TestGetActions
, GetActions
)
671 doc
.Parse(GetParam().def
);
673 EXPECT_EQ(CGFTestable::GetActions(doc
.RootElement(), "test", action
), GetParam().result
);
674 EXPECT_EQ(action
.GetActionCount(), GetParam().actions
.size());
676 for (const auto& act
: GetParam().actions
)
678 EXPECT_EQ(action
, ref
);
681 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
, TestGetActions
, testing::ValuesIn(ActionsTests
));
683 TEST_P(TestGetAlignment
, GetAlignment
)
686 doc
.Parse(GetParam().def
);
688 EXPECT_EQ(CGFTestable::GetAlignment(doc
.RootElement(), "test", align
), GetParam().result
);
689 EXPECT_EQ(align
, GetParam().align
);
692 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
,
694 testing::ValuesIn(AlignmentTests
));
696 TEST_P(TestGetAlignmentY
, GetAlignmentY
)
699 doc
.Parse(GetParam().def
);
700 uint32_t align
= std::numeric_limits
<uint32_t>::max();
701 EXPECT_EQ(CGFTestable::GetAlignmentY(doc
.RootElement(), "test", align
), GetParam().result
);
702 EXPECT_EQ(align
, GetParam().align
);
705 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
,
707 testing::ValuesIn(AlignmentYTests
));
709 TEST_P(TestAspectRatio
, GetAspectRatio
)
712 doc
.Parse(GetParam().def
);
714 EXPECT_EQ(CGFTestable::GetAspectRatio(doc
.RootElement(), "test", ratio
), GetParam().result
);
715 EXPECT_EQ(ratio
.ratio
, GetParam().ratio
.ratio
);
716 EXPECT_EQ(ratio
.align
, GetParam().ratio
.align
);
717 EXPECT_EQ(ratio
.scaleDiffuse
, GetParam().ratio
.scaleDiffuse
);
720 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
,
722 testing::ValuesIn(AspectRatioTests
));
724 TEST_P(TestGetColor
, GetColor
)
726 CGUITestComponent comp
;
728 doc
.Parse(GetParam().def
);
729 UTILS::COLOR::Color value
= std::numeric_limits
<uint32_t>::max();
730 EXPECT_EQ(CGFTestable::GetColor(doc
.RootElement(), "test", value
), GetParam().result
);
731 EXPECT_EQ(value
, GetParam().value
);
734 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
, TestGetColor
, testing::ValuesIn(ColorTests
));
736 TEST_P(TestGetDimension
, GetDimension
)
739 doc
.Parse(GetParam().def
);
740 float min
= 0.f
, value
= 0.f
;
741 EXPECT_EQ(CGFTestable::GetDimension(doc
.RootElement(), "test", 0.1f
, value
, min
),
743 EXPECT_EQ(min
, GetParam().min
);
744 EXPECT_EQ(value
, GetParam().value
);
747 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
,
749 testing::ValuesIn(DimensionTests
));
751 TEST_P(TestGetDimensions
, GetDimensions
)
754 doc
.Parse(GetParam().def
);
755 float left
= 0.f
, width
= 0.f
, min_width
= 0.f
;
756 EXPECT_EQ(CGFTestable::GetDimensions(doc
.RootElement(), "left", "right", "center_left",
757 "center_right", "width", 0.1f
, left
, width
, min_width
),
759 EXPECT_EQ(left
, GetParam().left
);
760 EXPECT_EQ(width
, GetParam().width
);
761 EXPECT_EQ(min_width
, GetParam().min_width
);
764 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
,
766 testing::ValuesIn(DimensionsTests
));
768 TEST_P(TestGetFloatRange
, GetFloatRange
)
771 doc
.Parse(GetParam().def
);
772 float min
= 0.f
, max
= 0.f
, interval
= 0.f
;
773 EXPECT_EQ(CGFTestable::GetFloatRange(doc
.RootElement(), "test", min
, max
, interval
),
775 EXPECT_EQ(min
, GetParam().min
);
776 EXPECT_EQ(max
, GetParam().max
);
777 EXPECT_EQ(interval
, GetParam().interval
);
780 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
,
782 testing::ValuesIn(FloatRangeTests
));
784 TEST_P(TestGetHitRect
, GetHitRect
)
787 doc
.Parse(GetParam().def
);
788 CRect rect
, parentRect
{1.0, 2.0, 3.0, 4.0};
789 EXPECT_EQ(CGFTestable::GetHitRect(doc
.RootElement(), rect
, parentRect
), GetParam().result
);
790 EXPECT_EQ(rect
.x1
, GetParam().rect
.x1
);
791 EXPECT_EQ(rect
.x2
, GetParam().rect
.x2
);
792 EXPECT_EQ(rect
.y1
, GetParam().rect
.y1
);
793 EXPECT_EQ(rect
.y2
, GetParam().rect
.y2
);
796 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
, TestGetHitRect
, testing::ValuesIn(HitRectTests
));
798 TEST_P(TestGetInfoLabel
, GetInfoLabel
)
800 CGUITestComponent comp
;
801 ASSERT_TRUE(g_localizeStrings
.Load(g_langInfo
.GetLanguagePath(), "resource.language.en_gb"));
803 doc
.Parse(GetParam().def
);
804 KODI::GUILIB::GUIINFO::CGUIInfoLabel infoLabel
;
805 EXPECT_EQ(CGFTestable::GetInfoLabelFromElement(doc
.RootElement(), infoLabel
, 100),
807 EXPECT_EQ(infoLabel
.GetLabel(INFO::DEFAULT_CONTEXT
), GetParam().label
);
808 EXPECT_EQ(infoLabel
.GetFallback(), GetParam().fallback
);
811 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
,
813 testing::ValuesIn(InfoLabelTests
));
815 TEST_P(TestGetInfoLabels
, GetInfoLabels
)
817 CGUITestComponent comp
;
818 ASSERT_TRUE(g_localizeStrings
.Load(g_langInfo
.GetLanguagePath(), "resource.language.en_gb"));
820 doc
.Parse(GetParam().def
);
821 std::vector
<KODI::GUILIB::GUIINFO::CGUIInfoLabel
> infoLabel
;
822 CGFTestable::GetInfoLabels(doc
.RootElement(), "test", infoLabel
, 100);
823 EXPECT_EQ(infoLabel
.size(), GetParam().labels
.size());
824 for (size_t i
= 0; i
< infoLabel
.size(); ++i
)
826 EXPECT_EQ(infoLabel
[i
].GetLabel(INFO::DEFAULT_CONTEXT
), GetParam().labels
[i
][0]);
827 EXPECT_EQ(infoLabel
[i
].GetFallback(), GetParam().labels
[i
][1]);
831 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
,
833 testing::ValuesIn(InfoLabelsTests
));
835 TEST_P(TestGetIntRange
, GetIntRange
)
838 doc
.Parse(GetParam().def
);
839 int min
= 0, max
= 0, interval
= 0;
840 EXPECT_EQ(CGFTestable::GetIntRange(doc
.RootElement(), "test", min
, max
, interval
),
842 EXPECT_EQ(min
, GetParam().min
);
843 EXPECT_EQ(max
, GetParam().max
);
844 EXPECT_EQ(interval
, GetParam().interval
);
847 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
, TestGetIntRange
, testing::ValuesIn(IntRangeTests
));
849 TEST_P(TestGetMovingSpeed
, GetMovingSpeed
)
852 doc
.Parse(GetParam().def
);
853 UTILS::MOVING_SPEED::MapEventConfig config
;
854 EXPECT_EQ(CGFTestable::GetMovingSpeedConfig(doc
.RootElement(), "test", config
),
856 EXPECT_EQ(config
, GetParam().config
);
859 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
,
861 testing::ValuesIn(MovingSpeedTests
));
863 TEST_P(TestGetPosition
, GetPosition
)
866 doc
.Parse(GetParam().def
);
868 EXPECT_EQ(CGFTestable::GetPosition(doc
.RootElement(), "test", 0.1f
, pos
), GetParam().result
);
869 EXPECT_EQ(pos
, GetParam().pos
);
872 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
, TestGetPosition
, testing::ValuesIn(PositionTests
));
874 TEST_P(TestGetScroller
, GetScroller
)
877 doc
.Parse(GetParam().def
);
879 EXPECT_EQ(CGFTestable::GetScroller(doc
.RootElement(), "test", value
), GetParam().result
);
880 EXPECT_EQ(value
.GetDuration(), GetParam().duration
);
881 if (!GetParam().values
.empty())
883 value
.ScrollTo(GetParam().values
[0].first
);
884 EXPECT_TRUE(value
.Update(1));
886 for (const auto& def
: GetParam().values
)
888 EXPECT_TRUE(value
.Update(def
.first
));
889 EXPECT_FLOAT_EQ(value
.GetValue(), def
.second
);
890 value
.ScrollTo(def
.first
);
891 EXPECT_TRUE(value
.Update(1));
895 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
, TestGetScroller
, testing::ValuesIn(ScrollerTests
));
897 TEST_P(TestGetString
, GetString
)
899 ASSERT_TRUE(g_localizeStrings
.Load(g_langInfo
.GetLanguagePath(), "resource.language.en_gb"));
901 doc
.Parse(GetParam().def
);
903 EXPECT_EQ(CGFTestable::GetString(doc
.RootElement(), "test", value
), GetParam().result
);
904 EXPECT_EQ(value
, GetParam().value
);
907 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
, TestGetString
, testing::ValuesIn(StringTests
));
909 TEST_P(TestGetTexture
, GetTexture
)
911 CGUITestComponent comp
;
913 doc
.Parse(GetParam().def
);
915 EXPECT_EQ(CGFTestable::GetTexture(doc
.RootElement(), "test", info
), GetParam().result
);
916 EXPECT_EQ(info
.border
, GetParam().info
.border
);
917 EXPECT_EQ(info
.diffuse
, GetParam().info
.diffuse
);
918 EXPECT_EQ(info
.diffuseColor
, GetParam().info
.diffuseColor
);
919 EXPECT_EQ(info
.filename
, GetParam().info
.filename
);
920 EXPECT_EQ(info
.m_infill
, GetParam().info
.m_infill
);
921 EXPECT_EQ(info
.orientation
, GetParam().info
.orientation
);
922 EXPECT_EQ(info
.useLarge
, GetParam().info
.useLarge
);
925 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
, TestGetTexture
, testing::ValuesIn(TextureTests
));
927 TEST_P(TestGetType
, GetType
)
930 doc
.Parse(GetParam().def
);
932 EXPECT_EQ(CGFTestable::GetType(doc
.RootElement()), GetParam().type
);
935 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory
, TestGetType
, testing::ValuesIn(TypeTests
));