vx11 / randr / randr_test.v
146 lines · 134 sloc · 5.27 KB · 6de7c1113616d30335010eea79fd03d19722b474
Raw
1module randr
2
3import vx11
4
5#include "@VMODROOT/randr/tests/abi.h"
6
7fn C.vx11_rr_test_fill_mode(&XRRModeInfo)
8fn C.vx11_rr_test_fill_output(&XRROutputInfo)
9fn C.vx11_rr_test_fill_crtc_event(&XRRCrtcChangeNotifyEvent)
10fn C.vx11_rr_test_fill_screen_event(&XRRScreenChangeNotifyEvent)
11fn C.vx11_rr_test_fill_property(&XRRPropertyInfo, &vx11.CLong)
12
13fn test_c_long_and_short_field_widths() {
14 mut m := XRRModeInfo{ name: unsafe { nil } }
15 C.vx11_rr_test_fill_mode(&m)
16 id := m.id
17 clock := m.dotClock
18 flags := m.modeFlags
19 v_total := m.vTotal
20 assert id == RRMode(~vx11.CULong(0))
21 assert clock == ~vx11.CULong(0)
22 assert flags == ModeFlags(~vx11.CULong(0))
23 assert v_total == ~u32(0)
24 mut o := XRROutputInfo{ name: unsafe { nil }, crtcs: unsafe { nil }, clones: unsafe { nil }, modes: unsafe { nil } }
25 C.vx11_rr_test_fill_output(&o)
26 time := o.timestamp
27 mm := o.mm_height
28 status := o.connection
29 order := o.subpixel_order
30 preferred := o.npreferred
31 assert time == vx11.Time(~vx11.CULong(0))
32 assert mm == ~vx11.CULong(0)
33 assert status == ConnectionStatus(0xffff)
34 assert order == SubpixelOrder(0xffff)
35 assert preferred == i32(-2147483648)
36 mut values := [vx11.CLong(0)]
37 mut p := XRRPropertyInfo{ values: unsafe { nil } }
38 C.vx11_rr_test_fill_property(&p, values.data)
39 first := unsafe { p.values[0] }
40 assert first == -(vx11.CLong(1) << (sizeof(vx11.CLong) * 8 - 1))
41 assert p.immutable == 1
42}
43
44fn test_event_layouts_fit_xevent() {
45 assert sizeof(XRRScreenChangeNotifyEvent) <= sizeof(vx11.XEvent)
46 assert sizeof(XRRNotifyEvent) <= sizeof(vx11.XEvent)
47 assert sizeof(XRROutputChangeNotifyEvent) <= sizeof(vx11.XEvent)
48 assert sizeof(XRRCrtcChangeNotifyEvent) <= sizeof(vx11.XEvent)
49 assert sizeof(XRROutputPropertyNotifyEvent) <= sizeof(vx11.XEvent)
50 assert sizeof(XRRProviderChangeNotifyEvent) <= sizeof(vx11.XEvent)
51 assert sizeof(XRRProviderPropertyNotifyEvent) <= sizeof(vx11.XEvent)
52 assert sizeof(XRRResourceChangeNotifyEvent) <= sizeof(vx11.XEvent)
53}
54
55fn test_event_decoding_checks_type_and_subtype() {
56 e := &Extension{ connection: unsafe { nil }, event_base: 89, error_base: 147, major: 1, minor: 6 }
57 mut raw := vx11.XEvent{}
58 C.vx11_rr_test_fill_crtc_event(unsafe { &XRRCrtcChangeNotifyEvent(&raw) })
59 unsafe {
60 raw.@type = 89 + notify
61 (&XRRNotifyEvent(&raw)).subtype = notify_crtc_change
62 }
63 event := vx11.Event{ kind: 89 + notify, raw: raw }
64 crtc := e.crtc_change(event) or { panic('missing CRTC change') }
65 rotation := crtc.rotation
66 height := crtc.height
67 assert crtc.crtc == RRCrtc(~vx11.CULong(0))
68 assert rotation == Rotation(0xffff)
69 assert crtc.x == i32(-2147483648)
70 assert height == ~u32(0)
71 assert e.output_change(event) == none
72 assert e.screen_change(event) == none
73 assert e.crtc_change(vx11.Event{ kind: 90 + notify, raw: raw }) == none
74 mut screen_raw := vx11.XEvent{}
75 C.vx11_rr_test_fill_screen_event(unsafe { &XRRScreenChangeNotifyEvent(&screen_raw) })
76 screen := e.screen_change(vx11.Event{ kind: 89, raw: screen_raw }) or { panic('missing screen change') }
77 size_index := screen.size_index
78 assert screen.config_timestamp == vx11.Time(~vx11.CULong(0))
79 assert size_index == SizeID(0xffff)
80 assert screen.mheight == i32(-2147483648)
81}
82
83fn test_rotation_validation() {
84 assert valid_rotation(rotate_0)
85 assert valid_rotation(rotate_270 | reflect_x | reflect_y)
86 assert !valid_rotation(0)
87 assert !valid_rotation(rotate_0 | rotate_90)
88 assert !valid_rotation(reflect_x)
89 assert !valid_rotation(Rotation(64) | rotate_0)
90 assert swaps_axes(rotate_90 | reflect_y)
91 assert !swaps_axes(rotate_180)
92}
93
94fn test_mode_refresh_rate() {
95 vga := ModeInfo{ dot_clock: 25175000, h_total: 800, v_total: 525 }
96 assert vga.refresh_rate() > 59.93 && vga.refresh_rate() < 59.95
97 interlaced := ModeInfo{ dot_clock: 74250000, h_total: 2200, v_total: 1125, flags: interlace }
98 assert interlaced.refresh_rate() == 60.0
99 doubled := ModeInfo{ dot_clock: 25175000, h_total: 800, v_total: 525, flags: double_scan }
100 assert doubled.refresh_rate() < 30.0
101 assert ModeInfo{ dot_clock: 1000 }.refresh_rate() == 0
102}
103
104fn test_identity_transform() {
105 t := identity_transform()
106 for row in 0 .. 3 {
107 for col in 0 .. 3 {
108 assert t.matrix[row][col] == if row == col { 65536 } else { 0 }
109 }
110 }
111}
112
113fn test_snapshot_lookups() {
114 r := Resources{
115 crtcs: [CrtcInfo{ id: 10, mode: 30 }, CrtcInfo{ id: 11 }]
116 outputs: [OutputInfo{ id: 20, name: 'DP-1', crtc: 10, modes: [RRMode(30), 31], preferred: 1 }]
117 modes: [ModeInfo{ id: 30, name: '1920x1080' }, ModeInfo{ id: 31, name: '1280x720' }]
118 }
119 assert r.output_named('DP-1')?.id == 20
120 assert r.output_named('HDMI-1') == none
121 assert r.crtc(10)?.enabled()
122 assert !r.crtc(11)?.enabled()
123 assert r.mode(31)?.name == '1280x720'
124 assert r.mode_named('1920x1080')?.id == 30
125 assert r.output(20)?.preferred_modes() == [RRMode(30)]
126 assert r.output(20)?.connected()
127}
128
129fn test_list_copy_validation() {
130 values := [u16(1), 2, 3]
131 assert copy_list(&u16(values.data), 3)! == values
132 assert copy_list(&u16(unsafe { nil }), 0)!.len == 0
133 if _ := copy_list(&u16(unsafe { nil }), 1) {
134 assert false
135 }
136 if _ := copy_list(&u16(values.data), -1) {
137 assert false
138 }
139 assert c_string(c'HDMI-1', 4) == 'HDMI'
140 assert c_string(unsafe { nil }, 3) == ''
141}
142
143fn test_status_messages() {
144 assert status_error('CRTC configuration', set_config_invalid_config_time).msg().contains('query it again')
145 assert status_error('panning', 9).msg() == 'panning failed: status 9'
146}
147