21 Commits
Author SHA1 Message Date
Chris Thrasher e0b3a8e28d Add more sfKeyboard tests 2025-01-13 15:53:31 -07:00
Miron Alexandru 58cd82b532 Update Network module code 2025-01-12 21:19:21 -07:00
Chris Thrasher 2adc2db065 Fix grammar 2025-01-01 11:32:59 -07:00
Chris Thrasher b607308b3f Add tests for sfShape 2024-12-24 11:29:54 -06:00
Chris Thrasher e37de74852 Remove leftover comment 2024-12-24 11:29:54 -06:00
Chris Thrasher 96d41a2459 Add tests for sfPrimitiveType 2024-12-24 11:29:54 -06:00
Chris Thrasher 112abc1ab7 Add tests for sfView 2024-12-24 11:29:54 -06:00
Chris Thrasher b0b4d253d2 Add tests for sfVertexArray 2024-12-24 11:29:54 -06:00
Chris Thrasher 82d0ff2012 Add missing Freetype dependency 2024-12-23 22:33:59 -06:00
Chris Thrasher 589b86d4c0 Fix const correctness issues 2024-12-23 16:17:45 -06:00
Chris Thrasher feb431a689 Add tests for sfRenderStates 2024-12-23 10:31:53 -06:00
Chris Thrasher f6949a5a06 Add tests for sfTransform 2024-12-23 10:31:53 -06:00
Chris Thrasher ed185c838d Add tests for sfStencilMode 2024-12-23 10:31:53 -06:00
Chris Thrasher ab1a1a2299 Add tests for sfCoordinateType 2024-12-22 17:28:57 -06:00
Chris Thrasher bb8a261bb8 Add tests for sfColor 2024-12-22 17:28:57 -06:00
Chris Thrasher b3e6e23ffd Add tests for sfBlendMode 2024-12-22 17:28:57 -06:00
Chris Thrasher e46663cf38 Add tests for sfRect 2024-12-22 17:28:57 -06:00
Chris Thrasher e7a41e864f Add tests for Audio module 2024-12-22 17:05:49 -06:00
Chris Thrasher ae540e2396 Fix README typo 2024-12-22 14:58:58 -06:00
Chris Thrasher 14e06ccea4 Centrally define SFML version 2024-12-21 20:38:26 -06:00
Chris Thrasher a185b440ef Use SFML 3.0.0 tag 2024-12-21 19:08:15 -06:00
30 changed files with 1231 additions and 16 deletions

No files matched your search

