[WASAPI] fix stream types and frequencies enumeration
[xbmc.git] / xbmc / guilib / test / TestGUIControlFactory.cpp
blob70f51cd6760af0b4e1035be49aa11aa883c0674b
1 /*
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.
7 */
9 #include "GUIInfoManager.h"
10 #include "LangInfo.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"
22 #include <limits>
23 #include <string>
25 #include <gtest/gtest.h>
27 using namespace KODI;
29 class CGFTestable : public CGUIControlFactory
31 public:
32 static std::string GetType(const TiXmlElement* pControlNode)
34 return CGUIControlFactory::GetType(pControlNode);
37 static bool GetIntRange(const TiXmlNode* pRootNode,
38 const char* strTag,
39 int& iMinValue,
40 int& iMaxValue,
41 int& iIntervalValue)
43 return CGUIControlFactory::GetIntRange(pRootNode, strTag, iMinValue, iMaxValue, iIntervalValue);
46 static bool GetFloatRange(const TiXmlNode* pRootNode,
47 const char* strTag,
48 float& fMinValue,
49 float& fMaxValue,
50 float& fIntervalValue)
52 return CGUIControlFactory::GetFloatRange(pRootNode, strTag, fMinValue, fMaxValue,
53 fIntervalValue);
56 static bool GetPosition(const TiXmlNode* node,
57 const char* tag,
58 const float parentSize,
59 float& value)
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,
71 const char* leftTag,
72 const char* rightTag,
73 const char* centerLeftTag,
74 const char* centerRightTag,
75 const char* widthTag,
76 const float parentSize,
77 float& left,
78 float& width,
79 float& min_width)
81 return CGUIControlFactory::GetDimensions(node, leftTag, rightTag, centerLeftTag, centerRightTag,
82 widthTag, parentSize, left, width, min_width);
85 static bool GetMovingSpeedConfig(const TiXmlNode* pRootNode,
86 const char* strTag,
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);
105 namespace
108 using namespace std::string_literals;
110 class CGUITestColorManager : public CGUIColorManager
112 public:
113 CGUITestColorManager()
115 CXBMCTinyXML xmlDoc;
116 xmlDoc.Parse(R"(<colors>
117 <color name="white">ffffffff</color>
118 <color name="black">00000000</color>
119 <color name="navy">ff000080</color>
120 </colors>)"s);
121 LoadXML(xmlDoc);
125 class CGUITestComponent : public CGUIComponent
127 public:
128 CGUITestComponent() : CGUIComponent(false)
130 m_guiColorManager = std::make_unique<CGUITestColorManager>();
131 m_guiInfoManager = std::make_unique<CGUIInfoManager>();
132 CServiceBroker::RegisterGUI(this);
136 struct ActionsTest
138 std::string def;
139 std::vector<CGUIAction::CExecutableAction> actions;
140 bool result = true;
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>
151 </root>)"s,
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},
158 struct AlignmentTest
160 std::string def;
161 uint32_t align;
162 bool result = true;
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
193 std::string def;
194 CAspectRatio ratio;
195 bool result = true;
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}},
215 AspectRatioTest{
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}},
220 AspectRatioTest{
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},
225 struct ColorTest
227 std::string def;
228 UTILS::COLOR::Color value;
229 bool result = true;
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
247 std::string def;
248 std::string condition;
249 std::string hidden;
250 bool result = true;
253 class TestConditionalVisibility : public testing::WithParamInterface<ConditionalVisibilityTest>,
254 public testing::Test
258 const auto ConditionalVisibilityTests = std::array{
259 ConditionalVisibilityTest{R"(<root>
260 <visible>foo</visible>
261 </root>)"s,
262 "foo"s, ""s},
263 ConditionalVisibilityTest{R"(<root>
264 <visible allowhiddenfocus="bar">foo</visible>
265 </root>)"s,
266 "foo"s, "bar"s},
267 ConditionalVisibilityTest{R"(<root>
268 <visible allowhiddenfocus="bar">foo</visible>
269 <visible allowhiddenfocus="foobar">bar</visible>
270 </root>)"s,
271 "[foo] + [bar]"s, "foobar"s},
272 ConditionalVisibilityTest{R"(<root/>)", ""s, ""s, false},
275 struct DimensionTest
277 std::string def;
278 float min, value;
279 bool result = true;
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,
294 3.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
302 std::string def;
303 float left, width, min_width;
304 bool result = true;
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},
317 DimensionsTest{
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},
322 template<class T>
323 struct RangeTest
325 std::string def;
326 T min, max, interval;
327 bool result = true;
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},
343 struct HitRectTest
345 std::string def;
346 CRect rect;
347 bool result = true;
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},
364 struct InfoLabelTest
366 std::string def;
367 std::string label;
368 std::string fallback;
369 bool result = true;
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
387 std::string def;
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>
403 </root>)"s,
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
423 std::string def;
424 UTILS::MOVING_SPEED::MapEventConfig config;
425 bool result = true;
428 class TestGetMovingSpeed : public testing::WithParamInterface<MovingSpeedTest>, public testing::Test
432 const auto MovingSpeedTests = std::array{
433 MovingSpeedTest{
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"/>
441 </test></root>)"s,
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}},
450 MovingSpeedTest{
451 R"(<root><test>
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"/>
457 </test></root>)"s,
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},
470 struct PositionTest
472 std::string def;
473 float pos;
474 bool result = true;
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},
490 struct ScrollerTest
492 std::string def;
493 int duration;
494 std::vector<std::pair<int, float>> values;
495 bool result = true;
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,
505 400,
506 {{100, 24.75f}, {200, 62.186874f}}},
507 ScrollerTest{R"(<root><test tween="quadratic">400</test></root>)"s,
508 400,
509 {{100, 43.374378f}, {200, 85.701675f}}},
510 ScrollerTest{R"(<root><test tween="cubic">400</test></root>)"s,
511 400,
512 {{100, 57.389225f}, {200, 94.593353f}}},
513 ScrollerTest{R"(<root><test tween="sine">400</test></root>)"s,
514 400,
515 {{100, 37.905243f}, {200, 81.640106f}}},
516 ScrollerTest{
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,
519 400,
520 {{100, 65.85923f}, {200, 95.376564f}}},
521 ScrollerTest{R"(<root><test tween="bounce">400</test></root>)"s,
522 400,
523 {{100, 46.325039f}, {200, 87.514725f}}},
524 ScrollerTest{R"(<root><test tween="elastic">400</test></root>)"s,
525 400,
526 {{100, 91.834221f}, {200, 100.14141f}}},
527 ScrollerTest{R"(<root><test tween="linear" easing="in">400</test></root>)"s,
528 400,
529 {{100, 24.75f}, {200, 62.186874f}}},
530 ScrollerTest{R"(<root><test tween="linear" easing="inout">400</test></root>)"s,
531 400,
532 {{100, 24.75f}, {200, 62.186874f}}},
533 ScrollerTest{R"(<root><test tween="quadratic" easing="in">400</test></root>)"s,
534 400,
535 {{100, 6.1256237f}, {200, 29.360115f}}},
536 ScrollerTest{R"(<root><test tween="quadratic" easing="inout">400</test></root>)"s,
537 400,
538 {{100, 24.502501f}, {200, 61.87281f}}},
539 ScrollerTest{R"(<root><test tween="cubic" easing="in">400</test></root>)"s,
540 400,
541 {{100, 1.5160923f}, {200, 13.642845f}}},
542 ScrollerTest{R"(<root><test tween="cubic" easing="inout">400</test></root>)"s,
543 400,
544 {{100, 6.0643692f}, {200, 88.081032f}}},
545 ScrollerTest{R"(<root><test tween="sine" easing="in">400</test></root>)"s,
546 400,
547 {{100, 7.4624777f}, {200, 34.309639f}}},
548 ScrollerTest{R"(<root><test tween="sine" easing="inout">400</test></root>)"s,
549 400,
550 {{100, 14.368075f}, {200, 74.68074f}}},
551 ScrollerTest{R"(<root><test tween="back" easing="in">400</test></root>)"s,
552 400,
553 {{100, -6.3273964f}, {200, -15.736771f}}},
554 ScrollerTest{R"(<root><test tween="back" easing="inout">400</test></root>)"s,
555 400,
556 {{100, -9.9900274f}, {200, 121.89823f}}},
557 ScrollerTest{R"(<root><test tween="circle" easing="in">400</test></root>)"s,
558 400,
559 {{100, 3.1112075f}, {200, 15.952465f}}},
560 ScrollerTest{R"(<root><test tween="circle" easing="inout">400</test></root>)"s,
561 400,
562 {{100, 6.5553517f}, {200, 87.345459f}}},
563 ScrollerTest{R"(<root><test tween="bounce" easing="in">400</test></root>)"s,
564 400,
565 {{100, 2.9874623f}, {200, 25.886932f}}},
566 ScrollerTest{R"(<root><test tween="bounce" easing="inout">400</test></root>)"s,
567 400,
568 {{100, 11.881172f}, {200, 79.502777f}}},
569 ScrollerTest{R"(<root><test tween="elastic" easing="in">400</test></root>)"s,
570 400,
571 {{100, -0.5421927f}, {200, -1.9441023f}}},
572 ScrollerTest{R"(<root><test tween="elastic" easing="inout">400</test></root>)"s,
573 400,
574 {{100, 1.085682f}, {200, 97.521629f}}},
575 ScrollerTest{R"(<root><test/></root>)"s, 200, {}, false},
576 ScrollerTest{R"(<root/>)"s, 200, {}, false},
579 struct StringTest
581 std::string def;
582 std::string value;
583 bool result = true;
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},
598 struct TextureTest
600 std::string def;
601 CTextureInfo info;
602 bool result = true;
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},
643 true},
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},
647 false},
650 struct TypeTest
652 std::string def;
653 std::string type;
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},
666 } // namespace
668 TEST_P(TestGetActions, GetActions)
670 CXBMCTinyXML doc;
671 doc.Parse(GetParam().def);
672 CGUIAction action;
673 EXPECT_EQ(CGFTestable::GetActions(doc.RootElement(), "test", action), GetParam().result);
674 EXPECT_EQ(action.GetActionCount(), GetParam().actions.size());
675 CGUIAction ref;
676 for (const auto& act : GetParam().actions)
677 ref.Append(act);
678 EXPECT_EQ(action, ref);
681 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory, TestGetActions, testing::ValuesIn(ActionsTests));
683 TEST_P(TestGetAlignment, GetAlignment)
685 CXBMCTinyXML doc;
686 doc.Parse(GetParam().def);
687 uint32_t align{};
688 EXPECT_EQ(CGFTestable::GetAlignment(doc.RootElement(), "test", align), GetParam().result);
689 EXPECT_EQ(align, GetParam().align);
692 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory,
693 TestGetAlignment,
694 testing::ValuesIn(AlignmentTests));
696 TEST_P(TestGetAlignmentY, GetAlignmentY)
698 CXBMCTinyXML doc;
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,
706 TestGetAlignmentY,
707 testing::ValuesIn(AlignmentYTests));
709 TEST_P(TestAspectRatio, GetAspectRatio)
711 CXBMCTinyXML doc;
712 doc.Parse(GetParam().def);
713 CAspectRatio ratio;
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,
721 TestAspectRatio,
722 testing::ValuesIn(AspectRatioTests));
724 TEST_P(TestGetColor, GetColor)
726 CGUITestComponent comp;
727 CXBMCTinyXML doc;
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)
738 CXBMCTinyXML doc;
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),
742 GetParam().result);
743 EXPECT_EQ(min, GetParam().min);
744 EXPECT_EQ(value, GetParam().value);
747 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory,
748 TestGetDimension,
749 testing::ValuesIn(DimensionTests));
751 TEST_P(TestGetDimensions, GetDimensions)
753 CXBMCTinyXML doc;
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),
758 GetParam().result);
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,
765 TestGetDimensions,
766 testing::ValuesIn(DimensionsTests));
768 TEST_P(TestGetFloatRange, GetFloatRange)
770 CXBMCTinyXML doc;
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),
774 GetParam().result);
775 EXPECT_EQ(min, GetParam().min);
776 EXPECT_EQ(max, GetParam().max);
777 EXPECT_EQ(interval, GetParam().interval);
780 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory,
781 TestGetFloatRange,
782 testing::ValuesIn(FloatRangeTests));
784 TEST_P(TestGetHitRect, GetHitRect)
786 CXBMCTinyXML doc;
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"));
802 CXBMCTinyXML doc;
803 doc.Parse(GetParam().def);
804 KODI::GUILIB::GUIINFO::CGUIInfoLabel infoLabel;
805 EXPECT_EQ(CGFTestable::GetInfoLabelFromElement(doc.RootElement(), infoLabel, 100),
806 GetParam().result);
807 EXPECT_EQ(infoLabel.GetLabel(INFO::DEFAULT_CONTEXT), GetParam().label);
808 EXPECT_EQ(infoLabel.GetFallback(), GetParam().fallback);
811 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory,
812 TestGetInfoLabel,
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"));
819 CXBMCTinyXML doc;
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,
832 TestGetInfoLabels,
833 testing::ValuesIn(InfoLabelsTests));
835 TEST_P(TestGetIntRange, GetIntRange)
837 CXBMCTinyXML doc;
838 doc.Parse(GetParam().def);
839 int min = 0, max = 0, interval = 0;
840 EXPECT_EQ(CGFTestable::GetIntRange(doc.RootElement(), "test", min, max, interval),
841 GetParam().result);
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)
851 CXBMCTinyXML doc;
852 doc.Parse(GetParam().def);
853 UTILS::MOVING_SPEED::MapEventConfig config;
854 EXPECT_EQ(CGFTestable::GetMovingSpeedConfig(doc.RootElement(), "test", config),
855 GetParam().result);
856 EXPECT_EQ(config, GetParam().config);
859 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory,
860 TestGetMovingSpeed,
861 testing::ValuesIn(MovingSpeedTests));
863 TEST_P(TestGetPosition, GetPosition)
865 CXBMCTinyXML doc;
866 doc.Parse(GetParam().def);
867 float pos = 0.f;
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)
876 CXBMCTinyXML doc;
877 doc.Parse(GetParam().def);
878 CScroller value;
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"));
900 CXBMCTinyXML doc;
901 doc.Parse(GetParam().def);
902 std::string value;
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;
912 CXBMCTinyXML doc;
913 doc.Parse(GetParam().def);
914 CTextureInfo info;
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)
929 CXBMCTinyXML doc;
930 doc.Parse(GetParam().def);
931 std::string type;
932 EXPECT_EQ(CGFTestable::GetType(doc.RootElement()), GetParam().type);
935 INSTANTIATE_TEST_SUITE_P(TestGUIControlFactory, TestGetType, testing::ValuesIn(TypeTests));