Skip to content

Commit bac7fc4

Browse files
Merge pull request #30 from suve/test-type-sizes
Test type sizes
2 parents 076ac8e + a29273d commit bac7fc4

File tree

3 files changed

+247
-5
lines changed

3 files changed

+247
-5
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ jobs:
3737
source: units/SDL3_textengine.pas
3838
verbosity: ewnh
3939

40-
ubuntu-24-04:
41-
runs-on: ubuntu-24.04
40+
# This job runs inside a Fedora Rawhide container instead of straight
41+
# on the Ubuntu runner, because (at the moment of writing this comment)
42+
# the latest Ubuntu version supported by GitHub Actions is 24.04, which
43+
# does not have an SDL3 package.
44+
fedora-rawhide:
45+
runs-on: ubuntu-latest
46+
container: registry.fedoraproject.org/fedora:rawhide
4247
steps:
4348
- name: Install FPC
4449
run: |
45-
export DEBIAN_FRONTEND=noninteractive
46-
sudo apt update
47-
sudo apt install -y fpc
50+
dnf install --assumeyes --setopt=install_weak_deps=False diffutils gcc fpc SDL3-devel
4851
- name: Checkout code
4952
uses: actions/checkout@v2
5053
- name: Compile SDL3 unit
@@ -67,6 +70,8 @@ jobs:
6770
with:
6871
source: units/SDL3_textengine.pas
6972
verbosity: ewnh
73+
- name: Run type-sizes test
74+
run: ./tests/type-sizes.sh
7075

7176
windows-2025:
7277
runs-on: windows-2025