+7 -4
View File
@@ -6,6 +6,9 @@ concurrency:
group: environment-${{github.ref}}
cancel-in-progress: true
env:
SFML_VERSION: 3.0.0
defaults:
run:
shell: bash
@@ -43,13 +46,13 @@ jobs:
- name: Install Linux Dependencies
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libxi-dev libudev-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev
run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libxi-dev libudev-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev libfreetype-dev
- name: Checkout SFML
uses: actions/checkout@v4
with:
repository: SFML/SFML
ref: master
ref: ${{env.SFML_VERSION}}
path: SFML
- name: Configure SFML CMake
@@ -104,7 +107,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: SFML/SFML
ref: master
ref: ${{env.SFML_VERSION}}
path: SFML
- name: Configure SFML CMake
@@ -138,7 +141,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: SFML/SFML
ref: master
ref: ${{env.SFML_VERSION}}
path: SFML
- name: Configure SFML
+2 -2
View File
@@ -150,7 +150,7 @@ CSFML_GRAPHICS_API void sfVertexArray_setPrimitiveType(sfVertexArray* vertexArra
/// \return Primitive type
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfPrimitiveType sfVertexArray_getPrimitiveType(sfVertexArray* vertexArray);
CSFML_GRAPHICS_API sfPrimitiveType sfVertexArray_getPrimitiveType(const sfVertexArray* vertexArray);
////////////////////////////////////////////////////////////
/// \brief Compute the bounding rectangle of a vertex array
@@ -163,4 +163,4 @@ CSFML_GRAPHICS_API sfPrimitiveType sfVertexArray_getPrimitiveType(sfVertexArray*
/// \return Bounding rectangle of the vertex array
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfFloatRect sfVertexArray_getBounds(sfVertexArray* vertexArray);
CSFML_GRAPHICS_API sfFloatRect sfVertexArray_getBounds(const sfVertexArray* vertexArray);
+1 -1
View File
@@ -166,7 +166,7 @@ CSFML_GRAPHICS_API void sfVertexBuffer_swap(sfVertexBuffer* left, sfVertexBuffer
/// \return OpenGL handle of the vertex buffer or 0 if not yet created
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API unsigned int sfVertexBuffer_getNativeHandle(sfVertexBuffer* vertexBuffer);
CSFML_GRAPHICS_API unsigned int sfVertexBuffer_getNativeHandle(const sfVertexBuffer* vertexBuffer);
////////////////////////////////////////////////////////////
/// \brief Set the type of primitives to draw
+3 -3
View File
@@ -191,7 +191,7 @@ CSFML_GRAPHICS_API sfFloatRect sfView_getViewport(const sfView* view);
CSFML_GRAPHICS_API sfFloatRect sfView_getScissor(const sfView* view);
////////////////////////////////////////////////////////////
/// \brief Move a view relatively to its current position
/// \brief Move a view relative to its current position
///
/// \param view View object
/// \param offset Offset
@@ -200,7 +200,7 @@ CSFML_GRAPHICS_API sfFloatRect sfView_getScissor(const sfView* view);
CSFML_GRAPHICS_API void sfView_move(sfView* view, sfVector2f offset);
////////////////////////////////////////////////////////////
/// \brief Rotate a view relatively to its current orientation
/// \brief Rotate a view relative to its current orientation
///
/// \param view View object
/// \param angle Angle to rotate, in degrees
@@ -209,7 +209,7 @@ CSFML_GRAPHICS_API void sfView_move(sfView* view, sfVector2f offset);
CSFML_GRAPHICS_API void sfView_rotate(sfView* view, float angle);
////////////////////////////////////////////////////////////
/// \brief Resize a view rectangle relatively to its current size
/// \brief Resize a view rectangle relative to its current size
///
/// Resizing the view simulates a zoom, as the zone displayed on
/// screen grows or shrinks.
+1 -1
View File
@@ -132,7 +132,7 @@ CSFML_NETWORK_API void sfIpAddress_toString(sfIpAddress address, char* string);
/// address, and should be used for optimization purposes only
/// (like sending the address through a socket).
/// The integer produced by this function can then be converted
/// back to a sfIpAddress with sfIpAddress_FromInteger.
/// back to a sfIpAddress with sfIpAddress_fromInteger.
///
/// \param address Address object
///
+6
View File
@@ -75,6 +75,8 @@ CSFML_NETWORK_API void sfPacket_append(sfPacket* packet, const void* data, size_
///
/// The next read operation will read data from this position
///
/// \param packet Packet object
///
/// \return The byte offset of the current read position
///
/// \see append
@@ -163,6 +165,8 @@ CSFML_NETWORK_API int16_t sfPacket_readInt16(sfPacket* packet);
CSFML_NETWORK_API uint16_t sfPacket_readUint16(sfPacket* packet);
CSFML_NETWORK_API int32_t sfPacket_readInt32(sfPacket* packet);
CSFML_NETWORK_API uint32_t sfPacket_readUint32(sfPacket* packet);
CSFML_NETWORK_API int64_t sfPacket_readInt64(sfPacket* packet);
CSFML_NETWORK_API uint64_t sfPacket_readUint64(sfPacket* packet);
CSFML_NETWORK_API float sfPacket_readFloat(sfPacket* packet);
CSFML_NETWORK_API double sfPacket_readDouble(sfPacket* packet);
CSFML_NETWORK_API void sfPacket_readString(sfPacket* packet, char* string);
@@ -181,6 +185,8 @@ CSFML_NETWORK_API void sfPacket_writeInt16(sfPacket* packet, int16_t);
CSFML_NETWORK_API void sfPacket_writeUint16(sfPacket* packet, uint16_t);
CSFML_NETWORK_API void sfPacket_writeInt32(sfPacket* packet, int32_t);
CSFML_NETWORK_API void sfPacket_writeUint32(sfPacket* packet, uint32_t);
CSFML_NETWORK_API void sfPacket_writeInt64(sfPacket* packet, int64_t);
CSFML_NETWORK_API void sfPacket_writeUint64(sfPacket* packet, uint64_t);
CSFML_NETWORK_API void sfPacket_writeFloat(sfPacket* packet, float);
CSFML_NETWORK_API void sfPacket_writeDouble(sfPacket* packet, double);
CSFML_NETWORK_API void sfPacket_writeString(sfPacket* packet, const char* string);
+24
View File
@@ -99,6 +99,10 @@ CSFML_NETWORK_API unsigned short sfTcpListener_getLocalPort(const sfTcpListener*
/// If the socket was previously listening to another port,
/// it will be stopped first and bound to the new port.
///
/// When providing `sfTcpListener_anyPort()` as port, the listener
/// will request an available port from the system.
/// The chosen port can be retrieved by calling `sfTcpListener_getLocalPort()`.
///
/// If there is no specific address to listen to, pass sfIpAddress_Any
///
/// \param listener TCP listener object
@@ -110,6 +114,17 @@ CSFML_NETWORK_API unsigned short sfTcpListener_getLocalPort(const sfTcpListener*
////////////////////////////////////////////////////////////
CSFML_NETWORK_API sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port, sfIpAddress address);
////////////////////////////////////////////////////////////
/// \brief Stop listening and close the socket
///
/// This function gracefully stops the listener. If the
/// socket is not listening, this function has no effect.
///
/// \param listener TCP listener object
///
////////////////////////////////////////////////////////////
CSFML_NETWORK_API void sfTcpListener_close(sfTcpListener* listener);
////////////////////////////////////////////////////////////
/// \brief Accept a new connection
///
@@ -127,3 +142,12 @@ CSFML_NETWORK_API sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, u
///
////////////////////////////////////////////////////////////
CSFML_NETWORK_API sfSocketStatus sfTcpListener_accept(sfTcpListener* listener, sfTcpSocket** connected);
////////////////////////////////////////////////////////////
/// \brief Return the special value that tells the system
/// to pick any available port
///
/// \return The value to use for any port
///
////////////////////////////////////////////////////////////
CSFML_NETWORK_API unsigned short sfTcpListener_anyPort(void);
+13
View File
@@ -102,6 +102,10 @@ CSFML_NETWORK_API unsigned short sfUdpSocket_getLocalPort(const sfUdpSocket* soc
/// system to automatically pick an available port, and then
/// call sfUdpSocket_getLocalPort to retrieve the chosen port.
///
/// When providing `sfUdpSocket_anyPort()` as port, the listener
/// will request an available port from the system.
/// The chosen port can be retrieved by calling `sfUdpSocket_getLocalPort()`.
///
/// If there is no specific address to listen to, pass sfIpAddress_Any
///
/// \param socket UDP socket object
@@ -215,3 +219,12 @@ CSFML_NETWORK_API sfSocketStatus
///
////////////////////////////////////////////////////////////
CSFML_NETWORK_API unsigned int sfUdpSocket_maxDatagramSize(void);
////////////////////////////////////////////////////////////
/// \brief Return the special value that tells the system
/// to pick any available port
///
/// \return The value to use for any port
///
////////////////////////////////////////////////////////////
CSFML_NETWORK_API unsigned short sfUdpSocket_anyPort(void);
+1 -1
View File
@@ -9,7 +9,7 @@ SFML is a simple, fast, cross-platform and object-oriented multimedia API. It pr
Development is focused on the next major version in the `master` branch. No more features are planned for the 2.x release series.
- The [`master`](https://github.com/SFML/CSFML/tree/master) branch contains work in progress for the next major version CSFML 3. As such it's considered unstable, but any testing and feedback is highly appreciated.
- The [`2.6.1`](https://github.com/SFML/CSFML/tree/2.6.1) tag is the latest official SFML release and will be the last minor release in the 2.x series.
- The [`2.6.1`](https://github.com/SFML/CSFML/tree/2.6.1) tag is the latest official CSFML release and will be the last minor release in the 2.x series.
- The [`2.6.x`](https://github.com/SFML/CSFML/tree/2.6.x) branch contains the latest bugfix work on CSFML 2.6.x, matching SFML's `2.6.x` branch.
## Authors
+2 -2
View File
@@ -104,7 +104,7 @@ void sfVertexArray_setPrimitiveType(sfVertexArray* vertexArray, sfPrimitiveType
////////////////////////////////////////////////////////////
sfPrimitiveType sfVertexArray_getPrimitiveType(sfVertexArray* vertexArray)
sfPrimitiveType sfVertexArray_getPrimitiveType(const sfVertexArray* vertexArray)
{
assert(vertexArray);
return static_cast<sfPrimitiveType>(vertexArray->getPrimitiveType());
@@ -112,7 +112,7 @@ sfPrimitiveType sfVertexArray_getPrimitiveType(sfVertexArray* vertexArray)
////////////////////////////////////////////////////////////
sfFloatRect sfVertexArray_getBounds(sfVertexArray* vertexArray)
sfFloatRect sfVertexArray_getBounds(const sfVertexArray* vertexArray)
{
assert(vertexArray);
return convertRect(vertexArray->getBounds());
+1 -1
View File
@@ -92,7 +92,7 @@ void sfVertexBuffer_swap(sfVertexBuffer* left, sfVertexBuffer* right)
////////////////////////////////////////////////////////////
unsigned int sfVertexBuffer_getNativeHandle(sfVertexBuffer* vertexBuffer)
unsigned int sfVertexBuffer_getNativeHandle(const sfVertexBuffer* vertexBuffer)
{
assert(vertexBuffer);
return vertexBuffer->getNativeHandle();
+1 -1
View File
@@ -48,7 +48,7 @@ namespace
////////////////////////////////////////////////////////////
const sfIpAddress sfIpAddress_None = sfIpAddress_fromBytes(0, 0, 0, 0);
const sfIpAddress sfIpAddress_None = {{0}};
////////////////////////////////////////////////////////////
+24
View File
@@ -156,6 +156,20 @@ uint32_t sfPacket_readUint32(sfPacket* packet)
*packet >> value;
return value;
}
int64_t sfPacket_readInt64(sfPacket* packet)
{
assert(packet);
int64_t value = 0;
*packet >> value;
return value;
}
uint64_t sfPacket_readUint64(sfPacket* packet)
{
assert(packet);
uint64_t value = 0;
*packet >> value;
return value;
}
float sfPacket_readFloat(sfPacket* packet)
{
assert(packet);
@@ -219,6 +233,16 @@ void sfPacket_writeUint32(sfPacket* packet, uint32_t value)
assert(packet);
*packet << value;
}
void sfPacket_writeInt64(sfPacket* packet, int64_t value)
{
assert(packet);
*packet << value;
}
void sfPacket_writeUint64(sfPacket* packet, uint64_t value)
{
assert(packet);
*packet << value;
}
void sfPacket_writeFloat(sfPacket* packet, float value)
{
assert(packet);
+15
View File
@@ -86,6 +86,14 @@ sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port
}
////////////////////////////////////////////////////////////
void sfTcpListener_close(sfTcpListener* listener)
{
assert(listener);
listener->close();
}
////////////////////////////////////////////////////////////
sfSocketStatus sfTcpListener_accept(sfTcpListener* listener, sfTcpSocket** connected)
{
@@ -102,3 +110,10 @@ sfSocketStatus sfTcpListener_accept(sfTcpListener* listener, sfTcpSocket** conne
return status;
}
////////////////////////////////////////////////////////////
unsigned short sfTcpListener_anyPort()
{
return 0;
}
+7
View File
@@ -203,3 +203,10 @@ unsigned int sfUdpSocket_maxDatagramSize()
{
return sf::UdpSocket::MaxDatagramSize;
}
////////////////////////////////////////////////////////////
unsigned short sfUdpSocket_anyPort()
{
return 0;
}
+29
View File
@@ -0,0 +1,29 @@
#include <CSFML/Audio/SoundChannel.h>
#include <SFML/Audio/SoundChannel.hpp>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("[Audio] sfSoundChannel")
{
STATIC_CHECK(sfSoundChannelUnspecified == static_cast<int>(sf::SoundChannel::Unspecified));
STATIC_CHECK(sfSoundChannelMono == static_cast<int>(sf::SoundChannel::Mono));
STATIC_CHECK(sfSoundChannelFrontLeft == static_cast<int>(sf::SoundChannel::FrontLeft));
STATIC_CHECK(sfSoundChannelFrontRight == static_cast<int>(sf::SoundChannel::FrontRight));
STATIC_CHECK(sfSoundChannelFrontCenter == static_cast<int>(sf::SoundChannel::FrontCenter));
STATIC_CHECK(sfSoundChannelFrontLeftOfCenter == static_cast<int>(sf::SoundChannel::FrontLeftOfCenter));
STATIC_CHECK(sfSoundChannelFrontRightOfCenter == static_cast<int>(sf::SoundChannel::FrontRightOfCenter));
STATIC_CHECK(sfSoundChannelLowFrequencyEffects == static_cast<int>(sf::SoundChannel::LowFrequencyEffects));
STATIC_CHECK(sfSoundChannelBackLeft == static_cast<int>(sf::SoundChannel::BackLeft));
STATIC_CHECK(sfSoundChannelBackRight == static_cast<int>(sf::SoundChannel::BackRight));
STATIC_CHECK(sfSoundChannelBackCenter == static_cast<int>(sf::SoundChannel::BackCenter));
STATIC_CHECK(sfSoundChannelSideLeft == static_cast<int>(sf::SoundChannel::SideLeft));
STATIC_CHECK(sfSoundChannelSideRight == static_cast<int>(sf::SoundChannel::SideRight));
STATIC_CHECK(sfSoundChannelTopCenter == static_cast<int>(sf::SoundChannel::TopCenter));
STATIC_CHECK(sfSoundChannelTopFrontLeft == static_cast<int>(sf::SoundChannel::TopFrontLeft));
STATIC_CHECK(sfSoundChannelTopFrontRight == static_cast<int>(sf::SoundChannel::TopFrontRight));
STATIC_CHECK(sfSoundChannelTopFrontCenter == static_cast<int>(sf::SoundChannel::TopFrontCenter));
STATIC_CHECK(sfSoundChannelTopBackLeft == static_cast<int>(sf::SoundChannel::TopBackLeft));
STATIC_CHECK(sfSoundChannelTopBackRight == static_cast<int>(sf::SoundChannel::TopBackRight));
STATIC_CHECK(sfSoundChannelTopBackCenter == static_cast<int>(sf::SoundChannel::TopBackCenter));
}
+24
View File
@@ -44,6 +44,23 @@ target_link_libraries(test-csfml-window PRIVATE csfml-window Catch2::Catch2WithM
set_target_warnings(test-csfml-window)
catch_discover_tests(test-csfml-window)
add_executable(test-csfml-graphics
Graphics/BlendMode.test.cpp
Graphics/Color.test.cpp
Graphics/CoordinateType.test.cpp
Graphics/PrimitiveType.test.cpp
Graphics/Rect.test.cpp
Graphics/RenderStates.test.cpp
Graphics/Shape.test.cpp
Graphics/StencilMode.test.cpp
Graphics/Transform.test.cpp
Graphics/VertexArray.test.cpp
Graphics/View.test.cpp
)
target_link_libraries(test-csfml-graphics PRIVATE csfml-graphics Catch2::Catch2WithMain SFML::Graphics)
set_target_warnings(test-csfml-graphics)
catch_discover_tests(test-csfml-graphics)
add_executable(test-csfml-network
Network/Ftp.test.cpp
Network/Http.test.cpp
@@ -54,6 +71,13 @@ target_link_libraries(test-csfml-network PRIVATE csfml-network Catch2::Catch2Wit
set_target_warnings(test-csfml-network)
catch_discover_tests(test-csfml-network)
add_executable(test-csfml-audio
Audio/SoundChannel.test.cpp
)
target_link_libraries(test-csfml-audio PRIVATE csfml-audio Catch2::Catch2WithMain SFML::Audio)
set_target_warnings(test-csfml-audio)
catch_discover_tests(test-csfml-audio)
# Copy DLLs into the same directory
if(SFML_OS_WINDOWS AND NOT CSFML_LINK_SFML_STATICALLY)
foreach(SFML_TARGET SFML::System SFML::Window SFML::Graphics SFML::Audio SFML::Network)
+105
View File
@@ -0,0 +1,105 @@
#include <CSFML/Graphics/BlendMode.h>
#include <SFML/Graphics/BlendMode.hpp>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("[Graphics] sfBlendMode")
{
SECTION("sfBlendFactor")
{
STATIC_CHECK(sfBlendFactorZero == static_cast<int>(sf::BlendMode::Factor::Zero));
STATIC_CHECK(sfBlendFactorOne == static_cast<int>(sf::BlendMode::Factor::One));
STATIC_CHECK(sfBlendFactorSrcColor == static_cast<int>(sf::BlendMode::Factor::SrcColor));
STATIC_CHECK(sfBlendFactorOneMinusSrcColor == static_cast<int>(sf::BlendMode::Factor::OneMinusSrcColor));
STATIC_CHECK(sfBlendFactorDstColor == static_cast<int>(sf::BlendMode::Factor::DstColor));
STATIC_CHECK(sfBlendFactorOneMinusDstColor == static_cast<int>(sf::BlendMode::Factor::OneMinusDstColor));
STATIC_CHECK(sfBlendFactorSrcAlpha == static_cast<int>(sf::BlendMode::Factor::SrcAlpha));
STATIC_CHECK(sfBlendFactorOneMinusSrcAlpha == static_cast<int>(sf::BlendMode::Factor::OneMinusSrcAlpha));
STATIC_CHECK(sfBlendFactorDstAlpha == static_cast<int>(sf::BlendMode::Factor::DstAlpha));
STATIC_CHECK(sfBlendFactorOneMinusDstAlpha == static_cast<int>(sf::BlendMode::Factor::OneMinusDstAlpha));
}
SECTION("sfBlendEquation")
{
STATIC_CHECK(sfBlendEquationAdd == static_cast<int>(sf::BlendMode::Equation::Add));
STATIC_CHECK(sfBlendEquationSubtract == static_cast<int>(sf::BlendMode::Equation::Subtract));
STATIC_CHECK(sfBlendEquationReverseSubtract == static_cast<int>(sf::BlendMode::Equation::ReverseSubtract));
STATIC_CHECK(sfBlendEquationMin == static_cast<int>(sf::BlendMode::Equation::Min));
STATIC_CHECK(sfBlendEquationMax == static_cast<int>(sf::BlendMode::Equation::Max));
}
SECTION("Construction")
{
constexpr sfBlendMode blendMode{};
STATIC_CHECK(blendMode.colorSrcFactor == sfBlendFactorZero);
STATIC_CHECK(blendMode.colorDstFactor == sfBlendFactorZero);
STATIC_CHECK(blendMode.colorEquation == sfBlendEquationAdd);
STATIC_CHECK(blendMode.alphaSrcFactor == sfBlendFactorZero);
STATIC_CHECK(blendMode.alphaDstFactor == sfBlendFactorZero);
STATIC_CHECK(blendMode.alphaEquation == sfBlendEquationAdd);
}
SECTION("Constants")
{
SECTION("sfBlendAlpha")
{
CHECK(sfBlendAlpha.colorSrcFactor == sfBlendFactorSrcAlpha);
CHECK(sfBlendAlpha.colorDstFactor == sfBlendFactorOneMinusSrcAlpha);
CHECK(sfBlendAlpha.colorEquation == sfBlendEquationAdd);
CHECK(sfBlendAlpha.alphaSrcFactor == sfBlendFactorOne);
CHECK(sfBlendAlpha.alphaDstFactor == sfBlendFactorOneMinusSrcAlpha);
CHECK(sfBlendAlpha.alphaEquation == sfBlendEquationAdd);
}
SECTION("sfBlendAdd")
{
CHECK(sfBlendAdd.colorSrcFactor == sfBlendFactorSrcAlpha);
CHECK(sfBlendAdd.colorDstFactor == sfBlendFactorOne);
CHECK(sfBlendAdd.colorEquation == sfBlendEquationAdd);
CHECK(sfBlendAdd.alphaSrcFactor == sfBlendFactorOne);
CHECK(sfBlendAdd.alphaDstFactor == sfBlendFactorOne);
CHECK(sfBlendAdd.alphaEquation == sfBlendEquationAdd);
}
SECTION("sfBlendMultiply")
{
CHECK(sfBlendMultiply.colorSrcFactor == sfBlendFactorDstColor);
CHECK(sfBlendMultiply.colorDstFactor == sfBlendFactorZero);
CHECK(sfBlendMultiply.colorEquation == sfBlendEquationAdd);
CHECK(sfBlendMultiply.alphaSrcFactor == sfBlendFactorDstColor);
CHECK(sfBlendMultiply.alphaDstFactor == sfBlendFactorZero);
CHECK(sfBlendMultiply.alphaEquation == sfBlendEquationAdd);
}
SECTION("sfBlendMin")
{
CHECK(sfBlendMin.colorSrcFactor == sfBlendFactorOne);
CHECK(sfBlendMin.colorDstFactor == sfBlendFactorOne);
CHECK(sfBlendMin.colorEquation == sfBlendEquationMin);
CHECK(sfBlendMin.alphaSrcFactor == sfBlendFactorOne);
CHECK(sfBlendMin.alphaDstFactor == sfBlendFactorOne);
CHECK(sfBlendMin.alphaEquation == sfBlendEquationMin);
}
SECTION("sfBlendMax")
{
CHECK(sfBlendMax.colorSrcFactor == sfBlendFactorOne);
CHECK(sfBlendMax.colorDstFactor == sfBlendFactorOne);
CHECK(sfBlendMax.colorEquation == sfBlendEquationMax);
CHECK(sfBlendMax.alphaSrcFactor == sfBlendFactorOne);
CHECK(sfBlendMax.alphaDstFactor == sfBlendFactorOne);
CHECK(sfBlendMax.alphaEquation == sfBlendEquationMax);
}
SECTION("sfBlendNone")
{
CHECK(sfBlendNone.colorSrcFactor == sfBlendFactorOne);
CHECK(sfBlendNone.colorDstFactor == sfBlendFactorZero);
CHECK(sfBlendNone.colorEquation == sfBlendEquationAdd);
CHECK(sfBlendNone.alphaSrcFactor == sfBlendFactorOne);
CHECK(sfBlendNone.alphaDstFactor == sfBlendFactorZero);
CHECK(sfBlendNone.alphaEquation == sfBlendEquationAdd);
}
}
}
+229
View File
@@ -0,0 +1,229 @@
#include <CSFML/Graphics/Color.h>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("[Graphics] sfColor")
{
SECTION("Construction")
{
constexpr sfColor color{};
STATIC_CHECK(color.r == 0);
STATIC_CHECK(color.g == 0);
STATIC_CHECK(color.b == 0);
STATIC_CHECK(color.a == 0);
}
SECTION("Constants")
{
SECTION("sfBlack")
{
CHECK(sfBlack.r == 0);
CHECK(sfBlack.g == 0);
CHECK(sfBlack.b == 0);
CHECK(sfBlack.a == 255);
}
SECTION("sfWhite")
{
CHECK(sfWhite.r == 255);
CHECK(sfWhite.g == 255);
CHECK(sfWhite.b == 255);
CHECK(sfWhite.a == 255);
}
SECTION("sfRed")
{
CHECK(sfRed.r == 255);
CHECK(sfRed.g == 0);
CHECK(sfRed.b == 0);
CHECK(sfRed.a == 255);
}
SECTION("sfGreen")
{
CHECK(sfGreen.r == 0);
CHECK(sfGreen.g == 255);
CHECK(sfGreen.b == 0);
CHECK(sfGreen.a == 255);
}
SECTION("sfBlue")
{
CHECK(sfBlue.r == 0);
CHECK(sfBlue.g == 0);
CHECK(sfBlue.b == 255);
CHECK(sfBlue.a == 255);
}
SECTION("sfYellow")
{
CHECK(sfYellow.r == 255);
CHECK(sfYellow.g == 255);
CHECK(sfYellow.b == 0);
CHECK(sfYellow.a == 255);
}
SECTION("sfMagenta")
{
CHECK(sfMagenta.r == 255);
CHECK(sfMagenta.g == 0);
CHECK(sfMagenta.b == 255);
CHECK(sfMagenta.a == 255);
}
SECTION("sfCyan")
{
CHECK(sfCyan.r == 0);
CHECK(sfCyan.g == 255);
CHECK(sfCyan.b == 255);
CHECK(sfCyan.a == 255);
}
SECTION("sfTransparent")
{
CHECK(sfTransparent.r == 0);
CHECK(sfTransparent.g == 0);
CHECK(sfTransparent.b == 0);
CHECK(sfTransparent.a == 0);
}
}
SECTION("sfColor_fromRGB")
{
const sfColor color = sfColor_fromRGB(1, 2, 3);
CHECK(color.r == 1);
CHECK(color.g == 2);
CHECK(color.b == 3);
CHECK(color.a == 255);
}
SECTION("sfColor_fromRGBA")
{
const sfColor color = sfColor_fromRGBA(4, 5, 6, 7);
CHECK(color.r == 4);
CHECK(color.g == 5);
CHECK(color.b == 6);
CHECK(color.a == 7);
}
SECTION("sfColor_fromInteger")
{
sfColor color = sfColor_fromInteger(0);
CHECK(color.r == 0);
CHECK(color.g == 0);
CHECK(color.b == 0);
CHECK(color.a == 0);
color = sfColor_fromInteger(1'000);
CHECK(color.r == 0);
CHECK(color.g == 0);
CHECK(color.b == 3);
CHECK(color.a == 232);
color = sfColor_fromInteger(1'000'000);
CHECK(color.r == 0);
CHECK(color.g == 15);
CHECK(color.b == 66);
CHECK(color.a == 64);
color = sfColor_fromInteger(1'000'000'000);
CHECK(color.r == 59);
CHECK(color.g == 154);
CHECK(color.b == 202);
CHECK(color.a == 0);
color = sfColor_fromInteger(std::numeric_limits<std::uint32_t>::max());
CHECK(color.r == 255);
CHECK(color.g == 255);
CHECK(color.b == 255);
CHECK(color.a == 255);
}
SECTION("sfColor_toInteger")
{
CHECK(sfColor_toInteger(sfBlack) == 255);
CHECK(sfColor_toInteger(sfWhite) == 4'294'967'295);
CHECK(sfColor_toInteger(sfRed) == 4'278'190'335);
CHECK(sfColor_toInteger(sfGreen) == 16'711'935);
CHECK(sfColor_toInteger(sfBlue) == 65'535);
CHECK(sfColor_toInteger(sfYellow) == 4'294'902'015);
CHECK(sfColor_toInteger(sfMagenta) == 4'278'255'615);
CHECK(sfColor_toInteger(sfYellow) == 4'294'902'015);
CHECK(sfColor_toInteger(sfTransparent) == 0);
}
SECTION("sfColor_add")
{
sfColor color = sfColor_add({}, {});
CHECK(color.r == 0);
CHECK(color.g == 0);
CHECK(color.b == 0);
CHECK(color.a == 0);
color = sfColor_add({1, 2, 3, 4}, {5, 6, 7, 8});
CHECK(color.r == 6);
CHECK(color.g == 8);
CHECK(color.b == 10);
CHECK(color.a == 12);
color = sfColor_add({10, 20, 30, 40}, {200, 210, 220, 230});
CHECK(color.r == 210);
CHECK(color.g == 230);
CHECK(color.b == 250);
CHECK(color.a == 255);
color = sfColor_add({255, 255, 255, 255}, {255, 255, 255, 25});
CHECK(color.r == 255);
CHECK(color.g == 255);
CHECK(color.b == 255);
CHECK(color.a == 255);
}
SECTION("sfColor_subtract")
{
sfColor color = sfColor_subtract({}, {});
CHECK(color.r == 0);
CHECK(color.g == 0);
CHECK(color.b == 0);
CHECK(color.a == 0);
color = sfColor_subtract({}, {10, 20, 30, 40});
CHECK(color.r == 0);
CHECK(color.g == 0);
CHECK(color.b == 0);
CHECK(color.a == 0);
color = sfColor_subtract({100, 90, 80, 70}, {30, 40, 50, 60});
CHECK(color.r == 70);
CHECK(color.g == 50);
CHECK(color.b == 30);
CHECK(color.a == 10);
}
SECTION("sfColor_modulate")
{
sfColor color = sfColor_modulate({}, {});
CHECK(color.r == 0);
CHECK(color.g == 0);
CHECK(color.b == 0);
CHECK(color.a == 0);
color = sfColor_modulate({}, {1, 2, 3, 4});
CHECK(color.r == 0);
CHECK(color.g == 0);
CHECK(color.b == 0);
CHECK(color.a == 0);
color = sfColor_modulate({5, 6, 7, 8}, {1, 2, 3, 4});
CHECK(color.r == 0);
CHECK(color.g == 0);
CHECK(color.b == 0);
CHECK(color.a == 0);
color = sfColor_modulate({128, 196, 216, 255}, {0, 128, 255, 128});
CHECK(color.r == 0);
CHECK(color.g == 98);
CHECK(color.b == 216);
CHECK(color.a == 128);
}
}
+11
View File
@@ -0,0 +1,11 @@
#include <CSFML/Graphics/CoordinateType.h>
#include <SFML/Graphics/CoordinateType.hpp>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("[Graphics] sfCoordinateType")
{
STATIC_CHECK(sfCoordinateTypeNormalized == static_cast<int>(sf::CoordinateType::Normalized));
STATIC_CHECK(sfCoordinateTypePixels == static_cast<int>(sf::CoordinateType::Pixels));
}
+15
View File
@@ -0,0 +1,15 @@
#include <CSFML/Graphics/PrimitiveType.h>
#include <SFML/Graphics/PrimitiveType.hpp>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("[Graphics] sfPrimitiveType")
{
STATIC_CHECK(sfPoints == static_cast<int>(sf::PrimitiveType::Points));
STATIC_CHECK(sfLines == static_cast<int>(sf::PrimitiveType::Lines));
STATIC_CHECK(sfLineStrip == static_cast<int>(sf::PrimitiveType::LineStrip));
STATIC_CHECK(sfTriangles == static_cast<int>(sf::PrimitiveType::Triangles));
STATIC_CHECK(sfTriangleStrip == static_cast<int>(sf::PrimitiveType::TriangleStrip));
STATIC_CHECK(sfTriangleFan == static_cast<int>(sf::PrimitiveType::TriangleFan));
}
+56
View File
@@ -0,0 +1,56 @@
#include <CSFML/Graphics/Rect.h>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("[Graphics] sfRect")
{
SECTION("Construction")
{
SECTION("float")
{
const sfFloatRect rect{};
CHECK(rect.position.x == 0.f);
CHECK(rect.position.y == 0.f);
CHECK(rect.size.x == 0.f);
CHECK(rect.size.y == 0.f);
}
SECTION("int")
{
const sfFloatRect rect{};
CHECK(rect.position.x == 0);
CHECK(rect.position.y == 0);
CHECK(rect.size.x == 0);
CHECK(rect.size.y == 0);
}
}
SECTION("contains(Vector2)")
{
SECTION("float")
{
const sfFloatRect rect{{0, 0}, {10, 10}};
CHECK(sfFloatRect_contains(&rect, {0, 0}));
CHECK(sfFloatRect_contains(&rect, {9, 0}));
CHECK(sfFloatRect_contains(&rect, {0, 9}));
CHECK(sfFloatRect_contains(&rect, {9, 9}));
CHECK(!sfFloatRect_contains(&rect, {9, 10}));
CHECK(!sfFloatRect_contains(&rect, {10, 9}));
CHECK(!sfFloatRect_contains(&rect, {10, 10}));
CHECK(!sfFloatRect_contains(&rect, {15, 15}));
}
SECTION("int")
{
const sfIntRect rect{{0, 0}, {10, 10}};
CHECK(sfIntRect_contains(&rect, {0, 0}));
CHECK(sfIntRect_contains(&rect, {9, 0}));
CHECK(sfIntRect_contains(&rect, {0, 9}));
CHECK(sfIntRect_contains(&rect, {9, 9}));
CHECK(!sfIntRect_contains(&rect, {9, 10}));
CHECK(!sfIntRect_contains(&rect, {10, 9}));
CHECK(!sfIntRect_contains(&rect, {10, 10}));
CHECK(!sfIntRect_contains(&rect, {15, 15}));
}
}
}
+41
View File
@@ -0,0 +1,41 @@
#include <CSFML/Graphics/RenderStates.h>
#include <SFML/Graphics/RenderStates.hpp>
#include <catch2/catch_test_macros.hpp>
#include "CSFML/Graphics/CoordinateType.h"
TEST_CASE("[Graphics] sfRenderStates")
{
SECTION("Construction")
{
constexpr sfRenderStates renderStates{};
STATIC_CHECK(renderStates.blendMode.colorSrcFactor == sfBlendFactorZero);
STATIC_CHECK(renderStates.blendMode.colorDstFactor == sfBlendFactorZero);
STATIC_CHECK(renderStates.blendMode.colorEquation == sfBlendEquationAdd);
STATIC_CHECK(renderStates.blendMode.alphaSrcFactor == sfBlendFactorZero);
STATIC_CHECK(renderStates.blendMode.alphaDstFactor == sfBlendFactorZero);
STATIC_CHECK(renderStates.blendMode.alphaEquation == sfBlendEquationAdd);
STATIC_CHECK(renderStates.stencilMode.stencilComparison == sfStencilComparisonNever);
STATIC_CHECK(renderStates.stencilMode.stencilUpdateOperation == sfStencilUpdateOperationKeep);
STATIC_CHECK(renderStates.stencilMode.stencilReference.value == 0);
STATIC_CHECK(renderStates.stencilMode.stencilMask.value == 0);
STATIC_CHECK(!renderStates.stencilMode.stencilOnly);
for (const auto element : renderStates.transform.matrix)
CHECK(element == 0);
STATIC_CHECK(renderStates.coordinateType == sfCoordinateTypeNormalized);
STATIC_CHECK(renderStates.texture == nullptr);
STATIC_CHECK(renderStates.shader == nullptr);
}
SECTION("sfRenderStates_default")
{
CHECK(sfRenderStates_default.blendMode.alphaDstFactor == sfBlendAlpha.alphaDstFactor);
CHECK(sfRenderStates_default.blendMode.colorDstFactor == sfBlendAlpha.colorDstFactor);
CHECK(sfRenderStates_default.blendMode.colorEquation == sfBlendAlpha.colorEquation);
CHECK(sfRenderStates_default.blendMode.alphaSrcFactor == sfBlendAlpha.alphaSrcFactor);
CHECK(sfRenderStates_default.blendMode.alphaDstFactor == sfBlendAlpha.alphaDstFactor);
CHECK(sfRenderStates_default.blendMode.alphaEquation == sfBlendAlpha.alphaEquation);
}
}
+107
View File
@@ -0,0 +1,107 @@
#include <CSFML/Graphics/Shape.h>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("[Graphics] sfShape")
{
const auto getPointCount = [](void* userData) -> std::size_t
{ return static_cast<std::vector<sfVector2f>*>(userData)->size(); };
const auto getPoint = [](std::size_t index, void* userData) -> sfVector2f
{ return static_cast<std::vector<sfVector2f>*>(userData)->operator[](index); };
std::vector<sfVector2f> points = {{0, 0}, {30, 0}, {0, 30}};
SECTION("sfShape_create")
{
const sfShape* shape = sfShape_create(getPointCount, getPoint, &points);
const sfVector2f position = sfShape_getPosition(shape);
CHECK(position.x == 0);
CHECK(position.y == 0);
CHECK(sfShape_getRotation(shape) == 0);
const sfVector2f scale = sfShape_getScale(shape);
CHECK(scale.x == 1);
CHECK(scale.y == 1);
const sfVector2f origin = sfShape_getOrigin(shape);
CHECK(origin.x == 0);
CHECK(origin.y == 0);
const sfTransform transform = sfShape_getTransform(shape);
const std::vector matrix(std::data(transform.matrix), std::data(transform.matrix) + std::size(transform.matrix));
CHECK(matrix == std::vector<float>({1, 0, 0, 0, 1, 0, 0, 0, 1}));
const sfTransform inverseTransform = sfShape_getInverseTransform(shape);
const std::vector inverseMatrix(std::data(inverseTransform.matrix),
std::data(inverseTransform.matrix) + std::size(inverseTransform.matrix));
CHECK(inverseMatrix == std::vector<float>({1, 0, 0, 0, 1, 0, 0, 0, 1}));
CHECK(sfShape_getTexture(shape) == nullptr);
const sfIntRect textureRect = sfShape_getTextureRect(shape);
CHECK(textureRect.position.x == 0);
CHECK(textureRect.position.y == 0);
CHECK(textureRect.size.x == 0);
CHECK(textureRect.size.y == 0);
const sfColor fillColor = sfShape_getFillColor(shape);
CHECK(fillColor.r == sfWhite.r);
CHECK(fillColor.g == sfWhite.g);
CHECK(fillColor.b == sfWhite.b);
CHECK(fillColor.a == sfWhite.a);
const sfColor outlineColor = sfShape_getOutlineColor(shape);
CHECK(outlineColor.r == sfWhite.r);
CHECK(outlineColor.g == sfWhite.g);
CHECK(outlineColor.b == sfWhite.b);
CHECK(outlineColor.a == sfWhite.a);
CHECK(sfShape_getOutlineThickness(shape) == 0);
CHECK(sfShape_getPointCount(shape) == 3);
const sfVector2f point = sfShape_getPoint(shape, 0);
CHECK(point.x == 0);
CHECK(point.y == 0);
const sfVector2f geometricCenter = sfShape_getGeometricCenter(shape);
CHECK(geometricCenter.x == 10);
CHECK(geometricCenter.y == 10);
const sfFloatRect localBounds = sfShape_getLocalBounds(shape);
CHECK(localBounds.position.x == 0);
CHECK(localBounds.position.y == 0);
CHECK(localBounds.size.x == 0);
CHECK(localBounds.size.y == 0);
const sfFloatRect globalBounds = sfShape_getGlobalBounds(shape);
CHECK(globalBounds.position.x == 0);
CHECK(globalBounds.position.y == 0);
CHECK(globalBounds.size.x == 0);
CHECK(globalBounds.size.y == 0);
sfShape_destroy(shape);
}
SECTION("Set/get position")
{
sfShape* shape = sfShape_create(getPointCount, getPoint, &points);
sfShape_setPosition(shape, {10, 20});
const sfVector2f position = sfShape_getPosition(shape);
CHECK(position.x == 10);
CHECK(position.y == 20);
sfShape_destroy(shape);
}
SECTION("Set/get rotation")
{
sfShape* shape = sfShape_create(getPointCount, getPoint, &points);
sfShape_setRotation(shape, 45);
CHECK(sfShape_getRotation(shape) == 45);
sfShape_destroy(shape);
}
SECTION("Set/get scale")
{
sfShape* shape = sfShape_create(getPointCount, getPoint, &points);
sfShape_setScale(shape, {0.5f, 0.75f});
const sfVector2f scale = sfShape_getScale(shape);
CHECK(scale.x == 0.5f);
CHECK(scale.y == 0.75f);
sfShape_destroy(shape);
}
SECTION("Set/get origin")
{
sfShape* shape = sfShape_create(getPointCount, getPoint, &points);
sfShape_setOrigin(shape, {80, 90});
const sfVector2f origin = sfShape_getOrigin(shape);
CHECK(origin.x == 80);
CHECK(origin.y == 90);
sfShape_destroy(shape);
}
}
+55
View File
@@ -0,0 +1,55 @@
#include <CSFML/Graphics/StencilMode.h>
#include <SFML/Graphics/StencilMode.hpp>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("[Graphics] sfStencilMode")
{
SECTION("sfStencilComparison")
{
STATIC_CHECK(sfStencilComparisonNever == static_cast<int>(sf::StencilComparison::Never));
STATIC_CHECK(sfStencilComparisonLess == static_cast<int>(sf::StencilComparison::Less));
STATIC_CHECK(sfStencilComparisonLessEqual == static_cast<int>(sf::StencilComparison::LessEqual));
STATIC_CHECK(sfStencilComparisonGreater == static_cast<int>(sf::StencilComparison::Greater));
STATIC_CHECK(sfStencilComparisonGreaterEqual == static_cast<int>(sf::StencilComparison::GreaterEqual));
STATIC_CHECK(sfStencilComparisonEqual == static_cast<int>(sf::StencilComparison::Equal));
STATIC_CHECK(sfStencilComparisonNotEqual == static_cast<int>(sf::StencilComparison::NotEqual));
STATIC_CHECK(sfStencilComparisonAlways == static_cast<int>(sf::StencilComparison::Always));
}
SECTION("sfStencilUpdateOperation")
{
STATIC_CHECK(sfStencilUpdateOperationKeep == static_cast<int>(sf::StencilUpdateOperation::Keep));
STATIC_CHECK(sfStencilUpdateOperationZero == static_cast<int>(sf::StencilUpdateOperation::Zero));
STATIC_CHECK(sfStencilUpdateOperationReplace == static_cast<int>(sf::StencilUpdateOperation::Replace));
STATIC_CHECK(sfStencilUpdateOperationIncrement == static_cast<int>(sf::StencilUpdateOperation::Increment));
STATIC_CHECK(sfStencilUpdateOperationDecrement == static_cast<int>(sf::StencilUpdateOperation::Decrement));
STATIC_CHECK(sfStencilUpdateOperationInvert == static_cast<int>(sf::StencilUpdateOperation::Invert));
}
SECTION("sfStencilValue")
{
constexpr sfStencilValue stencilValue{};
STATIC_CHECK(stencilValue.value == 0);
}
SECTION("sfStencilMode")
{
constexpr sfStencilMode stencilMode{};
STATIC_CHECK(stencilMode.stencilComparison == sfStencilComparisonNever);
STATIC_CHECK(stencilMode.stencilUpdateOperation == sfStencilUpdateOperationKeep);
STATIC_CHECK(stencilMode.stencilReference.value == 0);
STATIC_CHECK(stencilMode.stencilMask.value == 0);
STATIC_CHECK(!stencilMode.stencilOnly);
}
SECTION("sfStencilMode_default")
{
CHECK(sfStencilMode_default.stencilComparison == sfStencilComparisonAlways);
CHECK(sfStencilMode_default.stencilUpdateOperation == sfStencilUpdateOperationKeep);
CHECK(sfStencilMode_default.stencilReference.value == 0);
CHECK(sfStencilMode_default.stencilMask.value == ~0u);
CHECK(!sfStencilMode_default.stencilOnly);
}
}
+128
View File
@@ -0,0 +1,128 @@
#include <CSFML/Graphics/Transform.h>
#include <catch2/catch_test_macros.hpp>
#include <array>
TEST_CASE("[Graphics] sfTransform")
{
SECTION("Construction")
{
constexpr sfTransform transform{};
STATIC_CHECK(std::size(transform.matrix) == 9);
for (const auto element : transform.matrix)
CHECK(element == 0);
}
SECTION("sfTransform_Identity")
{
CHECK(sfTransform_Identity.matrix[0] == 1);
CHECK(sfTransform_Identity.matrix[1] == 0);
CHECK(sfTransform_Identity.matrix[2] == 0);
CHECK(sfTransform_Identity.matrix[3] == 0);
CHECK(sfTransform_Identity.matrix[4] == 1);
CHECK(sfTransform_Identity.matrix[5] == 0);
CHECK(sfTransform_Identity.matrix[6] == 0);
CHECK(sfTransform_Identity.matrix[7] == 0);
CHECK(sfTransform_Identity.matrix[8] == 1);
}
SECTION("sfTransform_fromMatrix")
{
const auto transform = sfTransform_fromMatrix(1, 2, 3, 4, 5, 6, 7, 8, 9);
CHECK(transform.matrix[0] == 1);
CHECK(transform.matrix[1] == 2);
CHECK(transform.matrix[2] == 3);
CHECK(transform.matrix[3] == 4);
CHECK(transform.matrix[4] == 5);
CHECK(transform.matrix[5] == 6);
CHECK(transform.matrix[6] == 7);
CHECK(transform.matrix[7] == 8);
CHECK(transform.matrix[8] == 9);
}
SECTION("sfTransform_getMatrix")
{
const auto transform = sfTransform_fromMatrix(1, 2, 3, 4, 5, 6, 7, 8, 9);
std::array<float, 16> matrix{};
matrix.fill(std::numeric_limits<float>::signaling_NaN());
sfTransform_getMatrix(&transform, matrix.data());
CHECK(matrix[0] == 1);
CHECK(matrix[1] == 4);
CHECK(matrix[2] == 0);
CHECK(matrix[3] == 7);
CHECK(matrix[4] == 2);
CHECK(matrix[5] == 5);
CHECK(matrix[6] == 0);
CHECK(matrix[7] == 8);
CHECK(matrix[8] == 0);
CHECK(matrix[9] == 0);
CHECK(matrix[10] == 1);
CHECK(matrix[11] == 0);
CHECK(matrix[12] == 3);
CHECK(matrix[13] == 6);
CHECK(matrix[14] == 0);
CHECK(matrix[15] == 9);
}
SECTION("sfTransform_getInverse")
{
SECTION("Identity")
{
const auto inverse = sfTransform_getInverse(&sfTransform_Identity);
for (std::size_t i = 0; i < std::size(inverse.matrix); ++i)
CHECK(inverse.matrix[0] == sfTransform_Identity.matrix[0]);
}
SECTION("Non-identity")
{
const auto transform = sfTransform_fromMatrix(1, 2, 3, 4, 5, 4, 3, 2, 1);
const auto inverse = sfTransform_getInverse(&transform);
CHECK(inverse.matrix[0] == 0.375f);
CHECK(inverse.matrix[1] == -0.5f);
CHECK(inverse.matrix[2] == 0.875f);
CHECK(inverse.matrix[3] == -1);
CHECK(inverse.matrix[4] == 1);
CHECK(inverse.matrix[5] == -1);
CHECK(inverse.matrix[6] == 0.875f);
CHECK(inverse.matrix[7] == -0.5f);
CHECK(inverse.matrix[8] == 0.375f);
}
}
SECTION("sfTransform_transformPoint")
{
}
SECTION("sfTransform_transformRect")
{
}
SECTION("sfTransform_combine")
{
}
SECTION("sfTransform_translate")
{
}
SECTION("sfTransform_rotate")
{
}
SECTION("sfTransform_rotateWithCenter")
{
}
SECTION("sfTransform_scale")
{
}
SECTION("sfTransform_scaleWithCenter")
{
}
SECTION("sfTransform_equal")
{
}
}
+116
View File
@@ -0,0 +1,116 @@
#include <CSFML/Graphics/VertexArray.h>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("[Graphics] sfVertexArray")
{
SECTION("sfVertexArray_create")
{
const sfVertexArray* vertexArray = sfVertexArray_create();
CHECK(sfVertexArray_getVertexCount(vertexArray) == 0);
CHECK(sfVertexArray_getPrimitiveType(vertexArray) == sfPoints);
const sfFloatRect bounds = sfVertexArray_getBounds(vertexArray);
CHECK(bounds.position.x == 0);
CHECK(bounds.position.y == 0);
CHECK(bounds.size.x == 0);
CHECK(bounds.size.y == 0);
sfVertexArray_destroy(vertexArray);
}
SECTION("sfVertexArray_copy")
{
sfVertexArray* vertexArray1 = sfVertexArray_create();
sfVertexArray_resize(vertexArray1, 10);
sfVertexArray_setPrimitiveType(vertexArray1, sfLines);
const sfVertexArray* vertexArray2 = sfVertexArray_copy(vertexArray1);
CHECK(sfVertexArray_getVertexCount(vertexArray2) == 10);
CHECK(sfVertexArray_getPrimitiveType(vertexArray2) == sfLines);
sfVertexArray_destroy(vertexArray2);
sfVertexArray_destroy(vertexArray1);
}
SECTION("sfVertexArray_resize")
{
sfVertexArray* vertexArray = sfVertexArray_create();
sfVertexArray_resize(vertexArray, 42);
const auto vertexCount = sfVertexArray_getVertexCount(vertexArray);
CHECK(vertexCount == 42);
for (std::size_t i = 0; i < vertexCount; ++i)
{
const auto& vertex = *sfVertexArray_getVertex(vertexArray, i);
CHECK(vertex.position.x == 0);
CHECK(vertex.position.y == 0);
CHECK(+vertex.color.r == sfWhite.r);
CHECK(+vertex.color.g == sfWhite.g);
CHECK(+vertex.color.b == sfWhite.b);
CHECK(+vertex.color.a == sfWhite.a);
CHECK(vertex.texCoords.x == 0);
CHECK(vertex.texCoords.y == 0);
}
sfVertexArray_destroy(vertexArray);
}
SECTION("sfVertexArray_clear")
{
sfVertexArray* vertexArray = sfVertexArray_create();
sfVertexArray_resize(vertexArray, 13);
sfVertexArray_setPrimitiveType(vertexArray, sfLines);
sfVertexArray_clear(vertexArray);
CHECK(sfVertexArray_getVertexCount(vertexArray) == 0);
CHECK(sfVertexArray_getPrimitiveType(vertexArray) == sfLines);
sfVertexArray_destroy(vertexArray);
}
SECTION("sfVertexArray_append")
{
sfVertexArray* vertexArray = sfVertexArray_create();
sfVertexArray_append(vertexArray, {{1, 2}, {3, 4, 5, 6}, {7, 8}});
CHECK(sfVertexArray_getVertexCount(vertexArray) == 1);
const auto& vertex = *sfVertexArray_getVertex(vertexArray, 0);
CHECK(vertex.position.x == 1);
CHECK(vertex.position.y == 2);
CHECK(+vertex.color.r == 3);
CHECK(+vertex.color.g == 4);
CHECK(+vertex.color.b == 5);
CHECK(+vertex.color.a == 6);
CHECK(vertex.texCoords.x == 7);
CHECK(vertex.texCoords.y == 8);
sfVertexArray_destroy(vertexArray);
}
SECTION("sfVertexArray_getBounds")
{
sfVertexArray* vertexArray = sfVertexArray_create();
sfVertexArray_append(vertexArray, {{1, 1}, {}, {}});
sfVertexArray_append(vertexArray, {{2, 2}, {}, {}});
sfFloatRect bounds = sfVertexArray_getBounds(vertexArray);
CHECK(bounds.position.x == 1);
CHECK(bounds.position.y == 1);
CHECK(bounds.size.x == 1);
CHECK(bounds.size.y == 1);
*sfVertexArray_getVertex(vertexArray, 0) = {{0, 0}, {}, {}};
bounds = sfVertexArray_getBounds(vertexArray);
CHECK(bounds.position.x == 0);
CHECK(bounds.position.y == 0);
CHECK(bounds.size.x == 2);
CHECK(bounds.size.y == 2);
*sfVertexArray_getVertex(vertexArray, 0) = {{5, 5}, {}, {}};
bounds = sfVertexArray_getBounds(vertexArray);
CHECK(bounds.position.x == 2);
CHECK(bounds.position.y == 2);
CHECK(bounds.size.x == 3);
CHECK(bounds.size.y == 3);
sfVertexArray_append(vertexArray, {{10, 10}, {}, {}});
bounds = sfVertexArray_getBounds(vertexArray);
CHECK(bounds.position.x == 2);
CHECK(bounds.position.y == 2);
CHECK(bounds.size.x == 8);
CHECK(bounds.size.y == 8);
sfVertexArray_destroy(vertexArray);
}
}
+157
View File
@@ -0,0 +1,157 @@
#include <CSFML/Graphics/View.h>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("[Graphics] sfView")
{
SECTION("sfView_create")
{
const sfView* view = sfView_create();
const sfVector2f center = sfView_getCenter(view);
CHECK(center.x == 500);
CHECK(center.y == 500);
const sfVector2f size = sfView_getSize(view);
CHECK(size.x == 1000);
CHECK(size.y == 1000);
CHECK(sfView_getRotation(view) == 0);
const sfFloatRect viewport = sfView_getViewport(view);
CHECK(viewport.position.x == 0);
CHECK(viewport.position.y == 0);
CHECK(viewport.size.x == 1);
CHECK(viewport.size.y == 1);
const sfFloatRect scissor = sfView_getScissor(view);
CHECK(scissor.position.x == 0);
CHECK(scissor.position.y == 0);
CHECK(scissor.size.x == 1);
CHECK(scissor.size.y == 1);
sfView_destroy(view);
}
SECTION("sfView_createFromRect")
{
const sfView* view = sfView_createFromRect({{50, 100}, {240, 360}});
const sfVector2f center = sfView_getCenter(view);
CHECK(center.x == 170);
CHECK(center.y == 280);
const sfVector2f size = sfView_getSize(view);
CHECK(size.x == 240);
CHECK(size.y == 360);
CHECK(sfView_getRotation(view) == 0);
const sfFloatRect viewport = sfView_getViewport(view);
CHECK(viewport.position.x == 0);
CHECK(viewport.position.y == 0);
CHECK(viewport.size.x == 1);
CHECK(viewport.size.y == 1);
const sfFloatRect scissor = sfView_getScissor(view);
CHECK(scissor.position.x == 0);
CHECK(scissor.position.y == 0);
CHECK(scissor.size.x == 1);
CHECK(scissor.size.y == 1);
sfView_destroy(view);
}
SECTION("sfView_copy")
{
sfView* view1 = sfView_createFromRect({{50, 100}, {240, 360}});
sfView_setViewport(view1, {{25, 40}, {100, 200}});
sfView_setScissor(view1, {{0.75f, 0.25f}, {0, 0.5f}});
const sfView* view2 = sfView_copy(view1);
const sfVector2f center = sfView_getCenter(view2);
CHECK(center.x == 170);
CHECK(center.y == 280);
const sfVector2f size = sfView_getSize(view2);
CHECK(size.x == 240);
CHECK(size.y == 360);
CHECK(sfView_getRotation(view2) == 0);
const sfFloatRect viewport = sfView_getViewport(view2);
CHECK(viewport.position.x == 25);
CHECK(viewport.position.y == 40);
CHECK(viewport.size.x == 100);
CHECK(viewport.size.y == 200);
const sfFloatRect scissor = sfView_getScissor(view2);
CHECK(scissor.position.x == 0.75f);
CHECK(scissor.position.y == 0.25f);
CHECK(scissor.size.x == 0);
CHECK(scissor.size.y == 0.5f);
sfView_destroy(view2);
sfView_destroy(view1);
}
SECTION("sfView_setCenter")
{
sfView* view = sfView_create();
sfView_setCenter(view, {400, 600});
const sfVector2f center = sfView_getCenter(view);
CHECK(center.x == 400);
CHECK(center.y == 600);
sfView_destroy(view);
}
SECTION("sfView_setSize")
{
sfView* view = sfView_create();
sfView_setSize(view, {150, 350});
const sfVector2f size = sfView_getSize(view);
CHECK(size.x == 150);
CHECK(size.y == 350);
sfView_destroy(view);
}
SECTION("sfView_setRotation")
{
sfView* view = sfView_create();
sfView_setRotation(view, 45);
CHECK(sfView_getRotation(view) == 45);
sfView_destroy(view);
}
SECTION("sfView_setViewport")
{
sfView* view = sfView_create();
sfView_setViewport(view, {{25, 40}, {100, 200}});
const sfFloatRect viewport = sfView_getViewport(view);
CHECK(viewport.position.x == 25);
CHECK(viewport.position.y == 40);
CHECK(viewport.size.x == 100);
CHECK(viewport.size.y == 200);
sfView_destroy(view);
}
SECTION("sfView_setScissor")
{
sfView* view = sfView_create();
sfView_setScissor(view, {{0.75f, 0.25f}, {0, 0.5f}});
const sfFloatRect scissor = sfView_getScissor(view);
CHECK(scissor.position.x == 0.75f);
CHECK(scissor.position.y == 0.25f);
CHECK(scissor.size.x == 0);
CHECK(scissor.size.y == 0.5f);
sfView_destroy(view);
}
SECTION("sfView_move, sfView_rotate, sfView_zoom")
{
sfView* view = sfView_create();
sfView_move(view, {15, 35});
sfView_rotate(view, 180);
sfView_zoom(view, 2);
const sfVector2f center = sfView_getCenter(view);
CHECK(center.x == 515);
CHECK(center.y == 535);
const sfVector2f size = sfView_getSize(view);
CHECK(size.x == 2000);
CHECK(size.y == 2000);
CHECK(sfView_getRotation(view) == 180);
const sfFloatRect viewport = sfView_getViewport(view);
CHECK(viewport.position.x == 0);
CHECK(viewport.position.y == 0);
CHECK(viewport.size.x == 1);
CHECK(viewport.size.y == 1);
const sfFloatRect scissor = sfView_getScissor(view);
CHECK(scissor.position.x == 0);
CHECK(scissor.position.y == 0);
CHECK(scissor.size.x == 1);
CHECK(scissor.size.y == 1);
sfView_destroy(view);
}
}
+7
View File
@@ -2,6 +2,8 @@
#include <catch2/catch_test_macros.hpp>
#include <cstring>
TEST_CASE("[Network] sfIpAddress")
{
SECTION("Constants")
@@ -10,6 +12,11 @@ TEST_CASE("[Network] sfIpAddress")
CHECK(sfIpAddress_toInteger(sfIpAddress_Any) == 0);
CHECK(sfIpAddress_toInteger(sfIpAddress_LocalHost) == 0x7F000001);
CHECK(sfIpAddress_toInteger(sfIpAddress_Broadcast) == 0xFFFFFFFF);
CHECK(std::strcmp(sfIpAddress_None.address, "") == 0);
CHECK(std::strcmp(sfIpAddress_Any.address, "0.0.0.0") == 0);
CHECK(std::strcmp(sfIpAddress_LocalHost.address, "127.0.0.1") == 0);
CHECK(std::strcmp(sfIpAddress_Broadcast.address, "255.255.255.255") == 0);
}
SECTION("sfIpAddress_fromString")
+43
View File
@@ -26,4 +26,47 @@ TEST_CASE("[Window] sfKeyboard")
STATIC_CHECK(sfScanD == static_cast<int>(sf::Keyboard::Scan::D));
STATIC_CHECK(sfScancodeCount == sf::Keyboard::ScancodeCount);
}
SECTION("sfKeyboard_isKeyPressed")
{
CHECK(!sfKeyboard_isKeyPressed(sfKeyW));
CHECK(!sfKeyboard_isKeyPressed(sfKeyA));
CHECK(!sfKeyboard_isKeyPressed(sfKeyS));
CHECK(!sfKeyboard_isKeyPressed(sfKeyD));
}
SECTION("sfKeyboard_isScancodePressed")
{
CHECK(!sfKeyboard_isScancodePressed(sfScanW));
CHECK(!sfKeyboard_isScancodePressed(sfScanA));
CHECK(!sfKeyboard_isScancodePressed(sfScanS));
CHECK(!sfKeyboard_isScancodePressed(sfScanD));
}
SECTION("sfKeyboard_localize")
{
CHECK(sfKeyboard_localize(sfScanSpace) == sfKeySpace);
}
SECTION("sfKeyboard_delocalize")
{
CHECK(sfKeyboard_delocalize(sfKeySpace) == sfScanSpace);
}
SECTION("sfKeyboard_getDescription")
{
using namespace std::string_literals;
CHECK(sfKeyboard_getDescription(sfScanF1) == "F1"s);
CHECK(sfKeyboard_getDescription(sfScanF2) == "F2"s);
CHECK(sfKeyboard_getDescription(sfScanF3) == "F3"s);
CHECK(sfKeyboard_getDescription(sfScanF4) == "F4"s);
CHECK(sfKeyboard_getDescription(sfScanF5) == "F5"s);
CHECK(sfKeyboard_getDescription(sfScanF6) == "F6"s);
CHECK(sfKeyboard_getDescription(sfScanF7) == "F7"s);
CHECK(sfKeyboard_getDescription(sfScanF8) == "F8"s);
CHECK(sfKeyboard_getDescription(sfScanF9) == "F9"s);
CHECK(sfKeyboard_getDescription(sfScanF10) == "F10"s);
CHECK(sfKeyboard_getDescription(sfScanF11) == "F11"s);
CHECK(sfKeyboard_getDescription(sfScanF12) == "F12"s);
}
}