summaryrefslogtreecommitdiffstats
path: root/client/SDL/dialogs/test/TestSDLDialogs.cpp
blob: 558fb4c6e955a87292c920db4488948dbff4057f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "../sdl_selectlist.hpp"
#include "../sdl_input_widgets.hpp"

#include <freerdp/api.h>
#include <winpr/wlog.h>

BOOL sdl_log_error_ex(Uint32 res, wLog* log, const char* what, const char* file, size_t line,
                      const char* fkt)
{
	return FALSE;
}

static bool test_input_dialog()
{
	const auto title = "sometitle";
	std::vector<std::string> labels;
	std::vector<std::string> initial;
	std::vector<Uint32> flags;
	for (size_t x = 0; x < 12; x++)
	{
		labels.push_back("label" + std::to_string(x));
		initial.push_back(std::to_string(x));

		Uint32 flag = 0;
		if ((x % 2) != 0)
			flag |= SdlInputWidget::SDL_INPUT_MASK;
		if ((x % 3) == 0)
			flag |= SdlInputWidget::SDL_INPUT_READONLY;

		flags.push_back(flag);
	}
	SdlInputWidgetList list{ title, labels, initial, flags };
	std::vector<std::string> result;
	auto rc = list.run(result);
	if (rc < 0)
	{
		return false;
	}
	if (result.size() != labels.size())
	{
		return false;
	}
	return true;
}

static bool test_select_dialog()
{
	const auto title = "sometitle";
	std::vector<std::string> labels;
	for (size_t x = 0; x < 12; x++)
	{
		labels.push_back("label" + std::to_string(x));
	}
	SdlSelectList list{ title, labels };
	auto rc = list.run();
	if (rc < 0)
	{
		return false;
	}
	if (static_cast<size_t>(rc) >= labels.size())
		return false;

	return true;
}

extern "C"
{
	FREERDP_API int TestSDLDialogs(int argc, char* argv[]);
}

int TestSDLDialogs(int argc, char* argv[])
{
	int rc = 0;

	(void)argc;
	(void)argv;

#if 0
	SDL_Init(SDL_INIT_VIDEO);
	try
	{
#if 1
		if (!test_input_dialog())
			throw -1;
#endif
#if 1
		if (!test_select_dialog())
			throw -2;
#endif
	}
	catch (int e)
	{
		rc = e;
	}
	SDL_Quit();

#endif
	return rc;
}