Skip to content

Commit 3f2b428

Browse files
committed
v4.5.1
1 parent 32daf4e commit 3f2b428

File tree

4 files changed

+249
-28
lines changed

4 files changed

+249
-28
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.11)
22
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
33
project (raylib_cpp
4-
VERSION 4.5.0
4+
VERSION 4.5.1
55
DESCRIPTION "raylib-cpp C++ Object Oriented Wrapper for raylib"
66
HOMEPAGE_URL "https://github.com/robloach/raylib-cpp"
77
LANGUAGES C CXX

clib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "raylib-cpp",
3-
"version": "4.2.8",
3+
"version": "4.5.1",
44
"repo": "RobLoach/raylib-cpp",
55
"description": "raylib-cpp: C++ Object-Oriented Wrapper for raylib",
66
"homepage": "https://github.com/robloach/raylib-cpp",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "raylib-cpp",
3-
"version": "4.5.0",
3+
"version": "4.5.1",
44
"description": "raylib-cpp: C++ Object-Oriented Wrapper for raylib",
55
"main": "index.js",
66
"private": true,

tests/raylib-assert.h

Lines changed: 246 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
* raylib-assert - Assertion library for raylib.
44
* https://github.com/robloach/raylib-assert
55
*
6-
* Copyright 2021 Rob Loach (@RobLoach)
6+
* Version: v2.0.0
7+
*
8+
* Copyright 2023 Rob Loach (@RobLoach)
79
*
810
* DEPENDENCIES:
9-
* raylib https://www.raylib.com/
11+
* raylib 4.5+ https://www.raylib.com
1012
*
1113
* LICENSE: zlib/libpng
1214
*
@@ -37,10 +39,16 @@
3739
extern "C" {
3840
#endif
3941

40-
#include "raylib.h" // NOLINT
41-
4242
// How to report failed assertions
4343
#ifndef RAYLIB_ASSERT_LOG
44+
/**
45+
* The Trace Log Level used to report to TraceLog() on failed assertions. Defaults to LOG_FATAL.
46+
*
47+
* @example
48+
* #define RAYLIB_ASSERT_LOG LOG_WARNING
49+
*
50+
* @see TraceLogLevel
51+
*/
4452
#define RAYLIB_ASSERT_LOG LOG_FATAL
4553
#endif
4654

@@ -51,20 +59,138 @@ extern "C" {
5159
#endif
5260
#endif
5361

62+
#ifndef RAYLIB_ASSERT_TRACELOG
63+
/**
64+
* The TraceLog() function to use.
65+
*
66+
* @see TraceLog()
67+
*/
68+
#define RAYLIB_ASSERT_TRACELOG TraceLog
69+
#endif
70+
71+
#ifndef RAYLIB_ASSERT_TEXTFORMAT
72+
/**
73+
* The TextFormat() function to use when formating text.
74+
*
75+
* @see TextFormat()
76+
*/
77+
#define RAYLIB_ASSERT_TEXTFORMAT TextFormat
78+
#endif
79+
5480
// Variadic Arguments
5581
#define RAYLIB_ASSERT_CAT( A, B ) A ## B
5682
#define RAYLIB_ASSERT_SELECT( NAME, NUM ) RAYLIB_ASSERT_CAT( NAME ## _, NUM )
5783
#define RAYLIB_ASSERT_GET_COUNT( _1, _2, _3, _4, _5, _6, _7, RAYLIB_ASSERT_COUNT, ... ) RAYLIB_ASSERT_COUNT
5884
#define RAYLIB_ASSERT_VA_SIZE( ... ) RAYLIB_ASSERT_GET_COUNT( __VA_ARGS__, 7, 6, 5, 4, 3, 2, 1 )
5985
#define RAYLIB_ASSERT_VA_SELECT( NAME, ... ) RAYLIB_ASSERT_SELECT( NAME, RAYLIB_ASSERT_VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)
6086

61-
#define Assert(...) RAYLIB_ASSERT_VA_SELECT( Assert, __VA_ARGS__ )
62-
#define AssertEqual(...) RAYLIB_ASSERT_VA_SELECT( AssertEqual, __VA_ARGS__ )
63-
#define AssertNot(...) RAYLIB_ASSERT_VA_SELECT( AssertNot, __VA_ARGS__ )
64-
#define AssertFail(...) RAYLIB_ASSERT_VA_SELECT( AssertFail, __VA_ARGS__ )
87+
/**
88+
* Assert whether the given condition is true.
89+
*
90+
* @param condition The condition that is expected to be true.
91+
* @param message (Optional) The message to provide on failed assertions.
92+
* @param p1 (Optional) The first parameter in the message.
93+
* @param p2 (Optional) The second parameter in the message.
94+
* @param p3 (Optional) The third parameter in the message.
95+
* @param p4 (Optional) The fourth parameter in the message.
96+
* @param p5 (Optional) The fifth parameter in the message.
97+
*/
98+
#define Assert(...) RAYLIB_ASSERT_VA_SELECT(Assert, __VA_ARGS__)
99+
100+
/**
101+
* Assert whether the two given parameters are equal.
102+
*
103+
* @param actual The actual value.
104+
* @param expected The expected value.
105+
* @param message (Optional) The message to provide on failed assertions.
106+
* @param p1 (Optional) The first parameter in the message.
107+
* @param p2 (Optional) The second parameter in the message.
108+
* @param p3 (Optional) The third parameter in the message.
109+
* @param p4 (Optional) The fourth parameter in the message.
110+
*/
111+
#define AssertEqual(...) RAYLIB_ASSERT_VA_SELECT(AssertEqual, __VA_ARGS__)
112+
113+
/**
114+
* Assert whether the given condition is false.
115+
*
116+
* @param condition The condition that is expected to be false.
117+
* @param message (Optional) The message to provide on failed assertions.
118+
* @param p1 (Optional) The first parameter in the message.
119+
* @param p2 (Optional) The second parameter in the message.
120+
* @param p3 (Optional) The third parameter in the message.
121+
* @param p4 (Optional) The fourth parameter in the message.
122+
* @param p5 (Optional) The fifth parameter in the message.
123+
*/
124+
#define AssertNot(...) RAYLIB_ASSERT_VA_SELECT(AssertNot, __VA_ARGS__)
125+
126+
/**
127+
* Assert whether the two given parameters are not equal.
128+
*
129+
* @param actual The actual value.
130+
* @param notexpected The expected value that shouldn't equal the actual value.
131+
* @param message (Optional) The message to provide on failed assertions.
132+
* @param p1 (Optional) The first parameter in the message.
133+
* @param p2 (Optional) The second parameter in the message.
134+
* @param p3 (Optional) The third parameter in the message.
135+
* @param p4 (Optional) The fourth parameter in the message.
136+
*/
137+
#define AssertNotEqual(...) RAYLIB_ASSERT_VA_SELECT(AssertNotEqual, __VA_ARGS__)
138+
139+
/**
140+
* Sets a failed assertion, with the given message.
141+
*
142+
* @param message (Optional) The message to provide for the failed assertion.
143+
* @param p1 (Optional) The first parameter in the message.
144+
* @param p2 (Optional) The second parameter in the message.
145+
* @param p3 (Optional) The third parameter in the message.
146+
* @param p4 (Optional) The fourth parameter in the message.
147+
* @param p5 (Optional) The fifth parameter in the message.
148+
* @param p6 (Optional) The sixth parameter in the message.
149+
*/
150+
#define AssertFail(...) RAYLIB_ASSERT_VA_SELECT(AssertFail, __VA_ARGS__)
151+
152+
/**
153+
* Assert whether an image is loaded.
154+
*
155+
* @param image The image to check for valid data.
156+
* @param message (Optional) The message to provide on failed assertions.
157+
* @param p1 (Optional) The first parameter in the message.
158+
* @param p2 (Optional) The second parameter in the message.
159+
* @param p3 (Optional) The third parameter in the message.
160+
* @param p4 (Optional) The fourth parameter in the message.
161+
* @param p5 (Optional) The fifth parameter in the message.
162+
*/
163+
#define AssertImage(...) RAYLIB_ASSERT_VA_SELECT(AssertImage, __VA_ARGS__)
164+
165+
/**
166+
* Assert whether two images are the same.
167+
*
168+
* @param image1 The first image to check is equal to the second.
169+
* @param image2 The second image to check is equal to the first.
170+
* @param message (Optional) The message to provide on failed assertions.
171+
* @param p1 (Optional) The first parameter in the message.
172+
* @param p2 (Optional) The second parameter in the message.
173+
* @param p3 (Optional) The third parameter in the message.
174+
* @param p4 (Optional) The fourth parameter in the message.
175+
*/
176+
#define AssertImageSame(...) RAYLIB_ASSERT_VA_SELECT(AssertImageSame, __VA_ARGS__)
177+
178+
/**
179+
* Assert whether two colors are the same.
180+
*
181+
* @param color1 The first color to check.
182+
* @param color2 The second color to check.
183+
* @param message (Optional) The message to provide on failed assertions.
184+
* @param p1 (Optional) The first parameter in the message.
185+
* @param p2 (Optional) The second parameter in the message.
186+
* @param p3 (Optional) The third parameter in the message.
187+
* @param p4 (Optional) The fourth parameter in the message.
188+
*/
189+
#define AssertColorSame(...) RAYLIB_ASSERT_VA_SELECT(AssertColorSame, __VA_ARGS__)
65190

66191
// Assert()
67192
#ifdef RAYLIB_ASSERT_NDEBUG
193+
#define Assert_0()
68194
#define Assert_1(condition)
69195
#define Assert_2(condition, message)
70196
#define Assert_3(condition, message, p1)
@@ -73,25 +199,38 @@ extern "C" {
73199
#define Assert_6(condition, message, p1, p2, p3, p4)
74200
#define Assert_7(condition, message, p1, p2, p3, p4, p5)
75201
#else
202+
#define Assert_0() AssertFail_1("No condition provided for Assert()")
76203
#define Assert_1(condition) Assert_2(condition, #condition)
77-
#define Assert_2(condition, message) if (!((bool)(condition))) { TraceLog(RAYLIB_ASSERT_LOG, "ASSERT: %s (%s:%i)", message, __FILE__, __LINE__); }
78-
#define Assert_3(condition, message, p1) Assert_2(condition, TextFormat(message, p1))
79-
#define Assert_4(condition, message, p1, p2) Assert_2(condition, TextFormat(message, p1, p2))
80-
#define Assert_5(condition, message, p1, p2, p3) Assert_2(condition, TextFormat(message, p1, p2, p3))
81-
#define Assert_6(condition, message, p1, p2, p3, p4) Assert_2(condition, TextFormat(message, p1, p2, p3, p4))
82-
#define Assert_7(condition, message, p1, p2, p3, p4, p5) Assert_2(condition, TextFormat(message, p1, p2, p3, p4, p5))
204+
#define Assert_2(condition, message) do { if (!((bool)(condition))) { RAYLIB_ASSERT_TRACELOG(RAYLIB_ASSERT_LOG, "ASSERT: %s (%s:%i)", message, __FILE__, __LINE__); } } while(0)
205+
#define Assert_3(condition, message, p1) Assert_2(condition, RAYLIB_ASSERT_TEXTFORMAT(message, p1))
206+
#define Assert_4(condition, message, p1, p2) Assert_2(condition, RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2))
207+
#define Assert_5(condition, message, p1, p2, p3) Assert_2(condition, RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2, p3))
208+
#define Assert_6(condition, message, p1, p2, p3, p4) Assert_2(condition, RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2, p3, p4))
209+
#define Assert_7(condition, message, p1, p2, p3, p4, p5) Assert_2(condition, RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2, p3, p4, p5))
83210
#endif
84211

85212
// AssertEqual()
213+
#define AssertEqual_0() AssertFail_1("No condition provided for AssertEqual()")
86214
#define AssertEqual_1(condition) Assert_2(condition, #condition)
87-
#define AssertEqual_2(actual, expected) Assert_4((actual) == (expected), "%s == %s", #actual, #expected)
215+
#define AssertEqual_2(actual, expected) Assert_4((actual) == (expected), "AssertEqual(%s, %s) - Provided arguments are not equal", #actual, #expected)
88216
#define AssertEqual_3(actual, expected, message) Assert_2((actual) == (expected), message)
89217
#define AssertEqual_4(actual, expected, message, p1) Assert_3((actual) == (expected), message, p1)
90218
#define AssertEqual_5(actual, expected, message, p1, p2) Assert_4((actual) == (expected), message, p1, p2)
91219
#define AssertEqual_6(actual, expected, message, p1, p2, p3) Assert_5((actual) == (expected), message, p1, p2, p3)
92220
#define AssertEqual_7(actual, expected, message, p1, p2, p3, p4) Assert_6((actual) == (expected), message, p1, p2, p3, p4)
93221

222+
// AssertNotEqual()
223+
#define AssertNotEqual_0() AssertFail_1("No condition provided for AssertNotEqual()")
224+
#define AssertNotEqual_1(condition) AssertNot_2(condition, #condition)
225+
#define AssertNotEqual_2(actual, expected) Assert_4((actual) != (expected), "AssertNotEqual(%s, %s) - Provided arguments are equal", #actual, #expected)
226+
#define AssertNotEqual_3(actual, expected, message) Assert_2((actual) != (expected), message)
227+
#define AssertNotEqual_4(actual, expected, message, p1) Assert_3((actual) != (expected), message, p1)
228+
#define AssertNotEqual_5(actual, expected, message, p1, p2) Assert_4((actual) != (expected), message, p1, p2)
229+
#define AssertNotEqual_6(actual, expected, message, p1, p2, p3) Assert_5((actual) != (expected), message, p1, p2, p3)
230+
#define AssertNotEqual_7(actual, expected, message, p1, p2, p3, p4) Assert_6((actual) != (expected), message, p1, p2, p3, p4)
231+
94232
// AssertNot()
233+
#define AssertNot_0() AssertFail_1("No condition provided for AssertNot()")
95234
#define AssertNot_1(condition) Assert_2(!(bool)(condition), #condition)
96235
#define AssertNot_2(condition, message) Assert_2(!(bool)(condition), message)
97236
#define AssertNot_3(condition, message, p1) Assert_3(!(bool)(condition), message, p1)
@@ -111,18 +250,100 @@ extern "C" {
111250
#define AssertFail_6(message, p1, p2, p3, p4, p5)
112251
#define AssertFail_7(message, p1, p2, p3, p4, p5, p6)
113252
#else
114-
#define AssertFail_0() TraceLog(RAYLIB_ASSERT_LOG, "ASSERT: AssertFail() (%s:%i)", __FILE__, __LINE__)
115-
#define AssertFail_1(message) TraceLog(RAYLIB_ASSERT_LOG, "ASSERT: %s (%s:%i)", message, __FILE__, __LINE__)
116-
#define AssertFail_2(message, p1) AssertFail_1(TextFormat(message, p1))
117-
#define AssertFail_3(message, p1, p2) AssertFail_1(TextFormat(message, p1, p2))
118-
#define AssertFail_4(message, p1, p2, p3) AssertFail_1(TextFormat(message, p1, p2, p3))
119-
#define AssertFail_5(message, p1, p2, p3, p4) AssertFail_1(TextFormat(message, p1, p2, p3, p4))
120-
#define AssertFail_6(message, p1, p2, p3, p4, p5) AssertFail_1(TextFormat(message, p1, p2, p3, p4, p5))
121-
#define AssertFail_7(message, p1, p2, p3, p4, p5, p6) AssertFail_1(TextFormat(message, p1, p2, p3, p4, p5, p6))
253+
#define AssertFail_0() RAYLIB_ASSERT_TRACELOG(RAYLIB_ASSERT_LOG, "ASSERT: AssertFail() (%s:%i)", __FILE__, __LINE__)
254+
#define AssertFail_1(message) RAYLIB_ASSERT_TRACELOG(RAYLIB_ASSERT_LOG, "ASSERT: %s (%s:%i)", message, __FILE__, __LINE__)
255+
#define AssertFail_2(message, p1) AssertFail_1(RAYLIB_ASSERT_TEXTFORMAT(message, p1))
256+
#define AssertFail_3(message, p1, p2) AssertFail_1(RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2))
257+
#define AssertFail_4(message, p1, p2, p3) AssertFail_1(RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2, p3))
258+
#define AssertFail_5(message, p1, p2, p3, p4) AssertFail_1(RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2, p3, p4))
259+
#define AssertFail_6(message, p1, p2, p3, p4, p5) AssertFail_1(RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2, p3, p4, p5))
260+
#define AssertFail_7(message, p1, p2, p3, p4, p5, p6) AssertFail_1(RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2, p3, p4, p5, p6))
122261
#endif
123262

124-
// AssertBreakpoint()
125-
#define AssertBreakpoint() AssertFail_1("AssertBreakpoint()")
263+
// AssertImage()
264+
#define AssertImage_0() AssertFail_1("No image provided for AssertImage()")
265+
#define AssertImage_1(image) Assert_3(IsImageReady(image), "AssertImage(%s) - Image not loaded", #image)
266+
#define AssertImage_2(image, message) Assert_2(IsImageReady(image), message)
267+
#define AssertImage_3(image, message, p1) Assert_3(IsImageReady(image), message, p1)
268+
#define AssertImage_4(image, message, p1, p2) Assert_4(IsImageReady(image), message, p1, p2)
269+
#define AssertImage_5(image, message, p1, p2, p3) Assert_5(IsImageReady(image), message, p1, p2, p3)
270+
#define AssertImage_6(image, message, p1, p2, p3, p4) Assert_6(IsImageReady(image), message, p1, p2, p3, p4)
271+
272+
// AssertTexture()
273+
#define AssertTexture_0() AssertFail_1("No texture provided for AssertTexture()")
274+
#define AssertTexture_1(texture) Assert_3(IsTextureReady(texture), "AssertTexture(%s) - Texture not loaded", #texture)
275+
#define AssertTexture_2(texture, message) Assert_2(IsTextureReady(texture), message)
276+
#define AssertTexture_3(texture, message, p1) Assert_3(IsTextureReady(texture), message, p1)
277+
#define AssertTexture_4(texture, message, p1, p2) Assert_4(IsTextureReady(texture), message, p1, p2)
278+
#define AssertTexture_5(texture, message, p1, p2, p3) Assert_5(IsTextureReady(texture), message, p1, p2, p3)
279+
#define AssertTexture_6(texture, message, p1, p2, p3, p4) Assert_6(IsTextureReady(texture), message, p1, p2, p3, p4)
280+
281+
// AssertImageSame()
282+
#ifdef RAYLIB_ASSERT_NDEBUG
283+
#define AssertImageSame_0()
284+
#define AssertImageSame_1(image)
285+
#define AssertImageSame_2(image1, image2)
286+
#define AssertImageSame_3(image1, image2, message)
287+
#define AssertImageSame_4(image1, image2, message, p1)
288+
#define AssertImageSame_5(image1, image2, message, p1, p2)
289+
#define AssertImageSame_6(image1, image2, message, p1, p2, p3)
290+
#define AssertImageSame_7(image1, image2, message, p1, p2, p3, p4)
291+
#else
292+
#define AssertImageSame_0() AssertFail_1("AssertImageSame(): No images provided to AssertImageSame(), expected 2")
293+
#define AssertImageSame_1(image) AssertFail_1("Only one image provided for AssertImageSame()")
294+
#define AssertImageSame_2(image1, image2) AssertImageSame_5(image1, image2, "AssertImageSame(%s, %s) - Images do not match", #image1, #image2)
295+
#define AssertImageSame_3(image1, image2, message) do { \
296+
if (image1.width != image2.width || image1.height != image2.height || image1.format != image2.format) { \
297+
AssertFail_1(message); \
298+
break; \
299+
} \
300+
Color* colors1 = LoadImageColors(image1); \
301+
Color* colors2 = LoadImageColors(image2); \
302+
bool failure = false; \
303+
for (int i = 0; i < image1.width * image1.height; i++) { \
304+
Color color1 = colors1[i]; \
305+
Color color2 = colors2[i]; \
306+
if (color1.r != color2.r || color1.g != color2.g || color1.b != color2.b || color1.a != color2.a) { \
307+
failure = true; \
308+
break; \
309+
} \
310+
} \
311+
UnloadImageColors(colors1); \
312+
UnloadImageColors(colors2); \
313+
if (failure) { \
314+
AssertFail_1(message); \
315+
} \
316+
} while(0)
317+
#define AssertImageSame_4(image1, image2, message, p1) AssertImageSame_3(image1, image2, RAYLIB_ASSERT_TEXTFORMAT(message, p1))
318+
#define AssertImageSame_5(image1, image2, message, p1, p2) AssertImageSame_3(image1, image2, RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2))
319+
#define AssertImageSame_6(image1, image2, message, p1, p2, p3) AssertImageSame_3(image1, image2, RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2, p3))
320+
#define AssertImageSame_7(image1, image2, message, p1, p2, p3, p4) AssertImageSame_3(image1, image2, RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2, p3, p4))
321+
#endif
322+
323+
// AssertColorSame()
324+
#ifdef RAYLIB_ASSERT_NDEBUG
325+
#define AssertColorSame_0()
326+
#define AssertColorSame_1(color)
327+
#define AssertColorSame_2(color1, color2)
328+
#define AssertColorSame_3(color1, color2, message)
329+
#define AssertColorSame_4(color1, color2, message, p1)
330+
#define AssertColorSame_5(color1, color2, message, p1, p2)
331+
#define AssertColorSame_6(color1, color2, message, p1, p2, p3)
332+
#define AssertColorSame_7(color1, color2, message, p1, p2, p3, p4)
333+
#else
334+
#define AssertColorSame_0() AssertFail_1("Colors not provided to AssertColorSame()")
335+
#define AssertColorSame_1(color) AssertFail_1("Expected two colors for AssertColorSame()")
336+
#define AssertColorSame_2(color1, color2) AssertColorSame_5(color1, color2, "AssertColorSame(%s, %s) - Colors do not match", #color1, #color2)
337+
#define AssertColorSame_3(color1, color2, message) do { \
338+
if (color1.r != color2.r || color1.g != color2.g || color1.b != color2.b || color1.a != color2.a) { \
339+
AssertFail_1(message); \
340+
}\
341+
} while (0)
342+
#define AssertColorSame_4(color1, color2, message, p1) AssertColorSame_3(color1, color2, RAYLIB_ASSERT_TEXTFORMAT(message, p1))
343+
#define AssertColorSame_5(color1, color2, message, p1, p2) AssertColorSame_3(color1, color2, RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2))
344+
#define AssertColorSame_6(color1, color2, message, p1, p2, p3) AssertColorSame_3(color1, color2, RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2, p3))
345+
#define AssertColorSame_7(color1, color2, message, p1, p2, p3, p4) AssertColorSame_3(color1, color2, RAYLIB_ASSERT_TEXTFORMAT(message, p1, p2, p3, p4))
346+
#endif
126347

127348
#ifdef __cplusplus
128349
}

0 commit comments

Comments
 (0)