Skip to content

Commit

Permalink
Merge pull request #36 from Free-Pascal-meets-SDL-Website/addtest-2
Browse files Browse the repository at this point in the history
Add (first) test (SDL_Init), compilation and execution workflow
  • Loading branch information
Free-Pascal-meets-SDL-Website authored Apr 13, 2022
2 parents 9f1baaa + 9e0fa7b commit 756e8c6
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
41 changes: 39 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ master ]

jobs:
macos-11:
macos-11-big-sur:
runs-on: macos-11
steps:
- name: Install FPC
Expand Down Expand Up @@ -46,6 +46,21 @@ jobs:
with:
source: units/sdl2_ttf.pas
verbosity: ewnh
- name: Install SDL2 library
run: brew install sdl2
- name: Get SDL2 library version and path(s)
run: |
sdl2-config --version
sdl2-config --libs
- name: Test 1 - Compile Init Test
uses: suve/[email protected]
with:
source: tests/testinit.pas
flags: Fl/usr/local/lib
verbosity: ewnh
- name: Test 1 - Run Init Test
run: |
./tests/testinit
ubuntu-20-04:
runs-on: ubuntu-20.04
steps:
Expand Down Expand Up @@ -86,6 +101,18 @@ jobs:
with:
source: units/sdl2_ttf.pas
verbosity: ewnh
- name: Install SDL2 library
run: sudo apt-get install libsdl2-dev
- name: Test 1 - Compile Init Test
uses: suve/[email protected]
with:
source: tests/testinit.pas
verbosity: ewnh
- name: Test 1 - Run Init Test
run: |
mkdir ~/tmp
export XDG_RUNTIME_DIR=~/tmp
./tests/testinit
windows-2022:
runs-on: windows-2022
steps:
Expand Down Expand Up @@ -124,4 +151,14 @@ jobs:
with:
source: units/sdl2_ttf.pas
verbosity: ewnh

- name: Test 1 - Compile Init Test
uses: suve/[email protected]
with:
source: tests/testinit.pas
flags: Flunits
verbosity: ewnh
# !!! Since no SDL2.DLL is available via chocolatey, the run will fail.
# TODO: Find solution to install SDL2 binary.
# - name: Test 1 - Run Init Test
# run: |
# ./tests/testinit.exe
56 changes: 56 additions & 0 deletions tests/testinit.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
program testinit;

{
Test initilization of SDL2 system with a sample of flags.
This file is part of
SDL2-for-Pascal
Copyright (C) 2020-2022 PGD Community
Visit: https://github.com/PascalGameDevelopment/SDL2-for-Pascal
}

{$I testsettings.inc}

uses
Classes, SysUtils, SDL2;

type
ESDL2Error = class(Exception);

const
Flags: array[0..12] of TSDL_Init = (
{ single flags }
SDL_INIT_TIMER, SDL_INIT_AUDIO, SDL_INIT_VIDEO,
SDL_INIT_JOYSTICK, SDL_INIT_HAPTIC, SDL_INIT_GAMECONTROLLER,
SDL_INIT_EVENTS, SDL_INIT_SENSOR, SDL_INIT_NOPARACHUTE,
SDL_INIT_EVERYTHING,
{ typically combined flags }
SDL_INIT_AUDIO or SDL_INIT_VIDEO,
SDL_INIT_VIDEO or SDL_INIT_JOYSTICK,
SDL_INIT_VIDEO or SDL_INIT_GAMECONTROLLER or SDL_INIT_AUDIO);

var
Flag: TSDL_Init;
begin
write('Start SDL2 inilization test... ');
for Flag in Flags do
begin
try
if SDL_Init(Flag) <> 0 then
raise ESDL2Error.Create('SDL_Init failed: Flag = ' + IntToStr(Flag));
except
on E: ESDL2Error do
try
SDL_Quit;
except
raise;
end;
end;
SDL_Quit;
end;
writeln(' finished.');
end.

5 changes: 5 additions & 0 deletions tests/testsettings.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{$IFDEF FPC}
{$MODE DELPHI}{$H+}
{$UNITPATH ../units} // Does this work in Delphi?
{$ENDIF}

3 changes: 3 additions & 0 deletions units/sdl2.pas
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ interface
{$IFDEF UNIX}
{$IFDEF DARWIN}
SDL_LibName = 'libSDL2.dylib';
{$IFDEF FPC}
{$LINKLIB libSDL2}
{$ENDIF}
{$ELSE}
{$IFDEF FPC}
SDL_LibName = 'libSDL2.so';
Expand Down

0 comments on commit 756e8c6

Please sign in to comment.