Skip to content

Add MAC Address Tests to Catch2 Test Suite#157

Open
kyriesk wants to merge 3 commits intothoth-tech:mainfrom
kyriesk:unit-test/mac-address
Open

Add MAC Address Tests to Catch2 Test Suite#157
kyriesk wants to merge 3 commits intothoth-tech:mainfrom
kyriesk:unit-test/mac-address

Conversation

@kyriesk
Copy link
Copy Markdown

@kyriesk kyriesk commented Mar 24, 2026

Description

This pull request migrates MAC address conversion and validation tests from the legacy test_networking.cpp test functions to the modern Catch2 test framework in unit_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

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

Note: This is primarily a test refactoring with no changes to core functionality.

Changes Made

  1. 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 cases
    • TEST_CASE("can convert hex string to mac address string") - Tests hex to MAC conversion with validation
    • TEST_CASE("check the validation of mac address") - Tests MAC address validation for valid and invalid formats
  2. Test Coverage Includes:

    • Valid MAC addresses (standard format with colons)
    • Hex conversion accuracy (both directions)
    • Invalid MAC addresses (wrong length, invalid characters, wrong format)
    • Edge cases and boundary conditions
    • Standard output for verification

How Has This Been Tested?

The converted tests maintain 100% parity with the original test_networking.cpp functions. All assertions from the original standalone tests have been preserved and converted to Catch2 REQUIRE macros. The tests have been executed against the networking library functions:

  • mac_to_hex() - Converts MAC address string to hexadecimal string
  • hex_to_mac() - Converts hexadecimal string to MAC address format
  • is_valid_mac() - Validates MAC address format

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 (maintained from original tests)
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have requested a review from @[maintainer-handle] on the Pull Request

@kyriesk
Copy link
Copy Markdown
Author

kyriesk commented Mar 29, 2026

To run these tests on WSL/Linux:

cd projects/cmake
cmake --preset Linux
cmake --build build/
cd ../../bin
./skunit_tests "check the validation of mac address"
./skunit_tests "can convert hex string to mac address string"
./skunit_tests "can convert mac address string to hex string"

Copy link
Copy Markdown

@kottochii kottochii left a comment

Choose a reason for hiding this comment

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

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.

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