Skip to content

Add 'bitmap creation, save, load, and pixel verification' test (original PR#161) - #173

Open
rory-cd wants to merge 3 commits into
thoth-tech:mainfrom
rory-cd:unit-test/save-bitmap
Open

Add 'bitmap creation, save, load, and pixel verification' test (original PR#161)#173
rory-cd wants to merge 3 commits into
thoth-tech:mainfrom
rory-cd:unit-test/save-bitmap

Conversation

@rory-cd

@rory-cd rory-cd commented Aug 20, 2026

Copy link
Copy Markdown

Description

This PR is a copy of #161, created by former contributor @kyriesk. The original PR had changes requested, which I have implemented along with some minor updates:

  • The saved bitmap file is now deleted from disk immediately after being loaded
  • Test is broken up into sections
  • Bitmap checks are now performed with has_bitmap() rather than comparisons with nullptr

The file cleanup is a little messy, but save_bitmap() defaults to the user's Desktop, with their home directory as a fallback. Since the function does not return the saved filepath, manual path construction is required in order to delete the created file (I believe - happy to be corrected).

Original Description (#161)

This pull request adds comprehensive unit tests for bitmap creation, manipulation, and saving functionality in SplashKit. The new test verifies that bitmaps can be created with specific dimensions, filled with different colors using fill_rectangle_on_bitmap(), and that individual pixels can be correctly retrieved and verified using get_pixel() with color component extraction functions.

The test creates a 5x5 bitmap with five distinct color rows (white, red, green, blue, and black), then validates each color by checking the RGB components of sampled pixels to ensure the bitmap graphics functions work correctly.

Type of change

  • New feature (non-breaking change which adds functionality)

Changes Made

  • Added new test case "bitmap creation, save, and pixel verification" to coresdk/src/test/unit_tests/unit_test_graphics.cpp
  • Test covers:
    • create_bitmap() - bitmap creation with specified dimensions
    • fill_rectangle_on_bitmap() - filling bitmap regions with colors
    • color_white(), color_red(), color_green(), color_blue(), color_black() - color creation functions
    • get_pixel() - pixel retrieval from bitmap
    • red_of(), green_of(), blue_of() - RGB component extraction
    • save_bitmap() - bitmap persistence to disk
    • free_bitmap() - resource cleanup

How Has This Been Tested?

The new test was run using the skunit_tests test suite. The test:

  1. Creates a 5x5 bitmap
  2. Fills each row with a distinct color pattern
  3. Verifies pixel colors using get_pixel() and component extraction
  4. Saves the bitmap to disk for persistence
  5. Cleans up resources with free_bitmap()

All tests were run and verified to pass:

cd projects/cmake
cmake --preset Linux
cmake --build build/
cd ../../bin
./skunit_tests "[bitmap]"

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
  • My changes generate no new warnings
  • I have requested a review from ... on the Pull Request

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.

2 participants