Skip to content

Add two test cases to unit_test_web_server.cpp#160

Open
kyriesk wants to merge 2 commits into
thoth-tech:mainfrom
kyriesk:unit-test/web-server
Open

Add two test cases to unit_test_web_server.cpp#160
kyriesk wants to merge 2 commits into
thoth-tech:mainfrom
kyriesk:unit-test/web-server

Conversation

@kyriesk
Copy link
Copy Markdown

@kyriesk kyriesk commented Apr 12, 2026

Description

This PR enhances the web server unit tests by adding comprehensive edge case coverage to unit_test_web_server.cpp. The investigation analyzed both interactive tests (test_web_server.cpp, test_web_service.cpp) to determine what could be adapted to automated unit tests.

Investigation findings:

  • Interactive tests (run_single_server_test, run_multiple_server_test, run_restful_web_service) require running servers and cannot be converted to unit tests because http_request is an opaque handle that can only be created by a running web server
  • URI parsing functions like split_uri_stubs() are pure functions that work perfectly as unit tests

Changes made:

  • Added split uri stubs edge cases test case with 7 sections covering trailing slashes, consecutive slashes, nested paths, numeric segments, query strings, fragments, percent-encoded characters, and empty segments
  • Added request uri parsing test case with 3 sections testing path extraction, root path handling, and segment order preservation
  • Added documentation comments listing 13+ future test candidates that could be implemented if http_request mocking were supported

Fixes #(none - enhancement)

Type of change

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

How Has This Been Tested?

All tests were run and verified to pass:

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

Results: All tests passed (31 assertions in 3 test cases)

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 (added comments about integration test limitations)
  • 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 (Testing expansion) / Refactor

Code Quality

  • Repository: Correct. The PR is made to splashkit-core.
  • Readability: Issue identified with indentation. The PR changes the indentation style from the project-standard 4 spaces to 3 spaces. This creates inconsistency with other unit test files (e.g., unit_test_geometry.cpp) and the rest of the coresdk.
  • Maintainability: High. The added test cases for edge scenarios (multiple slashes, percent encoding, query vs. fragment) make it much easier to maintain and verify changes to URI parsing in the future.

Functionality

  • Correctness: The new tests accurately reflect how URI segments should be parsed. Specifically, handling consecutive slashes as empty stubs (// -> "") and correctly stripping query parameters while preserving fragments where appropriate is vital for routing.
  • Impact on Existing Functionality: No negative impact on library code.

Testing

  • Test Coverage: Significant improvement. The PR moves beyond basic success cases and covers complex URI structures that are likely to be encountered in real-world web applications.
  • Test Results: Logic check confirms the expected outputs align with standard URI parsing expectations.

Documentation

  • Documentation: Excellent addition of comments detailing why certain tests are currently omitted (requiring a running server) and outlining future candidates for testing.

Pull Request Details

  • Checklist Completion: All relevant items reviewed.

@222448082Ashen
Copy link
Copy Markdown

Recommendations & Observations

  1. Standardize Indentation: Please revert the indentation changes to use 4 spaces instead of 3. Consistency across the codebase is important for readability and to prevent "diff noise" in future changes.
  2. Fragment Handling: I noticed a test case for fragments:
    CHECK(split_uri_stubs("/api/users#section") == (vector<string>){"api", "users#section"});
    In many URI parsers, the fragment (#) is technically not part of the path segments. If SplashKit intended to treat #section as part of the last segment, this test is correct. However, if the fragment should be stripped like query parameters (?), this might need a revisit. Based on current SplashKit implementation, this test confirms the existing behavior.

@kyriesk kyriesk requested a review from 222448082Ashen May 15, 2026 03:46
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