@@ -20,6 +20,31 @@ class BinaryCompatibilityTestCase extends TestCase
20
20
{
21
21
private const DIR_STORAGE = __DIR__ . '/storage ' ;
22
22
23
+ protected function skipIfVersionNotCompatible (Version $ version , string $ binary ): void
24
+ {
25
+ $ this ->skipIfNoFFISupport ();
26
+
27
+ $ ffi = \FFI ::cdef (<<<'CPP'
28
+ typedef struct SDL_version {
29
+ uint8_t major;
30
+ uint8_t minor;
31
+ uint8_t patch;
32
+ } SDL_version;
33
+
34
+ extern const SDL_version * TTF_Linked_Version(void);
35
+ CPP, $ binary );
36
+
37
+ $ ver = $ ffi ->TTF_Linked_Version ();
38
+ $ actual = \sprintf ('%d.%d.%d ' , $ ver ->major , $ ver ->minor , $ ver ->patch );
39
+
40
+ if (\version_compare ($ version ->toString (), $ actual , '> ' )) {
41
+ $ message = 'Unable to check compatibility because the installed version of the '
42
+ . 'library (v%s) is lower than the tested headers (v%s) ' ;
43
+
44
+ $ this ->markTestSkipped (\sprintf ($ message , $ actual , $ version ->toString ()));
45
+ }
46
+ }
47
+
23
48
/**
24
49
* @requires OSFAMILY Windows
25
50
*
@@ -34,15 +59,13 @@ public function testWindowsBinaryCompatibility(Version $version): void
34
59
->extract ('SDL2.dll ' , self ::DIR_STORAGE . '/SDL2.dll ' );
35
60
}
36
61
37
- if (!\is_file (self ::DIR_STORAGE . '/SDL2_ttf.dll ' )) {
62
+ if (!\is_file ($ binary = self ::DIR_STORAGE . '/SDL2_ttf.dll ' )) {
38
63
Downloader::zip ('https://github.com/libsdl-org/SDL_ttf/releases/download/release-2.0.18/SDL2_ttf-2.0.18-win32-x64.zip ' )
39
64
->extract ('SDL2_ttf.dll ' , self ::DIR_STORAGE . '/SDL2_ttf.dll ' );
40
65
}
41
66
42
- $ this ->assertHeadersCompatibleWith (
43
- SDL2TTF ::create ($ version ),
44
- self ::DIR_STORAGE . '/SDL2_ttf.dll '
45
- );
67
+ $ this ->skipIfVersionNotCompatible ($ version , $ binary );
68
+ $ this ->assertHeadersCompatibleWith (SDL2TTF ::create ($ version ), $ binary );
46
69
}
47
70
48
71
/**
@@ -52,14 +75,14 @@ public function testWindowsBinaryCompatibility(Version $version): void
52
75
*/
53
76
public function testDarwinBinaryCompatibility (Version $ version ): void
54
77
{
55
- if (!Locator::exists ('libSDL2_ttf-2.0.0.dylib ' )) {
78
+ $ binary = Locator::resolve ('libSDL2_ttf-2.0.0.dylib ' );
79
+
80
+ if ($ binary === null ) {
56
81
$ this ->markTestSkipped ('sdl2_ttf not installed ' );
57
82
}
58
83
59
- $ this ->assertHeadersCompatibleWith (
60
- SDL2TTF ::create ($ version ),
61
- Locator::resolve ('libSDL2_ttf-2.0.0.dylib ' )
62
- );
84
+ $ this ->skipIfVersionNotCompatible ($ version , $ binary );
85
+ $ this ->assertHeadersCompatibleWith (SDL2TTF ::create ($ version ), $ binary );
63
86
}
64
87
65
88
/**
@@ -69,13 +92,13 @@ public function testDarwinBinaryCompatibility(Version $version): void
69
92
*/
70
93
public function testLinuxBinaryCompatibility (Version $ version ): void
71
94
{
72
- if (!Locator::exists ('libSDL2_ttf-2.0.so.0 ' )) {
95
+ $ binary = Locator::resolve ('libSDL2_ttf-2.0.so.0 ' );
96
+
97
+ if ($ binary === null ) {
73
98
$ this ->markTestSkipped ('sdl2_ttf not installed ' );
74
99
}
75
100
76
- $ this ->assertHeadersCompatibleWith (
77
- SDL2TTF ::create ($ version ),
78
- Locator::resolve ('libSDL2_ttf-2.0.so.0 ' )
79
- );
101
+ $ this ->skipIfVersionNotCompatible ($ version , $ binary );
102
+ $ this ->assertHeadersCompatibleWith (SDL2TTF ::create ($ version ), $ binary );
80
103
}
81
104
}
0 commit comments