tests/type-sizes.sh

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
#!/bin/bash
2+
3+
set -eu -o pipefail
4+
5+
if [ -t 1 ]; then
6+
ANSI_BOLD="$(printf "\x1b[1m")"
7+
ANSI_GREEN="$(printf "\x1b[32m")"
8+
ANSI_RED="$(printf "\x1b[31m")"
9+
ANSI_RESET="$(printf "\x1b[0m")"
10+
else
11+
ANSI_BOLD=""
12+
ANSI_GREEN=""
13+
ANSI_RED=""
14+
ANSI_RESET=""
15+
fi
16+
17+
# -- cd to script directory
18+
19+
cd "$(dirname "${0}")"
20+
SDL_UNITS_PATH="$(pwd)/../units/"
21+
22+
TEMP_DIR="$(mktemp --directory)"
23+
PASCAL_SOURCE="${TEMP_DIR}/test.pas"
24+
C_SOURCE="${TEMP_DIR}/test.c"
25+
26+
# -- generate sources
27+
28+
cat > "${PASCAL_SOURCE}" << EOF
29+
program test;
30+
31+
uses
32+
SDL3;
33+
34+
Begin
35+
EOF
36+
37+
cat > "${C_SOURCE}" << EOF
38+
#include <stdbool.h>
39+
#include <stddef.h>
40+
#include <stdio.h>
41+
42+
#include <SDL3/SDL.h>
43+
44+
int main(void) {
45+
EOF
46+
47+
for TYPENAME in \
48+
SDL_AppResult \
49+
SDL_ArrayOrder \
50+
SDL_AudioDeviceEvent \
51+
SDL_AudioDeviceID \
52+
SDL_AudioFormat \
53+
SDL_AudioSpec \
54+
SDL_BitmapOrder \
55+
SDL_BlendFactor \
56+
SDL_BlendMode \
57+
SDL_BlendOperation \
58+
SDL_CameraDeviceEvent \
59+
SDL_CameraID \
60+
SDL_CameraPosition \
61+
SDL_CameraSpec \
62+
SDL_Capitalization \
63+
SDL_ChromaLocation \
64+
SDL_ClipboardEvent \
65+
SDL_Color \
66+
SDL_ColorPrimaries \
67+
SDL_ColorRange \
68+
SDL_Colorspace \
69+
SDL_ColorType \
70+
SDL_CommonEvent \
71+
SDL_DateTime \
72+
SDL_DialogFileFilter \
73+
SDL_DisplayEvent \
74+
SDL_DisplayID \
75+
SDL_DisplayMode \
76+
SDL_DisplayOrientation \
77+
SDL_DropEvent \
78+
SDL_EnumerationResult \
79+
SDL_Event \
80+
SDL_EventAction \
81+
SDL_EventType \
82+
SDL_FColor \
83+
SDL_FileDialogType \
84+
SDL_Finger \
85+
SDL_FingerID \
86+
SDL_FlashOperation \
87+
SDL_FlipMode \
88+
SDL_Folder \
89+
SDL_FPoint \
90+
SDL_FRect \
91+
SDL_GamepadAxis \
92+
SDL_GamepadAxisEvent \
93+
SDL_GamepadBinding \
94+
SDL_GamepadBindingType \
95+
SDL_GamepadButton \
96+
SDL_GamepadButtonEvent \
97+
SDL_GamepadButtonLabel \
98+
SDL_GamepadDeviceEvent \
99+
SDL_GamepadSensorEvent \
100+
SDL_GamepadTouchpadEvent \
101+
SDL_GamepadType \
102+
SDL_GlobFlags \
103+
SDL_HapticCondition \
104+
SDL_HapticConstant \
105+
SDL_HapticCustom \
106+
SDL_HapticDirection \
107+
SDL_HapticEffect \
108+
SDL_HapticID \
109+
SDL_HapticLeftRight \
110+
SDL_HapticPeriodic \
111+
SDL_HapticRamp \
112+
SDL_HintPriority \
113+
SDL_HitTestResult \
114+
SDL_InitFlags \
115+
SDL_JoyAxisEvent \
116+
SDL_JoyBallEvent \
117+
SDL_JoyBatteryEvent \
118+
SDL_JoyButtonEvent \
119+
SDL_JoyDeviceEvent \
120+
SDL_JoyHatEvent \
121+
SDL_JoystickConnectionState \
122+
SDL_JoystickID \
123+
SDL_JoystickType \
124+
SDL_KeyboardDeviceEvent \
125+
SDL_KeyboardEvent \
126+
SDL_KeyboardID \
127+
SDL_Keycode \
128+
SDL_Keymod \
129+
SDL_Locale \
130+
SDL_LogCategory \
131+
SDL_LogPriority \
132+
SDL_MatrixCoefficients \
133+
SDL_MessageBoxButtonFlags \
134+
SDL_MessageBoxColorType \
135+
SDL_MessageBoxFlags \
136+
SDL_MouseButtonEvent \
137+
SDL_MouseButtonFlags \
138+
SDL_MouseDeviceEvent \
139+
SDL_MouseID \
140+
SDL_MouseMotionEvent \
141+
SDL_MouseWheelDirection \
142+
SDL_MouseWheelEvent \
143+
SDL_Palette \
144+
SDL_PackedLayout \
145+
SDL_PackedOrder \
146+
SDL_PathInfo \
147+
SDL_PathType \
148+
SDL_PenAxis \
149+
SDL_PenAxisEvent \
150+
SDL_PenButtonEvent \
151+
SDL_PenID \
152+
SDL_PenInputFlags \
153+
SDL_PenMotionEvent \
154+
SDL_PenProximityEvent \
155+
SDL_PenTouchEvent \
156+
SDL_PixelFormat \
157+
SDL_PixelFormatDetails \
158+
SDL_PixelType \
159+
SDL_Point \
160+
SDL_PowerState \
161+
SDL_PropertiesID \
162+
SDL_PropertyType \
163+
SDL_QuitEvent \
164+
SDL_Rect \
165+
SDL_RendererLogicalPresentation \
166+
SDL_ScaleMode \
167+
SDL_Scancode \
168+
SDL_SensorEvent \
169+
SDL_SensorID \
170+
SDL_SensorType \
171+
SDL_SurfaceFlags \
172+
SDL_SystemCursor \
173+
SDL_SystemTheme \
174+
SDL_TextEditingEvent \
175+
SDL_TextEditingCandidatesEvent \
176+
SDL_TextInputEvent \
177+
SDL_TextInputType \
178+
SDL_TextureAccess \
179+
SDL_ThreadID \
180+
SDL_ThreadPriority \
181+
SDL_ThreadState \
182+
SDL_TimeFormat \
183+
SDL_TimerID \
184+
SDL_TouchDeviceType \
185+
SDL_TouchFingerEvent \
186+
SDL_TouchID \
187+
SDL_TransferCharacteristics \
188+
SDL_TrayEntryFlags \
189+
SDL_UserEvent \
190+
SDL_Vertex \
191+
SDL_VirtualJoystickDesc \
192+
SDL_VirtualJoystickSensorDesc \
193+
SDL_VirtualJoystickTouchpadDesc \
194+
SDL_WindowEvent \
195+
SDL_WindowFlags \
196+
SDL_WindowID \
197+
; do
198+
echo $'\t'"Writeln('${TYPENAME}: ', SizeOf(T${TYPENAME}));" >> "${PASCAL_SOURCE}"
199+
echo $'\t'"printf(\"${TYPENAME}: %zu\n\", sizeof(${TYPENAME}));" >> "${C_SOURCE}"
200+
done
201+
202+
echo "End." >> "${PASCAL_SOURCE}"
203+
echo $'\t'"return 0;"$'\n'"}" >> "${C_SOURCE}"
204+
205+
# -- sources generated
206+
207+
PASCAL_BINARY="${TEMP_DIR}/pascal"
208+
C_BINARY="${TEMP_DIR}/c"
209+
210+
fpc -v0e "-Fu${SDL_UNITS_PATH}" "-o${PASCAL_BINARY}" "${PASCAL_SOURCE}"
211+
gcc -std=c23 -Wall -Wpedantic -Werror -o "${C_BINARY}" "${C_SOURCE}"
212+
213+
# -- programs compiled
214+
215+
PASCAL_OUTPUT="${TEMP_DIR}/result-pas.txt"
216+
C_OUTPUT="${TEMP_DIR}/result-c.txt"
217+
218+
"${PASCAL_BINARY}" > "${PASCAL_OUTPUT}"
219+
"${C_BINARY}" > "${C_OUTPUT}"
220+
pr -mt <(echo "-- Pascal --"; cat "${PASCAL_OUTPUT}") <(echo "-- C --"; cat "${C_OUTPUT}")
221+
222+
set +e
223+
DIFF="$(diff --width=80 --suppress-common-lines --side-by-side "${PASCAL_OUTPUT}" "${C_OUTPUT}")"
224+
EXIT_CODE="${?}"
225+
226+
echo ""
227+
if [ "${EXIT_CODE}" -eq 0 ]; then
228+
echo "${ANSI_BOLD}[${ANSI_GREEN}PASS${ANSI_RESET}${ANSI_BOLD}]${ANSI_RESET} Outputs match"
229+
else
230+
echo "${ANSI_BOLD}[${ANSI_RED}FAIL${ANSI_RESET}${ANSI_BOLD}]${ANSI_RESET} Outputs differ!"
231+
echo "${DIFF}"
232+
fi
233+
234+
rm -rf "${TEMP_DIR}"
235+
exit "${EXIT_CODE}"

units/SDL_events.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ type
443443
direction: TSDL_MouseWheelDirection; {*< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back }
444444
mouse_x: cfloat; {*< X coordinate, relative to window }
445445
mouse_y: cfloat; {*< Y coordinate, relative to window }
446+
integer_x: cint32; {*< The amount scrolled horizontally, accumulated to whole scroll "ticks" (added in 3.2.12) *}
447+
integer_y: cint32; {*< The amount scrolled vertically, accumulated to whole scroll "ticks" (added in 3.2.12) *}
446448
end;
447449

448450
{*

0 commit comments

Comments
 (0)