Skip to content

Commit

Permalink
Fix sdl2-ttf tests (add support of incomplete versions)
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Mar 12, 2022
1 parent cbb3a56 commit 50ebf64
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions tests/BinaryCompatibilityTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@ class BinaryCompatibilityTestCase extends TestCase
{
private const DIR_STORAGE = __DIR__ . '/storage';

protected function skipIfVersionNotCompatible(Version $version, string $binary): void
{
$this->skipIfNoFFISupport();

$ffi = \FFI::cdef(<<<'CPP'
typedef struct SDL_version {
uint8_t major;
uint8_t minor;
uint8_t patch;
} SDL_version;
extern const SDL_version * TTF_Linked_Version(void);
CPP, $binary);

$ver = $ffi->TTF_Linked_Version();
$actual = \sprintf('%d.%d.%d', $ver->major, $ver->minor, $ver->patch);

if (\version_compare($version->toString(), $actual, '>')) {
$message = 'Unable to check compatibility because the installed version of the '
. 'library (v%s) is lower than the tested headers (v%s)';

$this->markTestSkipped(\sprintf($message, $actual, $version->toString()));
}
}

/**
* @requires OSFAMILY Windows
*
Expand All @@ -34,15 +59,13 @@ public function testWindowsBinaryCompatibility(Version $version): void
->extract('SDL2.dll', self::DIR_STORAGE . '/SDL2.dll');
}

if (!\is_file(self::DIR_STORAGE . '/SDL2_ttf.dll')) {
if (!\is_file($binary = self::DIR_STORAGE . '/SDL2_ttf.dll')) {
Downloader::zip('https://github.com/libsdl-org/SDL_ttf/releases/download/release-2.0.18/SDL2_ttf-2.0.18-win32-x64.zip')
->extract('SDL2_ttf.dll', self::DIR_STORAGE . '/SDL2_ttf.dll');
}

$this->assertHeadersCompatibleWith(
SDL2TTF::create($version),
self::DIR_STORAGE . '/SDL2_ttf.dll'
);
$this->skipIfVersionNotCompatible($version, $binary);
$this->assertHeadersCompatibleWith(SDL2TTF::create($version), $binary);
}

/**
Expand All @@ -52,14 +75,14 @@ public function testWindowsBinaryCompatibility(Version $version): void
*/
public function testDarwinBinaryCompatibility(Version $version): void
{
if (!Locator::exists('libSDL2_ttf-2.0.0.dylib')) {
$binary = Locator::resolve('libSDL2_ttf-2.0.0.dylib');

if ($binary === null) {
$this->markTestSkipped('sdl2_ttf not installed');
}

$this->assertHeadersCompatibleWith(
SDL2TTF::create($version),
Locator::resolve('libSDL2_ttf-2.0.0.dylib')
);
$this->skipIfVersionNotCompatible($version, $binary);
$this->assertHeadersCompatibleWith(SDL2TTF::create($version), $binary);
}

/**
Expand All @@ -69,13 +92,13 @@ public function testDarwinBinaryCompatibility(Version $version): void
*/
public function testLinuxBinaryCompatibility(Version $version): void
{
if (!Locator::exists('libSDL2_ttf-2.0.so.0')) {
$binary = Locator::resolve('libSDL2_ttf-2.0.so.0');

if ($binary === null) {
$this->markTestSkipped('sdl2_ttf not installed');
}

$this->assertHeadersCompatibleWith(
SDL2TTF::create($version),
Locator::resolve('libSDL2_ttf-2.0.so.0')
);
$this->skipIfVersionNotCompatible($version, $binary);
$this->assertHeadersCompatibleWith(SDL2TTF::create($version), $binary);
}
}

0 comments on commit 50ebf64

Please sign in to comment.