Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for version macros/functions #60

17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ jobs:
- name: Test 1 - Run Init Test
run: |
./tests/testinit
- name: Test 2 - Compile Version Test
uses: suve/[email protected]
with:
source: tests/testversion.pas
flags: Fl/usr/local/lib
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? - Without this part testversion.pas is not compiled, right?

Copy link
Collaborator

@suve suve Jun 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean strictly this line, where -Fl/usr/local/lib is passed to the compiler. The SDL packages installed from the repo should install libraries in /usr/lib, which is one of the locations where the compiler looks by default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why it is there, is that without this line the sdl2 library is not found. From my memory, it is related to a new way of storing libraries on big sur, they are in fact not some files stored in a folder anymore but in a more sophisticated indexed "library file".

See. 8f7b010

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, I missed that this is part of the Mac job. I suppose that since brew is not the official package manager, the authors decided to put stuff in /usr/local over /usr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see :)

verbosity: ewnh
- name: Test 2 - Run Version Test
run: |
./tests/testversion
ubuntu-20-04:
runs-on: ubuntu-20.04
steps:
Expand Down Expand Up @@ -113,6 +122,14 @@ jobs:
mkdir ~/tmp
export XDG_RUNTIME_DIR=~/tmp
./tests/testinit
- name: Test 2 - Compile Version Test
uses: suve/[email protected]
with:
source: tests/testversion.pas
verbosity: ewnh
- name: Test 2 - Run Version Test
run: |
./tests/testversion
windows-2022:
runs-on: windows-2022
steps:
Expand Down
56 changes: 56 additions & 0 deletions tests/testversion.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
program testversion;

{

Test version macros/functions of SDL2 system.

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);

var
CompiledVersion: TSDL_Version = (major: 0; minor: 0; patch: 0);
LinkedVersion: TSDL_Version = (major: 0; minor: 0; patch: 0);
VersionNum: Cardinal = 0;
begin
write('Start SDL2 version test... ');

try
VersionNum := SDL_VERSIONNUM(1,2,3);
if (VersionNum <> 1203) then
raise ESDL2Error.Create('SDL_VERSIONNUM failed: 1203 expected, found: ' + IntToStr(VersionNum));

SDL_VERSION(CompiledVersion);
if (SDL_COMPILEDVERSION <> SDL_VERSIONNUM(CompiledVersion.major, CompiledVersion.minor, CompiledVersion.patch)) then
raise ESDL2Error.Create('SDL_VERSION or SDL_COMPILEDVERSION failed: Version results do not match!');

if not SDL_VERSION_ATLEAST(2,0,0) then
raise ESDL2Error.Create('SDL_VERSION_ATLEAST failed: Version at least 2.0.0 should be true!');

if SDL_VERSION_ATLEAST(3,0,0) then
raise ESDL2Error.Create('SDL_VERSION_ATLEAST failed: Version at least 3.0.0 should be false!');

SDL_GetVersion(@LinkedVersion);
if @LinkedVersion = nil then
raise ESDL2Error.Create('SDL_GetVersion failed: ' + SDL_GetError());

if SDL_VERSIONNUM(LinkedVersion.major, LinkedVersion.minor, LinkedVersion.patch) = 0 then
raise ESDL2Error.Create('SDL_GetVersion failed: Returns 0.0.0 .');
except
end;

writeln('finished.');
end.