forked from lc-soft/LCUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_settings.c
124 lines (103 loc) · 3.34 KB
/
test_settings.c
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <LCUI_Build.h>
#include <LCUI/LCUI.h>
#include <LCUI/settings.h>
#include <LCUI/main.h>
#include <LCUI/timer.h>
#include "test.h"
#include "libtest.h"
static int settings_change_count = 0;
static void on_settings_change(LCUI_SysEvent object, void *data)
{
++settings_change_count;
}
static void check_settings_frame_rate_cap(void *arg)
{
char str[256];
int fps_limit = *((int *)arg);
int fps = LCUI_GetFrameCount();
sprintf(str, "should work when frame cap is %d (actual %d)", fps_limit,
fps);
it_b(str, fps <= fps_limit && fps > fps_limit / 2, TRUE);
LCUI_Quit();
}
static void test_default_settings(void)
{
LCUI_SettingsRec settings;
LCUI_Init();
LCUI_ResetSettings();
Settings_Init(&settings);
it_i("check default frame rate cap", settings.frame_rate_cap, 120);
it_i("check default parallel rendering threads",
settings.parallel_rendering_threads, 4);
it_b("check default record profile", settings.record_profile, FALSE);
it_b("check default fps meter", settings.fps_meter, FALSE);
it_b("check default paint flashing", settings.paint_flashing, FALSE);
LCUI_Destroy();
}
static void test_apply_settings(void)
{
LCUI_SettingsRec settings;
LCUI_Init();
int handler = LCUI_BindEvent(LCUI_SETTINGS_CHANGE, on_settings_change, NULL, NULL);
settings.frame_rate_cap = 60;
settings.parallel_rendering_threads = 2;
settings.record_profile = TRUE;
settings.fps_meter = TRUE;
settings.paint_flashing = TRUE;
LCUI_ApplySettings(&settings);
Settings_Init(&settings);
it_i("check frame rate cap", settings.frame_rate_cap, 60);
it_i("check parallel rendering threads",
settings.parallel_rendering_threads, 2);
it_b("check record profile", settings.record_profile, TRUE);
it_b("check fps meter", settings.fps_meter, TRUE);
it_b("check paint flashing", settings.paint_flashing, TRUE);
it_i("check settings change count", settings_change_count, 1);
settings.frame_rate_cap = -1;
settings.parallel_rendering_threads = -1;
LCUI_ApplySettings(&settings);
Settings_Init(&settings);
it_i("check frame rate cap minimum", settings.frame_rate_cap, 1);
it_i("check parallel rendering threads minimum",
settings.parallel_rendering_threads, 1);
it_i("check settings change count", settings_change_count, 2);
LCUI_ResetSettings();
it_i("check settings change count", settings_change_count, 3);
LCUI_UnbindEvent(handler);
LCUI_Destroy();
}
void test_settings_frame_rate_cap(void)
{
LCUI_SettingsRec settings;
LCUI_Init();
Settings_Init(&settings);
settings.frame_rate_cap = 30;
LCUI_ApplySettings(&settings);
LCUI_SetTimeout(1000, check_settings_frame_rate_cap,
&settings.frame_rate_cap);
LCUI_Main();
LCUI_Init();
settings.frame_rate_cap = 5;
LCUI_ApplySettings(&settings);
LCUI_SetTimeout(1000, check_settings_frame_rate_cap,
&settings.frame_rate_cap);
LCUI_Main();
LCUI_Init();
settings.frame_rate_cap = 90;
LCUI_ApplySettings(&settings);
LCUI_SetTimeout(1000, check_settings_frame_rate_cap,
&settings.frame_rate_cap);
LCUI_Main();
LCUI_Init();
settings.frame_rate_cap = 25;
LCUI_ApplySettings(&settings);
LCUI_SetTimeout(1000, check_settings_frame_rate_cap,
&settings.frame_rate_cap);
LCUI_Main();
}
void test_settings(void)
{
describe("test default settings", test_default_settings);
describe("test apply settings", test_apply_settings);
describe("test settings.frame_rate_cap", test_settings_frame_rate_cap);
}