Skip to content

Conversation

@rory-cd
Copy link

@rory-cd rory-cd commented Nov 17, 2025

Description

Adds unit test for the create_bitmap function from images.cpp (documentation here). The new test is named "can create and free a new bitmap".

This test includes sections covering the following:

  • Bitmap exists and is valid
  • Bitmap has correct dimensions
  • Bitmap is transparent
  • Bitmap can be drawn on
  • Bitmap can be freed

Note: Earlier unit tests performed on load_bitmap used the terms "created"/"creating". Since this function creates a new empty bitmap rather than loading from a file, the names/comments for the earlier tests have been renamed for clarity.

Type of change

  • [✓] Unit test addition

How Has This Been Tested?

Built the test project as per unit testing instructions, running skunit_tests with all tests passed.

Testing Checklist

  • [ ✓] Tested with skunit_tests

Checklist

  • [✓] My code follows the style guidelines of this project
  • [✓] I have performed a self-review of my own code
  • [✓] I have commented my code in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [✓] My changes generate no new warnings
  • [ ] I have requested a review from ... on the Pull Request

Copy link

@222448082Ashen 222448082Ashen left a comment

Choose a reason for hiding this comment

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

Description

This update adds a full set of unit tests for bitmap loading, creation, sizing, bounding shapes, and cleanup. The goal is to improve test coverage for the bitmap system and ensure behaviour is consistent across platforms.

Type of change

  • Documentation / examples only
  • New tests

Testing

The new tests cover:

  • Loading multiple bitmaps and checking validity, width, and height
  • Handling missing bitmap files
  • Freeing individual bitmaps and freeing all bitmaps
  • Retrieving bounding rectangle, bounding circle and center point
  • Creating a new bitmap, checking dimensions, checking transparency, and drawing on it

Run using the usual CMake flow:

POSIX (Linux/macOS/MSYS2)

cd projects/cmake
mkdir -p build && cd build
cmake ..
cmake --build . --parallel
ctest --output-on-failure

Windows PowerShell

cmake -S . -B build
cmake --build build --config Debug --parallel
ctest --test-dir build --output-on-failure

Required checklist

  • Unit tests added under coresdk/src/test/
  • All tests pass locally
  • No generated files were modified
  • No public API changes
  • No new resources required

Cross-platform notes

Tests passed locally on the available platform. CI will confirm Linux/macOS behaviour.

Files changed / reviewer notes

Key file:

  • coresdk/src/test/bitmap_tests.cpp — new test suite

Tests depend on the following sample assets already in the test resources folder:

  • rocket_sprt.png
  • frog.png
  • background.png

No translator, binding or API changes involved.

Copy link

@Broccoli811 Broccoli811 left a comment

Choose a reason for hiding this comment

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

This is a clear and well structured unit test that matches the PR description accurately. The test covers all essential behaviours requested in the task card targeting the "create_bitmap" function. You have included other tests like dimensions, transparency, and drawing which are nice additions.

I have run a test in my local machine, and the expected results matched the wanted behaviour.

The structure aligns with existing SplashKit testing patterns, and the use of SECTIONs keeps each behaviour isolated and easy to read. Everything in the description is reflected correctly in the code.

Right now, free_bitmap(bmp) only runs inside the final SECTION. If an earlier test fails such as dimension or transparency checks, the bitmap will not be freed. This isn’t significantly important but can cause memory to accumulate over multiple failed runs.

(You can take note of the previous test above where they free the bitmap outside of the SECTIONs)

Overall, this is a solid addition to the unit test suite and improves coverage of bitmap creation. Nice work!

@rory-cd
Copy link
Author

rory-cd commented Nov 27, 2025

Thanks @Broccoli811, good pick up! I've freed the bitmap outside of the SECTION as suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants