Skip to content

Add 'bitmap creation, save, load, and pixel verification' test#161

Open
kyriesk wants to merge 1 commit intothoth-tech:mainfrom
kyriesk:unit-test/save-bitmap
Open

Add 'bitmap creation, save, load, and pixel verification' test#161
kyriesk wants to merge 1 commit intothoth-tech:mainfrom
kyriesk:unit-test/save-bitmap

Conversation

@kyriesk
Copy link
Copy Markdown

@kyriesk kyriesk commented Apr 23, 2026

Description

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

Copy link
Copy Markdown

@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.

General Information

  • Type of Change: New feature (Unit Testing)

Code Quality

  • Repository: Correct. The PR is made to splashkit-core.
  • Readability: High. The comments clearly explain each step of the test (creating the pattern, verifying rows).
  • Maintainability: High. Uses standard SplashKit color and bitmap functions.

Functionality

  • Correctness: The test case title mentions "load", but the implementation currently lacks a load_bitmap step. It verifies the pixels on the original test_bmp in memory but does not verify if the saved file on disk can be successfully reloaded and contains the correct data.
  • Impact on Existing Functionality: No impact on existing code.

Testing

  • Test Coverage: This PR adds valuable testing for get_pixel and save_bitmap.
  • Test Completeness: To fully satisfy the "save and load" requirement in the title, the test should load the saved bitmap from disk into a second bitmap object and compare its pixels to the expected colors.

Documentation

  • Documentation: The test code is well-commented and self-explanatory.

Pull Request Details

  • Checklist Completion: All relevant items reviewed.

@222448082Ashen
Copy link
Copy Markdown

Recommendations & Observations

  1. Implement the "Load" Verification: I recommend adding the following logic after save_bitmap to complete the test:
    // Load the saved bitmap back
    bitmap loaded_bmp = load_bitmap("loaded_test", "test_bitmap_pattern_5x5.png");
    REQUIRE(bitmap_width(loaded_bmp) == 5);
    REQUIRE(bitmap_height(loaded_bmp) == 5);
    
    // Verify a sample pixel from the loaded bitmap
    color loaded_pixel = get_pixel(loaded_bmp, 0, 0);
    REQUIRE(red_of(loaded_pixel) == red_of(color_white()));
    
    free_bitmap(loaded_bmp);
  2. Clean up Artifacts: Since save_bitmap writes a file to the system, consider adding a step to delete the temporary image file (test_bitmap_pattern_5x5.png) at the end of the test to keep the environment clean.
  3. Color Comparison: You can simplify the requirements by comparing the color objects directly: REQUIRE(pixel_w0 == color_white());. This is cleaner than checking each RGB component individually.

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