FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
SDL3/dialogs/test/TestSDLDialogs.cpp
1#include "../sdl_selectlist.hpp"
2#include "../sdl_input_widgets.hpp"
3
4#include <freerdp/api.h>
5#include <winpr/wlog.h>
6
7BOOL sdl_log_error_ex(Uint32 res, wLog* log, const char* what, const char* file, size_t line,
8 const char* fkt)
9{
10 return FALSE;
11}
12
13static bool test_input_dialog()
14{
15 const auto title = "sometitle";
16 std::vector<std::string> labels;
17 std::vector<std::string> initial;
18 std::vector<Uint32> flags;
19 for (size_t x = 0; x < 12; x++)
20 {
21 labels.push_back("label" + std::to_string(x));
22 initial.push_back(std::to_string(x));
23
24 Uint32 flag = 0;
25 if ((x % 2) != 0)
26 flag |= SdlInputWidget::SDL_INPUT_MASK;
27 if ((x % 3) == 0)
28 flag |= SdlInputWidget::SDL_INPUT_READONLY;
29
30 flags.push_back(flag);
31 }
32 SdlInputWidgetList list{ title, labels, initial, flags };
33 std::vector<std::string> result;
34 auto rc = list.run(result);
35 if (rc < 0)
36 {
37 return false;
38 }
39 if (result.size() != labels.size())
40 {
41 return false;
42 }
43 return true;
44}
45
46static bool test_select_dialog()
47{
48 const auto title = "sometitle";
49 std::vector<std::string> labels;
50 for (size_t x = 0; x < 12; x++)
51 {
52 labels.push_back("label" + std::to_string(x));
53 }
54 SdlSelectList list{ title, labels };
55 auto rc = list.run();
56 if (rc < 0)
57 {
58 return false;
59 }
60 if (static_cast<size_t>(rc) >= labels.size())
61 return false;
62
63 return true;
64}
65
66extern "C"
67{
68 FREERDP_API int TestSDLDialogs(int argc, char* argv[]);
69}
70
71int TestSDLDialogs(int argc, char* argv[])
72{
73 int rc = 0;
74
75 (void)argc;
76 (void)argv;
77
78#if 0
79 SDL_Init(SDL_INIT_VIDEO);
80 try
81 {
82#if 1
83 if (!test_input_dialog())
84 throw -1;
85#endif
86#if 1
87 if (!test_select_dialog())
88 throw -2;
89#endif
90 }
91 catch (int e)
92 {
93 rc = e;
94 }
95 SDL_Quit();
96
97#endif
98 return rc;
99}