Add MAC Address Tests to Catch2 Test Suite#157
Open
kyriesk wants to merge 5 commits into
Open
Conversation
Author
|
To run these tests on WSL/Linux: |
kottochii
approved these changes
Mar 29, 2026
kottochii
left a comment
There was a problem hiding this comment.
Peer review
I manually reviewed the test cases and they are testing the functionality as required. I also ran them on the local machine and ensured that they are passed.
222448082Ashen
approved these changes
May 8, 2026
222448082Ashen
left a comment
There was a problem hiding this comment.
General Information
- Type of Change: New feature (Unit Testing)
Code Quality
- Repository: Correct. The PR is made to
splashkit-core. - Readability: Issue with standard practices. The tests use
std::coutto print success messages. In unit testing frameworks like Catch2, tests should ideally remain silent on success, as the framework already provides a summary. This output can clutter the console during large test runs. - Maintainability: High. The use of macros (
TEST_MAC,TEST_MAC_HEX) for repeated values is a good practice.
Functionality
- Correctness: The tests accurately verify the conversion and validation logic:
is_valid_mac: Correctly identifies valid formats and rejects various invalid ones (wrong length, invalid characters, wrong separators).mac_to_hex: Successfully converts colon-separated MAC strings to0xprefixed hex strings.hex_to_mac: Correctly reverses the conversion.
- Impact on Existing Functionality: No impact on existing library code.
Testing
- Test Coverage: Excellent coverage for the new MAC-related networking utilities.
- Test Results: Logic check confirms the tests are comprehensive and correctly handle edge cases like invalid hex lengths.
Documentation
- Documentation: The test code is clear and follows the naming conventions of the project.
Pull Request Details
- Checklist Completion: All relevant items reviewed.
Recommendations & Observations
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request migrates MAC address conversion and validation tests from the legacy
test_networking.cpptest functions to the modern Catch2 test framework inunit_test_network.cpp.The following test cases have been converted from standalone C++ functions to Catch2 TEST_CASE format:
mac_to_hex_test()→TEST_CASE("can convert mac address string to hex string")hex_to_mac_test()→TEST_CASE("can convert hex string to mac address string")is_valid_mac_test()→TEST_CASE("check the validation of mac address")All test logic, assertions, and coverage remain identical to the original tests, ensuring no regression in functionality. This consolidation modernizes the test suite and improves maintainability by using a consistent test framework across the codebase.
Type of Change
Note: This is primarily a test refactoring with no changes to core functionality.
Changes Made
Added three new Catch2 test cases to
unit_test_network.cpp:TEST_CASE("can convert mac address string to hex string")- Tests MAC to hex conversion with positive, negative, and edge casesTEST_CASE("can convert hex string to mac address string")- Tests hex to MAC conversion with validationTEST_CASE("check the validation of mac address")- Tests MAC address validation for valid and invalid formatsTest Coverage Includes:
How Has This Been Tested?
The converted tests maintain 100% parity with the original
test_networking.cppfunctions. All assertions from the original standalone tests have been preserved and converted to Catch2REQUIREmacros. The tests have been executed against the networking library functions:mac_to_hex()- Converts MAC address string to hexadecimal stringhex_to_mac()- Converts hexadecimal string to MAC address formatis_valid_mac()- Validates MAC address formatTesting Checklist
Checklist