diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..47f1966 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,55 @@ +root = true + +# Language indent/EOL/charset overlap with .vscode/settings.json. +# Rulers, renderWhitespace, detectIndentation, mergeEditor, and +# language-server settings cannot be expressed here — they stay in +# settings.json. + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = tab +insert_final_newline = true +trim_trailing_whitespace = true + +# [bat] +[*.{bat,cmd}] +end_of_line = crlf +indent_size = 4 +indent_style = space + +# [c] +[*.{c,h}] +indent_size = 4 +indent_style = space + +# [cmake] +[{CMakeLists.txt,*.cmake}] +indent_size = 4 +indent_style = tab + +# [cpp] +[*.{cpp,cxx,hpp,hxx}] +indent_size = 4 +indent_style = space + +# [json] +[*.json] +indent_size = 2 +indent_style = space + +# [markdown] +[*.md] +indent_size = 2 +indent_style = space + +# [shellscript] +[*.{bash,sh,zsh}] +indent_size = 2 +indent_style = space + +# [yaml] +[*.{yaml,yml}] +indent_size = 2 +indent_style = space diff --git a/.gitattributes b/.gitattributes index 847b22d..1ad0590 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,22 +1,126 @@ -*.c linguist-language=C -*.h linguist-language=C +# .gitattributes — C / C++ (GitHub-hosted) +# +# Sources: GitHub Docs (line endings), git-scm gitattributes (diff=cpp), +# gitattributes/gitattributes C++.gitattributes + Common.gitattributes, +# github-linguist overrides. +# +# Linguist language-bar policy (Synesis): classify public C API headers as C +# and *.cmake as CMake scripts; keep helper scripts, IDE project files, and +# CMakeLists.txt config out of the advertised language mix. Prefer +# -linguist-detectable over linguist-detectable=false. -*.cpp linguist-language=C++ -*.hpp linguist-language=C++ -*.cxx linguist-language=C++ -*.hxx linguist-language=C++ +# Default: detect text, normalize to LF in the repository +* text=auto -*.cmake linguist-language=CMake +# --- Source --- +*.c text diff=cpp +*.c++ text diff=cpp +*.cc text diff=cpp +*.cpp text diff=cpp +*.cxx text diff=cpp +*.h text diff=cpp +*.h++ text diff=cpp +*.hh text diff=cpp +*.hpp text diff=cpp +*.hxx text diff=cpp +*.inc text +*.inl text +*.ipp text +*.tcc text +*.tpp text + +# --- Build / config --- +*.am text +*.cmake text +*.m4 text +*.mak text +*.mk text +*akefile text +CMakeLists.txt text +configure text eol=lf +configure.ac text + +# --- Scripts --- +*.bash text eol=lf +*.bat text eol=crlf +*.cmd text eol=crlf +*.ps1 text eol=crlf +*.sh text eol=lf +*.zsh text eol=lf + +# --- Docs / meta --- +*.adoc text +*.markdown text diff=markdown +*.md text diff=markdown +*.txt text +AUTHORS text +CHANGELOG text +CHANGES text +CONTRIBUTING text +COPYING text +LICENSE text +NEWS text +README text +TODO text +.gitattributes text +.gitignore text -*.cmd linguist-detectable=false -*.html linguist-detectable=false -*.sh linguist-detectable=false -*.dsp linguist-detectable=false -*.dsw linguist-detectable=false -*.sln linguist-detectable=false -*.vimrc linguist-detectable=false -*.vcxproj linguist-detectable=false +# --- Serialisation --- +*.json text +*.toml text +*.xml text +*.yaml text +*.yml text -CMakeLists.txt linguist-language=CMake -makefile linguist-detectable=false +# --- Compiled / binary artefacts --- +*.a binary +*.dll binary +*.dylib binary +*.exe binary +*.gch binary +*.la binary +*.lai binary +*.lib binary +*.lo binary +*.o binary +*.obj binary +*.out binary +*.pch binary +*.slo binary +*.so binary + +# --- Archives / images (common) --- +*.gif binary +*.gz binary +*.ico binary +*.jpeg binary +*.jpg binary +*.png binary +*.tar binary +*.zip binary + +# --- GitHub Linguist --- +**/build/** linguist-generated +**/cmake-build-*/** linguist-generated + +# Classification (C-primary / C API with C++ tests; *.cmake as CMake scripts) +*.c linguist-language=C +*.cmake linguist-language=CMake +*.cpp linguist-language=C++ +*.cxx linguist-language=C++ +*.h linguist-language=C +*.hpp linguist-language=C++ +*.hxx linguist-language=C++ +# Keep the bar on library languages (helpers / legacy IDE / docs / +# CMakeLists.txt config; leave *.cmake detectable as CMake) +*.cmd -linguist-detectable +*.dsp -linguist-detectable +*.dsw -linguist-detectable +*.html -linguist-detectable +*.sh -linguist-detectable +*.sln -linguist-detectable +*.vcxproj -linguist-detectable +*.vimrc -linguist-detectable +CMakeLists.txt -linguist-detectable +makefile -linguist-detectable diff --git a/.github/actions/install-sis-deps/action.yml b/.github/actions/install-sis-deps/action.yml new file mode 100644 index 0000000..73209b7 --- /dev/null +++ b/.github/actions/install-sis-deps/action.yml @@ -0,0 +1,109 @@ +name: Install Synesis dependencies +description: >- + Clones, builds, and installs the named Synesis Information Systems + dependencies into a single CMake prefix, and exports that prefix both as + the SIS_DEPS environment variable and as the `prefix` output. + +inputs: + build-type: + description: CMake build type, for single-configuration generators + required: false + default: Release + c-compiler: + description: C compiler name, or the selector `cl` + required: true + cpp-compiler: + description: C++ compiler name; unused for the `cl` selector + required: true + dependencies: + description: >- + Whitespace-separated synesissoftware repository names, in dependency + order. Each is configured against those already installed, so this + list is deliberately NOT in lexicographic order. + required: true + install-prefix: + description: Directory into which every dependency is installed + required: false + default: '' + toolchain: + description: >- + Toolchain selector, for a toolchain that is not implied by the compiler + names and needs its own generator; presently only `mingw`. Empty + otherwise, in which case the compiler names alone select the toolchain. + required: false + default: '' + +outputs: + prefix: + description: Directory into which every dependency was installed + value: ${{ steps.install.outputs.prefix }} + +runs: + using: composite + + steps: + - id: install + shell: bash + run: | + set -euo pipefail + + PREFIX="${{ inputs.install-prefix }}" + [ -n "$PREFIX" ] || PREFIX="${RUNNER_TEMP}/sis-deps" + + mkdir -p "$PREFIX" + + if [ "${{ inputs.toolchain }}" = "mingw" ]; then + export PATH="/mingw64/bin:$PATH" + fi + + for dep in ${{ inputs.dependencies }}; do + + echo "::group::Installing $dep" + + SRC="${RUNNER_TEMP}/${dep}-src" + BUILD="${RUNNER_TEMP}/${dep}-build" + + git clone --depth 1 "https://github.com/synesissoftware/${dep}" "$SRC" + + # NOTE: the generator and the build-type/compiler options are the + # *only* things that may differ between these paths; every other + # -D option is passed in all cases, so that no branch can silently + # ignore one. + if [ "${{ inputs.c-compiler }}" = "cl" ]; then + cmake -S "$SRC" -B "$BUILD" \ + -DBUILD_EXAMPLES=OFF \ + -DBUILD_TESTING=OFF \ + -DCMAKE_DISABLE_FIND_PACKAGE_MFC=TRUE \ + -DCMAKE_INSTALL_PREFIX="$PREFIX" \ + -DCMAKE_PREFIX_PATH="$PREFIX" + cmake --build "$BUILD" --config "${{ inputs.build-type }}" --parallel + cmake --install "$BUILD" --config "${{ inputs.build-type }}" + elif [ "${{ inputs.toolchain }}" = "mingw" ]; then + cmake -S "$SRC" -B "$BUILD" -G "MinGW Makefiles" \ + -DBUILD_EXAMPLES=OFF \ + -DBUILD_TESTING=OFF \ + -DCMAKE_BUILD_TYPE="${{ inputs.build-type }}" \ + -DCMAKE_C_COMPILER="${{ inputs.c-compiler }}" \ + -DCMAKE_CXX_COMPILER="${{ inputs.cpp-compiler }}" \ + -DCMAKE_INSTALL_PREFIX="$PREFIX" \ + -DCMAKE_PREFIX_PATH="$PREFIX" + cmake --build "$BUILD" --parallel 2 + cmake --install "$BUILD" + else + cmake -S "$SRC" -B "$BUILD" \ + -DBUILD_EXAMPLES=OFF \ + -DBUILD_TESTING=OFF \ + -DCMAKE_BUILD_TYPE="${{ inputs.build-type }}" \ + -DCMAKE_C_COMPILER="${{ inputs.c-compiler }}" \ + -DCMAKE_CXX_COMPILER="${{ inputs.cpp-compiler }}" \ + -DCMAKE_INSTALL_PREFIX="$PREFIX" \ + -DCMAKE_PREFIX_PATH="$PREFIX" + cmake --build "$BUILD" --parallel + cmake --install "$BUILD" + fi + + echo "::endgroup::" + done + + echo "prefix=$PREFIX" >> "$GITHUB_OUTPUT" + echo "SIS_DEPS=$PREFIX" >> "$GITHUB_ENV" diff --git a/.github/workflows/ci-cell.yml b/.github/workflows/ci-cell.yml new file mode 100644 index 0000000..65e1182 --- /dev/null +++ b/.github/workflows/ci-cell.yml @@ -0,0 +1,322 @@ +# +# Created: 13th October 2026 +# Updated: 13th October 2026 +# + +name: CI cell + +on: + workflow_call: + inputs: + cell-id: + required: true + type: string + os: + required: true + type: string + c-compiler: + required: true + type: string + cpp-compiler: + required: true + type: string + build-type: + required: false + type: string + default: Release + toolchain: + required: false + type: string + default: '' + +permissions: + contents: read + +jobs: + build: + name: Build (${{ inputs.cell-id }}) + runs-on: ${{ inputs.os }} + + steps: + - uses: actions/checkout@v4 + + - name: Install Clang (Ubuntu) + if: runner.os == 'Linux' && inputs.c-compiler == 'clang' + run: sudo apt-get update && sudo apt-get install -y clang + + - name: Setup MSYS2 MinGW + id: msys2 + if: runner.os == 'Windows' && inputs.toolchain == 'mingw' + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: >- + mingw-w64-x86_64-toolchain + mingw-w64-x86_64-cmake + mingw-w64-x86_64-make + + - name: Install test dependencies (STLSoft + xTests) + uses: ./.github/actions/install-sis-deps + with: + build-type: ${{ inputs.build-type }} + c-compiler: ${{ inputs.c-compiler }} + cpp-compiler: ${{ inputs.cpp-compiler }} + # Dependency order (deliberately not lexicographic): each package + # is configured against those already installed. + dependencies: STLSoft xTests + toolchain: ${{ inputs.toolchain }} + + - name: Configure + shell: bash + run: | + set -euo pipefail + if [ "${{ inputs.c-compiler }}" = "cl" ]; then + cmake -B build -S . \ + -DCMAKE_DISABLE_FIND_PACKAGE_MFC=TRUE \ + -DCMAKE_PREFIX_PATH="${{ env.SIS_DEPS }}" \ + -DBUILD_EXAMPLES=ON \ + -DBUILD_TESTING=ON + elif [ "${{ inputs.toolchain }}" = "mingw" ]; then + export PATH="/mingw64/bin:$PATH" + cmake -B build -S . -G "MinGW Makefiles" \ + -DCMAKE_BUILD_TYPE="${{ inputs.build-type }}" \ + -DCMAKE_C_COMPILER="${{ inputs.c-compiler }}" \ + -DCMAKE_CXX_COMPILER="${{ inputs.cpp-compiler }}" \ + -DCMAKE_PREFIX_PATH="${{ env.SIS_DEPS }}" \ + -DBUILD_EXAMPLES=ON \ + -DBUILD_TESTING=ON + else + cmake -B build -S . \ + -DCMAKE_BUILD_TYPE="${{ inputs.build-type }}" \ + -DCMAKE_C_COMPILER="${{ inputs.c-compiler }}" \ + -DCMAKE_CXX_COMPILER="${{ inputs.cpp-compiler }}" \ + -DCMAKE_PREFIX_PATH="${{ env.SIS_DEPS }}" \ + -DBUILD_EXAMPLES=ON \ + -DBUILD_TESTING=ON + fi + + - name: Build + shell: bash + run: | + set -euo pipefail + if [ "${{ inputs.c-compiler }}" = "cl" ]; then + cmake --build build --config "${{ inputs.build-type }}" --parallel + elif [ "${{ inputs.toolchain }}" = "mingw" ]; then + export PATH="/mingw64/bin:$PATH" + cmake --build build --parallel 2 + else + cmake --build build --parallel + fi + + - name: Test (CTest) + shell: bash + run: | + set -euo pipefail + if [ "${{ inputs.toolchain }}" = "mingw" ]; then + export PATH="/mingw64/bin:$PATH" + fi + ctest --test-dir build --output-on-failure \ + --build-config "${{ inputs.build-type }}" --timeout 60 \ + --no-tests=error + + - name: Upload build tree + uses: actions/upload-artifact@v4 + with: + name: sis-build-${{ inputs.cell-id }} + path: build + retention-days: 1 + + # Windows cells dogfood the native .cmd runners (never the .sh); every + # other cell uses the Bash runners. download-artifact strips execute bits. + run-examples: + name: Examples (${{ inputs.cell-id }}) + needs: build + runs-on: ${{ inputs.os }} + + steps: + - uses: actions/checkout@v4 + + - name: Setup MSYS2 MinGW + id: msys2 + if: runner.os == 'Windows' && inputs.toolchain == 'mingw' + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: mingw-w64-x86_64-toolchain + + - name: Download build tree + uses: actions/download-artifact@v4 + with: + name: sis-build-${{ inputs.cell-id }} + path: build + + # download-artifact does not restore Unix execute bits; + # run_all_*.sh discovery requires -perm -100 (or *.exe on Windows). + # Skip CMakeFiles and compiler deps — name globs also match + # e.g. test.unit.*.c.o.d / example*.cpp.o.d; chmod +x on those + # makes tip runners treat them as programs (exit 127). + - name: Restore execute bits on test and example binaries + if: runner.os != 'Windows' + shell: bash + run: | + set -euo pipefail + find build -type f \ + ! -path '*/CMakeFiles/*' \ + ! -name '*.d' \ + ! -name '*.o' \ + ! -name '*.obj' \ + \( \ + -name 'test_unit*' -o -name 'test.unit.*' -o \ + -name 'test_component*' -o -name 'test.component.*' -o \ + -name 'test_performance*' -o -name 'test.performance.*' -o \ + -name 'test_scratch*' -o -name 'test.scratch.*' -o \ + \( -name 'example*' ! -name '*.md' \) \ + \) -exec chmod +x {} + + + - name: Run examples (Bash) + if: runner.os != 'Windows' + shell: bash + run: | + set -euo pipefail + SIS_CMAKE_BUILD_DIR="${{ github.workspace }}/build" ./run_all_examples.sh -M + + - name: Run examples (native cmd) + if: runner.os == 'Windows' + shell: cmd + env: + MSYS2_LOCATION: ${{ steps.msys2.outputs.msys2-location }} + SIS_CMAKE_BUILD_DIR: ${{ github.workspace }}\build + run: | + if "${{ inputs.toolchain }}"=="mingw" set "PATH=%MSYS2_LOCATION%\mingw64\bin;%PATH%" + call run_all_examples.cmd + if errorlevel 1 exit /b 1 + + test-unit: + name: Unit tests (${{ inputs.cell-id }}) + needs: build + runs-on: ${{ inputs.os }} + + steps: + - uses: actions/checkout@v4 + + - name: Setup MSYS2 MinGW + id: msys2 + if: runner.os == 'Windows' && inputs.toolchain == 'mingw' + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: mingw-w64-x86_64-toolchain + + - name: Download build tree + uses: actions/download-artifact@v4 + with: + name: sis-build-${{ inputs.cell-id }} + path: build + + # download-artifact does not restore Unix execute bits; + # run_all_*.sh discovery requires -perm -100 (or *.exe on Windows). + # Skip CMakeFiles and compiler deps — name globs also match + # e.g. test.unit.*.c.o.d / example*.cpp.o.d; chmod +x on those + # makes tip runners treat them as programs (exit 127). + - name: Restore execute bits on test and example binaries + if: runner.os != 'Windows' + shell: bash + run: | + set -euo pipefail + find build -type f \ + ! -path '*/CMakeFiles/*' \ + ! -name '*.d' \ + ! -name '*.o' \ + ! -name '*.obj' \ + \( \ + -name 'test_unit*' -o -name 'test.unit.*' -o \ + -name 'test_component*' -o -name 'test.component.*' -o \ + -name 'test_performance*' -o -name 'test.performance.*' -o \ + -name 'test_scratch*' -o -name 'test.scratch.*' -o \ + \( -name 'example*' ! -name '*.md' \) \ + \) -exec chmod +x {} + + + - name: Run unit tests (Bash) + if: runner.os != 'Windows' + shell: bash + run: | + set -euo pipefail + SIS_CMAKE_BUILD_DIR="${{ github.workspace }}/build" ./run_all_unit_tests.sh -M --unit-only + + - name: Run unit tests (native cmd) + if: runner.os == 'Windows' + shell: cmd + env: + MSYS2_LOCATION: ${{ steps.msys2.outputs.msys2-location }} + SIS_CMAKE_BUILD_DIR: ${{ github.workspace }}\build + run: | + if "${{ inputs.toolchain }}"=="mingw" set "PATH=%MSYS2_LOCATION%\mingw64\bin;%PATH%" + call run_all_unit_tests.cmd --unit-only + if errorlevel 1 exit /b 1 + + test-scratch: + name: Scratch tests (${{ inputs.cell-id }}) + needs: build + runs-on: ${{ inputs.os }} + + steps: + - uses: actions/checkout@v4 + + - name: Setup MSYS2 MinGW + id: msys2 + if: runner.os == 'Windows' && inputs.toolchain == 'mingw' + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: mingw-w64-x86_64-toolchain + + - name: Download build tree + uses: actions/download-artifact@v4 + with: + name: sis-build-${{ inputs.cell-id }} + path: build + + # download-artifact does not restore Unix execute bits; + # run_all_*.sh discovery requires -perm -100 (or *.exe on Windows). + # Skip CMakeFiles and compiler deps — name globs also match + # e.g. test.unit.*.c.o.d / example*.cpp.o.d; chmod +x on those + # makes tip runners treat them as programs (exit 127). + - name: Restore execute bits on test and example binaries + if: runner.os != 'Windows' + shell: bash + run: | + set -euo pipefail + find build -type f \ + ! -path '*/CMakeFiles/*' \ + ! -name '*.d' \ + ! -name '*.o' \ + ! -name '*.obj' \ + \( \ + -name 'test_unit*' -o -name 'test.unit.*' -o \ + -name 'test_component*' -o -name 'test.component.*' -o \ + -name 'test_performance*' -o -name 'test.performance.*' -o \ + -name 'test_scratch*' -o -name 'test.scratch.*' -o \ + \( -name 'example*' ! -name '*.md' \) \ + \) -exec chmod +x {} + + + - name: Run scratch tests (Bash) + if: runner.os != 'Windows' + shell: bash + run: | + set -euo pipefail + SIS_CMAKE_BUILD_DIR="${{ github.workspace }}/build" ./run_all_scratch_tests.sh -M + + - name: Run scratch tests (native cmd) + if: runner.os == 'Windows' + shell: cmd + env: + MSYS2_LOCATION: ${{ steps.msys2.outputs.msys2-location }} + SIS_CMAKE_BUILD_DIR: ${{ github.workspace }}\build + run: | + if "${{ inputs.toolchain }}"=="mingw" set "PATH=%MSYS2_LOCATION%\mingw64\bin;%PATH%" + call run_all_scratch_tests.cmd + if errorlevel 1 exit /b 1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7380ebe --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,213 @@ +# +# Created: 13th October 2026 +# Updated: 13th October 2026 +# + +name: CI + +on: + push: + branches: + - master + - dev + - boilerplate + - idiomatic + - rc1 + - rc2 + - rc3 + pull_request: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + BUILD_TYPE: Release + +jobs: + cell: + name: CI (${{ matrix.id }}) + strategy: + fail-fast: false + matrix: + include: + - id: linux-clang + os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + - id: linux-gcc + os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + - id: macos-clang + os: macos-latest + c_compiler: clang + cpp_compiler: clang++ + - id: macos-gcc + os: macos-latest + c_compiler: gcc + cpp_compiler: g++ + - id: windows-cl + os: windows-latest + c_compiler: cl + cpp_compiler: cl + # `toolchain` carries what is not a compiler: MinGW needs its own + # generator and PATH, but the compilers it drives are gcc and g++ + - id: windows-mingw + os: windows-latest + c_compiler: gcc + cpp_compiler: g++ + toolchain: mingw + uses: ./.github/workflows/ci-cell.yml + with: + cell-id: ${{ matrix.id }} + os: ${{ matrix.os }} + c-compiler: ${{ matrix.c_compiler }} + cpp-compiler: ${{ matrix.cpp_compiler }} + build-type: Release + toolchain: ${{ matrix.toolchain }} + secrets: inherit + + install-smoke: + name: Install smoke (${{ matrix.os }}, ${{ matrix.toolchain || matrix.c_compiler }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + - os: macos-latest + c_compiler: clang + cpp_compiler: clang++ + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: windows-latest + c_compiler: gcc + cpp_compiler: g++ + toolchain: mingw + + steps: + - uses: actions/checkout@v4 + + - name: Install Clang (Ubuntu) + if: runner.os == 'Linux' && matrix.c_compiler == 'clang' + run: sudo apt-get update && sudo apt-get install -y clang + + - name: Setup MSYS2 MinGW + if: runner.os == 'Windows' && matrix.toolchain == 'mingw' + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: >- + mingw-w64-x86_64-toolchain + mingw-w64-x86_64-cmake + mingw-w64-x86_64-make + + - name: Configure + shell: bash + run: | + set -euo pipefail + if [ "${{ matrix.c_compiler }}" = "cl" ]; then + cmake -B build -S . \ + -DCMAKE_DISABLE_FIND_PACKAGE_MFC=TRUE \ + -DBUILD_EXAMPLES=OFF \ + -DBUILD_TESTING=OFF + elif [ "${{ matrix.toolchain }}" = "mingw" ]; then + export PATH="/mingw64/bin:$PATH" + cmake -B build -S . -G "MinGW Makefiles" \ + -DCMAKE_BUILD_TYPE="${{ env.BUILD_TYPE }}" \ + -DCMAKE_C_COMPILER="${{ matrix.c_compiler }}" \ + -DCMAKE_CXX_COMPILER="${{ matrix.cpp_compiler }}" \ + -DBUILD_EXAMPLES=OFF \ + -DBUILD_TESTING=OFF + else + cmake -B build -S . \ + -DCMAKE_BUILD_TYPE="${{ env.BUILD_TYPE }}" \ + -DCMAKE_C_COMPILER="${{ matrix.c_compiler }}" \ + -DCMAKE_CXX_COMPILER="${{ matrix.cpp_compiler }}" \ + -DBUILD_EXAMPLES=OFF \ + -DBUILD_TESTING=OFF + fi + + - name: Build + shell: bash + run: | + set -euo pipefail + if [ "${{ matrix.c_compiler }}" = "cl" ]; then + cmake --build build --config "${{ env.BUILD_TYPE }}" --parallel + elif [ "${{ matrix.toolchain }}" = "mingw" ]; then + export PATH="/mingw64/bin:$PATH" + cmake --build build --parallel 2 + else + cmake --build build --parallel + fi + + - name: Install + shell: bash + run: | + set -euo pipefail + PREFIX="${RUNNER_TEMP}/install-prefix" + echo "INSTALL_PREFIX=$PREFIX" >> "$GITHUB_ENV" + if [ "${{ matrix.c_compiler }}" = "cl" ]; then + cmake --install build --config "${{ env.BUILD_TYPE }}" --prefix "$PREFIX" + else + cmake --install build --prefix "$PREFIX" + fi + + - name: Verify install tree + shell: bash + run: | + set -euo pipefail + test -f "${INSTALL_PREFIX}/include/libpath/libpath.h" + test -f "${INSTALL_PREFIX}/lib/cmake/libpath/libpath-config.cmake" + + - name: Configure and run install smoke consumer + shell: bash + run: | + set -euo pipefail + CONSUMER="${RUNNER_TEMP}/consumer" + mkdir -p "$CONSUMER" + cat > "$CONSUMER/CMakeLists.txt" <<'EOF' + cmake_minimum_required(VERSION 3.13) + project(libpath_install_smoke C) + find_package(libpath REQUIRED) + add_executable(consumer consumer.c) + target_link_libraries(consumer PRIVATE libpath::core) + EOF + cat > "$CONSUMER/consumer.c" <<'EOF' + #include + int main(void) { return 0; } + EOF + if [ "${{ matrix.c_compiler }}" = "cl" ]; then + cmake -S "$CONSUMER" -B consumer-build \ + -DCMAKE_PREFIX_PATH="${INSTALL_PREFIX}" + cmake --build consumer-build --config "${{ env.BUILD_TYPE }}" --parallel + consumer-build/${{ env.BUILD_TYPE }}/consumer.exe + elif [ "${{ matrix.toolchain }}" = "mingw" ]; then + export PATH="/mingw64/bin:$PATH" + cmake -S "$CONSUMER" -B consumer-build -G "MinGW Makefiles" \ + -DCMAKE_BUILD_TYPE="${{ env.BUILD_TYPE }}" \ + -DCMAKE_C_COMPILER="${{ matrix.c_compiler }}" \ + -DCMAKE_CXX_COMPILER="${{ matrix.cpp_compiler }}" \ + -DCMAKE_PREFIX_PATH="${INSTALL_PREFIX}" + cmake --build consumer-build --parallel 2 + consumer-build/consumer.exe + else + cmake -S "$CONSUMER" -B consumer-build \ + -DCMAKE_BUILD_TYPE="${{ env.BUILD_TYPE }}" \ + -DCMAKE_C_COMPILER="${{ matrix.c_compiler }}" \ + -DCMAKE_CXX_COMPILER="${{ matrix.cpp_compiler }}" \ + -DCMAKE_PREFIX_PATH="${INSTALL_PREFIX}" + cmake --build consumer-build --parallel + consumer-build/consumer + fi diff --git a/.gitignore b/.gitignore index eed185f..226c160 100644 --- a/.gitignore +++ b/.gitignore @@ -1,166 +1,127 @@ -# Synesis Information Systems .gitignore for C/C++ libraries +# Synesis Information Systems .gitignore for C / C++ libraries # directories (by name) -/.git-old/ -/.vs/ +bin/ +ideas/ +ipch/ +lib/ +scripts/internal/ +Win32/ +x64/ +.idea/ .svn/ +.vs/ -.classpath -/.idea/ -/__pycache__ -/node_modules +__pycache__/ -/_build/ +/_analyses/ /_build-ci/ +/_build/ /_internal/ -/_analyses/ - -/bin/ -/ipch/ -/lib/ -bin/ -ipch/ -lib/ -/doc/ /docs/ /dox/ -/dox /ideas/ -ideas/ +/include/xcontract/ +/include/xcover/ /included/ +/node_modules/ /releases/ /scratch/ -/temp/ - -/--include -/--src -/-include -/-src - -/examples/bin -/examples/c/bin -/examples/cpp/bin - -/examples/lib -/examples/c/lib -/examples/cpp/lib - -projects/util/vc10-generated/ - -perf_test/ - -scripts/internal/ - -/include/b64/ -/include/shwild/ -/include/xcontract/ -/include/xcover/ -/include/xtests/ -/src/b64/ -/src/shwild/ /src/xcontract/ /src/xcover/ -/src/xtests/ +/target/ +/temp/ + +/examples/bin/ +/examples/c/bin/ +/examples/c/lib/ +/examples/cpp/bin/ +/examples/cpp/lib/ +/examples/lib/ -Debug Multithreaded DLL/ Debug Multithreaded Dll/ -Debug Multithreaded pseudoUNIX/ +Debug Multithreaded DLL/ Debug Multithreaded pseudoUnix/ +Debug Multithreaded pseudoUNIX/ Debug Multithreaded/ Debug/ +DebugDll/ DebugDLL/ DebugDLLUNIX/ -DebugDll/ -DebugMTDLL/ +DebugMt/ DebugMTDll/ +DebugMTDLL/ DebugMTUnix/ -DebugMt/ DebugNox/ -DebugUNIX/ DebugUnix/ -Release Multithreaded DLL/ +DebugUNIX/ Release Multithreaded Dll/ -Release Multithreaded pseudoUNIX/ +Release Multithreaded DLL/ Release Multithreaded pseudoUnix/ +Release Multithreaded pseudoUNIX/ Release Multithreaded/ Release/ +ReleaseDll/ ReleaseDLL/ ReleaseDLLUNIX/ -ReleaseDll/ -ReleaseMTDLL/ +ReleaseMt/ ReleaseMTDll/ +ReleaseMTDLL/ ReleaseMTUnix/ -ReleaseMt/ ReleaseNox/ ReleaseUnix/ UDebug/ UDebugMt/ -URelease/ -UReleaseMt/ -Unicode Debug Multithreaded DLL/ Unicode Debug Multithreaded Dll/ +Unicode Debug Multithreaded DLL/ Unicode Debug Multithreaded/ Unicode Debug/ -Unicode Release Multithreaded DLL/ Unicode Release Multithreaded Dll/ +Unicode Release Multithreaded DLL/ Unicode Release Multithreaded/ Unicode Release/ - -Win32/ -x64/ +URelease/ +UReleaseMt/ # directories (by pattern) -/build/ar* -/build/bc5* -/build/como* -/build/cw* -/build/gcc3* -/build/gcc4* -/build/icl* -/build/vc5* -/build/*.zip - /include-*/ # files (by name) .DS_Store + +.classpath +.env.development.local +.env.local +.env.production.local +.env.test.local .ruby-version -.ruby-version-exclusions .svnignore .svnignore-at-root .update_deps -.env.local -.env.development.local -.env.test.local -.env.production.local - -list_changes.cmd -logging-bailout.txt -prepare.cmd -sh.exe.stackdump -tidydir.cmd -update_deps.cmd +build/CMakeCache.txt build/makefile.tmpl build/makefile.tools.xml build/shwild.tmplgen -build/CMakeCache.txt - -include/fastformat/internal/dos2unix.has.been.performed include/pantheios/internal/dos2unix.has.been.performed include/stlsoft/dos2unix.has.been.performed include/stlsoft/internal/dos2unix.has.been.performed - +list_changes.cmd +logging-bailout.txt +prepare.cmd +sh.exe.stackdump test/testpatterns.orj test/tests-plan.txt +tidydir.cmd +update_deps.cmd # files (by pattern) @@ -168,8 +129,6 @@ test/tests-plan.txt *~ *.*~ *.???_obj -*.VC.db -*.VC.opendb *.a *.app *.aps @@ -177,6 +136,7 @@ test/tests-plan.txt *.bak *.chm *.class +*.csproj*user *.d *.diff *.dll @@ -213,32 +173,42 @@ test/tests-plan.txt *.slo *.so *.suo -*.swp *.sw[ponm] +*.swp *.test *.tlog *.tmp *.unsuccessfulbuild -*.vcproj*.user -*.vcxproj*.user -*.csproj*user -*.vcproj*user -*.vcxproj*user +*.VC.db +*.VC.opendb *.xcuserstate *.zip -*.vc71.sln -*.vc8.sln -*.vc9.sln +/build/*.tmpl +/build/*.tmplgen +/build/*.tools.xml +/build/*.zip +/build/ar* +/build/bc5* +/build/como* +/build/cw* +/build/gcc3* +/build/gcc4* +/build/icl* +/build/vc5* RCa0* RCb0* -build/*.tmplgen -build/*.tmpl -build/*.tools.xml - npm-debug.log* yarn-debug.log* yarn-error.log* +*.vc71.sln +*.vc8.sln +*.vc9.sln +*.vcproj*.user +*.vcproj*user +*.vcxproj*.user +*.vcxproj*user + diff --git a/.sis/ci_examples_allowed_to_fail.txt b/.sis/ci_examples_allowed_to_fail.txt new file mode 100644 index 0000000..4a6f6ac --- /dev/null +++ b/.sis/ci_examples_allowed_to_fail.txt @@ -0,0 +1,7 @@ +# Example programs that are allowed to fail: path-parse demos exit non-zero +# when invoked with no path argument (usage / invalid-args path). +# run_all_examples.{sh,cmd} still executes each of them, but reports a +# non-zero exit as anticipated rather than failing the run. +# List program names or stems (example.cpp.parse and +# example.cpp.parse.exe are equivalent). +example.cpp.parse diff --git a/.sis/project_name.txt b/.sis/project_name.txt new file mode 100644 index 0000000..097faed --- /dev/null +++ b/.sis/project_name.txt @@ -0,0 +1 @@ +libpath diff --git a/.vimrc b/.vimrc index 3be09bc..cebe6af 100644 --- a/.vimrc +++ b/.vimrc @@ -17,12 +17,12 @@ set fixeol set list set listchars=tab:->,trail:-,extends:>,precedes:<,nbsp:+ -" editor.detectIndentation: false — global defaults (editor.tabSize: 2, insertSpaces: false) -set tabstop=2 -set shiftwidth=2 -set softtabstop=2 -set noexpandtab +" editor.detectIndentation: false — global defaults (editor.tabSize: 4, insertSpaces: true) set colorcolumn=76 +set expandtab +set shiftwidth=4 +set softtabstop=4 +set tabstop=4 " colorcolumn draws a full-column tint in Vim (not a VS Code-style 1px line). " Keep it subtle via the ColorColumn highlight group; reapply after colorscheme changes. @@ -42,6 +42,8 @@ autocmd BufWritePre * %s/\s\+$//e augroup sis_c_cxx autocmd! + " [bat] + autocmd FileType bat,dosbatch setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4 colorcolumn=60,76 " [c] / [cpp] autocmd FileType c,cpp setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4 colorcolumn=60,64,68,72,76 @@ -49,19 +51,20 @@ augroup sis_c_cxx " [cmake] autocmd FileType cmake setlocal noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 - " [shellscript] - autocmd FileType sh,bash,zsh setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2 colorcolumn=60,76 - - " [bat] - autocmd FileType bat,dosbatch setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4 colorcolumn=60,76 - - " [json] / [markdown] / [yaml] / [ruby] - autocmd FileType json,markdown,yaml,ruby setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2 + " [json] / [markdown] / [ruby] / [yaml] + autocmd FileType json,markdown,ruby,yaml setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2 " [python] autocmd FileType python setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4 colorcolumn=60,76 + " [rust] + autocmd FileType rs setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4 colorcolumn=76 + + " [shellscript] + autocmd FileType bash,sh,zsh setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2 colorcolumn=60,76 + " [toml] autocmd FileType toml setlocal noexpandtab tabstop=2 shiftwidth=2 softtabstop=2 + augroup END diff --git a/.vscode/settings.json b/.vscode/settings.json index c992df2..6aa78f6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,8 +5,10 @@ "editor.tabSize": 4, }, "[c]": { + "editor.defaultFormatter": "ms-vscode.cpptools", + "editor.formatOnSave": true, "editor.insertSpaces": true, - "editor.rulers": [ 60, 64, 68, 72, 76 ], + "editor.rulers": [ 60, 64, 68, 72, 76, 120 ], "editor.tabSize": 4, }, "[cmake]": { @@ -14,8 +16,10 @@ "editor.tabSize": 4, }, "[cpp]": { + "editor.defaultFormatter": "ms-vscode.cpptools", + "editor.formatOnSave": true, "editor.insertSpaces": true, - "editor.rulers": [ 60, 64, 68, 72, 76 ], + "editor.rulers": [ 60, 64, 68, 72, 76, 120 ], "editor.tabSize": 4, }, "[json]": { @@ -34,6 +38,7 @@ }, "[ruby]": { "editor.insertSpaces": true, + "editor.rulers": [ 60, 76 ], "editor.tabSize": 2, }, "[shellscript]": { @@ -49,13 +54,28 @@ "editor.insertSpaces": true, "editor.tabSize": 2, }, + "C_Cpp.autocompleteAddParentheses": true, + "C_Cpp.clang_format_fallbackStyle": "none", + "C_Cpp.clang_format_style": "file", + "C_Cpp.default.cStandard": "c17", + "C_Cpp.default.cppStandard": "c++17", + "C_Cpp.enhancedColorization": "enabled", + "C_Cpp.errorSquiggles": "enabled", + "C_Cpp.formatting": "clangFormat", + "C_Cpp.intelliSenseEngine": "default", "cmake.configureOnOpen": false, + "debug.allowBreakpointsEverywhere": true, "editor.detectIndentation": false, "editor.insertSpaces": false, "editor.renderWhitespace": "all", "editor.rulers": [ 76 ], "editor.tabSize": 2, "files.associations": { + "*.gemspec": "ruby", + "*.mdoc": "troff", + "*.roff": "troff", + "Gemfile": "ruby", + "Rakefile": "ruby", "__bit_reference": "cpp", "__bits": "cpp", "__config": "cpp", @@ -76,13 +96,17 @@ "__tuple": "cpp", "__verbose_abort": "cpp", "algorithm": "cpp", + "api.h": "c", "array": "cpp", "atomic": "cpp", + "auto_buffer.h": "c", "bit": "cpp", "bitset": "cpp", "cctype": "cpp", "charconv": "cpp", "chrono": "cpp", + "clasp.h": "c", + "cli_helpers.h": "c", "clocale": "cpp", "cmath": "cpp", "compare": "cpp", @@ -109,6 +133,7 @@ "functional": "cpp", "implicit_link.h": "c", "initializer_list": "cpp", + "invoke.h": "c", "io.h": "c", "iomanip": "cpp", "ios": "cpp", @@ -119,29 +144,48 @@ "limits": "cpp", "list": "cpp", "locale": "cpp", + "main.h": "c", "map": "cpp", "memory": "cpp", "memory_resource": "cpp", "mutex": "cpp", + "net_helpers.h": "c", "new": "cpp", + "numbers": "cpp", "numeric": "cpp", "optional": "cpp", "ostream": "cpp", + "path_functions.h": "c", + "print": "cpp", "queue": "cpp", + "random": "cpp", + "ranges": "cpp", "ratio": "cpp", + "rc.h": "c", + "recls.h": "c", + "result_codes_.h": "c", + "semaphore": "cpp", "set": "cpp", "setenv.h": "c", "shwild.h": "c", + "sleep_functions.h": "c", + "span": "cpp", "sstream": "cpp", "stack": "cpp", + "stdatomic.h": "c", + "stdbool.h": "c", "stdexcept": "cpp", "stdio.h": "c", + "stock.h": "c", + "stop_token": "cpp", "streambuf": "cpp", "string": "cpp", "string_view": "cpp", "system_error": "cpp", "terse-api.h": "c", + "text_encoding": "cpp", "thread": "cpp", + "trace.h": "c", "tuple": "cpp", "type_traits": "cpp", "typeinfo": "cpp", @@ -152,7 +196,9 @@ "utility": "cpp", "variant": "cpp", "vector": "cpp", + "williamscrc.h": "c", "xfacet": "cpp", + "xhash": "cpp", "xiosbase": "cpp", "xlocale": "cpp", "xlocbuf": "cpp", @@ -170,5 +216,5 @@ }, "files.insertFinalNewline": true, "files.trimTrailingWhitespace": true, + "git.mergeEditor": false, } - diff --git a/AUTHORS.md b/AUTHORS.md index 703a314..fa73563 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,6 +1,14 @@ -# libpath - AUTHORS +# libpath - Authors +## Major Contributors: - +* Matt Wilson ([mwsis](https://github.com/mwsis)) + + +---- +Contributions are welcomed. + + + diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 0000000..bb16aab --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,69 @@ +# libpath - Changes + + +## 0.3.0-beta1 - 14th October 2026 + +* Applied **misc-dev-scripts** editor/Git/`.sis` drop-in templates (**.editorconfig**, **.gitattributes**, **.gitignore**, **.vimrc**, **.vscode/settings.json**); +* Added **.sis/project_name.txt** and **.sis/script_info_lines.txt**; listed **example.cpp.parse** in **.sis/ci_examples_allowed_to_fail.txt**; +* Aligned CMake helper scripts with **misc-dev-scripts** gold (SisClr), retaining **prepare_cmake.sh** `--stlsoft-root-dir` and `--simulate-windows-on-unix`; +* Added native Windows **run_all_*.cmd** runners and the full **run_all_*** suite (unit, component, automated, examples, scratch, performance); +* Added modular GitHub Actions CI (**ci.yml** / **ci-cell.yml**) with **install-sis-deps**, install-smoke, Windows `.cmd` dogfood, and execute-bit restore after artifact download; +* Added CMake scratch version reporter **test.scratch.versions** under **test/scratch/versions/**; +* Computed `LIBPATH_VER` from `LIBPATH_VER_MAJOR` / `_MINOR` / `_PATCH` / `_RELSTATUS` in **version.h**; +* Renamed the prerelease discriminator to `LIBPATH_VER_RELSTATUS` (`0x81` for **0.3.0-beta1**), retaining `LIBPATH_VER_ALPHABETA` as a documentation-hidden alias; +* Dropped a dead PRIVATE **STLSoft** link from the exported **core** target; absorbed `MSVC_USE_MT` in the top-level **CMakeLists.txt**; +* Registered unit tests via `add_test`; fixed **test.unit.parse.C** Windows path-offset and UNC compile issues; +* Shortened example directory/source to **examples/cpp/parse/** / **main.cpp** (target **example.cpp.parse**; formerly **example.cpp.parse.1**); +* Shortened unit-test directories to subject names under **test/unit/** (**compare**, **compare.C**, **equal**, **equal.C**, **parse**, **parse.C**, **shim-strings**, **type-strings**, **version**), with **entry.c** / **entry.cpp** sources and matching **test.unit.*** targets; +* Shortened scratch **test.scratch.compare.models** to **test/scratch/compare-models/** (**main.cpp**; target **test.scratch.compare-models**); +* Switched unit-test assertion statements to the **xTests** Terse API short forms (via **xtests/terse-api.h**); +* Created **CHANGES.md** from **HISTORY.md** and removed the subsumed **HISTORY.md**; upgraded **NEWS.md** to a three-column chronology with **Details**; +* Project boilerplate updates (**AUTHORS.md**, **FAQ.md**, **REQUISITES.md**, **TODO.md**, **LICENSE**, **README.md** CI badge and dependency links); + + +## 0.3.0-alpha1 - 15th March 2025 + +* Changed API; + + +## 0.2.0-alpha5 - 23rd February 2025 + +* Boilerplate tidying; + + +## 0.2.0-alpha4 - 23rd October 2024 + +* Minor updates; + + +## 0.2.0-alpha3 - 19th October 2024 + +* C++ overloads in the API; +* **CMake** build scripts enhancements; +* **CMake** improvements; +* MinGW compatibility; + + +## 0.2.0-alpha2 - 27th July 2024 + +* **CMake** compatibility; +* Windows compatibility; +* Visual C++ 17 compatibility; + + +## 0.1.5.21 - 11th February 2024 + +* Many changes; + + +## 0.1.4 - 20th November 2016 + +* Initial public release; + + +## 0.1.0 - 9th November 2012 + +* First (internal) implementation; + + + diff --git a/CMakeLists.txt b/CMakeLists.txt index 601c543..63797a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ # Purpose: Top-level CMake lists file for libpath # # Created: 7th February 2024 -# Updated: 23rd February 2025 +# Updated: 13th October 2026 # # ######################################################################## # @@ -41,12 +41,12 @@ string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) # handle version number set(RX_PROJ_TAG "${PROJECT_NAME_UPPER}") set(RX_WS "[ \t]") -file(READ "${CMAKE_SOURCE_DIR}/include/${PROJECT_NAME_LOWER}/${PROJECT_NAME_LOWER}.h" _header_file) +file(READ "${CMAKE_SOURCE_DIR}/include/${PROJECT_NAME_LOWER}/common/version.h" _header_file) string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_MAJOR${RX_WS}+([0-9]+)" MAJOR_DUMMY ${_header_file}) set(_VERSION_MAJOR ${CMAKE_MATCH_1}) string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_MINOR${RX_WS}+([0-9]+)" MINOR_DUMMY ${_header_file}) set(_VERSION_MINOR ${CMAKE_MATCH_1}) -string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_REVISION${RX_WS}+([0-9]+)" PATCH_DUMMY ${_header_file}) +string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_PATCH${RX_WS}+([0-9]+)" PATCH_DUMMY ${_header_file}) set(_VERSION_PATCH ${CMAKE_MATCH_1}) # set project version number here @@ -71,6 +71,18 @@ if(MSVC) set(CMAKE_C_STANDARD 90) set(CMAKE_CXX_STANDARD 98) endif() + + if(MSVC_USE_MT) + + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + endif(MSVC_USE_MT) +else(MSVC) + + if(MSVC_USE_MT) + + # this here just to absorb warning about not using `MSVC_USE_MT` (to + # enable **prepare_cmake.sh** to be simple) + endif(MSVC_USE_MT) endif(MSVC) diff --git a/FAQ.md b/FAQ.md index e69de29..07446ff 100644 --- a/FAQ.md +++ b/FAQ.md @@ -0,0 +1,28 @@ +# libpath - FAQ + +The FAQ list is under (constant) development. If you post a question on the +Issues forum (https://github.com/synesissoftware/libpath/issues) +it will be used to create one. + +- [Q1: "How do I build libpath?"](#q1-how-do-i-build-libpath) +- [Q2: "Does libpath have its own unit-tests?"](#q2-does-libpath-have-its-own-unit-tests) + + +# FAQs: + +## Q1: "How do I build libpath?" + +See instructions in [INSTALL.md](./INSTALL.md). + + +## Q2: "Does libpath have its own unit-tests?" + +Yes. Automated **unit** tests live under **test/unit**; they are expected to +**pass** (see **run_all_unit_tests.sh** in [INSTALL.md](./INSTALL.md)). + +**Scratch** programs under **test/scratch** are for human inspection and +smoke (for example **test.scratch.versions**); they are not the automated +unit suite. + + + diff --git a/HISTORY.md b/HISTORY.md deleted file mode 100644 index 2627024..0000000 --- a/HISTORY.md +++ /dev/null @@ -1,57 +0,0 @@ -# libpath - History - -15th March 2025 - 0.3.0-alpha1 released ---------------------------------------- - - * changed API; - - -23rd February 2025 - 0.2.0-alpha5 released ------------------------------------------- - - * boilerplate tidying - - -23rd October 2024 - 0.2.0-alpha4 released ------------------------------------------ - -* Minor updates; - - -19th October 2024 - 0.2.0-alpha3 released ------------------------------------------ - -* C++ overloads in the API; -* CMake build scripts enhancements; -* CMake improvements; -* MinGW compatibility; - - -27th July 2024 - 0.2.0-alpha2 released --------------------------------------- - -* CMake compability -* Windows compatibility -* Visual C++ 17 compatibility - - -11th February 2024 - 0.1.5.21 released --------------------------------------- - -* many changes - - -20th November 2016 - 0.1.4 released ------------------------------------ - -* initial public release - - -9th November 2012 ------------------ - -* first (internal) implementation - - - - diff --git a/INSTALL.md b/INSTALL.md index 3b854bc..48e35e9 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -46,7 +46,7 @@ The primary choice for installation is by use of **CMake**. not need this step.) 4. As a check, execute the built test program files via the - **build_run_all_unit_tests.sh** script, as in: + **run_all_unit_tests.sh** script, as in: ```bash $ ./run_all_unit_tests.sh @@ -59,7 +59,7 @@ The primary choice for installation is by use of **CMake**. $ sudo cmake --install ${SIS_CMAKE_BUILD_DIR:-./_build} --config Release ``` -7. Then to use the library, it is a simple matter as follows: +6. Then to use the library, it is a simple matter as follows: 1. Assuming a simple program that will verify the installation: diff --git a/LICENSE b/LICENSE index 8554931..f72483c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ libpath - BSD 3-Clause License -Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems +Copyright (c) 2019-2026, Matthew Wilson and Synesis Information Systems Copyright (c) 2012-2019, Matthew Wilson and Synesis Software All rights reserved. diff --git a/NEWS.md b/NEWS.md index 44fa2aa..db42639 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,16 +1,17 @@ -# libpath - News +# libpath - News -| Date | News Item | -| --------------------- | ----------------------------------------- | -| 15th March 2025 | libpath 0.3.0 (alpha 1) released | -| 23rd February 2025 | libpath 0.2.0 (alpha 5) released | -| 23rd October 2024 | libpath 0.2.0 (alpha 4) released | -| 19th October 2024 | libpath 0.2.0 (alpha 3) released | -| 27th July 2024 | libpath 0.2.0 (alpha 2) released | -| 11th February 2024 | libpath 0.1.5.21 released | -| 20th November 2016 | libpath 0.1.4 released | -| 9th November 2012 | project inception | +| Date | News Item | Details | +| ------------------- | ----------------------------------- | ------------------------------- | +| 14th October 2026 | Release of [**libpath** 0.3.0-beta1](https://github.com/synesissoftware/libpath/releases/tag/0.3.0-beta1) | Gold helpers; modular CI; `LIBPATH_VER_RELSTATUS` | +| 15th March 2025 | Release of [**libpath** 0.3.0-alpha1](https://github.com/synesissoftware/libpath/releases/tag/0.3.0-alpha1) | Changed API | +| 23rd February 2025 | Release of [**libpath** 0.2.0-alpha5](https://github.com/synesissoftware/libpath/releases/tag/0.2.0-alpha5) | Boilerplate tidying | +| 23rd October 2024 | Release of **libpath** 0.2.0-alpha4 | Minor updates | +| 19th October 2024 | Release of **libpath** 0.2.0-alpha3 | C++ overloads; **CMake**; MinGW | +| 27th July 2024 | Release of **libpath** 0.2.0-alpha2 | **CMake**; Windows; VC++ 17 | +| 11th February 2024 | Release of **libpath** 0.1.5.21 | Many changes | +| 20th November 2016 | Release of **libpath** 0.1.4 | Initial public release | +| 9th November 2012 | Project inception | First (internal) implementation | - + diff --git a/README.md b/README.md index d8204a6..29cadf4 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,14 @@ Path parsing library (for C and C++) +![C](https://img.shields.io/badge/C-00599C?style=flat&logo=c&logoColor=white) +![C++](https://img.shields.io/badge/C%2B%2B-00599C?style=flat&logo=c%2B%2B&logoColor=white) +[![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) +[![GitHub release](https://img.shields.io/github/v/release/synesissoftware/libpath.svg)](https://github.com/synesissoftware/libpath/releases/latest) +[![Last Commit](https://img.shields.io/github/last-commit/synesissoftware/libpath)](https://github.com/synesissoftware/libpath/commits/master) +[![CI](https://github.com/synesissoftware/libpath/actions/workflows/ci.yml/badge.svg)](https://github.com/synesissoftware/libpath/actions/workflows/ci.yml) + + ## Table of Contents - [Introduction](#introduction) @@ -68,8 +76,8 @@ If you'd like to help out with the project, please raise an issue via [GitHub Pa In order to run the test programs, **libpath** has the following development dependencies: -* [STLSoft 1.11](http://github.com/synesissoftware/STLSoft-1.11/); -* [xTests](http://github.com/synesissoftware/xTests/); +* [STLSoft](https://github.com/synesissoftware/STLSoft) **1.11** or later; +* [xTests](https://github.com/synesissoftware/xTests) **0.26** or later; ### Related projects diff --git a/REQUISITES.md b/REQUISITES.md index e69de29..6221252 100644 --- a/REQUISITES.md +++ b/REQUISITES.md @@ -0,0 +1,18 @@ +# libpath - Requisites + + +## Runtime / build + +**libpath** has no proper (runtime / build) dependencies outside the C +standard library and, for its C++ API, the C++ standard library. + + +## Development + +In order to build and run the test and example programs, **libpath** needs: + +* [STLSoft](https://github.com/synesissoftware/STLSoft) **1.11** or later; +* [xTests](https://github.com/synesissoftware/xTests) **0.26** or later; + + + diff --git a/build_cmake.sh b/build_cmake.sh index 3e0af65..a675a9d 100755 --- a/build_cmake.sh +++ b/build_cmake.sh @@ -1,19 +1,119 @@ #! /bin/bash -ScriptPath=$0 -Dir=$(cd $(dirname "$ScriptPath"); pwd) -Basename=$(basename "$ScriptPath") +# ########################################################## +# functions - 1 + +sis_cmake_is_truey() { + case "$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')" in + + 1|ok|on|true|yes|y) + + return 0 + ;; + *) + + return 1 + ;; + esac +} + + +# ########################################################## +# constants and variables + +Basename=$(basename "$0") +Dir=$(cd "$(dirname "$0")" && pwd) CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build} -MakeCmd=${SIS_CMAKE_COMMAND:-make} +ProjectNameFile="$Dir/.sis/project_name.txt" +ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile") +ScriptPath=$0 +AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}} IgnoreRemainingFlagsAndOptions=0 +SisUseColours=0 Targets=() # ########################################################## -# functions +# colours +# +# Enable when tput is available and either: +# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if +# empty/dumb), or +# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of +# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a +# TTY is OK). + +SisClr_Blue= +SisClr_Bold= +SisClr_Green= +SisClr_None= +SisClr_Red= +SisClr_Yellow= + +for arg in "$@"; do + + case $arg in + --always-use-colors|--always-use-colours|-A) + + AlwaysUseColours=1 + ;; + esac +done + +if command -v tput >/dev/null 2>&1; then + + if [ $AlwaysUseColours -ne 0 ]; then + + if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then + + TERM=xterm-256color + fi + + SisUseColours=1 + elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then + + SisUseColours=1 + fi +fi + +if [ $SisUseColours -ne 0 ]; then + + SisClr_Blue=${FG_BLUE:-$(tput setaf 4)} + SisClr_Bold=${FD_BOLD:-$(tput bold)} + SisClr_Green=${FG_GREEN:-$(tput setaf 2)} + SisClr_None=${FD_NONE:-$(tput sgr0)} + SisClr_Red=${FG_RED:-$(tput setaf 1)} + SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)} +fi + +CMakeDirClr="${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None}" +ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}" +ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}" + + +# ########################################################## +# functions - 2 + +sis_cmake_build() { -function join_by { local IFS="$1"; shift; echo "$*"; } + local config="${SIS_CMAKE_CONFIG:-Release}" + local args=(--build "$CMakeDir") + if [ -f "$CMakeDir/CMakeCache.txt" ] && grep -q '^CMAKE_CONFIGURATION_TYPES:' "$CMakeDir/CMakeCache.txt" 2>/dev/null; then + + args+=(--config "$config") + fi + if [ "$#" -gt 0 ]; then + + local t + for t in "$@"; do + + args+=(--target "$t") + done + fi + + cmake "${args[@]}" +} # ########################################################## @@ -23,21 +123,16 @@ while [[ $# -gt 0 ]]; do if [ $IgnoreRemainingFlagsAndOptions -ne 0 ]; then - Targets+=($1) - + Targets+=("$1") shift - continue - else - - if [ ! ${1:0:1} = '-' ]; then - - Targets+=($1) + fi - shift + if [ "${1:0:1}" != '-' ]; then - continue - fi + Targets+=("$1") + shift + continue fi case $1 in @@ -45,18 +140,33 @@ while [[ $# -gt 0 ]]; do IgnoreRemainingFlagsAndOptions=1 ;; + --always-use-colors|--always-use-colours|-A) + + # AlwaysUseColours=1 - this is handled by the for loop above + ;; --help) [ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt" cat << EOF Executes CMake-generated artefacts to (re)build project -$ScriptPath [ ... flags/options ... ] +${ScriptPath} [ ... flags/options ... ] Flags/options: behaviour: + (no arguments) + builds all default targets + + ... + builds one or more specific targets + + -A + --always-use-colors + --always-use-colours + forces use of colours even when stdout is not a TTY + standard flags: @@ -69,7 +179,7 @@ EOF ;; *) - >&2 echo "$ScriptPath: unrecognised argument '$1'; use --help for usage" + >&2 echo "${ScriptPathClr}: unrecognised argument '${SisClr_Red}${SisClr_Bold}$1${SisClr_None}'; use --help for usage" exit 1 ;; @@ -82,41 +192,26 @@ done # ########################################################## # main() -if [ ! -d "$CMakeDir" ]; then +if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ]; then - >&2 echo "$ScriptPath: CMake build directory '$CMakeDir' not found so nothing to do; use script 'prepare_cmake.sh' if you wish to prepare CMake artefacts" + >&2 echo "${ScriptPathClr}: CMake build directory '${CMakeDirClr}' not found or not configured; use script 'prepare_cmake.sh' first" exit 1 -else - - cd $CMakeDir - - if [ ! -f "$CMakeDir/Makefile" ]; then - - >&2 echo "$ScriptPath: CMake build directory '$CMakeDir' does not contain expected file 'Makefile', so a clean cannot be performed. It is recommended that you remove all CMake artefacts using script 'remove_cmake_artefacts.sh' followed by regeneration via 'prepare_cmake.sh'" - - cd ->/dev/null - - exit 1 - else - - if [ -z "$Targets" ]; then - - echo "Executing build (via command \`$MakeCmd\`)" - else - - echo "Executing build (via command \`$MakeCmd\`) with specific target(s) $(join_by , "${Targets[@]}")" - fi +fi - $MakeCmd ${Targets[*]} - status=$? +if [ ${#Targets[@]} -eq 0 ]; then - cd ->/dev/null + echo "Executing build of ${ProjectNameClr} (via cmake --build)" + sis_cmake_build + status=$? +else - exit $status - fi + echo "Executing build of ${ProjectNameClr} (via cmake --build) with specific target(s): ${Targets[*]}" + sis_cmake_build "${Targets[@]}" + status=$? fi +exit $status -# ############################## end of file ############################# # +# ############################## end of file ############################# # diff --git a/clean_cmake.sh b/clean_cmake.sh index a128668..733afbd 100755 --- a/clean_cmake.sh +++ b/clean_cmake.sh @@ -1,10 +1,117 @@ #! /bin/bash -ScriptPath=$0 -Dir=$(cd $(dirname "$ScriptPath"); pwd) -Basename=$(basename "$ScriptPath") +# ########################################################## +# functions - 1 + +sis_cmake_is_truey() { + case "$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')" in + + 1|ok|on|true|yes|y) + + return 0 + ;; + *) + + return 1 + ;; + esac +} + + +# ########################################################## +# constants and variables + +Basename=$(basename "$0") +Dir=$(cd "$(dirname "$0")" && pwd) CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build} -MakeCmd=${SIS_CMAKE_COMMAND:-make} +ProjectNameFile="$Dir/.sis/project_name.txt" +ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile") +ScriptPath=$0 + +AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}} +SisUseColours=0 + + +# ########################################################## +# colours +# +# Enable when tput is available and either: +# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if +# empty/dumb), or +# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of +# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a +# TTY is OK). + +SisClr_Blue= +SisClr_Bold= +SisClr_Green= +SisClr_None= +SisClr_Red= +SisClr_Yellow= + +for arg in "$@"; do + + case $arg in + --always-use-colors|--always-use-colours|-A) + + AlwaysUseColours=1 + ;; + esac +done + +if command -v tput >/dev/null 2>&1; then + + if [ $AlwaysUseColours -ne 0 ]; then + + if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then + + TERM=xterm-256color + fi + + SisUseColours=1 + elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then + + SisUseColours=1 + fi +fi + +if [ $SisUseColours -ne 0 ]; then + + SisClr_Blue=${FG_BLUE:-$(tput setaf 4)} + SisClr_Bold=${FD_BOLD:-$(tput bold)} + SisClr_Green=${FG_GREEN:-$(tput setaf 2)} + SisClr_None=${FD_NONE:-$(tput sgr0)} + SisClr_Red=${FG_RED:-$(tput setaf 1)} + SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)} +fi + +CMakeDirClr="${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None}" +ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}" +ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}" + + +# ########################################################## +# functions - 2 + +sis_cmake_build() { + + local config="${SIS_CMAKE_CONFIG:-Release}" + local args=(--build "$CMakeDir") + if [ -f "$CMakeDir/CMakeCache.txt" ] && grep -q '^CMAKE_CONFIGURATION_TYPES:' "$CMakeDir/CMakeCache.txt" 2>/dev/null; then + + args+=(--config "$config") + fi + if [ "$#" -gt 0 ]; then + + local t + for t in "$@"; do + + args+=(--target "$t") + done + fi + + cmake "${args[@]}" +} # ########################################################## @@ -13,18 +120,27 @@ MakeCmd=${SIS_CMAKE_COMMAND:-make} while [[ $# -gt 0 ]]; do case $1 in + --always-use-colors|--always-use-colours|-A) + + # AlwaysUseColours=1 - this is handled by the for loop above + ;; --help) [ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt" cat << EOF -Executes CMake-generated artefacts to clean project +Cleans CMake-generated build artefacts via cmake --build --target clean -$ScriptPath [ ... flags/options ... ] +${ScriptPath} [ ... flags/options ... ] Flags/options: behaviour: + -A + --always-use-colors + --always-use-colours + forces use of colours even when stdout is not a TTY + standard flags: @@ -37,7 +153,7 @@ EOF ;; *) - >&2 echo "$ScriptPath: unrecognised argument '$1'; use --help for usage" + >&2 echo "${ScriptPathClr}: unrecognised argument '${SisClr_Red}${SisClr_Bold}$1${SisClr_None}'; use --help for usage" exit 1 ;; @@ -50,35 +166,16 @@ done # ########################################################## # main() -if [ ! -d "$CMakeDir" ]; then +if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ]; then - >&2 echo "$ScriptPath: CMake build directory '$CMakeDir' not found so nothing to do; use script 'prepare_cmake.sh' if you wish to prepare CMake artefacts" + >&2 echo "${ScriptPathClr}: CMake build directory '${CMakeDirClr}' not found or not configured; nothing to clean" exit 1 -else - - cd $CMakeDir - - if [ ! -f "$CMakeDir/Makefile" ]; then - - >&2 echo "$ScriptPath: CMake build directory '$CMakeDir' does not contain expected file 'Makefile', so a clean cannot be performed. It is recommended that you remove all CMake artefacts using script 'remove_cmake_artefacts.sh' followed by regeneration via 'prepare_cmake.sh'" - - cd ->/dev/null - - exit 1 - else - - echo "Cleaning build (via command \`$MakeCmd clean\`)" - - $MakeCmd clean - status=$? - - cd ->/dev/null - - exit $status - fi fi +echo "Executing clean of ${ProjectNameClr} (via cmake --build --target clean)" +sis_cmake_build clean +exit $? -# ############################## end of file ############################# # +# ############################## end of file ############################# # diff --git a/cmake/TargetMacros.cmake b/cmake/TargetMacros.cmake index 425de75..9906fe1 100644 --- a/cmake/TargetMacros.cmake +++ b/cmake/TargetMacros.cmake @@ -54,6 +54,11 @@ function(define_automated_test_program program_name entry_point_source_name) ${X_MSVC_CUSTOM_WARNINGS_} > ) + + add_test( + NAME ${program_name} + COMMAND ${program_name} + ) endfunction(define_automated_test_program) diff --git a/ctest_cmake.sh b/ctest_cmake.sh new file mode 100755 index 0000000..4e09ee2 --- /dev/null +++ b/ctest_cmake.sh @@ -0,0 +1,239 @@ +#! /bin/bash + +# ########################################################## +# functions - 1 + +sis_cmake_is_truey() { + case "$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')" in + + 1|ok|on|true|yes|y) + + return 0 + ;; + *) + + return 1 + ;; + esac +} + + +# ########################################################## +# constants and variables + +Basename=$(basename "$0") +Dir=$(cd "$(dirname "$0")" && pwd) +CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build} +ProjectNameFile="$Dir/.sis/project_name.txt" +ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile") +ScriptPath=$0 + +AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}} +CTestVerbose= +RunMake=1 +SisUseColours=0 + + +# ########################################################## +# colours +# +# Enable when tput is available and either: +# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if +# empty/dumb), or +# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of +# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a +# TTY is OK). + +SisClr_Blue= +SisClr_Bold= +SisClr_Green= +SisClr_None= +SisClr_Red= +SisClr_Yellow= + +for arg in "$@"; do + + case $arg in + --always-use-colors|--always-use-colours|-A) + + AlwaysUseColours=1 + ;; + esac +done + +if command -v tput >/dev/null 2>&1; then + + if [ $AlwaysUseColours -ne 0 ]; then + + if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then + + TERM=xterm-256color + fi + + SisUseColours=1 + elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then + + SisUseColours=1 + fi +fi + +if [ $SisUseColours -ne 0 ]; then + + SisClr_Blue=${FG_BLUE:-$(tput setaf 4)} + SisClr_Bold=${FD_BOLD:-$(tput bold)} + SisClr_Green=${FG_GREEN:-$(tput setaf 2)} + SisClr_None=${FD_NONE:-$(tput sgr0)} + SisClr_Red=${FG_RED:-$(tput setaf 1)} + SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)} +fi + +CMakeDirClr="${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None}" +ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}" +ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}" + + +# ########################################################## +# functions - 2 + +sis_cmake_build() { + + local config="${SIS_CMAKE_CONFIG:-Release}" + local args=(--build "$CMakeDir") + if [ -f "$CMakeDir/CMakeCache.txt" ] && grep -q '^CMAKE_CONFIGURATION_TYPES:' "$CMakeDir/CMakeCache.txt" 2>/dev/null; then + + args+=(--config "$config") + fi + if [ "$#" -gt 0 ]; then + + local t + for t in "$@"; do + + args+=(--target "$t") + done + fi + + cmake "${args[@]}" +} + + +# ########################################################## +# command-line handling + +while [[ $# -gt 0 ]]; do + + case $1 in + --always-use-colors|--always-use-colours|-A) + + # AlwaysUseColours=1 - this is handled by the for loop above + ;; + --no-make|-M) + + RunMake=0 + ;; + --verbose|-V) + + CTestVerbose=--verbose + ;; + --help) + + [ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt" + cat << EOF +Runs CMake's CTest test program(s) + +${ScriptPath} [ ... flags/options ... ] + +Flags/options: + + behaviour: + + -A + --always-use-colors + --always-use-colours + forces use of colours even when stdout is not a TTY + + -M + --no-make + does not execute a build before running tests + + -V + --verbose + verbose test output + + + standard flags: + + --help + displays this help and terminates + +EOF + + exit 0 + ;; + *) + + >&2 echo "${ScriptPathClr}: unrecognised argument '${SisClr_Red}${SisClr_Bold}$1${SisClr_None}'; use --help for usage" + + exit 1 + ;; + esac + + shift +done + + +# ########################################################## +# main() + +status=0 + +if [ $RunMake -ne 0 ]; then + + echo + echo "Executing build of ${ProjectNameClr} (via cmake --build) and then running CTest" + + mkdir -p "$CMakeDir" || exit 1 + + if [ ! -f "$CMakeDir/CMakeCache.txt" ]; then + + >&2 echo "${ScriptPathClr}: '${CMakeDirClr}' is not configured; use prepare_cmake.sh first" + + exit 1 + fi + + sis_cmake_build + status=$? +else + + if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ]; then + + >&2 echo "${ScriptPathClr}: cannot run in '--no-make' mode without a previous successful configure/build" + + exit 1 + fi +fi + +if [ $status -eq 0 ]; then + + echo + echo "Running ${ProjectNameClr} CMake tests" + + # Multi-config generators (e.g. Visual Studio) need -C ; + # mirror sis_cmake_build's CMAKE_CONFIGURATION_TYPES detection. + ctest_args=(--test-dir "$CMakeDir" --output-on-failure) + if [ -n "$CTestVerbose" ]; then + + ctest_args+=("$CTestVerbose") + fi + if [ -f "$CMakeDir/CMakeCache.txt" ] && grep -q '^CMAKE_CONFIGURATION_TYPES:' "$CMakeDir/CMakeCache.txt" 2>/dev/null; then + + ctest_args+=(-C "${SIS_CMAKE_CONFIG:-Release}") + fi + + ctest "${ctest_args[@]}" + status=$? +fi + +exit $status + + +# ############################## end of file ############################# # diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index e69de29..5f5ef05 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -0,0 +1 @@ +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index be938f3..5828626 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -1,6 +1,3 @@ - -add_subdirectory(example.cpp.parse.1) - - -# ############################## end of file ############################# # +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +add_subdirectory(parse) diff --git a/examples/cpp/example.cpp.parse.1/CMakeLists.txt b/examples/cpp/parse/CMakeLists.txt similarity index 58% rename from examples/cpp/example.cpp.parse.1/CMakeLists.txt rename to examples/cpp/parse/CMakeLists.txt index 53b9f41..e17e02c 100644 --- a/examples/cpp/example.cpp.parse.1/CMakeLists.txt +++ b/examples/cpp/parse/CMakeLists.txt @@ -1,2 +1,2 @@ # SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten -define_example_program(example.cpp.parse.1 example.cpp.parse.1.cpp) +define_example_program(example.cpp.parse main.cpp) diff --git a/examples/cpp/example.cpp.parse.1/example.cpp.parse.1.cpp b/examples/cpp/parse/main.cpp similarity index 93% rename from examples/cpp/example.cpp.parse.1/example.cpp.parse.1.cpp rename to examples/cpp/parse/main.cpp index 0af7dae..e86bd79 100644 --- a/examples/cpp/example.cpp.parse.1/example.cpp.parse.1.cpp +++ b/examples/cpp/parse/main.cpp @@ -1,3 +1,17 @@ +/* ///////////////////////////////////////////////////////////////////////// + * File: examples/cpp/parse/main.cpp + * + * Purpose: Illustrates use of libpath C++ API to parse a path. + * + * Created: 27th July 2024 + * Updated: 14th October 2026 + * + * ////////////////////////////////////////////////////////////////////// */ + + +/* ///////////////////////////////////////////////////////////////////////// + * includes + */ #include diff --git a/include/libpath/common/version.h b/include/libpath/common/version.h index ac1353d..0baec80 100644 --- a/include/libpath/common/version.h +++ b/include/libpath/common/version.h @@ -4,13 +4,13 @@ * Purpose: Portability discrimination for libpath library. * * Created: 9th November 2012 - * Updated: 14th March 2025 + * Updated: 14th October 2026 * * Home: https://github.com/synesissoftware/libpath * - * Copyright (c) 2019-2025, Matthew Wilson and Synesis Information Systems + * Copyright (c) 2019-2026, Matthew Wilson and Synesis Information Systems * Copyright (c) 2012-2019, Matthew Wilson and Synesis Software - * All rights reserved. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -73,39 +73,43 @@ * changes. */ -/** @def LIBPATH_VER_ALPHABETA - * The alpha-beta number of libpath +/** @def LIBPATH_VER_RELSTATUS + * The release-status number of libpath * - * This number indicates the alpha/beta/release-candidate nature of the - * released version of the library. + * This number indicates the pre-alpha / alpha / beta / release-candidate / + * full-release nature of the released version of the library. A value of + * 0xFF means a full release. */ -/** @def LIBPATH +/** @def LIBPATH_VER * The current composite version number of libpath * - * In addition to the individual version symbols - LIBPATH_MAJOR, - * LIBPATH_MINOR and LIBPATH_PATCH - a composite symbol - * LIBPATH is defined, where: + * In addition to the individual version symbols - LIBPATH_VER_MAJOR, + * LIBPATH_VER_MINOR, LIBPATH_VER_PATCH, and LIBPATH_VER_RELSTATUS - a + * composite symbol LIBPATH_VER is defined, where: * - bits 24-31: the major version * - bits 16-23: the minor version * - bits 8-15: the patch version - * - bits 0-7: the alpha-beta number; if not alpha/beta, it is 0xFF + * - bits 0-7: the release status; if a full release, it is 0xFF */ #define LIBPATH_VER_MAJOR 0 #define LIBPATH_VER_MINOR 3 #define LIBPATH_VER_PATCH 0 -#define LIBPATH_VER_ALPHABETA 41 +#define LIBPATH_VER_RELSTATUS 0x81 #define LIBPATH_VER \ (0\ | ( LIBPATH_VER_MAJOR << 24 ) \ | ( LIBPATH_VER_MINOR << 16 ) \ | ( LIBPATH_VER_PATCH << 8 ) \ - | ( LIBPATH_VER_ALPHABETA << 0 ) \ + | ( LIBPATH_VER_RELSTATUS << 0 ) \ ) -#define LIBPATH_VER_REVISION LIBPATH_VER_PATCH +#ifndef LIBPATH_DOCUMENTATION_SKIP_SECTION +# define LIBPATH_VER_ALPHABETA LIBPATH_VER_RELSTATUS +# define LIBPATH_VER_REVISION LIBPATH_VER_PATCH +#endif /* !LIBPATH_DOCUMENTATION_SKIP_SECTION */ /* ////////////////////////////////////////////////////////////////////// */ diff --git a/prepare_cmake.sh b/prepare_cmake.sh index 5f03a74..236e329 100755 --- a/prepare_cmake.sh +++ b/prepare_cmake.sh @@ -1,20 +1,136 @@ #! /bin/bash -ScriptPath=$0 -Dir=$(cd $(dirname "$ScriptPath"); pwd) -Basename=$(basename "$ScriptPath") +# ########################################################## +# functions - 1 + +sis_cmake_is_truey() { + case "$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')" in + + 1|ok|on|true|yes|y) + + return 0 + ;; + *) + + return 1 + ;; + esac +} + + +# ########################################################## +# constants and variables + +Basename=$(basename "$0") +Dir=$(cd "$(dirname "$0")" && pwd) CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build} -MakeCmd=${SIS_CMAKE_COMMAND:-make} +ProjectNameFile="$Dir/.sis/project_name.txt" +ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile") +ScriptPath=$0 +AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}} +BuildSharedLibs=0 Configuration=Release ExamplesDisabled=0 -MinGW=0 +MinGW=$(sis_cmake_is_truey "${SIS_CMAKE_MINGW:-}" && echo 1 || echo 0) +MSVC_MT=0 RunMake=0 -STLSoftDirGiven= -SimulateWindowsOnUnix=0 +SisUseColours=0 TestingDisabled=0 VerboseMakefile=0 +# ########################################################## +# PROJECT-SPECIFIC FLAGS (customise per library; keep marker) +# +# Add project-only options here (e.g. --no-cpp, --stlsoft-root-dir, +# --no-shwild). The common body below must stay aligned with +# misc-dev-scripts/shell-scripts/cmake-helpers/prepare_cmake.sh. + + +SimulateWindowsOnUnix=0 +STLSoftDirGiven= + +# ########################################################## +# colours +# +# Enable when tput is available and either: +# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if +# empty/dumb), or +# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of +# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a +# TTY is OK). + +SisClr_Blue= +SisClr_Bold= +SisClr_Green= +SisClr_None= +SisClr_Red= +SisClr_Yellow= + +for arg in "$@"; do + + case $arg in + --always-use-colors|--always-use-colours|-A) + + AlwaysUseColours=1 + ;; + esac +done + +if command -v tput >/dev/null 2>&1; then + + if [ $AlwaysUseColours -ne 0 ]; then + + if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then + + TERM=xterm-256color + fi + + SisUseColours=1 + elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then + + SisUseColours=1 + fi +fi + +if [ $SisUseColours -ne 0 ]; then + + SisClr_Blue=${FG_BLUE:-$(tput setaf 4)} + SisClr_Bold=${FD_BOLD:-$(tput bold)} + SisClr_Green=${FG_GREEN:-$(tput setaf 2)} + SisClr_None=${FD_NONE:-$(tput sgr0)} + SisClr_Red=${FG_RED:-$(tput setaf 1)} + SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)} +fi + +CMakeDirClr="${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None}" +ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}" +ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}" + + +# ########################################################## +# functions - 2 + +sis_cmake_build() { + + local config="${SIS_CMAKE_CONFIG:-Release}" + local args=(--build "$CMakeDir") + if [ -f "$CMakeDir/CMakeCache.txt" ] && grep -q '^CMAKE_CONFIGURATION_TYPES:' "$CMakeDir/CMakeCache.txt" 2>/dev/null; then + + args+=(--config "$config") + fi + if [ "$#" -gt 0 ]; then + + local t + for t in "$@"; do + + args+=(--target "$t") + done + fi + + cmake "${args[@]}" +} + # ########################################################## # command-line handling @@ -22,19 +138,27 @@ VerboseMakefile=0 while [[ $# -gt 0 ]]; do case $1 in - -v|--cmake-verbose-makefile) + --always-use-colors|--always-use-colours|-A) + + # AlwaysUseColours=1 - this is handled by the for loop above + ;; + --build-shared-libs) + + BuildSharedLibs=1 + ;; + --cmake-verbose-makefile|-v) VerboseMakefile=1 ;; - -d|--debug-configuration) + --debug-configuration|-d) Configuration=Debug ;; - -E|--disable-examples) + --disable-examples|-E) ExamplesDisabled=1 ;; - -T|--disable-testing) + --disable-testing|-T) TestingDisabled=1 ;; @@ -42,7 +166,11 @@ while [[ $# -gt 0 ]]; do MinGW=1 ;; - -m|--run-make) + --msvc-mt) + + MSVC_MT=1 + ;; + --run-make|-m) RunMake=1 ;; @@ -50,7 +178,7 @@ while [[ $# -gt 0 ]]; do SimulateWindowsOnUnix=1 ;; - -s|--stlsoft-root-dir) + --stlsoft-root-dir|-s) shift STLSoftDirGiven=$1 @@ -61,38 +189,46 @@ while [[ $# -gt 0 ]]; do cat << EOF Creates/reinitialises the CMake build script(s) -$ScriptPath [ ... flags/options ... ] +${ScriptPath} [ ... flags/options ... ] Flags/options: behaviour: + -A + --always-use-colors + --always-use-colours + forces use of colours even when stdout is not a TTY + + --build-shared-libs + builds ${ProjectName} as a shared library (BUILD_SHARED_LIBS=ON) + -v --cmake-verbose-makefile - configures CMake to run verbosely (by setting CMAKE_VERBOSE_MAKEFILE - to be ON) + configures CMake to run verbosely (CMAKE_VERBOSE_MAKEFILE=ON) -d --debug-configuration - use Debug configuration (by setting CMAKE_BUILD_TYPE=Debug). Default - is to use Release + use Debug configuration (CMAKE_BUILD_TYPE=Debug). Default is Release -E --disable-examples - disables building of examples (by setting BUILD_EXAMPLES=OFF) + disables building of examples (BUILD_EXAMPLES=OFF) -T --disable-testing - disables building of tests (by setting BUILD_TESTING=OFF). This is - necessary, for example, when installing on a system that does not - (yet) have xTests - which itself depends on STLSOFT - installed + disables building of tests (BUILD_TESTING=OFF) --mingw uses explicitly the "MinGW Makefiles" generator + --msvc-mt + when using Visual C++ (MSVC), select the static runtime library + -m --run-make - executes make after a successful running of CMake + executes a build via cmake --build after a successful configure + --simulate-windows-on-unix defines the LIBPATH_OS_SIMULATE_WINDOWS_ON_UNIX object-like @@ -104,7 +240,6 @@ Flags/options: as the variable STLSOFT, and which will override the environment variable STLSOFT (if present) - standard flags: --help @@ -116,7 +251,7 @@ EOF ;; *) - >&2 echo "$ScriptPath: unrecognised argument '$1'; use --help for usage" + >&2 echo "${ScriptPathClr}: unrecognised argument '${SisClr_Red}${SisClr_Bold}$1${SisClr_None}'; use --help for usage" exit 1 ;; @@ -129,64 +264,68 @@ done # ########################################################## # main() -mkdir -p $CMakeDir || exit 1 - -cd $CMakeDir +mkdir -p "$CMakeDir" || exit 1 -echo "Executing CMake (in ${CMakeDir})" +echo +echo "Executing CMake for ${ProjectNameClr} (in ${CMakeDirClr})" +if [ $BuildSharedLibs -eq 0 ]; then CMakeBuildSharedLibsFlag="OFF" ; else CMakeBuildSharedLibsFlag="ON" ; fi if [ $ExamplesDisabled -eq 0 ]; then CMakeBuildExamplesFlag="ON" ; else CMakeBuildExamplesFlag="OFF" ; fi -if [ -z $STLSoftDirGiven ]; then CMakeSTLSoftVariable="" ; else CMakeSTLSoftVariable="-DSTLSOFT=$STLSoftDirGiven/" ; fi +if [ $MSVC_MT -eq 0 ]; then CMakeMsvcMtFlag="OFF" ; else CMakeMsvcMtFlag="ON" ; fi if [ $SimulateWindowsOnUnix -eq 0 ]; then CMakeSimulateWindowsOnUnixFlag="OFF" ; else CMakeSimulateWindowsOnUnixFlag="ON" ; fi +if [ -z "$STLSoftDirGiven" ]; then CMakeSTLSoftVariable="" ; else CMakeSTLSoftVariable="-DSTLSOFT=$STLSoftDirGiven/" ; fi if [ $TestingDisabled -eq 0 ]; then CMakeBuildTestingFlag="ON" ; else CMakeBuildTestingFlag="OFF" ; fi if [ $VerboseMakefile -eq 0 ]; then CMakeVerboseMakefileFlag="OFF" ; else CMakeVerboseMakefileFlag="ON" ; fi +# NOTE: the generator is the *only* thing that may differ between the MinGW +# and the default paths; every -D option is passed in both cases, so that no +# flag can be silently ignored according to the generator selected. + +CMakeGeneratorArgs=() + +if [ -n "${SIS_CMAKE_GENERATOR:-}" ] && [ $MinGW -eq 0 ]; then + + CMakeGeneratorArgs=(-G "$SIS_CMAKE_GENERATOR") +fi + if [ $MinGW -ne 0 ]; then - cmake \ - $CMakeSTLSoftVariable \ - -DBUILD_EXAMPLES:BOOL=$CMakeBuildExamplesFlag \ - -DBUILD_TESTING:BOOL=$CMakeBuildTestingFlag \ - -DCMAKE_BUILD_TYPE=$Configuration \ - -DLIBPATH_OS_SIMULATE_WINDOWS_ON_UNIX:BOOL=$CMakeSimulateWindowsOnUnixFlag \ - -G "MinGW Makefiles" \ - -S $Dir \ - -B $CMakeDir \ - || (cd ->/dev/null ; exit 1) -else - - cmake \ - $CMakeSTLSoftVariable \ - -DBUILD_EXAMPLES:BOOL=$CMakeBuildExamplesFlag \ - -DBUILD_TESTING:BOOL=$CMakeBuildTestingFlag \ - -DCMAKE_BUILD_TYPE=$Configuration \ - -DCMAKE_VERBOSE_MAKEFILE:BOOL=$CMakeVerboseMakefileFlag \ - -DLIBPATH_OS_SIMULATE_WINDOWS_ON_UNIX:BOOL=$CMakeSimulateWindowsOnUnixFlag \ - -S $Dir \ - -B $CMakeDir \ - || (cd ->/dev/null ; exit 1) + CMakeGeneratorArgs=(-G "MinGW Makefiles") fi +cmake \ + -DBUILD_EXAMPLES:BOOL=$CMakeBuildExamplesFlag \ + -DBUILD_SHARED_LIBS:BOOL=$CMakeBuildSharedLibsFlag \ + -DBUILD_TESTING:BOOL=$CMakeBuildTestingFlag \ + -DCMAKE_BUILD_TYPE=$Configuration \ + -DCMAKE_VERBOSE_MAKEFILE:BOOL=$CMakeVerboseMakefileFlag \ + -DLIBPATH_OS_SIMULATE_WINDOWS_ON_UNIX:BOOL=$CMakeSimulateWindowsOnUnixFlag \ + -DMSVC_USE_MT:BOOL=$CMakeMsvcMtFlag \ + $CMakeSTLSoftVariable \ + "${CMakeGeneratorArgs[@]}" \ + -B "$CMakeDir" \ + -S "$Dir" \ + || exit 1 + status=0 if [ $RunMake -ne 0 ]; then - echo "Executing build (via command \`$MakeCmd\`)" + echo + echo "Executing build of ${ProjectNameClr} (via cmake --build)" - $MakeCmd + sis_cmake_build status=$? fi -cd ->/dev/null - if [ $VerboseMakefile -ne 0 ]; then - echo -e "contents of $CMakeDir:" - ls -al $CMakeDir + echo + echo -e "contents of ${CMakeDirClr}:" + ls -al "$CMakeDir" fi exit $status # ############################## end of file ############################# # - diff --git a/remove_cmake_artefacts.sh b/remove_cmake_artefacts.sh index 7416db9..377d3ab 100755 --- a/remove_cmake_artefacts.sh +++ b/remove_cmake_artefacts.sh @@ -1,10 +1,16 @@ #! /bin/bash -ScriptPath=$0 -Dir=$(cd $(dirname "$ScriptPath"); pwd) -Basename=$(basename "$ScriptPath") +# ########################################################## +# constants and variables + +Basename=$(basename "$0") +Dir=$(cd "$(dirname "$0")" && pwd) CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build} +ProjectNameFile="$Dir/.sis/project_name.txt" +ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile") +ScriptPath=$0 +AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}} Directories=( CMakeFiles Testing @@ -22,14 +28,73 @@ Files=( cmake_install.cmake install_manifest.txt ) +SisUseColours=0 + + +# ########################################################## +# colours +# +# Enable when tput is available and either: +# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if +# empty/dumb), or +# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of +# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a +# TTY is OK). + +SisClr_Blue= +SisClr_Bold= +SisClr_Green= +SisClr_None= +SisClr_Red= +SisClr_Yellow= + +for arg in "$@"; do + + case $arg in + --always-use-colors|--always-use-colours|-A) + + AlwaysUseColours=1 + ;; + esac +done + +if command -v tput >/dev/null 2>&1; then + + if [ $AlwaysUseColours -ne 0 ]; then + + if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then + + TERM=xterm-256color + fi + + SisUseColours=1 + elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then + + SisUseColours=1 + fi +fi + +if [ $SisUseColours -ne 0 ]; then + + SisClr_Blue=${FG_BLUE:-$(tput setaf 4)} + SisClr_Bold=${FD_BOLD:-$(tput bold)} + SisClr_Green=${FG_GREEN:-$(tput setaf 2)} + SisClr_None=${FD_NONE:-$(tput sgr0)} + SisClr_Red=${FG_RED:-$(tput setaf 1)} + SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)} +fi + +CMakeDirClr="${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None}" +ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}" +ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}" # ########################################################## # operating environment detection -OsName="$(uname -s)" +OsName="$(uname -s 2>/dev/null || echo Unknown)" case "${OsName}" in - CYGWIN*|MINGW*|MSYS_NT*) + CYGWIN*|MINGW*|MSYS_NT*|Windows_NT) Directories+=( ARM64 @@ -41,9 +106,6 @@ case "${OsName}" in "*.sln" "*.vcxproj" ) - ;; - *) - ;; esac @@ -54,18 +116,27 @@ esac while [[ $# -gt 0 ]]; do case $1 in + --always-use-colors|--always-use-colours|-A) + + # AlwaysUseColours=1 - this is handled by the for loop above + ;; --help) [ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt" cat << EOF Removes all known CMake artefacts -$ScriptPath [ ... flags/options ... ] +${ScriptPath} [ ... flags/options ... ] Flags/options: behaviour: + -A + --always-use-colors + --always-use-colours + forces use of colours even when stdout is not a TTY + standard flags: @@ -78,7 +149,7 @@ EOF ;; *) - >&2 echo "$ScriptPath: unrecognised argument '$1'; use --help for usage" + >&2 echo "${ScriptPathClr}: unrecognised argument '${SisClr_Red}${SisClr_Bold}$1${SisClr_None}'; use --help for usage" exit 1 ;; @@ -93,59 +164,50 @@ done if [ ! -d "$CMakeDir" ]; then - echo "$ScriptPath: CMake build directory '$CMakeDir' not found so nothing to do; use script 'prepare_cmake.sh' if you wish to prepare CMake artefacts" + echo "${ScriptPathClr}: CMake build directory '${CMakeDirClr}' not found so nothing to do; use script 'prepare_cmake.sh' if you wish to prepare CMake artefacts" exit 0 -else - - echo "Removing all cmake artefacts in '$CMakeDir'" +fi - num_dirs_removed=0 - num_files_removed=0 +echo "Removing all ${ProjectNameClr} cmake artefacts in '${CMakeDirClr}'" - for d in ${Directories[@]} - do +num_dirs_removed=0 +num_files_removed=0 - fq_dir_path="$CMakeDir/$d" +for d in "${Directories[@]}"; do - [ -d "$fq_dir_path" ] || continue + fq_dir_path="$CMakeDir/$d" - echo "removing directory '$d'" + [ -d "$fq_dir_path" ] || continue - rm -dfr "$fq_dir_path" + echo "removing directory '$d'" - num_dirs_removed=$((num_dirs_removed+1)) - done + rm -dfr "$fq_dir_path" - cd "$CMakeDir" + num_dirs_removed=$((num_dirs_removed+1)) +done - for f in ${Files[@]} - do +for f in "${Files[@]}"; do - for fq_file_path in $f - do + for fq_file_path in "$CMakeDir"/$f; do - [ -f "$fq_file_path" ] || continue + [ -f "$fq_file_path" ] || continue - echo "removing file '$fq_file_path'" + echo "removing file '$fq_file_path'" - rm -f "$fq_file_path" + rm -f "$fq_file_path" - num_files_removed=$((num_files_removed+1)) - done + num_files_removed=$((num_files_removed+1)) done +done - cd ->/dev/null - - if [ 0 -eq $num_dirs_removed ] && [ 0 -eq $num_files_removed ]; then +if [ 0 -eq $num_dirs_removed ] && [ 0 -eq $num_files_removed ]; then - echo "nothing to do" - else + echo "nothing to do" +else - echo "removed $num_dirs_removed directories and $num_files_removed files" - fi + echo "removed $num_dirs_removed directories and $num_files_removed files" fi # ############################## end of file ############################# # - diff --git a/run_all_automated_tests.cmd b/run_all_automated_tests.cmd new file mode 100644 index 0000000..b6dd937 --- /dev/null +++ b/run_all_automated_tests.cmd @@ -0,0 +1,106 @@ +@echo off + +SETLOCAL + +SET SCRIPT_DIRECTORY=%~dp0 +SET SCRIPT_PATH_DOC=%~n0[%~x0] + +SET UnitOnly=0 +SET ComponentOnly=0 + +FOR %%a IN (%*) DO ( + + IF /I {--help}=={%%a} ( + + IF EXIST "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" ( + + type "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" + ) + ECHO ^ + +Runs all ^(matching^) automated test programs ^(unit and component^) ^ + +^ + +%SCRIPT_PATH_DOC% [ ... flags/options ... ] ^ + +^ + +Flags/options: ^ + + behaviour: ^ + +^ + + --unit-only ^ + + runs only unit-test programs ^ + +^ + + --component-only ^ + + runs only component-test programs ^ + +^ + + standard flags: ^ + +^ + + --help ^ + + displays this help and terminates ^ + + + EXIT /B 0 + ) ELSE IF /I {--unit-only}=={%%a} ( + + SET UnitOnly=1 + ) ELSE IF /I {--component-only}=={%%a} ( + + SET ComponentOnly=1 + ) ELSE ( + + ECHO "%SCRIPT_DIRECTORY%: unrecognised argument '%%a'; use --help for usage" 1>&2 + + EXIT /B 1 + ) +) + +IF %UnitOnly% NEQ 0 IF %ComponentOnly% NEQ 0 ( + + ECHO %SCRIPT_PATH_DOC%: --unit-only and --component-only are mutually exclusive 1>&2 + + EXIT /B 1 +) + +IF %UnitOnly% NEQ 0 ( + CALL "%SCRIPT_DIRECTORY%run_all_unit_tests.cmd" + EXIT /B %ERRORLEVEL% +) + +IF %ComponentOnly% NEQ 0 ( + CALL "%SCRIPT_DIRECTORY%run_all_component_tests.cmd" + EXIT /B %ERRORLEVEL% +) + +SET "ProjectName=" +FOR /F "usebackq delims=" %%p IN ("%SCRIPT_DIRECTORY%.sis\project_name.txt") DO SET "ProjectName=%%p" + +IF NOT DEFINED ProjectName ( + + ECHO %SCRIPT_PATH_DOC%: could not read project name from .sis\project_name.txt 1>&2 + + EXIT /B 1 +) + +ECHO Running all %ProjectName% automated test programs ^(unit and component^) + +CALL "%SCRIPT_DIRECTORY%run_all_unit_tests.cmd" +IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% + +CALL "%SCRIPT_DIRECTORY%run_all_component_tests.cmd" +EXIT /B %ERRORLEVEL% + +ENDLOCAL diff --git a/run_all_automated_tests.sh b/run_all_automated_tests.sh new file mode 100755 index 0000000..2c13b16 --- /dev/null +++ b/run_all_automated_tests.sh @@ -0,0 +1,180 @@ +#! /bin/bash + +# ########################################################## +# constants and variables + +Basename=$(basename "$0") +Dir=$(cd "$(dirname "$0")" && pwd) +CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build} +ProjectNameFile="$Dir/.sis/project_name.txt" +ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile") +ScriptPath=$0 + +AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}} +ComponentOnly=0 +ForwardedArgs=() +SisUseColours=0 +UnitOnly=0 + + +# ########################################################## +# colours +# +# Enable when tput is available and either: +# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if +# empty/dumb), or +# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of +# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a +# TTY is OK). + +SisClr_Blue= +SisClr_Bold= +SisClr_Green= +SisClr_None= +SisClr_Red= +SisClr_Yellow= + +for arg in "$@"; do + + case $arg in + --always-use-colors|--always-use-colours|-A) + + AlwaysUseColours=1 + ;; + esac +done + +if command -v tput >/dev/null 2>&1; then + + if [ $AlwaysUseColours -ne 0 ]; then + + if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then + + TERM=xterm-256color + fi + + SisUseColours=1 + elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then + + SisUseColours=1 + fi +fi + +if [ $SisUseColours -ne 0 ]; then + + SisClr_Blue=${FG_BLUE:-$(tput setaf 4)} + SisClr_Bold=${FD_BOLD:-$(tput bold)} + SisClr_Green=${FG_GREEN:-$(tput setaf 2)} + SisClr_None=${FD_NONE:-$(tput sgr0)} + SisClr_Red=${FG_RED:-$(tput setaf 1)} + SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)} +fi + +ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}" +ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}" + + +# ########################################################## +# command-line handling + +while [[ $# -gt 0 ]]; do + + case $1 in + --always-use-colors|--always-use-colours|-A) + + # AlwaysUseColours=1 - handled above; forward so category runners see it + ForwardedArgs+=("$1") + ;; + --unit-only) + + UnitOnly=1 + ;; + --component-only) + + ComponentOnly=1 + ;; + --help) + + [ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt" + cat << EOF +Runs all (matching) automated test programs (unit and component) + +${ScriptPath} [ ... flags/options ... ] + +Flags/options: + + behaviour: + + -A + --always-use-colors + --always-use-colours + forces use of colours even when stdout is not a TTY + + --component-only + runs only component-test programs + + --unit-only + runs only unit-test programs + + (all other flags are forwarded to the category runner script) + + + standard flags: + + --help + displays this help and terminates + +EOF + + exit 0 + ;; + *) + + ForwardedArgs+=("$1") + ;; + esac + + shift +done + +if [ $UnitOnly -ne 0 ] && [ $ComponentOnly -ne 0 ]; then + + >&2 echo "${ScriptPathClr}: ${SisClr_Red}${SisClr_Bold}--unit-only${SisClr_None} and ${SisClr_Red}${SisClr_Bold}--component-only${SisClr_None} are mutually exclusive" + + exit 1 +fi + + +# ########################################################## +# main() + +status=0 + +if [ $UnitOnly -ne 0 ]; then + + "$Dir/run_all_unit_tests.sh" "${ForwardedArgs[@]}" + exit $? +fi + +if [ $ComponentOnly -ne 0 ]; then + + "$Dir/run_all_component_tests.sh" "${ForwardedArgs[@]}" + exit $? +fi + +echo +echo "Running all ${ProjectNameClr} automated test programs (unit and component)" + +"$Dir/run_all_unit_tests.sh" "${ForwardedArgs[@]}" +status=$? + +if [ $status -eq 0 ]; then + + "$Dir/run_all_component_tests.sh" "${ForwardedArgs[@]}" + status=$? +fi + +exit $status + + +# ############################## end of file ############################# # diff --git a/run_all_component_tests.cmd b/run_all_component_tests.cmd new file mode 100644 index 0000000..970c9ba --- /dev/null +++ b/run_all_component_tests.cmd @@ -0,0 +1,94 @@ +@echo off + +SETLOCAL + +SET SCRIPT_DIRECTORY=%~dp0 +SET SCRIPT_PATH_DOC=%~n0[%~x0] + +IF DEFINED SIS_CMAKE_BUILD_DIR ( + + SET CMAKE_DIR=%SIS_CMAKE_BUILD_DIR% +) ELSE ( + + SET CMAKE_DIR=%SCRIPT_DIRECTORY%_build +) + +FOR %%a IN (%*) DO ( + + IF /I {--help}=={%%a} ( + + IF EXIST "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" ( + + type "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" + ) + ECHO ^ + +Runs all ^(matching^) component-test programs ^ + +^ + +%SCRIPT_PATH_DOC% [ ... flags/options ... ] ^ + +^ + +Flags/options: ^ + + behaviour: ^ + +^ + + --component-only ^ + + accepted for compatibility; this script always runs component tests only ^ + +^ + + standard flags: ^ + +^ + + --help ^ + + displays this help and terminates ^ + + + EXIT /B 0 + ) ELSE IF /I {--component-only}=={%%a} ( + + REM Benign: this script is already component-only + ) ELSE ( + + ECHO "%SCRIPT_DIRECTORY%: unrecognised argument '%%a'; use --help for usage" 1>&2 + + EXIT /B 1 + ) +) + +if NOT EXIST "%CMAKE_DIR%" ( + + ECHO "CMake build directory '%CMAKE_DIR%' does not exist" + + EXIT /B 1 +) + +SET "ProjectName=" +FOR /F "usebackq delims=" %%p IN ("%SCRIPT_DIRECTORY%.sis\project_name.txt") DO SET "ProjectName=%%p" + +IF NOT DEFINED ProjectName ( + + ECHO %SCRIPT_PATH_DOC%: could not read project name from .sis\project_name.txt 1>&2 + + EXIT /B 1 +) + +ECHO Running all %ProjectName% component-test programs + +FOR /F "usebackq" %%f IN (`DIR /A:-D /B /S "%CMAKE_DIR%" ^| FINDSTR /I test.*component.*\.exe$`) DO ( + + ECHO . + ECHO executing %%f + %%f + IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% +) + +ENDLOCAL diff --git a/run_all_component_tests.sh b/run_all_component_tests.sh new file mode 100755 index 0000000..c0bd27e --- /dev/null +++ b/run_all_component_tests.sh @@ -0,0 +1,300 @@ +#! /bin/bash + +# ########################################################## +# functions - 1 + +sis_cmake_is_truey() { + case "$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')" in + + 1|ok|on|true|yes|y) + + return 0 + ;; + *) + + return 1 + ;; + esac +} + + +# ########################################################## +# constants and variables + +Basename=$(basename "$0") +Dir=$(cd "$(dirname "$0")" && pwd) +CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build} +ProjectNameFile="$Dir/.sis/project_name.txt" +ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile") +ScriptPath=$0 + +AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}} +ListOnly=0 +RunMake=1 +SisUseColours=0 +Verbosity=${XTESTS_VERBOSITY:-${TEST_VERBOSITY:-3}} + + +# ########################################################## +# colours +# +# Enable when tput is available and either: +# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if +# empty/dumb), or +# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of +# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a +# TTY is OK). + +SisClr_Blue= +SisClr_Bold= +SisClr_Green= +SisClr_None= +SisClr_Red= +SisClr_Yellow= + +for arg in "$@"; do + + case $arg in + --always-use-colors|--always-use-colours|-A) + + AlwaysUseColours=1 + ;; + esac +done + +if command -v tput >/dev/null 2>&1; then + + if [ $AlwaysUseColours -ne 0 ]; then + + if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then + + TERM=xterm-256color + fi + + SisUseColours=1 + elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then + + SisUseColours=1 + fi +fi + +if [ $SisUseColours -ne 0 ]; then + + SisClr_Blue=${FG_BLUE:-$(tput setaf 4)} + SisClr_Bold=${FD_BOLD:-$(tput bold)} + SisClr_Green=${FG_GREEN:-$(tput setaf 2)} + SisClr_None=${FD_NONE:-$(tput sgr0)} + SisClr_Red=${FG_RED:-$(tput setaf 1)} + SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)} +fi + +CMakeDirClr="${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None}" +ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}" +ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}" + + +# ########################################################## +# functions - 2 + +sis_cmake_build() { + + local config="${SIS_CMAKE_CONFIG:-Release}" + local args=(--build "$CMakeDir") + if [ -f "$CMakeDir/CMakeCache.txt" ] && grep -q '^CMAKE_CONFIGURATION_TYPES:' "$CMakeDir/CMakeCache.txt" 2>/dev/null; then + + args+=(--config "$config") + fi + if [ "$#" -gt 0 ]; then + + local t + for t in "$@"; do + + args+=(--target "$t") + done + fi + + cmake "${args[@]}" +} + + +# ########################################################## +# command-line handling + +while [[ $# -gt 0 ]]; do + + case $1 in + --always-use-colors|--always-use-colours|-A) + + # AlwaysUseColours=1 - this is handled by the for loop above + ;; + --component-only) + + # Benign: this script is already component-only (aggregate / CI may + # pass it) + ;; + --list-only|-l) + + ListOnly=1 + ;; + --no-make|-M) + + RunMake=0 + ;; + --verbosity) + + shift + Verbosity=$1 + ;; + --help) + + [ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt" + cat << EOF +Runs all (matching) component-test programs + +${ScriptPath} [ ... flags/options ... ] + +Flags/options: + + behaviour: + + -A + --always-use-colors + --always-use-colours + forces use of colours even when stdout is not a TTY + + --component-only + accepted for compatibility; this script always runs component tests + only + + -l + --list-only + lists the target programs but does not execute them + + -M + --no-make + does not execute a build before running programs + + --verbosity + specifies an explicit verbosity, forwarded to each program + + + standard flags: + + --help + displays this help and terminates + +EOF + + exit 0 + ;; + *) + + >&2 echo "${ScriptPathClr}: unrecognised argument '${SisClr_Red}${SisClr_Bold}$1${SisClr_None}'; use --help for usage" + + exit 1 + ;; + esac + + shift +done + + +# ########################################################## +# main() + +status=0 + +if [ $RunMake -ne 0 ]; then + + if [ $ListOnly -eq 0 ]; then + + echo + echo "Executing build of ${ProjectNameClr} (via cmake --build) and then running all component-test programs" + + mkdir -p "$CMakeDir" || exit 1 + + if [ ! -f "$CMakeDir/CMakeCache.txt" ]; then + + >&2 echo "${ScriptPathClr}: '${CMakeDirClr}' is not configured; use prepare_cmake.sh first" + + exit 1 + fi + + sis_cmake_build + status=$? + fi +else + + if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ]; then + + >&2 echo "${ScriptPathClr}: cannot run in '--no-make' mode without a previous successful configure/build" + + exit 1 + fi +fi + +if [ $status -eq 0 ]; then + + if [ $ListOnly -ne 0 ]; then + + echo + echo "Listing all ${ProjectNameClr} component-test programs" + else + + echo + echo "Running all ${ProjectNameClr} component-test programs" + fi + + NumPrograms=0 + + while IFS= read -r -d '' f; do + + case "$f" in + *.pdb|*.ilk|*.log|*.obj|*.o) + continue + ;; + esac + + NumPrograms=$((NumPrograms + 1)) + + fClr="${SisClr_Blue}${SisClr_Bold}${f}${SisClr_None}" + + if [ $ListOnly -ne 0 ]; then + + echo "would execute ${fClr}:" + + continue + fi + + if [ $Verbosity -ge 3 ]; then + + echo + fi + if [ $Verbosity -ge 2 ]; then + + echo "executing ${fClr}:" + fi + + if "$f" --verbosity="$Verbosity"; then + + : + else + + status=$? + + break 1 + fi + done < <(find "$CMakeDir" -type f \( -name 'test_component*' -o -name 'test.component.*' \) \( -perm -100 -o -name '*.exe' \) -print0 2>/dev/null | sort -z) + + if [ $NumPrograms -eq 0 ]; then + + echo "${ScriptPathClr}: found no component-test programs under '${CMakeDirClr}' (none found)" + + exit 0 + fi +fi + +exit $status + + +# ############################## end of file ############################# # diff --git a/run_all_examples.cmd b/run_all_examples.cmd new file mode 100644 index 0000000..b10e3d2 --- /dev/null +++ b/run_all_examples.cmd @@ -0,0 +1,131 @@ +@echo off + +SETLOCAL + +SET SCRIPT_DIRECTORY=%~dp0 +SET SCRIPT_PATH_DOC=%~n0[%~x0] +SET "ALLOWED_TO_FAIL_FILE=%SCRIPT_DIRECTORY%.sis\ci_examples_allowed_to_fail.txt" +SET "PROGRAM_STATUS=0" + +IF DEFINED SIS_CMAKE_BUILD_DIR ( + + SET CMAKE_DIR=%SIS_CMAKE_BUILD_DIR% +) ELSE ( + + SET CMAKE_DIR=%SCRIPT_DIRECTORY%_build +) + +FOR %%a IN (%*) DO ( + + IF /I {--help}=={%%a} ( + + IF EXIST "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" ( + + type "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" + ) + ECHO ^ + +Runs all ^(matching^) example programs ^ + +^ + +%SCRIPT_PATH_DOC% [ ... flags/options ... ] ^ + +^ + +Flags/options: ^ + + behaviour: ^ + +^ + + standard flags: ^ + +^ + + --help ^ + + displays this help and terminates ^ + +^ + + files: ^ + +^ + + .sis\ci_examples_allowed_to_fail.txt ^ + + optional list of example programs ^(one name per line; ^ + + lines beginning with '#' are ignored^) that are allowed to fail; ^ + + such a program is still executed, but a non-zero exit is ^ + + reported as anticipated and does not stop the run ^ + + + EXIT /B 0 + ) ELSE ( + + ECHO "%SCRIPT_DIRECTORY%: unrecognised argument '%%a'; use --help for usage" 1>&2 + + EXIT /B 1 + ) +) + +if NOT EXIST "%CMAKE_DIR%" ( + + ECHO "CMake build directory '%CMAKE_DIR%' does not exist" + + EXIT /B 1 +) + +SET "ProjectName=" +FOR /F "usebackq delims=" %%p IN ("%SCRIPT_DIRECTORY%.sis\project_name.txt") DO SET "ProjectName=%%p" + +IF NOT DEFINED ProjectName ( + + ECHO %SCRIPT_PATH_DOC%: could not read project name from .sis\project_name.txt 1>&2 + + EXIT /B 1 +) + +REM Examples that require human input may honour SIS_EXAMPLE_SMOKE for a +REM no-arg built-in tmpfile demo (see example.c.cstring_vector). +SET SIS_EXAMPLE_SMOKE=1 + +ECHO Running all %ProjectName% example programs + +FOR /F "usebackq" %%f IN (`DIR /A:-D /B /S "%CMAKE_DIR%" ^| FINDSTR /I example.*\.exe$`) DO CALL :run_program "%%f" + +ENDLOCAL & EXIT /B %PROGRAM_STATUS% + + +REM ########################################################## +REM subroutines + +:run_program +IF %PROGRAM_STATUS% NEQ 0 EXIT /B 0 +ECHO . +ECHO executing %~1 +"%~1" +SET "FAILURE_STATUS=%ERRORLEVEL%" +IF %FAILURE_STATUS% EQU 0 EXIT /B 0 +CALL :is_allowed_to_fail "%~1" +IF NOT DEFINED ALLOWED_TO_FAIL GOTO run_program_failed +ECHO anticipated failure: %~1 exited with status %FAILURE_STATUS%; it is listed in .sis\ci_examples_allowed_to_fail.txt +EXIT /B 0 +:run_program_failed +SET "PROGRAM_STATUS=%FAILURE_STATUS%" +EXIT /B 0 + +:is_allowed_to_fail +SET "ALLOWED_TO_FAIL=" +IF NOT EXIST "%ALLOWED_TO_FAIL_FILE%" EXIT /B 0 +FOR /F "usebackq eol=# tokens=1" %%n IN ("%ALLOWED_TO_FAIL_FILE%") DO CALL :match_allowed "%%n" "%~n1" "%~nx1" +EXIT /B 0 + +:match_allowed +IF /I "%~1"=="%~2" SET "ALLOWED_TO_FAIL=1" +IF /I "%~1"=="%~3" SET "ALLOWED_TO_FAIL=1" +EXIT /B 0 diff --git a/run_all_examples.sh b/run_all_examples.sh index 36154da..722326a 100755 --- a/run_all_examples.sh +++ b/run_all_examples.sh @@ -1,14 +1,163 @@ #! /bin/bash -ScriptPath=$0 -Dir=$(cd $(dirname "$ScriptPath"); pwd) -Basename=$(basename "$ScriptPath") +# ########################################################## +# functions - 1 + +sis_cmake_is_truey() { + case "$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')" in + + 1|ok|on|true|yes|y) + + return 0 + ;; + *) + + return 1 + ;; + esac +} + + +# ########################################################## +# constants and variables + +Basename=$(basename "$0") +Dir=$(cd "$(dirname "$0")" && pwd) CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build} -[[ -n "$MSYSTEM" ]] && DefaultMakeCmd=mingw32-make.exe || DefaultMakeCmd=make -MakeCmd=${SIS_CMAKE_MAKE_COMMAND:-${SIS_CMAKE_COMMAND:-$DefaultMakeCmd}} +ProjectNameFile="$Dir/.sis/project_name.txt" +ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile") +ScriptPath=$0 +AllowedToFailFile="$Dir/.sis/ci_examples_allowed_to_fail.txt" +AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}} ListOnly=0 RunMake=1 +SisUseColours=0 + + +# ########################################################## +# colours +# +# Enable when tput is available and either: +# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if +# empty/dumb), or +# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of +# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a +# TTY is OK). + +SisClr_Blue= +SisClr_Bold= +SisClr_Green= +SisClr_None= +SisClr_Red= +SisClr_Yellow= + +for arg in "$@"; do + + case $arg in + --always-use-colors|--always-use-colours|-A) + + AlwaysUseColours=1 + ;; + esac +done + +if command -v tput >/dev/null 2>&1; then + + if [ $AlwaysUseColours -ne 0 ]; then + + if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then + + TERM=xterm-256color + fi + + SisUseColours=1 + elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then + + SisUseColours=1 + fi +fi + +if [ $SisUseColours -ne 0 ]; then + + SisClr_Blue=${FG_BLUE:-$(tput setaf 4)} + SisClr_Bold=${FD_BOLD:-$(tput bold)} + SisClr_Green=${FG_GREEN:-$(tput setaf 2)} + SisClr_None=${FD_NONE:-$(tput sgr0)} + SisClr_Red=${FG_RED:-$(tput setaf 1)} + SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)} +fi + +CMakeDirClr="${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None}" +ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}" +ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}" + + +# ########################################################## +# functions - 2 + +sis_cmake_build() { + + local config="${SIS_CMAKE_CONFIG:-Release}" + local args=(--build "$CMakeDir") + if [ -f "$CMakeDir/CMakeCache.txt" ] && grep -q '^CMAKE_CONFIGURATION_TYPES:' "$CMakeDir/CMakeCache.txt" 2>/dev/null; then + + args+=(--config "$config") + fi + if [ "$#" -gt 0 ]; then + + local t + for t in "$@"; do + + args+=(--target "$t") + done + fi + + cmake "${args[@]}" +} + +# Reduces a program path to its (lowercase) name, without any directory or +# .exe suffix. +sis_program_stem() { + + local p="${1//\\//}" + + p="${p##*/}" + + case "$p" in + *.exe|*.EXE) p="${p%.*}" ;; + esac + + printf '%s' "$p" | tr '[:upper:]' '[:lower:]' +} + +# Succeeds if the program is named (by name or stem, case-insensitively) in +# the optional .sis/ci_examples_allowed_to_fail.txt file; blank lines and +# lines beginning with '#' are ignored. +sis_is_allowed_to_fail() { + + local name line + + [ -f "$AllowedToFailFile" ] || return 1 + + name=$(sis_program_stem "$1") + + while IFS= read -r line || [ -n "$line" ]; do + + line="${line//$'\r'/}" + + case "$line" in + ''|\#*) continue ;; + esac + + if [ "$name" = "$(sis_program_stem "$line")" ]; then + + return 0 + fi + done < "$AllowedToFailFile" + + return 1 +} # ########################################################## @@ -17,6 +166,10 @@ RunMake=1 while [[ $# -gt 0 ]]; do case $1 in + --always-use-colors|--always-use-colours|-A) + + # AlwaysUseColours=1 - this is handled by the for loop above + ;; --list-only|-l) ListOnly=1 @@ -29,21 +182,35 @@ while [[ $# -gt 0 ]]; do [ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt" cat << EOF -Runs all example programs +Runs all (matching) example programs -$ScriptPath [ ... flags/options ... ] +${ScriptPath} [ ... flags/options ... ] Flags/options: behaviour: + -A + --always-use-colors + --always-use-colours + forces use of colours even when stdout is not a TTY + -l --list-only lists the target programs but does not execute them -M --no-make - does not execute CMake and make before running tests + does not execute a build before running programs + + + files: + + .sis/ci_examples_allowed_to_fail.txt + optional list of example programs (one name per line; blank lines + and lines beginning with '#' are ignored) that are allowed to fail; + such a program is still executed, but a non-zero exit is reported as + anticipated and neither stops the run nor affects the exit status standard flags: @@ -57,7 +224,7 @@ EOF ;; *) - >&2 echo "$ScriptPath: unrecognised argument '$1'; use --help for usage" + >&2 echo "${ScriptPathClr}: unrecognised argument '${SisClr_Red}${SisClr_Bold}$1${SisClr_None}'; use --help for usage" exit 1 ;; @@ -76,22 +243,28 @@ if [ $RunMake -ne 0 ]; then if [ $ListOnly -eq 0 ]; then - echo "Executing build (via command \`$MakeCmd\`) and then running all example programs" + echo + echo "Executing build of ${ProjectNameClr} (via cmake --build) and then running all example programs" - mkdir -p $CMakeDir || exit 1 + mkdir -p "$CMakeDir" || exit 1 - cd $CMakeDir + if [ ! -f "$CMakeDir/CMakeCache.txt" ]; then - $MakeCmd - status=$? + >&2 echo "${ScriptPathClr}: '${CMakeDirClr}' is not configured; use prepare_cmake.sh first" + + exit 1 + fi - cd ->/dev/null + sis_cmake_build + status=$? fi else - if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ] || [ ! -d "$CMakeDir/CMakeFiles" ]; then + if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ]; then + + >&2 echo "${ScriptPathClr}: cannot run in '--no-make' mode without a previous successful configure/build" - >&2 echo "$ScriptPath: cannot run in '--no-make' mode without a previous successful build step" + exit 1 fi fi @@ -99,31 +272,77 @@ if [ $status -eq 0 ]; then if [ $ListOnly -ne 0 ]; then - echo "Listing all example programs" + echo + echo "Listing all ${ProjectNameClr} example programs" else - echo "Running all example programs" + echo + echo "Running all ${ProjectNameClr} example programs" fi - for f in $(find $CMakeDir/examples -type f -exec test -x {} \; -print) - do + # Examples that require human input may honour SIS_EXAMPLE_SMOKE for a + # no-arg built-in tmpfile demo (see example.c.cstring_vector). + export SIS_EXAMPLE_SMOKE=1 + + NumPrograms=0 + + while IFS= read -r -d '' f; do + + case "$f" in + *.pdb|*.ilk|*.log|*.obj|*.o) + continue + ;; + esac + + NumPrograms=$((NumPrograms + 1)) + + fClr="${SisClr_Blue}${SisClr_Bold}${f}${SisClr_None}" if [ $ListOnly -ne 0 ]; then - echo "would execute $f:" + if sis_is_allowed_to_fail "$f"; then + + echo "would execute ${fClr} (allowed to fail):" + else + + echo "would execute ${fClr}:" + fi continue fi echo - echo "executing $f:" + echo "executing ${fClr}:" + + if "$f"; then - $f - done + : + else + + fStatus=$? + + if sis_is_allowed_to_fail "$f"; then + + echo "${SisClr_Yellow}${SisClr_Bold}anticipated failure${SisClr_None}: ${fClr} exited with status ${fStatus}; it is listed in .sis/ci_examples_allowed_to_fail.txt" + + continue + fi + + status=$fStatus + + break 1 + fi + done < <(find "$CMakeDir" -type f \( -name 'example*' ! -name '*.md' \) \( -perm -100 -o -name '*.exe' \) -print0 2>/dev/null | sort -z) + + if [ $NumPrograms -eq 0 ]; then + + echo "${ScriptPathClr}: found no example programs under '${CMakeDirClr}' (none found)" + + exit 0 + fi fi exit $status # ############################## end of file ############################# # - diff --git a/run_all_performance_tests.cmd b/run_all_performance_tests.cmd new file mode 100644 index 0000000..ae97766 --- /dev/null +++ b/run_all_performance_tests.cmd @@ -0,0 +1,85 @@ +@echo off + +SETLOCAL + +SET SCRIPT_DIRECTORY=%~dp0 +SET SCRIPT_PATH_DOC=%~n0[%~x0] + +IF DEFINED SIS_CMAKE_BUILD_DIR ( + + SET CMAKE_DIR=%SIS_CMAKE_BUILD_DIR% +) ELSE ( + + SET CMAKE_DIR=%SCRIPT_DIRECTORY%_build +) + +FOR %%a IN (%*) DO ( + + IF /I {--help}=={%%a} ( + + IF EXIST "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" ( + + type "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" + ) + ECHO ^ + +Runs all ^(matching^) performance-test programs ^ + +^ + +%SCRIPT_PATH_DOC% [ ... flags/options ... ] ^ + +^ + +Flags/options: ^ + + behaviour: ^ + +^ + + standard flags: ^ + +^ + + --help ^ + + displays this help and terminates ^ + + + EXIT /B 0 + ) ELSE ( + + ECHO "%SCRIPT_DIRECTORY%: unrecognised argument '%%a'; use --help for usage" 1>&2 + + EXIT /B 1 + ) +) + +if NOT EXIST "%CMAKE_DIR%" ( + + ECHO "CMake build directory '%CMAKE_DIR%' does not exist" + + EXIT /B 1 +) + +SET "ProjectName=" +FOR /F "usebackq delims=" %%p IN ("%SCRIPT_DIRECTORY%.sis\project_name.txt") DO SET "ProjectName=%%p" + +IF NOT DEFINED ProjectName ( + + ECHO %SCRIPT_PATH_DOC%: could not read project name from .sis\project_name.txt 1>&2 + + EXIT /B 1 +) + +ECHO Running all %ProjectName% performance-test programs + +FOR /F "usebackq" %%f IN (`DIR /A:-D /B /S "%CMAKE_DIR%" ^| FINDSTR /I test.*performance.*\.exe$`) DO ( + + ECHO . + ECHO executing %%f + %%f + IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% +) + +ENDLOCAL diff --git a/run_all_performance_tests.sh b/run_all_performance_tests.sh new file mode 100755 index 0000000..3feaaff --- /dev/null +++ b/run_all_performance_tests.sh @@ -0,0 +1,276 @@ +#! /bin/bash + +# ########################################################## +# functions - 1 + +sis_cmake_is_truey() { + case "$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')" in + + 1|ok|on|true|yes|y) + + return 0 + ;; + *) + + return 1 + ;; + esac +} + + +# ########################################################## +# constants and variables + +Basename=$(basename "$0") +Dir=$(cd "$(dirname "$0")" && pwd) +CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build} +ProjectNameFile="$Dir/.sis/project_name.txt" +ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile") +ScriptPath=$0 + +AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}} +ListOnly=0 +RunMake=1 +SisUseColours=0 + + +# ########################################################## +# colours +# +# Enable when tput is available and either: +# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if +# empty/dumb), or +# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of +# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a +# TTY is OK). + +SisClr_Blue= +SisClr_Bold= +SisClr_Green= +SisClr_None= +SisClr_Red= +SisClr_Yellow= + +for arg in "$@"; do + + case $arg in + --always-use-colors|--always-use-colours|-A) + + AlwaysUseColours=1 + ;; + esac +done + +if command -v tput >/dev/null 2>&1; then + + if [ $AlwaysUseColours -ne 0 ]; then + + if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then + + TERM=xterm-256color + fi + + SisUseColours=1 + elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then + + SisUseColours=1 + fi +fi + +if [ $SisUseColours -ne 0 ]; then + + SisClr_Blue=${FG_BLUE:-$(tput setaf 4)} + SisClr_Bold=${FD_BOLD:-$(tput bold)} + SisClr_Green=${FG_GREEN:-$(tput setaf 2)} + SisClr_None=${FD_NONE:-$(tput sgr0)} + SisClr_Red=${FG_RED:-$(tput setaf 1)} + SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)} +fi + +CMakeDirClr="${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None}" +ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}" +ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}" + + +# ########################################################## +# functions - 2 + +sis_cmake_build() { + + local config="${SIS_CMAKE_CONFIG:-Release}" + local args=(--build "$CMakeDir") + if [ -f "$CMakeDir/CMakeCache.txt" ] && grep -q '^CMAKE_CONFIGURATION_TYPES:' "$CMakeDir/CMakeCache.txt" 2>/dev/null; then + + args+=(--config "$config") + fi + if [ "$#" -gt 0 ]; then + + local t + for t in "$@"; do + + args+=(--target "$t") + done + fi + + cmake "${args[@]}" +} + + +# ########################################################## +# command-line handling + +while [[ $# -gt 0 ]]; do + + case $1 in + --always-use-colors|--always-use-colours|-A) + + # AlwaysUseColours=1 - this is handled by the for loop above + ;; + --list-only|-l) + + ListOnly=1 + ;; + --no-make|-M) + + RunMake=0 + ;; + --help) + + [ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt" + cat << EOF +Runs all (matching) performance-test programs + +${ScriptPath} [ ... flags/options ... ] + +Flags/options: + + behaviour: + + -A + --always-use-colors + --always-use-colours + forces use of colours even when stdout is not a TTY + + -l + --list-only + lists the target programs but does not execute them + + -M + --no-make + does not execute a build before running programs + + + standard flags: + + --help + displays this help and terminates + +EOF + + exit 0 + ;; + *) + + >&2 echo "${ScriptPathClr}: unrecognised argument '${SisClr_Red}${SisClr_Bold}$1${SisClr_None}'; use --help for usage" + + exit 1 + ;; + esac + + shift +done + + +# ########################################################## +# main() + +status=0 + +if [ $RunMake -ne 0 ]; then + + if [ $ListOnly -eq 0 ]; then + + echo + echo "Executing build of ${ProjectNameClr} (via cmake --build) and then running all performance-test programs" + + mkdir -p "$CMakeDir" || exit 1 + + if [ ! -f "$CMakeDir/CMakeCache.txt" ]; then + + >&2 echo "${ScriptPathClr}: '${CMakeDirClr}' is not configured; use prepare_cmake.sh first" + + exit 1 + fi + + sis_cmake_build + status=$? + fi +else + + if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ]; then + + >&2 echo "${ScriptPathClr}: cannot run in '--no-make' mode without a previous successful configure/build" + + exit 1 + fi +fi + +if [ $status -eq 0 ]; then + + if [ $ListOnly -ne 0 ]; then + + echo + echo "Listing all ${ProjectNameClr} performance-test programs" + else + + echo + echo "Running all ${ProjectNameClr} performance-test programs" + fi + + NumPrograms=0 + + while IFS= read -r -d '' f; do + + case "$f" in + *.pdb|*.ilk|*.log|*.obj|*.o) + continue + ;; + esac + + NumPrograms=$((NumPrograms + 1)) + + fClr="${SisClr_Blue}${SisClr_Bold}${f}${SisClr_None}" + + if [ $ListOnly -ne 0 ]; then + + echo "would execute ${fClr}:" + + continue + fi + + echo + echo "executing ${fClr}:" + + if "$f"; then + + : + else + + status=$? + + break 1 + fi + done < <(find "$CMakeDir" -type f \( -name 'test_performance*' -o -name 'test.performance.*' \) \( -perm -100 -o -name '*.exe' \) -print0 2>/dev/null | sort -z) + + if [ $NumPrograms -eq 0 ]; then + + echo "${ScriptPathClr}: found no performance-test programs under '${CMakeDirClr}' (none found)" + + exit 0 + fi +fi + +exit $status + + +# ############################## end of file ############################# # diff --git a/run_all_scratch_tests.cmd b/run_all_scratch_tests.cmd new file mode 100644 index 0000000..0402fb1 --- /dev/null +++ b/run_all_scratch_tests.cmd @@ -0,0 +1,127 @@ +@echo off + +SETLOCAL + +SET SCRIPT_DIRECTORY=%~dp0 +SET SCRIPT_PATH_DOC=%~n0[%~x0] +SET "ALLOWED_TO_FAIL_FILE=%SCRIPT_DIRECTORY%.sis\ci_scratch_tests_allowed_to_fail.txt" +SET "PROGRAM_STATUS=0" + +IF DEFINED SIS_CMAKE_BUILD_DIR ( + + SET CMAKE_DIR=%SIS_CMAKE_BUILD_DIR% +) ELSE ( + + SET CMAKE_DIR=%SCRIPT_DIRECTORY%_build +) + +FOR %%a IN (%*) DO ( + + IF /I {--help}=={%%a} ( + + IF EXIST "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" ( + + type "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" + ) + ECHO ^ + +Runs all ^(matching^) scratch-test programs ^ + +^ + +%SCRIPT_PATH_DOC% [ ... flags/options ... ] ^ + +^ + +Flags/options: ^ + + behaviour: ^ + +^ + + standard flags: ^ + +^ + + --help ^ + + displays this help and terminates ^ + +^ + + files: ^ + +^ + + .sis\ci_scratch_tests_allowed_to_fail.txt ^ + + optional list of scratch-test programs ^(one name per line; ^ + + lines beginning with '#' are ignored^) that are allowed to fail; ^ + + such a program is still executed, but a non-zero exit is ^ + + reported as anticipated and does not stop the run ^ + + + EXIT /B 0 + ) ELSE ( + + ECHO "%SCRIPT_DIRECTORY%: unrecognised argument '%%a'; use --help for usage" 1>&2 + + EXIT /B 1 + ) +) + +if NOT EXIST "%CMAKE_DIR%" ( + + ECHO "CMake build directory '%CMAKE_DIR%' does not exist" + + EXIT /B 1 +) + +SET "ProjectName=" +FOR /F "usebackq delims=" %%p IN ("%SCRIPT_DIRECTORY%.sis\project_name.txt") DO SET "ProjectName=%%p" + +IF NOT DEFINED ProjectName ( + + ECHO %SCRIPT_PATH_DOC%: could not read project name from .sis\project_name.txt 1>&2 + + EXIT /B 1 +) + +ECHO Running all %ProjectName% scratch-test programs + +FOR /F "usebackq" %%f IN (`DIR /A:-D /B /S "%CMAKE_DIR%" ^| FINDSTR /I test.*scratch.*\.exe$`) DO CALL :run_program "%%f" + +ENDLOCAL & EXIT /B %PROGRAM_STATUS% + + +REM ########################################################## +REM subroutines + +:run_program +IF %PROGRAM_STATUS% NEQ 0 EXIT /B 0 +ECHO . +ECHO executing %~1 +"%~1" +SET "FAILURE_STATUS=%ERRORLEVEL%" +IF %FAILURE_STATUS% EQU 0 EXIT /B 0 +CALL :is_allowed_to_fail "%~1" +IF NOT DEFINED ALLOWED_TO_FAIL GOTO run_program_failed +ECHO anticipated failure: %~1 exited with status %FAILURE_STATUS%; it is listed in .sis\ci_scratch_tests_allowed_to_fail.txt +EXIT /B 0 +:run_program_failed +SET "PROGRAM_STATUS=%FAILURE_STATUS%" +EXIT /B 0 + +:is_allowed_to_fail +SET "ALLOWED_TO_FAIL=" +IF NOT EXIST "%ALLOWED_TO_FAIL_FILE%" EXIT /B 0 +FOR /F "usebackq eol=# tokens=1" %%n IN ("%ALLOWED_TO_FAIL_FILE%") DO CALL :match_allowed "%%n" "%~n1" "%~nx1" +EXIT /B 0 + +:match_allowed +IF /I "%~1"=="%~2" SET "ALLOWED_TO_FAIL=1" +IF /I "%~1"=="%~3" SET "ALLOWED_TO_FAIL=1" +EXIT /B 0 diff --git a/run_all_scratch_tests.sh b/run_all_scratch_tests.sh index 7aa99d8..6e06f13 100755 --- a/run_all_scratch_tests.sh +++ b/run_all_scratch_tests.sh @@ -1,15 +1,163 @@ #! /bin/bash -ScriptPath=$0 -Dir=$(cd $(dirname "$ScriptPath"); pwd) -Basename=$(basename "$ScriptPath") +# ########################################################## +# functions - 1 + +sis_cmake_is_truey() { + case "$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')" in + + 1|ok|on|true|yes|y) + + return 0 + ;; + *) + + return 1 + ;; + esac +} + + +# ########################################################## +# constants and variables + +Basename=$(basename "$0") +Dir=$(cd "$(dirname "$0")" && pwd) CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build} -[[ -n "$MSYSTEM" ]] && DefaultMakeCmd=mingw32-make.exe || DefaultMakeCmd=make -MakeCmd=${SIS_CMAKE_MAKE_COMMAND:-${SIS_CMAKE_COMMAND:-$DefaultMakeCmd}} +ProjectNameFile="$Dir/.sis/project_name.txt" +ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile") +ScriptPath=$0 +AllowedToFailFile="$Dir/.sis/ci_scratch_tests_allowed_to_fail.txt" +AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}} ListOnly=0 RunMake=1 -Verbosity=${XTESTS_VERBOSITY:-${TEST_VERBOSITY:-3}} +SisUseColours=0 + + +# ########################################################## +# colours +# +# Enable when tput is available and either: +# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if +# empty/dumb), or +# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of +# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a +# TTY is OK). + +SisClr_Blue= +SisClr_Bold= +SisClr_Green= +SisClr_None= +SisClr_Red= +SisClr_Yellow= + +for arg in "$@"; do + + case $arg in + --always-use-colors|--always-use-colours|-A) + + AlwaysUseColours=1 + ;; + esac +done + +if command -v tput >/dev/null 2>&1; then + + if [ $AlwaysUseColours -ne 0 ]; then + + if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then + + TERM=xterm-256color + fi + + SisUseColours=1 + elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then + + SisUseColours=1 + fi +fi + +if [ $SisUseColours -ne 0 ]; then + + SisClr_Blue=${FG_BLUE:-$(tput setaf 4)} + SisClr_Bold=${FD_BOLD:-$(tput bold)} + SisClr_Green=${FG_GREEN:-$(tput setaf 2)} + SisClr_None=${FD_NONE:-$(tput sgr0)} + SisClr_Red=${FG_RED:-$(tput setaf 1)} + SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)} +fi + +CMakeDirClr="${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None}" +ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}" +ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}" + + +# ########################################################## +# functions - 2 + +sis_cmake_build() { + + local config="${SIS_CMAKE_CONFIG:-Release}" + local args=(--build "$CMakeDir") + if [ -f "$CMakeDir/CMakeCache.txt" ] && grep -q '^CMAKE_CONFIGURATION_TYPES:' "$CMakeDir/CMakeCache.txt" 2>/dev/null; then + + args+=(--config "$config") + fi + if [ "$#" -gt 0 ]; then + + local t + for t in "$@"; do + + args+=(--target "$t") + done + fi + + cmake "${args[@]}" +} + +# Reduces a program path to its (lowercase) name, without any directory or +# .exe suffix. +sis_program_stem() { + + local p="${1//\\//}" + + p="${p##*/}" + + case "$p" in + *.exe|*.EXE) p="${p%.*}" ;; + esac + + printf '%s' "$p" | tr '[:upper:]' '[:lower:]' +} + +# Succeeds if the program is named (by name or stem, case-insensitively) in +# the optional .sis/ci_scratch_tests_allowed_to_fail.txt file; blank lines +# and lines beginning with '#' are ignored. +sis_is_allowed_to_fail() { + + local name line + + [ -f "$AllowedToFailFile" ] || return 1 + + name=$(sis_program_stem "$1") + + while IFS= read -r line || [ -n "$line" ]; do + + line="${line//$'\r'/}" + + case "$line" in + ''|\#*) continue ;; + esac + + if [ "$name" = "$(sis_program_stem "$line")" ]; then + + return 0 + fi + done < "$AllowedToFailFile" + + return 1 +} # ########################################################## @@ -18,6 +166,10 @@ Verbosity=${XTESTS_VERBOSITY:-${TEST_VERBOSITY:-3}} while [[ $# -gt 0 ]]; do case $1 in + --always-use-colors|--always-use-colours|-A) + + # AlwaysUseColours=1 - this is handled by the for loop above + ;; --list-only|-l) ListOnly=1 @@ -26,33 +178,40 @@ while [[ $# -gt 0 ]]; do RunMake=0 ;; - --verbosity) - - shift - Verbosity=$1 - ;; --help) [ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt" cat << EOF -Runs all (matching) performance-test and scratch-test programs +Runs all (matching) scratch-test programs -$ScriptPath [ ... flags/options ... ] +${ScriptPath} [ ... flags/options ... ] Flags/options: behaviour: + -A + --always-use-colors + --always-use-colours + forces use of colours even when stdout is not a TTY + -l --list-only lists the target programs but does not execute them -M --no-make - does not execute CMake and make before running tests + does not execute a build before running programs + - --verbosity - specifies an explicit verbosity for the unit-test(s) + files: + + .sis/ci_scratch_tests_allowed_to_fail.txt + optional list of scratch-test programs (one name per line; blank + lines and lines beginning with '#' are ignored) that are allowed to + fail; such a program is still executed, but a non-zero exit is + reported as anticipated and neither stops the run nor affects the + exit status standard flags: @@ -66,7 +225,7 @@ EOF ;; *) - >&2 echo "$ScriptPath: unrecognised argument '$1'; use --help for usage" + >&2 echo "${ScriptPathClr}: unrecognised argument '${SisClr_Red}${SisClr_Bold}$1${SisClr_None}'; use --help for usage" exit 1 ;; @@ -85,22 +244,28 @@ if [ $RunMake -ne 0 ]; then if [ $ListOnly -eq 0 ]; then - echo "Executing build (via command \`$MakeCmd\`) and then running all scratch (and performance) test programs" + echo + echo "Executing build of ${ProjectNameClr} (via cmake --build) and then running all scratch-test programs" - mkdir -p $CMakeDir || exit 1 + mkdir -p "$CMakeDir" || exit 1 - cd $CMakeDir + if [ ! -f "$CMakeDir/CMakeCache.txt" ]; then - $MakeCmd - status=$? + >&2 echo "${ScriptPathClr}: '${CMakeDirClr}' is not configured; use prepare_cmake.sh first" - cd ->/dev/null + exit 1 + fi + + sis_cmake_build + status=$? fi else - if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ] || [ ! -d "$CMakeDir/CMakeFiles" ]; then + if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ]; then + + >&2 echo "${ScriptPathClr}: cannot run in '--no-make' mode without a previous successful configure/build" - >&2 echo "$ScriptPath: cannot run in '--no-make' mode without a previous successful build step" + exit 1 fi fi @@ -108,38 +273,73 @@ if [ $status -eq 0 ]; then if [ $ListOnly -ne 0 ]; then - echo "Listing all scratch (and performance) test programs" + echo + echo "Listing all ${ProjectNameClr} scratch-test programs" else - echo "Running all scratch (and performance) test programs" + echo + echo "Running all ${ProjectNameClr} scratch-test programs" fi - for f in $(find $CMakeDir -type f '(' -name 'test_scratch*' -o -name 'test.scratch.*' -o -name 'test_performance*' -o -name 'test.performance.*' ')' -exec test -x {} \; -print) - do + NumPrograms=0 + + while IFS= read -r -d '' f; do + + case "$f" in + *.pdb|*.ilk|*.log|*.obj|*.o) + continue + ;; + esac + + NumPrograms=$((NumPrograms + 1)) + + fClr="${SisClr_Blue}${SisClr_Bold}${f}${SisClr_None}" if [ $ListOnly -ne 0 ]; then - echo "would execute $f:" + if sis_is_allowed_to_fail "$f"; then + + echo "would execute ${fClr} (allowed to fail):" + else + + echo "would execute ${fClr}:" + fi continue fi - if [ $Verbosity -ge 3 ]; then + echo + echo "executing ${fClr}:" - echo - fi - if [ $Verbosity -ge 2 ]; then + if "$f"; then + + : + else + + fStatus=$? + + if sis_is_allowed_to_fail "$f"; then + + echo "${SisClr_Yellow}${SisClr_Bold}anticipated failure${SisClr_None}: ${fClr} exited with status ${fStatus}; it is listed in .sis/ci_scratch_tests_allowed_to_fail.txt" + + continue + fi - echo "executing $f:" + status=$fStatus + + break 1 fi + done < <(find "$CMakeDir" -type f \( -name 'test_scratch*' -o -name 'test.scratch.*' \) \( -perm -100 -o -name '*.exe' \) -print0 2>/dev/null | sort -z) + + if [ $NumPrograms -eq 0 ]; then + + echo "${ScriptPathClr}: found no scratch-test programs under '${CMakeDirClr}' (none found)" - # NOTE: we do not break on fail, because, this being a unit-testing library, some tests actually fail intentionally - $f - done + exit 0 + fi fi exit $status # ############################## end of file ############################# # - diff --git a/run_all_unit_tests.cmd b/run_all_unit_tests.cmd new file mode 100644 index 0000000..18b040a --- /dev/null +++ b/run_all_unit_tests.cmd @@ -0,0 +1,94 @@ +@echo off + +SETLOCAL + +SET SCRIPT_DIRECTORY=%~dp0 +SET SCRIPT_PATH_DOC=%~n0[%~x0] + +IF DEFINED SIS_CMAKE_BUILD_DIR ( + + SET CMAKE_DIR=%SIS_CMAKE_BUILD_DIR% +) ELSE ( + + SET CMAKE_DIR=%SCRIPT_DIRECTORY%_build +) + +FOR %%a IN (%*) DO ( + + IF /I {--help}=={%%a} ( + + IF EXIST "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" ( + + type "%SCRIPT_DIRECTORY%.sis\script_info_lines.txt" + ) + ECHO ^ + +Runs all ^(matching^) unit-test programs ^ + +^ + +%SCRIPT_PATH_DOC% [ ... flags/options ... ] ^ + +^ + +Flags/options: ^ + + behaviour: ^ + +^ + + --unit-only ^ + + accepted for compatibility; this script always runs unit tests only ^ + +^ + + standard flags: ^ + +^ + + --help ^ + + displays this help and terminates ^ + + + EXIT /B 0 + ) ELSE IF /I {--unit-only}=={%%a} ( + + REM Benign: this script is already unit-only + ) ELSE ( + + ECHO "%SCRIPT_DIRECTORY%: unrecognised argument '%%a'; use --help for usage" 1>&2 + + EXIT /B 1 + ) +) + +if NOT EXIST "%CMAKE_DIR%" ( + + ECHO "CMake build directory '%CMAKE_DIR%' does not exist" + + EXIT /B 1 +) + +SET "ProjectName=" +FOR /F "usebackq delims=" %%p IN ("%SCRIPT_DIRECTORY%.sis\project_name.txt") DO SET "ProjectName=%%p" + +IF NOT DEFINED ProjectName ( + + ECHO %SCRIPT_PATH_DOC%: could not read project name from .sis\project_name.txt 1>&2 + + EXIT /B 1 +) + +ECHO Running all %ProjectName% unit-test programs + +FOR /F "usebackq" %%f IN (`DIR /A:-D /B /S "%CMAKE_DIR%" ^| FINDSTR /I test.*unit.*\.exe$`) DO ( + + ECHO . + ECHO executing %%f + %%f + IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% +) + +ENDLOCAL diff --git a/run_all_unit_tests.sh b/run_all_unit_tests.sh index 24a1140..301ccae 100755 --- a/run_all_unit_tests.sh +++ b/run_all_unit_tests.sh @@ -1,14 +1,120 @@ #! /bin/bash -ScriptPath=$0 -Dir=$(cd $(dirname "$ScriptPath"); pwd) -Basename=$(basename "$ScriptPath") +# ########################################################## +# functions - 1 + +sis_cmake_is_truey() { + case "$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')" in + + 1|ok|on|true|yes|y) + + return 0 + ;; + *) + + return 1 + ;; + esac +} + + +# ########################################################## +# constants and variables + +Basename=$(basename "$0") +Dir=$(cd "$(dirname "$0")" && pwd) CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build} -MakeCmd=${SIS_CMAKE_COMMAND:-make} +ProjectNameFile="$Dir/.sis/project_name.txt" +ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile") +ScriptPath=$0 +AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}} ListOnly=0 RunMake=1 -Verbosity=3 +SisUseColours=0 +Verbosity=${XTESTS_VERBOSITY:-${TEST_VERBOSITY:-3}} + + +# ########################################################## +# colours +# +# Enable when tput is available and either: +# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if +# empty/dumb), or +# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of +# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a +# TTY is OK). + +SisClr_Blue= +SisClr_Bold= +SisClr_Green= +SisClr_None= +SisClr_Red= +SisClr_Yellow= + +for arg in "$@"; do + + case $arg in + --always-use-colors|--always-use-colours|-A) + + AlwaysUseColours=1 + ;; + esac +done + +if command -v tput >/dev/null 2>&1; then + + if [ $AlwaysUseColours -ne 0 ]; then + + if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then + + TERM=xterm-256color + fi + + SisUseColours=1 + elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then + + SisUseColours=1 + fi +fi + +if [ $SisUseColours -ne 0 ]; then + + SisClr_Blue=${FG_BLUE:-$(tput setaf 4)} + SisClr_Bold=${FD_BOLD:-$(tput bold)} + SisClr_Green=${FG_GREEN:-$(tput setaf 2)} + SisClr_None=${FD_NONE:-$(tput sgr0)} + SisClr_Red=${FG_RED:-$(tput setaf 1)} + SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)} +fi + +CMakeDirClr="${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None}" +ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}" +ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}" + + +# ########################################################## +# functions - 2 + +sis_cmake_build() { + + local config="${SIS_CMAKE_CONFIG:-Release}" + local args=(--build "$CMakeDir") + if [ -f "$CMakeDir/CMakeCache.txt" ] && grep -q '^CMAKE_CONFIGURATION_TYPES:' "$CMakeDir/CMakeCache.txt" 2>/dev/null; then + + args+=(--config "$config") + fi + if [ "$#" -gt 0 ]; then + + local t + for t in "$@"; do + + args+=(--target "$t") + done + fi + + cmake "${args[@]}" +} # ########################################################## @@ -17,14 +123,22 @@ Verbosity=3 while [[ $# -gt 0 ]]; do case $1 in - -l|--list-only) + --always-use-colors|--always-use-colours|-A) + + # AlwaysUseColours=1 - this is handled by the for loop above + ;; + --list-only|-l) ListOnly=1 ;; - -M|--no-make) + --no-make|-M) RunMake=0 ;; + --unit-only) + + # Benign: this script is already unit-only (aggregate / CI may pass it) + ;; --verbosity) shift @@ -36,22 +150,30 @@ while [[ $# -gt 0 ]]; do cat << EOF Runs all (matching) unit-test programs -$ScriptPath [ ... flags/options ... ] +${ScriptPath} [ ... flags/options ... ] Flags/options: behaviour: + -A + --always-use-colors + --always-use-colours + forces use of colours even when stdout is not a TTY + -l --list-only lists the target programs but does not execute them -M --no-make - does not execute CMake and make before running tests + does not execute a build before running programs + + --unit-only + accepted for compatibility; this script always runs unit tests only --verbosity - specifies an explicit verbosity for the unit-test(s) + specifies an explicit verbosity, forwarded to each program standard flags: @@ -65,7 +187,7 @@ EOF ;; *) - >&2 echo "$ScriptPath: unrecognised argument '$1'; use --help for usage" + >&2 echo "${ScriptPathClr}: unrecognised argument '${SisClr_Red}${SisClr_Bold}$1${SisClr_None}'; use --help for usage" exit 1 ;; @@ -84,22 +206,28 @@ if [ $RunMake -ne 0 ]; then if [ $ListOnly -eq 0 ]; then - echo "Executing build (via command \`$MakeCmd\`) and then running all component and unit test programs" + echo + echo "Executing build of ${ProjectNameClr} (via cmake --build) and then running all unit-test programs" - mkdir -p $CMakeDir || exit 1 + mkdir -p "$CMakeDir" || exit 1 - cd $CMakeDir + if [ ! -f "$CMakeDir/CMakeCache.txt" ]; then - $MakeCmd - status=$? + >&2 echo "${ScriptPathClr}: '${CMakeDirClr}' is not configured; use prepare_cmake.sh first" + + exit 1 + fi - cd ->/dev/null + sis_cmake_build + status=$? fi else - if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ] || [ ! -d "$CMakeDir/CMakeFiles" ]; then + if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ]; then - >&2 echo "$ScriptPath: cannot run in '--no-make' mode without a previous successful build step" + >&2 echo "${ScriptPathClr}: cannot run in '--no-make' mode without a previous successful configure/build" + + exit 1 fi fi @@ -107,18 +235,31 @@ if [ $status -eq 0 ]; then if [ $ListOnly -ne 0 ]; then - echo "Listing all component and unit test programs" + echo + echo "Listing all ${ProjectNameClr} unit-test programs" else - echo "Running all component and unit test programs" + echo + echo "Running all ${ProjectNameClr} unit-test programs" fi - for f in $(find $CMakeDir -type f '(' -name 'test_unit*' -o -name 'test.unit.*' -o -name 'test_component*' -o -name 'test.component.*' ')' -exec test -x {} \; -print) - do + NumPrograms=0 + + while IFS= read -r -d '' f; do + + case "$f" in + *.pdb|*.ilk|*.log|*.obj|*.o) + continue + ;; + esac + + NumPrograms=$((NumPrograms + 1)) + + fClr="${SisClr_Blue}${SisClr_Bold}${f}${SisClr_None}" if [ $ListOnly -ne 0 ]; then - echo "would execute $f:" + echo "would execute ${fClr}:" continue fi @@ -129,10 +270,10 @@ if [ $status -eq 0 ]; then fi if [ $Verbosity -ge 2 ]; then - echo "executing $f:" + echo "executing ${fClr}:" fi - if $f --verbosity=$Verbosity; then + if "$f" --verbosity="$Verbosity"; then : else @@ -141,11 +282,17 @@ if [ $status -eq 0 ]; then break 1 fi - done + done < <(find "$CMakeDir" -type f \( -name 'test_unit*' -o -name 'test.unit.*' \) \( -perm -100 -o -name '*.exe' \) -print0 2>/dev/null | sort -z) + + if [ $NumPrograms -eq 0 ]; then + + echo "${ScriptPathClr}: found no unit-test programs under '${CMakeDirClr}' (none found)" + + exit 0 + fi fi exit $status # ############################## end of file ############################# # - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 957fa1f..2afeb8b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,7 @@ # Purpose: CMake lists file for libpath core library # # Created: ... -# Updated: 18th October 2024 +# Updated: 13th October 2026 # # ######################################################################## # @@ -71,10 +71,8 @@ target_include_directories(core $ ) -target_link_libraries(core - PRIVATE - $<$:STLSoft::STLSoft> -) +# core is standalone: no PUBLIC/PRIVATE link to STLSoft or xTests. +# STLSoft and xTests are test-only (see top-level CMakeLists.txt). target_compile_options(core PRIVATE diff --git a/test/scratch/CMakeLists.txt b/test/scratch/CMakeLists.txt index d6f5b2d..9169d22 100644 --- a/test/scratch/CMakeLists.txt +++ b/test/scratch/CMakeLists.txt @@ -1,6 +1,3 @@ - -add_subdirectory(test.scratch.compare.models) - - -# ############################## end of file ############################# # - +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +add_subdirectory(compare-models) +add_subdirectory(versions) diff --git a/test/unit/test.unit.version/CMakeLists.txt b/test/scratch/compare-models/CMakeLists.txt similarity index 57% rename from test/unit/test.unit.version/CMakeLists.txt rename to test/scratch/compare-models/CMakeLists.txt index cbc7b6c..06ef07b 100644 --- a/test/unit/test.unit.version/CMakeLists.txt +++ b/test/scratch/compare-models/CMakeLists.txt @@ -1,2 +1,2 @@ # SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten -define_automated_test_program(test.unit.version test.unit.version.c) +define_example_program(test.scratch.compare-models main.cpp) diff --git a/test/scratch/test.scratch.compare.models/test.scratch.compare.models.cpp b/test/scratch/compare-models/main.cpp similarity index 93% rename from test/scratch/test.scratch.compare.models/test.scratch.compare.models.cpp rename to test/scratch/compare-models/main.cpp index 16693bb..f62835a 100644 --- a/test/scratch/test.scratch.compare.models/test.scratch.compare.models.cpp +++ b/test/scratch/compare-models/main.cpp @@ -1,10 +1,10 @@ /* ///////////////////////////////////////////////////////////////////////// - * File: test.scratch.compare.models.cpp + * File: test/scratch/compare-models/main.cpp * - * Purpose: Implementation file for the test.scratch.compare.models project. + * Purpose: Scratch exercise of libpath compare models. * * Created: 29th March 2013 - * Updated: 19th October 2024 + * Updated: 14th October 2026 * * ////////////////////////////////////////////////////////////////////// */ diff --git a/test/scratch/test.scratch.compare.models/CMakeLists.txt b/test/scratch/test.scratch.compare.models/CMakeLists.txt deleted file mode 100644 index 47b44a0..0000000 --- a/test/scratch/test.scratch.compare.models/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten -define_example_program(test.scratch.compare.models test.scratch.compare.models.cpp) diff --git a/test/unit/test.unit.parse.c/CMakeLists.txt b/test/scratch/versions/CMakeLists.txt similarity index 57% rename from test/unit/test.unit.parse.c/CMakeLists.txt rename to test/scratch/versions/CMakeLists.txt index b271006..316c4d2 100644 --- a/test/unit/test.unit.parse.c/CMakeLists.txt +++ b/test/scratch/versions/CMakeLists.txt @@ -1,2 +1,2 @@ # SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten -define_automated_test_program(test.unit.parse.c test.unit.parse.c.c) +define_example_program(test.scratch.versions main.cpp) diff --git a/test/scratch/versions/main.cpp b/test/scratch/versions/main.cpp new file mode 100644 index 0000000..81073e7 --- /dev/null +++ b/test/scratch/versions/main.cpp @@ -0,0 +1,55 @@ + +#include + +#include +#include + +#include + + +template< + typename T_stream +, typename T_integer +> +void +version( + T_stream& stm +, char const* prefix +, char const* libname +, char const* macroname +, T_integer libver +) +{ + stm + << prefix + << libname + << ": v" + << ((libver >> 24) & 0xff) + << '.' + << ((libver >> 16) & 0xff) + << '.' + << ((libver >> 8) & 0xff) + << '.' + << ((libver >> 0) & 0xff) + << " (" + << macroname + << " = 0x" + << std::hex << std::setfill('0') << std::setw(8) + << static_cast(libver) + << std::dec + << ")" + << std::endl + ; +} + + +int main(int /*argc*/, char* /*argv*/[]) +{ + { + unsigned const libver = LIBPATH_VER; + + version(std::cout, "", "libpath", "LIBPATH_VER", libver); + } + + return EXIT_SUCCESS; +} diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index b164989..31abad2 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -1,14 +1,10 @@ - -add_subdirectory(test.unit.compare.1) -add_subdirectory(test.unit.compare.1.c) -add_subdirectory(test.unit.equal.1) -add_subdirectory(test.unit.equal.1.c) -add_subdirectory(test.unit.parse.1) -add_subdirectory(test.unit.parse.c) -add_subdirectory(test.unit.shim_strings) -add_subdirectory(test.unit.type_strings) -add_subdirectory(test.unit.version) - - -# ############################## end of file ############################# # - +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +add_subdirectory(compare) +add_subdirectory(compare.C) +add_subdirectory(equal) +add_subdirectory(equal.C) +add_subdirectory(parse) +add_subdirectory(parse.C) +add_subdirectory(shim-strings) +add_subdirectory(type-strings) +add_subdirectory(version) diff --git a/test/unit/test.unit.parse.1/CMakeLists.txt b/test/unit/compare.C/CMakeLists.txt similarity index 56% rename from test/unit/test.unit.parse.1/CMakeLists.txt rename to test/unit/compare.C/CMakeLists.txt index 54dc9f1..32b6271 100644 --- a/test/unit/test.unit.parse.1/CMakeLists.txt +++ b/test/unit/compare.C/CMakeLists.txt @@ -1,2 +1,2 @@ # SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten -define_automated_test_program(test.unit.parse.1 test.unit.parse.1.cpp) +define_automated_test_program(test.unit.compare.C entry.c) diff --git a/test/unit/compare.C/entry.c b/test/unit/compare.C/entry.c new file mode 100644 index 0000000..1244a2a --- /dev/null +++ b/test/unit/compare.C/entry.c @@ -0,0 +1,758 @@ +/* ///////////////////////////////////////////////////////////////////////// + * File: test/unit/compare.C/entry.c + * + * Purpose: Unit-tests the libpath C compare API. + * + * Created: 28th March 2013 + * Updated: 14th October 2026 + * + * ////////////////////////////////////////////////////////////////////// */ + + +/* ///////////////////////////////////////////////////////////////////////// + * includes + */ + +/* ///////////////////////////////////// + * test component header file include(s) + */ + +#include + +/* ///////////////////////////////////// + * general includes + */ + +/* xTests header files */ +#include + +/* STLSoft header files */ +#include + +/* Standard C header files */ +#include +#include +#include + + +/* ///////////////////////////////////////////////////////////////////////// + * forward declarations + */ + +static void test_1_0(void); +static void test_1_1(void); +static void test_1_2(void); +static void test_1_3(void); +static void test_1_4(void); +static void test_1_5(void); +static void test_1_6(void); +static void test_1_7(void); +static void test_1_8(void); +static void test_1_9(void); +static void test_1_10(void); +static void test_1_11(void); +static void test_1_12(void); +static void test_1_13(void); +static void test_1_14(void); +static void test_1_15(void); +static void test_1_16(void); +static void test_1_17(void); + + +/* ///////////////////////////////////////////////////////////////////////// + * helper functions + */ + +int main(int argc, char* argv[]) +{ + int retCode = EXIT_SUCCESS; + int verbosity = 2; + + XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); + + if (XTESTS_START_RUNNER("test.unit.compare.C", verbosity)) + { + XTESTS_RUN_CASE(test_1_0); + XTESTS_RUN_CASE(test_1_1); + XTESTS_RUN_CASE(test_1_2); + XTESTS_RUN_CASE(test_1_3); + XTESTS_RUN_CASE(test_1_4); + XTESTS_RUN_CASE(test_1_5); + XTESTS_RUN_CASE(test_1_6); + XTESTS_RUN_CASE(test_1_7); + XTESTS_RUN_CASE(test_1_8); + XTESTS_RUN_CASE(test_1_9); + XTESTS_RUN_CASE(test_1_10); + XTESTS_RUN_CASE(test_1_11); + XTESTS_RUN_CASE(test_1_12); + XTESTS_RUN_CASE(test_1_13); + XTESTS_RUN_CASE(test_1_14); + XTESTS_RUN_CASE(test_1_15); + XTESTS_RUN_CASE(test_1_16); + XTESTS_RUN_CASE(test_1_17); + + XTESTS_PRINT_RESULTS(); + + XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); + } + + return retCode; +} + + +/* ///////////////////////////////////////////////////////////////////////// + * test function implementations + */ + +int +compare_paths( + char const* lhs +, char const* rhs +, char const* cwd +, char const* mem +) +{ + libpath_sint32_t flags = 0; + libpath_WorkingDirectoryContext_t ctxt; + int result; + LIBPATH_RC rc; + + STLSOFT_SUPPRESS_UNUSED(mem); + + ctxt.mechanism = libpath_WorkingDirectoryContextMechanism_CStyleString; + ctxt.details.cwd_css = cwd; + + rc = libpath_Compare_ComparePathsAsCStyleStrings( + lhs + , rhs + , flags + , &ctxt + , LIBPATH_LF_nullptr + , &result + ); + + if (LIBPATH_RC_OF(Success) != rc) + { + TEST_FAIL_WITH_QUALIFIER("call to `libpath_Compare_ComparePathsAsCStyleStrings()` failed", ""); + } + + return result; +} + + +static void test_1_0(void) +{ + // Just entry parts + + TEST_INT_EQ(0, compare_paths("file.ext", "file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("fil1.ext", "fil2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("fil2.ext", "fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + + TEST_INT_EQ(0, compare_paths("...", "...", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("...", "....", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("....", "...", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths("file.ext", "FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("fil1.ext", "fil2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("FIL2.EXT", "FIL1.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_1(void) +{ + // Just rooted entry parts + + TEST_INT_EQ(0, compare_paths("/file.ext", "/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("/fil1.ext", "/fil2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("/fil2.ext", "/fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths( "/file.ext", "/FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("\\file.ext", "/FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths( "/file.ext", "\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("\\file.ext", "\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths( "/fil1.ext", "/FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths( "/FIL2.EXT", "/fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("\\fil1.ext", "/FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\FIL2.EXT", "/fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths( "/fil1.ext", "\\FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths( "/FIL2.EXT", "\\fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("\\fil1.ext", "\\FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\FIL2.EXT", "\\fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_2(void) +{ + // Windows-rooted entry parts + +#ifdef LIBPATH_OS_IS_WINDOWS + + // case of entry-part + + TEST_INT_EQ(0, compare_paths( "C:/file.ext", "C:/FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("C:\\file.ext", "C:/FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths( "C:/file.ext", "C:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("C:\\file.ext", "C:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths( "C:/fil1.ext", "C:/FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths( "C:/FIL2.EXT", "C:/fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:\\fil1.ext", "C:/FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:\\FIL2.EXT", "C:/fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths( "C:/fil1.ext", "C:\\FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths( "C:/FIL2.EXT", "C:\\fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:\\fil1.ext", "C:\\FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:\\FIL2.EXT", "C:\\fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + + // case of volume part + + TEST_INT_EQ(0, compare_paths("C:\\file.ext", "C:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("C:\\file.ext", "c:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("c:\\file.ext", "C:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("c:\\file.ext", "c:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + + // different volumes + + TEST_INT_LT(0, compare_paths("C:\\file.ext", "D:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:\\file.ext", "d:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("c:\\file.ext", "D:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("c:\\file.ext", "d:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +#endif +} + +static void test_1_3(void) +{ + // Just directory parts + + TEST_INT_EQ(0, compare_paths("dir1/", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("dir1/", "dir2/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("dir2/", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths("dir1/", "DIR1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("DIR1/", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("DIR1/", "DIR1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("dir1/", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/", "dir1\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1\\", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1\\", "dir1\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("dir1/", "DIR2/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("DIR2/", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/", "DIR2\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("DIR2/", "dir1\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1\\", "DIR2/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("DIR2\\", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1\\", "DIR2\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("DIR2\\", "dir1\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_4(void) +{ + // Just single dots dir - 1-dot + + TEST_INT_EQ(0, compare_paths(".", ".", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths(".", "./", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("./", ".", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("./", "./", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths(".", ".", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths(".", ".\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths(".\\", ".", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("./", ".\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths(".\\", "./", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths(".\\", ".\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_5(void) +{ + // Just single dots dir - 2-dot + + TEST_INT_EQ(0, compare_paths("..", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("..", "../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("../", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("../", "../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths("..", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("..", "..\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("..\\", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("../", "..\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("..\\", "../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("..\\", "..\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_6(void) +{ + // mixed dots entities + + TEST_INT_EQ(0, compare_paths(".", ".", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("..", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("...", "...", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths(".", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("..", "...", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); // '...' is a file; '..' is a directory + + TEST_INT_LT(0, compare_paths("...", "....", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("....", ".....", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +} + +static void test_1_7(void) +{ + // root directory + + TEST_INT_EQ(0, compare_paths("/", "/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths("/", "\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("\\", "/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("\\", "\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_8(void) +{ + // more complex relative paths + + TEST_INT_LT(0, compare_paths("dir1/dir2/file.ext", "dir1/dir3/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("dir1/dir3/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("dir1/dir2/file.ext", "dir1/dir21/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("dir1/dir21/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +} + +static void test_1_9(void) +{ + // absolute vs relative - no cwd + + TEST_INT_LT(0, compare_paths("file.ext", "/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("/file.ext", "file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/file.ext", "/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("/dir1/file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/dir2/file.ext", "/dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("/dir1/dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("/", "abcdefghijklmnopqrstuvwxyz.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_LT(0, compare_paths("file.ext", "C:\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:\\file.ext", "file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:\\dir1\\file.ext", "dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:\\dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "X:\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("X:\\", "abcdefghijklmnopqrstuvwxyz.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_10(void) +{ + // absolute vs rooted - no cwd + +#ifdef LIBPATH_OS_IS_WINDOWS + + TEST_INT_LT(0, compare_paths("\\file.ext", "C:\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:\\file.ext", "\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("\\dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:\\dir1\\file.ext", "\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("\\dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:\\dir1\\dir2\\file.ext", "\\dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("\\abcdefghijklmnopqrstuvwxyz.ext", "X:\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("X:\\", "\\abcdefghijklmnopqrstuvwxyz.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_11(void) +{ + // absolute vs relative - cwd + + TEST_INT_EQ(0, compare_paths( "/file1.ext", "file1.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths( "/file1.ext", "file2.ext", "/", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths( "/dir1/dir2/file1.ext", "file1.ext", "/dir1/dir2/", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths( "/dir1/dir2/file1.ext", "file2.ext", "/dir1/dir2/", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths( "/dir1/dir2/file1.ext", "dir2/file1.ext", "/dir1/", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths( "/dir1/dir2/file1.ext", "dir2/file2.ext", "/dir1/", LIBPATH_LF_nullptr)); + +#if LIBPATH_VER >= 0x00040000 + TEST_INT_EQ(0, compare_paths( "/dir1/dir2/file1.ext", "file1.ext", "//dir1//dir2/", LIBPATH_LF_nullptr)); +#endif + + TEST_INT_LT(0, compare_paths( "/file1.ext", "file2.ext", "/", LIBPATH_LF_nullptr)); + + + + TEST_INT_LT(0, compare_paths( "/file1.ext", "file2.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths( "/file1.ext", "file1.ext", "/", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("file.ext", "/file.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("/file.ext", "file.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/file.ext", "/dir1/file.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("/dir1/file.ext", "dir1/file.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/dir2/file.ext", "/dir1/dir2/file.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("/dir1/dir2/file.ext", "dir1/dir2/file.ext", "/", LIBPATH_LF_nullptr)); + + TEST_INT_GT(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "/", "/", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/", "abcdefghijklmnopqrstuvwxyz.ext", "/", LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_WINDOWS + + TEST_INT_EQ(0, compare_paths( "/file1.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths( "/file1.ext", "file2.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths( "/file2.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths( "/file1.ext", "file1.ext", "C:\\dir1\\", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths( "/file1.ext", "file2.ext", "C:\\dir1\\", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths( "/file2.ext", "file1.ext", "C:\\dir1\\", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths( "C:/file1.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths( "C:/file1.ext", "file2.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths( "C:/file2.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); + + TEST_INT_GT(0, compare_paths( "D:/file1.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths( "D:/file1.ext", "file2.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths( "D:/file2.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("file.ext", "C:\\file.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:\\file.ext", "file.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1\\file.ext", "C:\\dir1\\file.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:\\dir1\\file.ext", "dir1\\file.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:\\dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext", "/", LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "X:\\", "/", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("X:\\", "abcdefghijklmnopqrstuvwxyz.ext", "/", LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_12(void) +{ + // paths that need canonicalising + + // file1.ext <=> file1.ext + TEST_INT_EQ(0, compare_paths("file1.ext", "file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("file1.ext", "dir1/../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/../file1.ext", "file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("./file1.ext", "dir1/dir2/../../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/dir2/../../file1.ext", "./file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("./file1.ext", "dir1/../dir2/../dir3/../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/../dir2/../dir3/../file1.ext", "./file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + // dir1/file1.ext <=> dir1/file1.ext + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "dir1/./file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/./file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "./dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("./dir1/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "dir1/././././././././././././././././././././././././././././././././file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/././././././././././././././././././././././././././././././././file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "dir1/dir2/../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/dir2/../file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + // dir1/dir2/file1.ext <=> dir1/dir2/file1.ext + TEST_INT_EQ(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/dir2/file1.ext", "dir1/./dir2/./file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/./dir2/./file1.ext", "dir1/dir2/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/dir3/../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + // d1/d2/d3/d4/d5/file1.ext <=> d1/d2/d3/d4/d5/file1.ext + TEST_INT_EQ(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "./d1/./d2/./d3/./d4/./d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("./d1/./d2/./d3/./d4/./d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext", "d1/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + + // file1.ext <=> file2.ext + TEST_INT_LT(0, compare_paths("file1.ext", "file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("file1.ext", "dir1/../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/../file1.ext", "file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("./file1.ext", "dir1/dir2/../../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/dir2/../../file1.ext", "./file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("./file1.ext", "dir1/../dir2/../dir3/../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/../dir2/../dir3/../file1.ext", "./file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + // dir1/file1.ext <=> dir1/file2.ext + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "dir1/./file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/./file1.ext", "dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "./dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("./dir1/file1.ext", "dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "dir1/././././././././././././././././././././././././././././././././file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/././././././././././././././././././././././././././././././././file1.ext", "dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "dir1/dir2/../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/dir2/../file1.ext", "dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + // dir1/dir2/file1.ext <=> dir1/dir2/file2.ext + TEST_INT_LT(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/dir2/file1.ext", "dir1/./dir2/./file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/./dir2/./file1.ext", "dir1/dir2/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/dir3/../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + // d1/d2/d3/d4/d5/file1.ext <=> d1/d2/d3/d4/d5/file2.ext + TEST_INT_LT(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "./d1/./d2/./d3/./d4/./d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("./d1/./d2/./d3/./d4/./d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext", "d1/d2/d3/d4/d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + +} + +static void test_1_13(void) +{ + // trailing dots + + TEST_INT_EQ(0, compare_paths("dir1/dir2/..", "dir1/dir2/../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/dir2/..", "dir1/dir3/../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/dir3/..", "dir1/dir2/../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/dir2/..", "dir4/dir3/../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("dir4/dir3/..", "dir1/dir2/../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("dir1/dir2/.", "dir1/dir2/./", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +} + +static void test_1_14(void) +{ + // sliding [rel / cwd] + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d6/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d5/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d4/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d3/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d2/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file1.ext", "/d1", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file2.ext", "/d1", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d6/file1.ext", "/d1", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d5/d5/file1.ext", "/d1", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d4/d4/d5/file1.ext", "/d1", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d3/d4/d5/file1.ext", "/d1", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file1.ext", "/d2", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d1/d2", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file2.ext", "/d1/d2", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d6/file1.ext", "/d1/d2", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d5/d5/file1.ext", "/d1/d2", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d4/d5/file1.ext", "/d1/d2", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d1/d3", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d2/d2", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d2/d3", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file2.ext", "/d1/d2/d3", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d6/file1.ext", "/d1/d2/d3", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/d5/file1.ext", "/d1/d2/d3", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d2/d4", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d3/d3", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d2/d2/d3", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d3/d4", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file2.ext", "/d1/d2/d3/d4", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d6/file1.ext", "/d1/d2/d3/d4", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d3/d5", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d4/d4", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d3/d3/d4", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d2/d2/d3/d4", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d4/d5", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file2.ext", "/d1/d2/d3/d4/d5", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d4/d6", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d5/d5", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d4/d4/d5", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d3/d3/d4/d5", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d2/d2/d3/d4/d5", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d5/d6", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file2.ext", "/d1/d2/d3/d4/d5/d6", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d5/d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d6/d6", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d5/d5/d6", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d4/d4/d5/d6", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d3/d3/d4/d5/d6", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d2/d2/d3/d4/d5/d6", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d6/d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file2.ext", "/d1/d2/d3/d4/d5/d6/d7", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d6/d8", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d7/d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d6/d6/d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d5/d5/d6/d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d4/d4/d5/d6/d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d3/d3/d4/d5/d6/d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d2/d2/d3/d4/d5/d6/d7", LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_WINDOWS + + TEST_INT_EQ(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file2.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d8", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d7\\d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d6\\d6\\d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d5\\d5\\d6\\d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d4\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d3\\d3\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d2\\d2\\d3\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "D:\\d1\\d2\\d3\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); + +#endif +} + +static void test_1_15(void) +{ + // UNC roots + +#ifdef LIBPATH_OS_IS_WINDOWS + + TEST_INT_EQ(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("\\\\server1\\share1/dir1\\file1.ext", "\\\\server1\\share1\\dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1\\dir1\\file2.ext", "\\\\server1\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir2\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1\\dir2\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share2\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\\\server1\\share2\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server2\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\\\server2\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +#endif +} + +static void test_1_16(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + + TEST_INT_EQ(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file1.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file2.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("dir1\\file2.ext", "C:\\dir1\\file1.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1\\file1.ext", "C:\\dir2\\file1.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("dir2\\file1.ext", "C:\\dir1\\file1.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1\\file1.ext", "D:\\dir1\\file1.ext", "C:\\", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file1.ext", "D:\\", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file1.ext", "C:", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file2.ext", "C:", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\dir1\\file2.ext", "C:\\dir1\\file1.ext", "C:", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("\\dir1\\file1.ext", "C:\\dir2\\file1.ext", "C:", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\dir2\\file1.ext", "C:\\dir1\\file1.ext", "C:", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("\\dir1\\file1.ext", "D:\\dir1\\file1.ext", "C:", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file1.ext", "D:", LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_17(void) +{ + TEST_INT_LT(0, compare_paths("file1.ext", "file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("file2.ext", "file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "dir2/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("dir2/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("/dir1/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_WINDOWS + + // absolute, rooted, and relative paths + + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:/dir1/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:/dir1/file1.ext", "/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("/dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:/dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "C:/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + + // relative paths with volumes + + TEST_INT_EQ(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext", "D:", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "C:dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext", "D:", LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "D:", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "D:/dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); + + TEST_INT_GT(0, compare_paths("dir1/file2.ext", "C:/dir1/file1.ext", "C:/", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("dir2/file1.ext", "C:/dir1/file1.ext", "C:/", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/file2.ext", "C:/dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir2/file1.ext", "C:/dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "C:/", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "D:/", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "D:/dir1/file1.ext", "C:/", LIBPATH_LF_nullptr)); + + TEST_INT_LT(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file1.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file2.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:dir1/file1.ext", "C:/dir2/file1.ext", "/", LIBPATH_LF_nullptr)); + + TEST_INT_EQ(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir1/", LIBPATH_LF_nullptr)); + TEST_INT_EQ(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir1", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:file1.ext", "C:/dir1/file2.ext", "/dir1", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:file2.ext", "C:/dir1/file1.ext", "/dir1", LIBPATH_LF_nullptr)); + TEST_INT_LT(0, compare_paths("C:file1.ext", "C:/dir2/file1.ext", "/dir1", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir2", LIBPATH_LF_nullptr)); + + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext", "C:/", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "C:dir1/file1.ext", "/", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "file1.ext", "dir1", LIBPATH_LF_nullptr)); +#endif +} + + +/* ///////////////////////////// end of file //////////////////////////// */ + diff --git a/test/unit/compare/CMakeLists.txt b/test/unit/compare/CMakeLists.txt new file mode 100644 index 0000000..1b59cb4 --- /dev/null +++ b/test/unit/compare/CMakeLists.txt @@ -0,0 +1,2 @@ +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +define_automated_test_program(test.unit.compare entry.cpp) diff --git a/test/unit/compare/entry.cpp b/test/unit/compare/entry.cpp new file mode 100644 index 0000000..760cfee --- /dev/null +++ b/test/unit/compare/entry.cpp @@ -0,0 +1,777 @@ +/* ///////////////////////////////////////////////////////////////////////// + * File: test/unit/compare/entry.cpp + * + * Purpose: Unit-tests the libpath C++ compare API. + * + * Created: 17th February 2013 + * Updated: 14th October 2026 + * + * ////////////////////////////////////////////////////////////////////// */ + + +/* ///////////////////////////////////////////////////////////////////////// + * includes + */ + +/* ///////////////////////////////////// + * test component header file include(s) + */ + +#include + +/* ///////////////////////////////////// + * general includes + */ + +/* xTests header files */ +#include + +/* STLSoft header files */ +#include + +/* Standard C++ header files */ +#include +#include + +/* Standard C header files */ +#include +#include +#include + + +/* ///////////////////////////////////////////////////////////////////////// + * forward declarations + */ + +namespace +{ + + static void test_compare_filenames(void); + static void test_compare_slash_rooted_filenames(void); + static void test_compare_Windows_drive_rooted_filenames(void); + static void test_compare_relative_directory(void); + static void test_compare_dots_directory(void); + static void test_compare_2dotsdir(void); + static void test_compare_mixed_dots_directory(void); + static void test_compare_slash(void); + static void test_compare_2_dirs_and_filename(void); + static void test_compare_slash_rooted_filename(void); + static void test_Windows_mixed_rooted_paths(void); + static void test_mixed_with_root_pwd(void); + static void test_noncanonical_paths(void); + static void test_noncanonical_paths_trailing_dots(void); + static void test_sliding_rel_and_cwd(void); + static void test_compare_UNC_rooted_paths(void); + static void test_Windows_mixed_pwd(void); + static void test_mixed_comparisons(void); +} // anonymous namespace + + +/* ///////////////////////////////////////////////////////////////////////// + * helper functions + */ + +int main(int argc, char* argv[]) +{ + int retCode = EXIT_SUCCESS; + int verbosity = 2; + + XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); + + if (XTESTS_START_RUNNER("test.unit.compare", verbosity)) + { + XTESTS_RUN_CASE(test_compare_filenames); + XTESTS_RUN_CASE(test_compare_slash_rooted_filenames); + XTESTS_RUN_CASE(test_compare_Windows_drive_rooted_filenames); + XTESTS_RUN_CASE(test_compare_relative_directory); + XTESTS_RUN_CASE(test_compare_dots_directory); + XTESTS_RUN_CASE(test_compare_2dotsdir); + XTESTS_RUN_CASE(test_compare_mixed_dots_directory); + XTESTS_RUN_CASE(test_compare_slash); + XTESTS_RUN_CASE(test_compare_2_dirs_and_filename); + XTESTS_RUN_CASE(test_compare_slash_rooted_filename); + XTESTS_RUN_CASE(test_Windows_mixed_rooted_paths); + XTESTS_RUN_CASE(test_mixed_with_root_pwd); + XTESTS_RUN_CASE(test_noncanonical_paths); + XTESTS_RUN_CASE(test_noncanonical_paths_trailing_dots); + XTESTS_RUN_CASE(test_sliding_rel_and_cwd); + XTESTS_RUN_CASE(test_compare_UNC_rooted_paths); + XTESTS_RUN_CASE(test_Windows_mixed_pwd); + XTESTS_RUN_CASE(test_mixed_comparisons); + + XTESTS_PRINT_RESULTS(); + + XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); + } + + return retCode; +} + + +/* ///////////////////////////////////////////////////////////////////////// + * test function implementations + */ + +namespace +{ +// using libpath::comparing::compare_paths; + + inline + int + compare_paths( + char const* lhs + , char const* rhs + , char const* cwd = LIBPATH_LF_nullptr + , char const* /*mem*/ = LIBPATH_LF_nullptr + ) + { + libpath_sint32_t flags = 0; + libpath_WorkingDirectoryContext_t ctxt; + int result; + + ctxt.mechanism = libpath_WorkingDirectoryContextMechanism_CStyleString; + ctxt.details.cwd_css = cwd; + + LIBPATH_RC rc = libpath_Compare_ComparePathsAsCStyleStrings( + lhs + , rhs + , flags + , &ctxt + , LIBPATH_LF_nullptr + , &result + ); + + switch (rc) + { + case LIBPATH_RC_OF(FirstPathInvalid): + case LIBPATH_RC_OF(SecondPathInvalid): + case LIBPATH_RC_OF(WorkingDirectoryPathInvalid): + + break; + default: + + break; + } + + if (LIBPATH_RC_FAILURE(rc)) + { + return INT_MIN; + } + + return result; + } + + + +static void test_compare_filenames(void) +{ + // Just entry parts + + TEST_INT_EQ(0, compare_paths("file.ext", "file.ext")); + + TEST_INT_LT(0, compare_paths("fil1.ext", "fil2.ext")); + TEST_INT_GT(0, compare_paths("fil2.ext", "fil1.ext")); + + + TEST_INT_EQ(0, compare_paths("...", "...")); + + TEST_INT_LT(0, compare_paths("...", "....")); + TEST_INT_GT(0, compare_paths("....", "...")); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths("file.ext", "FILE.EXT")); + + TEST_INT_LT(0, compare_paths("fil1.ext", "fil2.ext")); + TEST_INT_GT(0, compare_paths("FIL2.EXT", "FIL1.EXT")); +#endif +} + +static void test_compare_slash_rooted_filenames(void) +{ + // Just rooted entry parts + + TEST_INT_EQ(0, compare_paths("/file.ext", "/file.ext")); + + TEST_INT_LT(0, compare_paths("/fil1.ext", "/fil2.ext")); + TEST_INT_GT(0, compare_paths("/fil2.ext", "/fil1.ext")); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths( "/file.ext", "/FILE.EXT")); + TEST_INT_EQ(0, compare_paths("\\file.ext", "/FILE.EXT")); + TEST_INT_EQ(0, compare_paths( "/file.ext", "\\FILE.EXT")); + TEST_INT_EQ(0, compare_paths("\\file.ext", "\\FILE.EXT")); + + TEST_INT_LT(0, compare_paths( "/fil1.ext", "/FIL2.EXT")); + TEST_INT_GT(0, compare_paths( "/FIL2.EXT", "/fil1.ext")); + TEST_INT_LT(0, compare_paths("\\fil1.ext", "/FIL2.EXT")); + TEST_INT_GT(0, compare_paths("\\FIL2.EXT", "/fil1.ext")); + TEST_INT_LT(0, compare_paths( "/fil1.ext", "\\FIL2.EXT")); + TEST_INT_GT(0, compare_paths( "/FIL2.EXT", "\\fil1.ext")); + TEST_INT_LT(0, compare_paths("\\fil1.ext", "\\FIL2.EXT")); + TEST_INT_GT(0, compare_paths("\\FIL2.EXT", "\\fil1.ext")); +#endif +} + +static void test_compare_Windows_drive_rooted_filenames(void) +{ + // Windows-rooted entry parts + +#ifdef LIBPATH_OS_IS_WINDOWS + + // case of entry-part + + TEST_INT_EQ(0, compare_paths( "C:/file.ext", "C:/FILE.EXT")); + TEST_INT_EQ(0, compare_paths("C:\\file.ext", "C:/FILE.EXT")); + TEST_INT_EQ(0, compare_paths( "C:/file.ext", "C:\\FILE.EXT")); + TEST_INT_EQ(0, compare_paths("C:\\file.ext", "C:\\FILE.EXT")); + + TEST_INT_LT(0, compare_paths( "C:/fil1.ext", "C:/FIL2.EXT")); + TEST_INT_GT(0, compare_paths( "C:/FIL2.EXT", "C:/fil1.ext")); + TEST_INT_LT(0, compare_paths("C:\\fil1.ext", "C:/FIL2.EXT")); + TEST_INT_GT(0, compare_paths("C:\\FIL2.EXT", "C:/fil1.ext")); + TEST_INT_LT(0, compare_paths( "C:/fil1.ext", "C:\\FIL2.EXT")); + TEST_INT_GT(0, compare_paths( "C:/FIL2.EXT", "C:\\fil1.ext")); + TEST_INT_LT(0, compare_paths("C:\\fil1.ext", "C:\\FIL2.EXT")); + TEST_INT_GT(0, compare_paths("C:\\FIL2.EXT", "C:\\fil1.ext")); + + + // case of volume part + + TEST_INT_EQ(0, compare_paths("C:\\file.ext", "C:\\FILE.EXT")); + TEST_INT_EQ(0, compare_paths("C:\\file.ext", "c:\\FILE.EXT")); + TEST_INT_EQ(0, compare_paths("c:\\file.ext", "C:\\FILE.EXT")); + TEST_INT_EQ(0, compare_paths("c:\\file.ext", "c:\\FILE.EXT")); + + + // different volumes + + TEST_INT_LT(0, compare_paths("C:\\file.ext", "D:\\FILE.EXT")); + TEST_INT_LT(0, compare_paths("C:\\file.ext", "d:\\FILE.EXT")); + TEST_INT_LT(0, compare_paths("c:\\file.ext", "D:\\FILE.EXT")); + TEST_INT_LT(0, compare_paths("c:\\file.ext", "d:\\FILE.EXT")); + +#endif +} + +static void test_compare_relative_directory(void) +{ + // Just directory parts + + TEST_INT_EQ(0, compare_paths("dir1/", "dir1/")); + + TEST_INT_LT(0, compare_paths("dir1/", "dir2/")); + TEST_INT_GT(0, compare_paths("dir2/", "dir1/")); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths("dir1/", "DIR1/")); + TEST_INT_EQ(0, compare_paths("DIR1/", "dir1/")); + TEST_INT_EQ(0, compare_paths("DIR1/", "DIR1/")); + + TEST_INT_EQ(0, compare_paths("dir1/", "dir1/")); + TEST_INT_EQ(0, compare_paths("dir1/", "dir1\\")); + TEST_INT_EQ(0, compare_paths("dir1\\", "dir1/")); + TEST_INT_EQ(0, compare_paths("dir1\\", "dir1\\")); + + TEST_INT_LT(0, compare_paths("dir1/", "DIR2/")); + TEST_INT_GT(0, compare_paths("DIR2/", "dir1/")); + TEST_INT_LT(0, compare_paths("dir1/", "DIR2\\")); + TEST_INT_GT(0, compare_paths("DIR2/", "dir1\\")); + TEST_INT_LT(0, compare_paths("dir1\\", "DIR2/")); + TEST_INT_GT(0, compare_paths("DIR2\\", "dir1/")); + TEST_INT_LT(0, compare_paths("dir1\\", "DIR2\\")); + TEST_INT_GT(0, compare_paths("DIR2\\", "dir1\\")); +#endif +} + +static void test_compare_dots_directory(void) +{ + // Just single dots dir - 1-dot + + TEST_INT_EQ(0, compare_paths(".", ".")); + TEST_INT_EQ(0, compare_paths(".", "./")); + TEST_INT_EQ(0, compare_paths("./", ".")); + TEST_INT_EQ(0, compare_paths("./", "./")); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths(".", ".")); + TEST_INT_EQ(0, compare_paths(".", ".\\")); + TEST_INT_EQ(0, compare_paths(".\\", ".")); + TEST_INT_EQ(0, compare_paths("./", ".\\")); + TEST_INT_EQ(0, compare_paths(".\\", "./")); + TEST_INT_EQ(0, compare_paths(".\\", ".\\")); +#endif +} + +static void test_compare_2dotsdir(void) +{ + // Just single dots dir - 2-dot + + TEST_INT_EQ(0, compare_paths("..", "..")); + TEST_INT_EQ(0, compare_paths("..", "../")); + TEST_INT_EQ(0, compare_paths("../", "..")); + TEST_INT_EQ(0, compare_paths("../", "../")); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths("..", "..")); + TEST_INT_EQ(0, compare_paths("..", "..\\")); + TEST_INT_EQ(0, compare_paths("..\\", "..")); + TEST_INT_EQ(0, compare_paths("../", "..\\")); + TEST_INT_EQ(0, compare_paths("..\\", "../")); + TEST_INT_EQ(0, compare_paths("..\\", "..\\")); +#endif +} + +static void test_compare_mixed_dots_directory(void) +{ + // mixed dots entities + + TEST_INT_EQ(0, compare_paths(".", ".")); + TEST_INT_EQ(0, compare_paths("..", "..")); + TEST_INT_EQ(0, compare_paths("...", "...")); + + TEST_INT_LT(0, compare_paths(".", "..")); + TEST_INT_GT(0, compare_paths("..", "...")); // '...' is a file; '..' is a directory + + TEST_INT_LT(0, compare_paths("...", "....")); + TEST_INT_LT(0, compare_paths("....", ".....")); +} + +static void test_compare_slash(void) +{ + // root directory + + TEST_INT_EQ(0, compare_paths("/", "/")); + +#ifdef LIBPATH_OS_IS_UNIX +#endif + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0, compare_paths("/", "\\")); + TEST_INT_EQ(0, compare_paths("\\", "/")); + TEST_INT_EQ(0, compare_paths("\\", "\\")); +#endif +} + +static void test_compare_2_dirs_and_filename(void) +{ + // more complex relative paths + + TEST_INT_LT(0, compare_paths("dir1/dir2/file.ext", "dir1/dir3/file.ext")); + TEST_INT_GT(0, compare_paths("dir1/dir3/file.ext", "dir1/dir2/file.ext")); + + TEST_INT_LT(0, compare_paths("dir1/dir2/file.ext", "dir1/dir21/file.ext")); + TEST_INT_GT(0, compare_paths("dir1/dir21/file.ext", "dir1/dir2/file.ext")); +} + +static void test_compare_slash_rooted_filename(void) +{ + // absolute vs relative - no cwd + + TEST_INT_LT(0, compare_paths("file.ext", "/file.ext")); + TEST_INT_GT(0, compare_paths("/file.ext", "file.ext")); + TEST_INT_LT(0, compare_paths("dir1/file.ext", "/dir1/file.ext")); + TEST_INT_GT(0, compare_paths("/dir1/file.ext", "dir1/file.ext")); + TEST_INT_LT(0, compare_paths("dir1/dir2/file.ext", "/dir1/dir2/file.ext")); + TEST_INT_GT(0, compare_paths("/dir1/dir2/file.ext", "dir1/dir2/file.ext")); + + TEST_INT_LT(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "/")); + TEST_INT_GT(0, compare_paths("/", "abcdefghijklmnopqrstuvwxyz.ext")); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_LT(0, compare_paths("file.ext", "C:\\file.ext")); + TEST_INT_GT(0, compare_paths("C:\\file.ext", "file.ext")); + TEST_INT_LT(0, compare_paths("dir1\\file.ext", "C:\\dir1\\file.ext")); + TEST_INT_GT(0, compare_paths("C:\\dir1\\file.ext", "dir1\\file.ext")); + TEST_INT_LT(0, compare_paths("dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext")); + TEST_INT_GT(0, compare_paths("C:\\dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext")); + + TEST_INT_LT(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "X:\\")); + TEST_INT_GT(0, compare_paths("X:\\", "abcdefghijklmnopqrstuvwxyz.ext")); +#endif +} + +static void test_Windows_mixed_rooted_paths(void) +{ + // absolute vs rooted - no cwd + +#ifdef LIBPATH_OS_IS_WINDOWS + + TEST_INT_LT(0, compare_paths("\\file.ext", "C:\\file.ext")); + TEST_INT_GT(0, compare_paths("C:\\file.ext", "\\file.ext")); + TEST_INT_LT(0, compare_paths("\\dir1\\file.ext", "C:\\dir1\\file.ext")); + TEST_INT_GT(0, compare_paths("C:\\dir1\\file.ext", "\\dir1\\file.ext")); + TEST_INT_LT(0, compare_paths("\\dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext")); + TEST_INT_GT(0, compare_paths("C:\\dir1\\dir2\\file.ext", "\\dir1\\dir2\\file.ext")); + + TEST_INT_LT(0, compare_paths("\\abcdefghijklmnopqrstuvwxyz.ext", "X:\\")); + TEST_INT_GT(0, compare_paths("X:\\", "\\abcdefghijklmnopqrstuvwxyz.ext")); +#endif +} + +static void test_mixed_with_root_pwd(void) +{ + // absolute vs relative - cwd + + TEST_INT_EQ(0, compare_paths( "/file1.ext", "file1.ext", "/")); + TEST_INT_LT(0, compare_paths( "/file1.ext", "file2.ext", "/")); + + TEST_INT_EQ(0, compare_paths( "/dir1/dir2/file1.ext", "file1.ext", "/dir1/dir2/")); + TEST_INT_LT(0, compare_paths( "/dir1/dir2/file1.ext", "file2.ext", "/dir1/dir2/")); + + TEST_INT_EQ(0, compare_paths( "/dir1/dir2/file1.ext", "dir2/file1.ext", "/dir1/")); + TEST_INT_LT(0, compare_paths( "/dir1/dir2/file1.ext", "dir2/file2.ext", "/dir1/")); + +#if LIBPATH_VER >= 0x00040000 + TEST_INT_EQ(0, compare_paths( "/dir1/dir2/file1.ext", "file1.ext", "//dir1//dir2/")); +#endif + + TEST_INT_LT(0, compare_paths( "/file1.ext", "file2.ext", "/")); + + TEST_INT_LT(0, compare_paths( "/file1.ext", "file2.ext", "/")); + TEST_INT_EQ(0, compare_paths( "/file1.ext", "file1.ext", "/")); + + TEST_INT_EQ(0, compare_paths("file.ext", "/file.ext", "/")); + TEST_INT_EQ(0, compare_paths("/file.ext", "file.ext", "/")); + TEST_INT_EQ(0, compare_paths("dir1/file.ext", "/dir1/file.ext", "/")); + TEST_INT_EQ(0, compare_paths("/dir1/file.ext", "dir1/file.ext", "/")); + TEST_INT_EQ(0, compare_paths("dir1/dir2/file.ext", "/dir1/dir2/file.ext", "/")); + TEST_INT_EQ(0, compare_paths("/dir1/dir2/file.ext", "dir1/dir2/file.ext", "/")); + + TEST_INT_GT(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "/", "/")); + TEST_INT_LT(0, compare_paths("/", "abcdefghijklmnopqrstuvwxyz.ext", "/")); + +#ifdef LIBPATH_OS_IS_WINDOWS + + TEST_INT_EQ(0, compare_paths( "/file1.ext", "file1.ext", "C:\\")); + TEST_INT_LT(0, compare_paths( "/file1.ext", "file2.ext", "C:\\")); + TEST_INT_GT(0, compare_paths( "/file2.ext", "file1.ext", "C:\\")); + + TEST_INT_LT(0, compare_paths( "/file1.ext", "file1.ext", "C:\\dir1\\")); + TEST_INT_LT(0, compare_paths( "/file1.ext", "file2.ext", "C:\\dir1\\")); + TEST_INT_LT(0, compare_paths( "/file2.ext", "file1.ext", "C:\\dir1\\")); + + TEST_INT_EQ(0, compare_paths( "C:/file1.ext", "file1.ext", "C:\\")); + TEST_INT_LT(0, compare_paths( "C:/file1.ext", "file2.ext", "C:\\")); + TEST_INT_GT(0, compare_paths( "C:/file2.ext", "file1.ext", "C:\\")); + + TEST_INT_GT(0, compare_paths( "D:/file1.ext", "file1.ext", "C:\\")); + TEST_INT_GT(0, compare_paths( "D:/file1.ext", "file2.ext", "C:\\")); + TEST_INT_GT(0, compare_paths( "D:/file2.ext", "file1.ext", "C:\\")); + + TEST_INT_LT(0, compare_paths("file.ext", "C:\\file.ext", "/")); + TEST_INT_GT(0, compare_paths("C:\\file.ext", "file.ext", "/")); + TEST_INT_LT(0, compare_paths("dir1\\file.ext", "C:\\dir1\\file.ext", "/")); + TEST_INT_GT(0, compare_paths("C:\\dir1\\file.ext", "dir1\\file.ext", "/")); + TEST_INT_LT(0, compare_paths("dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext", "/")); + TEST_INT_GT(0, compare_paths("C:\\dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext", "/")); + + TEST_INT_LT(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "X:\\", "/")); + TEST_INT_GT(0, compare_paths("X:\\", "abcdefghijklmnopqrstuvwxyz.ext", "/")); +#endif +} + +static void test_noncanonical_paths(void) +{ + // paths that need canonicalising + + // file1.ext <=> file1.ext + TEST_INT_EQ(0, compare_paths("file1.ext", "file1.ext")); + TEST_INT_EQ(0, compare_paths("file1.ext", "dir1/../file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/../file1.ext", "file1.ext")); + TEST_INT_EQ(0, compare_paths("./file1.ext", "dir1/dir2/../../file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/dir2/../../file1.ext", "./file1.ext")); + TEST_INT_EQ(0, compare_paths("./file1.ext", "dir1/../dir2/../dir3/../file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/../dir2/../dir3/../file1.ext", "./file1.ext")); + + // dir1/file1.ext <=> dir1/file1.ext + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "dir1/file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "dir1/./file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/./file1.ext", "dir1/file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "./dir1/file1.ext")); + TEST_INT_EQ(0, compare_paths("./dir1/file1.ext", "dir1/file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "dir1/././././././././././././././././././././././././././././././././file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/././././././././././././././././././././././././././././././././file1.ext", "dir1/file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "dir1/dir2/../file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/dir2/../file1.ext", "dir1/file1.ext")); + + // dir1/dir2/file1.ext <=> dir1/dir2/file1.ext + TEST_INT_EQ(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/dir2/file1.ext", "dir1/./dir2/./file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/./dir2/./file1.ext", "dir1/dir2/file1.ext")); + TEST_INT_EQ(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/dir3/../file1.ext")); + + // d1/d2/d3/d4/d5/file1.ext <=> d1/d2/d3/d4/d5/file1.ext + TEST_INT_EQ(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext")); + TEST_INT_EQ(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "./d1/./d2/./d3/./d4/./d5/file1.ext")); + TEST_INT_EQ(0, compare_paths("./d1/./d2/./d3/./d4/./d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext")); + + TEST_INT_EQ(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext")); + TEST_INT_EQ(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext")); + TEST_INT_EQ(0, compare_paths("d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext", "d1/d2/d3/d4/d5/file1.ext")); + + + // file1.ext <=> file2.ext + TEST_INT_LT(0, compare_paths("file1.ext", "file2.ext")); + TEST_INT_LT(0, compare_paths("file1.ext", "dir1/../file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/../file1.ext", "file2.ext")); + TEST_INT_LT(0, compare_paths("./file1.ext", "dir1/dir2/../../file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/dir2/../../file1.ext", "./file2.ext")); + TEST_INT_LT(0, compare_paths("./file1.ext", "dir1/../dir2/../dir3/../file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/../dir2/../dir3/../file1.ext", "./file2.ext")); + + // dir1/file1.ext <=> dir1/file2.ext + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "dir1/file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "dir1/./file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/./file1.ext", "dir1/file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "./dir1/file2.ext")); + TEST_INT_LT(0, compare_paths("./dir1/file1.ext", "dir1/file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "dir1/././././././././././././././././././././././././././././././././file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/././././././././././././././././././././././././././././././././file1.ext", "dir1/file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "dir1/dir2/../file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/dir2/../file1.ext", "dir1/file2.ext")); + + // dir1/dir2/file1.ext <=> dir1/dir2/file2.ext + TEST_INT_LT(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/dir2/file1.ext", "dir1/./dir2/./file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/./dir2/./file1.ext", "dir1/dir2/file2.ext")); + TEST_INT_LT(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/dir3/../file2.ext")); + + // d1/d2/d3/d4/d5/file1.ext <=> d1/d2/d3/d4/d5/file2.ext + TEST_INT_LT(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext")); + TEST_INT_LT(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "./d1/./d2/./d3/./d4/./d5/file2.ext")); + TEST_INT_LT(0, compare_paths("./d1/./d2/./d3/./d4/./d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext")); + + TEST_INT_LT(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext")); + TEST_INT_LT(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file2.ext")); + TEST_INT_LT(0, compare_paths("d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext", "d1/d2/d3/d4/d5/file2.ext")); +} + +static void test_noncanonical_paths_trailing_dots(void) +{ + // trailing dots + + TEST_INT_EQ(0, compare_paths("dir1/dir2/..", "dir1/dir2/../")); + TEST_INT_EQ(0, compare_paths("dir1/dir2/..", "dir1/dir3/../")); + TEST_INT_EQ(0, compare_paths("dir1/dir3/..", "dir1/dir2/../")); + TEST_INT_LT(0, compare_paths("dir1/dir2/..", "dir4/dir3/../")); + TEST_INT_GT(0, compare_paths("dir4/dir3/..", "dir1/dir2/../")); + + TEST_INT_EQ(0, compare_paths("dir1/dir2/.", "dir1/dir2/./")); +} + +static void test_sliding_rel_and_cwd(void) +{ + // sliding [rel / cwd] + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d5/file1.ext")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d5/file2.ext")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d6/file1.ext")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d5/d5/file1.ext")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d4/d4/d5/file1.ext")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d3/d3/d4/d5/file1.ext")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d2/d2/d3/d4/d5/file1.ext")); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file1.ext", "/d1")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file2.ext", "/d1")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d6/file1.ext", "/d1")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d5/d5/file1.ext", "/d1")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d4/d4/d5/file1.ext", "/d1")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d3/d4/d5/file1.ext", "/d1")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file1.ext", "/d2")); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d1/d2")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file2.ext", "/d1/d2")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d6/file1.ext", "/d1/d2")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d5/d5/file1.ext", "/d1/d2")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d4/d5/file1.ext", "/d1/d2")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d1/d3")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d2/d2")); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d2/d3")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file2.ext", "/d1/d2/d3")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d6/file1.ext", "/d1/d2/d3")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/d5/file1.ext", "/d1/d2/d3")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d2/d4")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d3/d3")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d2/d2/d3")); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d3/d4")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file2.ext", "/d1/d2/d3/d4")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d6/file1.ext", "/d1/d2/d3/d4")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d3/d5")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d4/d4")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d3/d3/d4")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d2/d2/d3/d4")); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d4/d5")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file2.ext", "/d1/d2/d3/d4/d5")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d4/d6")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d5/d5")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d4/d4/d5")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d3/d3/d4/d5")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d2/d2/d3/d4/d5")); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d5/d6")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file2.ext", "/d1/d2/d3/d4/d5/d6")); + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d5/d7")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d6/d6")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d5/d5/d6")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d4/d4/d5/d6")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d3/d3/d4/d5/d6")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d2/d2/d3/d4/d5/d6")); + + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d6/d7")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file2.ext", "/d1/d2/d3/d4/d5/d6/d7")); + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d6/d8")); + TEST_INT_EQ(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d7/d7")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d6/d6/d7")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d5/d5/d6/d7")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d4/d4/d5/d6/d7")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d3/d3/d4/d5/d6/d7")); + TEST_INT_LT(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d2/d2/d3/d4/d5/d6/d7")); + +#ifdef LIBPATH_OS_IS_WINDOWS + + TEST_INT_EQ(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d7")); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file2.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d7")); + TEST_INT_EQ(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d8")); + TEST_INT_EQ(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d7\\d7")); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d6\\d6\\d7")); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d5\\d5\\d6\\d7")); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d4\\d4\\d5\\d6\\d7")); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d3\\d3\\d4\\d5\\d6\\d7")); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d2\\d2\\d3\\d4\\d5\\d6\\d7")); + TEST_INT_LT(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "D:\\d1\\d2\\d3\\d4\\d5\\d6\\d7")); +#endif +} + +static void test_compare_UNC_rooted_paths(void) +{ + // UNC roots + +#ifdef LIBPATH_OS_IS_WINDOWS + + TEST_INT_EQ(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext")); + TEST_INT_EQ(0, compare_paths("\\\\server1\\share1/dir1\\file1.ext", "\\\\server1\\share1\\dir1/file1.ext")); + + TEST_INT_LT(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file2.ext")); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1\\dir1\\file2.ext", "\\\\server1\\share1\\dir1\\file1.ext")); + TEST_INT_LT(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir2\\file1.ext")); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1\\dir2\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext")); + TEST_INT_LT(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share2\\dir1\\file1.ext")); + TEST_INT_GT(0, compare_paths("\\\\server1\\share2\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext")); + TEST_INT_LT(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server2\\share1\\dir1\\file1.ext")); + TEST_INT_GT(0, compare_paths("\\\\server2\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext")); + +#endif +} + +static void test_Windows_mixed_pwd(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + + TEST_INT_EQ(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file1.ext", "C:\\")); + TEST_INT_LT(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file2.ext", "C:\\")); + TEST_INT_GT(0, compare_paths("dir1\\file2.ext", "C:\\dir1\\file1.ext", "C:\\")); + TEST_INT_LT(0, compare_paths("dir1\\file1.ext", "C:\\dir2\\file1.ext", "C:\\")); + TEST_INT_GT(0, compare_paths("dir2\\file1.ext", "C:\\dir1\\file1.ext", "C:\\")); + TEST_INT_LT(0, compare_paths("dir1\\file1.ext", "D:\\dir1\\file1.ext", "C:\\")); + TEST_INT_GT(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file1.ext", "D:\\")); + + TEST_INT_EQ(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file1.ext", "C:")); + TEST_INT_LT(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file2.ext", "C:")); + TEST_INT_GT(0, compare_paths("\\dir1\\file2.ext", "C:\\dir1\\file1.ext", "C:")); + TEST_INT_LT(0, compare_paths("\\dir1\\file1.ext", "C:\\dir2\\file1.ext", "C:")); + TEST_INT_GT(0, compare_paths("\\dir2\\file1.ext", "C:\\dir1\\file1.ext", "C:")); + TEST_INT_LT(0, compare_paths("\\dir1\\file1.ext", "D:\\dir1\\file1.ext", "C:")); + TEST_INT_GT(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file1.ext", "D:")); +#endif +} + +static void test_mixed_comparisons(void) +{ + TEST_INT_LT(0, compare_paths("file1.ext", "file2.ext")); + TEST_INT_GT(0, compare_paths("file2.ext", "file1.ext")); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "dir2/file1.ext")); + TEST_INT_GT(0, compare_paths("dir2/file1.ext", "dir1/file1.ext")); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "/dir1/file1.ext")); + TEST_INT_GT(0, compare_paths("/dir1/file1.ext", "dir1/file1.ext")); + +#ifdef LIBPATH_OS_IS_WINDOWS + + // absolute, rooted, and relative paths + + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext")); + TEST_INT_GT(0, compare_paths("C:/dir1/file1.ext", "dir1/file1.ext")); + TEST_INT_LT(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext")); + TEST_INT_GT(0, compare_paths("C:/dir1/file1.ext", "/dir1/file1.ext")); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext")); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext")); + TEST_INT_LT(0, compare_paths("/dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext")); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "/dir1/file1.ext")); + TEST_INT_LT(0, compare_paths("C:/dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext")); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "C:/dir1/file1.ext")); + + + // relative paths with volumes + + TEST_INT_EQ(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext")); + TEST_INT_EQ(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext", "C:")); + TEST_INT_EQ(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext", "D:")); + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "C:dir1/file1.ext", "C:")); + + TEST_INT_EQ(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext", "C:")); + TEST_INT_GT(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext", "D:")); + + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "C:")); + TEST_INT_GT(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "D:")); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "D:/dir1/file1.ext", "C:")); + + TEST_INT_GT(0, compare_paths("dir1/file2.ext", "C:/dir1/file1.ext", "C:/")); + TEST_INT_GT(0, compare_paths("dir2/file1.ext", "C:/dir1/file1.ext", "C:/")); + TEST_INT_LT(0, compare_paths("dir1/file2.ext", "C:/dir1/file1.ext", "C:")); + TEST_INT_LT(0, compare_paths("dir2/file1.ext", "C:/dir1/file1.ext", "C:")); + + TEST_INT_EQ(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "C:/")); + TEST_INT_GT(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "D:/")); + TEST_INT_LT(0, compare_paths("dir1/file1.ext", "D:/dir1/file1.ext", "C:/")); + + TEST_INT_LT(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file1.ext")); + TEST_INT_EQ(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file1.ext", "/")); + TEST_INT_LT(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file2.ext", "/")); + TEST_INT_LT(0, compare_paths("C:dir1/file1.ext", "C:/dir2/file1.ext", "/")); + + TEST_INT_EQ(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir1/")); + TEST_INT_EQ(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir1")); + TEST_INT_LT(0, compare_paths("C:file1.ext", "C:/dir1/file2.ext", "/dir1")); + TEST_INT_GT(0, compare_paths("C:file2.ext", "C:/dir1/file1.ext", "/dir1")); + TEST_INT_LT(0, compare_paths("C:file1.ext", "C:/dir2/file1.ext", "/dir1")); + TEST_INT_GT(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir2")); + + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext", "C:/")); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "C:dir1/file1.ext", "/")); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext", "C:")); + TEST_INT_GT(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "file1.ext", "dir1")); +#endif +} + +} // anonymous namespace + + +/* ///////////////////////////// end of file //////////////////////////// */ + diff --git a/test/unit/equal.C/CMakeLists.txt b/test/unit/equal.C/CMakeLists.txt new file mode 100644 index 0000000..66ee279 --- /dev/null +++ b/test/unit/equal.C/CMakeLists.txt @@ -0,0 +1,2 @@ +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +define_automated_test_program(test.unit.equal.C entry.c) diff --git a/test/unit/equal.C/entry.c b/test/unit/equal.C/entry.c new file mode 100644 index 0000000..06a42f4 --- /dev/null +++ b/test/unit/equal.C/entry.c @@ -0,0 +1,475 @@ +/* ///////////////////////////////////////////////////////////////////////// + * File: test/unit/equal.C/entry.c + * + * Purpose: Unit-tests the libpath C equal API. + * + * Created: 28th March 2013 + * Updated: 14th October 2026 + * + * ////////////////////////////////////////////////////////////////////// */ + + +/* ///////////////////////////////////////////////////////////////////////// + * includes + */ + +/* ///////////////////////////////////// + * test component header file include(s) + */ + +#include + +/* ///////////////////////////////////// + * general includes + */ + +/* xTests header files */ +#include + +/* STLSoft header files */ +#include + +/* Standard C header files */ +#include +#include +#include +#include + + +/* ///////////////////////////////////////////////////////////////////////// + * forward declarations + */ + +static void test_1_0(void); +static void test_1_1(void); +static void test_1_2(void); +static void test_1_3(void); +static void test_1_4(void); +static void test_1_5(void); +static void test_1_6(void); +static void test_1_7(void); +static void test_1_8(void); +static void test_1_9(void); +static void test_1_10(void); +static void test_1_11(void); + +static void test_1_20(void); + +static void test_1_30(void); +static void test_1_31(void); +static void test_1_32(void); +static void test_1_33(void); + +static void test_1_40(void); +static void test_1_41(void); +static void test_1_42(void); +static void test_1_43(void); +static void test_1_44(void); +static void test_1_45(void); + +static void test_1_50(void); + + +/* ///////////////////////////////////////////////////////////////////////// + * helper functions + */ + +int main(int argc, char* argv[]) +{ + int retCode = EXIT_SUCCESS; + int verbosity = 2; + + XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); + + if (XTESTS_START_RUNNER("test.unit.equal.C", verbosity)) + { + XTESTS_RUN_CASE(test_1_0); + XTESTS_RUN_CASE(test_1_1); + XTESTS_RUN_CASE(test_1_2); + XTESTS_RUN_CASE(test_1_3); + XTESTS_RUN_CASE(test_1_4); + XTESTS_RUN_CASE(test_1_5); + XTESTS_RUN_CASE(test_1_6); + XTESTS_RUN_CASE(test_1_7); + XTESTS_RUN_CASE(test_1_8); + XTESTS_RUN_CASE(test_1_9); + XTESTS_RUN_CASE(test_1_10); + XTESTS_RUN_CASE(test_1_11); + + XTESTS_RUN_CASE(test_1_20); + + XTESTS_RUN_CASE(test_1_30); + XTESTS_RUN_CASE(test_1_31); + XTESTS_RUN_CASE(test_1_32); + XTESTS_RUN_CASE(test_1_33); + + XTESTS_RUN_CASE(test_1_40); + XTESTS_RUN_CASE(test_1_41); + XTESTS_RUN_CASE(test_1_42); + XTESTS_RUN_CASE(test_1_43); + XTESTS_RUN_CASE(test_1_44); + XTESTS_RUN_CASE(test_1_45); + + XTESTS_RUN_CASE(test_1_50); + + XTESTS_PRINT_RESULTS(); + + XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); + } + + return retCode; +} + + +/* ///////////////////////////////////////////////////////////////////////// + * test function implementations + */ + +static +bool +path_equals( + char const* lhs +, char const* rhs +, char const* cwd /* = LIBPATH_LF_nullptr */ +, char const* mem /* = LIBPATH_LF_nullptr */ +) +{ + libpath_sint32_t flags = 0; + libpath_WorkingDirectoryContext_t ctxt; + int result; + LIBPATH_RC rc; + + STLSOFT_SUPPRESS_UNUSED(mem); + + ctxt.mechanism = libpath_WorkingDirectoryContextMechanism_CStyleString; + ctxt.details.cwd_css = cwd; + + rc = libpath_Equate_EquatePathsAsCStyleStrings( + lhs + , rhs + , flags + , &ctxt + , LIBPATH_LF_nullptr + , &result + ); + + switch (rc) + { + case LIBPATH_RC_OF(FirstPathInvalid): + case LIBPATH_RC_OF(SecondPathInvalid): + case LIBPATH_RC_OF(WorkingDirectoryPathInvalid): + + break; + default: + + break; + } + + return (LIBPATH_RC_OF(Success) == rc) && (0 != result); +} + + +static void test_1_0(void) +{ + TEST_BOOLEAN_FALSE(path_equals("", "", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +} + +static void test_1_1(void) +{ + TEST_BOOLEAN_FALSE(path_equals("", "a", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("a", "", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +} + +static void test_1_2(void) +{ + TEST_BOOLEAN_TRUE(path_equals("file", "file", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("fil1", "fil2", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +} + +static void test_1_3(void) +{ + TEST_BOOLEAN_TRUE(path_equals("file.ext", "file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("file.ex1", "file.ex2", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +} + +static void test_1_4(void) +{ + TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("dir1\\file.ext", "dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1\\file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_5(void) +{ + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("dir1\\file.ext", "dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("dir1\\file.ext", "dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_6(void) +{ + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/dir2/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/dir3/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/./file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "./dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/././././././././././././././././././././././././././././././././././././././././././././././file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/dir2/../dir3/../dir4/../dir5/../dir6/../dir7/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/dir2/dir3/dir4/dir5/dir6/dir7/../../../../../../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_TRUE(path_equals("../dir1/dir2/../file.ext", "../dir1/dir2/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +} + +static void test_1_7(void) +{ + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/dir2/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/dir3/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/./file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "./dir9/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/././././././././././././././././././././././././././././././././././././././././././././././file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir9/dir2/../dir3/../dir4/../dir5/../dir6/../dir7/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir9/dir2/dir3/dir4/dir5/dir6/dir7/../../../../../../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("../dir1/dir2/../file.ext", "../dir9/dir2/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +} + +static void test_1_8(void) +{ + TEST_BOOLEAN_FALSE(path_equals("dir1/../../file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "../dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +} + +static void test_1_9(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "C:\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_10(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share1\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share2\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server2\\share1\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server10\\share10\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_11(void) +{ + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1/dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1\\dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1/dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1\\dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1/dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1\\dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1\\dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_20(void) +{ + // Trailing slashes + + TEST_BOOLEAN_TRUE(path_equals("abc.def", "abc.def", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("abc.def/", "abc.def", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("abc.def", "abc.def/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("abc.def\\", "abc.def", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("abc.def", "abc.def\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif + TEST_BOOLEAN_TRUE(path_equals("abc.def/", "abc.def/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("abc.def\\", "abc.def/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("abc.def/", "abc.def\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("abc.def\\", "abc.def\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif + +} + +static void test_1_30(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir2", LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir8", LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir2/dir3/..", LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir4/.././file.ext", "/./dir1/dir2/dir3/dir4//..", LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/../file.ext", ".././file.ext", "/dir1/dir2/dir3/dir4", LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", ".././file.ext", "/dir1/dir2/dir3/dir4", LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/../file.ext", ".././../file.ext", "/dir1/dir2/dir3/dir4", LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/dir4/dir5/file.ext", "file.ext", "/dir1/dir2/dir3/dir4/dir5", LIBPATH_LF_nullptr)); +} + +static void test_1_31(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "dir3", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "dir3", "/dir1/dir2", LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/", "dir3/", "/dir1/dir2", LIBPATH_LF_nullptr)); +} + +static void test_1_32(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_33(void) +{ + TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "dir1/file.ext", "/", LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "C:\\dir1\\file.ext", "C:/", LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("\\dir1/file.ext", "C:\\dir1\\file.ext", "C:", LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_40(void) +{ + TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("\\dir1\\file.ext", "\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("\\dir1\\file.ext", "/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_41(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "c:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("c:\\dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("c:\\dir1\\file.ext", "c:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "c:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("c:/dir1/file.ext", "C:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("c:/dir1/file.ext", "c:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:/dir1/file.ext", "D:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:/dir1/file.ext", "D:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_TRUE(path_equals("C:dir1\\file.ext", "C:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:dir1\\file.ext", "C:dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:dir1/file.ext", "C:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:dir1/file.ext", "C:dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("C:dir1\\file.ext", "D:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:dir1\\file.ext", "D:dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:dir1/file.ext", "D:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:dir1/file.ext", "D:dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_42(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "dir1/file.ext", "/", LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "c:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "c:dir1\\file.ext", "/", LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "d:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "d:dir1\\file.ext", "/", LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_43(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "dir2/file.ext", "/dir1", LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir2\\file.ext", "/dir1", LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir2\\file.ext", "\\dir1\\", LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_44(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "dir2/file.ext", "/dir1/dir2/dir3/./../..", LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir2\\file.ext", "/dir1/dir2/dir3/./../..", LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir2\\file.ext", "\\dir1\\dir2\\dir3\\.\\..\\..", LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_45(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/dir3/./../../dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "./../../dir2/file.ext", "/dir1/dir2/dir3/", LIBPATH_LF_nullptr)); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\dir3\\.\\..\\..\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:.\\..\\..\\dir2\\file.ext", "/dir1/dir2/dir3", LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\dir3\\.\\..\\..\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:.\\..\\..\\dir2\\file.ext", "\\dir1\\dir2\\dir3", LIBPATH_LF_nullptr)); +#endif +} + +static void test_1_50(void) +{ + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/", "/dir1/dir2/dir3/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "/dir1/dir2/dir3", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3", "/dir1/dir2/dir3/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); +} + + +/* ///////////////////////////// end of file //////////////////////////// */ + diff --git a/test/unit/equal/CMakeLists.txt b/test/unit/equal/CMakeLists.txt new file mode 100644 index 0000000..313fff4 --- /dev/null +++ b/test/unit/equal/CMakeLists.txt @@ -0,0 +1,2 @@ +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +define_automated_test_program(test.unit.equal entry.cpp) diff --git a/test/unit/equal/entry.cpp b/test/unit/equal/entry.cpp new file mode 100644 index 0000000..559d500 --- /dev/null +++ b/test/unit/equal/entry.cpp @@ -0,0 +1,487 @@ +/* ///////////////////////////////////////////////////////////////////////// + * File: test/unit/equal/entry.cpp + * + * Purpose: Unit-tests the libpath C++ equal API. + * + * Created: 9th November 2012 + * Updated: 14th October 2026 + * + * ////////////////////////////////////////////////////////////////////// */ + + +/* ///////////////////////////////////////////////////////////////////////// + * includes + */ + +/* ///////////////////////////////////// + * test component header file include(s) + */ + +#include + +#include + +/* ///////////////////////////////////// + * general includes + */ + +/* xTests header files */ +#include + +/* STLSoft header files */ +#include + +/* Standard C++ header files */ +#include +#include + +/* Standard C header files */ +#include +#include +#include + + +/* ///////////////////////////////////////////////////////////////////////// + * forward declarations + */ + +namespace +{ + + static void test_1_0(void); + static void test_1_1(void); + static void test_1_2(void); + static void test_1_3(void); + static void test_1_4(void); + static void test_1_5(void); + static void test_1_6(void); + static void test_1_7(void); + static void test_1_8(void); + static void test_1_9(void); + static void test_1_10(void); + static void test_1_11(void); + + static void test_1_20(void); + + static void test_1_30(void); + static void test_1_31(void); + static void test_1_32(void); + static void test_1_33(void); + + static void test_1_40(void); + static void test_1_41(void); + static void test_1_42(void); + static void test_1_43(void); + static void test_1_44(void); + static void test_1_45(void); + + static void test_1_50(void); +} // anonymous namespace + + +/* ///////////////////////////////////////////////////////////////////////// + * helper functions + */ + +int main(int argc, char* argv[]) +{ + int retCode = EXIT_SUCCESS; + int verbosity = 2; + + XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); + + if (XTESTS_START_RUNNER("test.unit.equal", verbosity)) + { + XTESTS_RUN_CASE(test_1_0); + XTESTS_RUN_CASE(test_1_1); + XTESTS_RUN_CASE(test_1_2); + XTESTS_RUN_CASE(test_1_3); + XTESTS_RUN_CASE(test_1_4); + XTESTS_RUN_CASE(test_1_5); + XTESTS_RUN_CASE(test_1_6); + XTESTS_RUN_CASE(test_1_7); + XTESTS_RUN_CASE(test_1_8); + XTESTS_RUN_CASE(test_1_9); + XTESTS_RUN_CASE(test_1_10); + XTESTS_RUN_CASE(test_1_11); + + XTESTS_RUN_CASE(test_1_20); + + XTESTS_RUN_CASE(test_1_30); + XTESTS_RUN_CASE(test_1_31); + XTESTS_RUN_CASE(test_1_32); + XTESTS_RUN_CASE(test_1_33); + + XTESTS_RUN_CASE(test_1_40); + XTESTS_RUN_CASE(test_1_41); + XTESTS_RUN_CASE(test_1_42); + XTESTS_RUN_CASE(test_1_43); + XTESTS_RUN_CASE(test_1_44); + XTESTS_RUN_CASE(test_1_45); + + XTESTS_RUN_CASE(test_1_50); + + XTESTS_PRINT_RESULTS(); + + XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); + } + + return retCode; +} + + +/* ///////////////////////////////////////////////////////////////////////// + * test function implementations + */ + +namespace +{ + + inline + bool + path_equals( + char const* lhs + , char const* rhs + , char const* cwd = LIBPATH_LF_nullptr + , char const* /*mem*/ = LIBPATH_LF_nullptr + ) + { + libpath_sint32_t flags = 0; + libpath_WorkingDirectoryContext_t ctxt; + libpath_truthy_t result; + + ctxt.mechanism = libpath_WorkingDirectoryContextMechanism_CStyleString; + ctxt.details.cwd_css = cwd; + + LIBPATH_RC rc = libpath_Equate_EquatePathsAsCStyleStrings( + lhs + , rhs + , flags + , &ctxt + , LIBPATH_LF_nullptr + , &result + ); + + switch (rc) + { + case LIBPATH_RC_OF(FirstPathInvalid): + case LIBPATH_RC_OF(SecondPathInvalid): + case LIBPATH_RC_OF(WorkingDirectoryPathInvalid): + + break; + default: + + break; + } + + + return (LIBPATH_RC_OF(Success) == rc) && (result); + } + + +static void test_1_0(void) +{ + TEST_BOOLEAN_FALSE(path_equals("", "")); +} + +static void test_1_1(void) +{ + TEST_BOOLEAN_FALSE(path_equals("", "a")); + TEST_BOOLEAN_FALSE(path_equals("a", "")); +} + +static void test_1_2(void) +{ + TEST_BOOLEAN_TRUE(path_equals("file", "file")); + + TEST_BOOLEAN_FALSE(path_equals("fil1", "fil2")); +} + +static void test_1_3(void) +{ + TEST_BOOLEAN_TRUE(path_equals("file.ext", "file.ext")); + + TEST_BOOLEAN_FALSE(path_equals("file.ex1", "file.ex2")); +} + +static void test_1_4(void) +{ + TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/file.ext")); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("dir1\\file.ext", "dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1\\file.ext", "dir1/file.ext")); +#endif +} + +static void test_1_5(void) +{ + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir2/file.ext")); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("dir1\\file.ext", "dir2\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir2\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("dir1\\file.ext", "dir2/file.ext")); +#endif +} + +static void test_1_6(void) +{ + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/dir2/../file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/dir3/../file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/./file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "./dir1/file.ext")); + + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/././././././././././././././././././././././././././././././././././././././././././././././file.ext")); + + TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/dir2/../dir3/../dir4/../dir5/../dir6/../dir7/../file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/dir2/dir3/dir4/dir5/dir6/dir7/../../../../../../file.ext")); + + TEST_BOOLEAN_TRUE(path_equals("../dir1/dir2/../file.ext", "../dir1/dir2/../file.ext")); +} + +static void test_1_7(void) +{ + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/dir2/../file.ext")); + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/dir3/../file.ext")); + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/./file.ext")); + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/file.ext")); + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "./dir9/file.ext")); + + TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/././././././././././././././././././././././././././././././././././././././././././././././file.ext")); + + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir9/dir2/../dir3/../dir4/../dir5/../dir6/../dir7/../file.ext")); + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir9/dir2/dir3/dir4/dir5/dir6/dir7/../../../../../../file.ext")); + + TEST_BOOLEAN_FALSE(path_equals("../dir1/dir2/../file.ext", "../dir9/dir2/../file.ext")); +} + +static void test_1_8(void) +{ + TEST_BOOLEAN_FALSE(path_equals("dir1/../../file.ext", "dir1/file.ext")); + + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "../dir1/file.ext")); +} + +static void test_1_9(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:\\dir1\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "C:\\dir2\\file.ext")); +#endif +} + +static void test_1_10(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share1\\dir1\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share1\\dir2\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share2\\dir1\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server2\\share1\\dir1\\file.ext")); + + TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server10\\share10\\dir1\\file.ext")); +#endif +} + +static void test_1_11(void) +{ + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2/file.ext")); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1/dir2/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1/dir2\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1\\dir2/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext")); + + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1/dir2/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1/dir2\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1\\dir2/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1\\dir2\\file.ext")); + + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1/dir2/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1/dir2\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1\\dir2/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1\\dir2\\file.ext")); + + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1\\dir2/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1\\dir2\\file.ext")); +#endif +} + +static void test_1_20(void) +{ + // Trailing slashes + + TEST_BOOLEAN_TRUE(path_equals("abc.def", "abc.def")); + TEST_BOOLEAN_FALSE(path_equals("abc.def/", "abc.def")); + TEST_BOOLEAN_FALSE(path_equals("abc.def", "abc.def/")); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("abc.def\\", "abc.def")); + TEST_BOOLEAN_FALSE(path_equals("abc.def", "abc.def\\")); +#endif + TEST_BOOLEAN_TRUE(path_equals("abc.def/", "abc.def/")); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("abc.def\\", "abc.def/")); + TEST_BOOLEAN_TRUE(path_equals("abc.def/", "abc.def\\")); + TEST_BOOLEAN_TRUE(path_equals("abc.def\\", "abc.def\\")); +#endif + +} + +static void test_1_30(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir2")); + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir8")); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir2/dir3/..")); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir4/.././file.ext", "/./dir1/dir2/dir3/dir4//..")); + + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/../file.ext", ".././file.ext", "/dir1/dir2/dir3/dir4")); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", ".././file.ext", "/dir1/dir2/dir3/dir4")); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/../file.ext", ".././../file.ext", "/dir1/dir2/dir3/dir4")); + + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/dir4/dir5/file.ext", "file.ext", "/dir1/dir2/dir3/dir4/dir5")); +} + +static void test_1_31(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "dir3", LIBPATH_LF_nullptr)); + + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "dir3", "/dir1/dir2")); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/", "dir3/", "/dir1/dir2")); +} + +static void test_1_32(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/file.ext", "dir1/file.ext")); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "C:\\dir1\\file.ext")); +#endif +} + +static void test_1_33(void) +{ + TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "dir1/file.ext", "/")); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "C:\\dir1\\file.ext", "C:/")); + TEST_BOOLEAN_TRUE(path_equals("\\dir1/file.ext", "C:\\dir1\\file.ext", "C:")); +#endif +} + +static void test_1_40(void) +{ + TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "/dir1/file.ext")); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("\\dir1\\file.ext", "\\dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "\\dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("\\dir1\\file.ext", "/dir1/file.ext")); +#endif +} + +static void test_1_41(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:/dir1/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:\\dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:/dir1/file.ext")); + + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "c:\\dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("c:\\dir1\\file.ext", "C:\\dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("c:\\dir1\\file.ext", "c:\\dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:/dir1/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "c:/dir1/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("c:/dir1/file.ext", "C:/dir1/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("c:/dir1/file.ext", "c:/dir1/file.ext")); + + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:\\dir1\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:/dir1/file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:/dir1/file.ext", "D:\\dir1\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:/dir1/file.ext", "D:/dir1/file.ext")); + + TEST_BOOLEAN_TRUE(path_equals("C:dir1\\file.ext", "C:dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:dir1\\file.ext", "C:dir1/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:dir1/file.ext", "C:dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:dir1/file.ext", "C:dir1/file.ext")); + + TEST_BOOLEAN_FALSE(path_equals("C:dir1\\file.ext", "D:dir1\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:dir1\\file.ext", "D:dir1/file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:dir1/file.ext", "D:dir1\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:dir1/file.ext", "D:dir1/file.ext")); +#endif +} + +static void test_1_42(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/file.ext", "dir1/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "dir1/file.ext", "/")); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "c:dir1\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "c:dir1\\file.ext", "/")); + + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "d:dir1\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "d:dir1\\file.ext", "/")); +#endif +} + +static void test_1_43(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "dir2/file.ext", "/dir1")); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir2\\file.ext", "/dir1")); + + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir2\\file.ext", "\\dir1\\")); +#endif +} + +static void test_1_44(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "dir2/file.ext", "/dir1/dir2/dir3/./../..")); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir2\\file.ext", "/dir1/dir2/dir3/./../..")); + + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir2\\file.ext", "\\dir1\\dir2\\dir3\\.\\..\\..")); +#endif +} + +static void test_1_45(void) +{ + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/dir3/./../../dir2/file.ext")); + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "./../../dir2/file.ext", "/dir1/dir2/dir3/")); + +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\dir3\\.\\..\\..\\dir2\\file.ext")); + TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:.\\..\\..\\dir2\\file.ext", "/dir1/dir2/dir3")); + + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\dir3\\.\\..\\..\\dir2\\file.ext")); + TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:.\\..\\..\\dir2\\file.ext", "\\dir1\\dir2\\dir3")); +#endif +} + +static void test_1_50(void) +{ + TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/", "/dir1/dir2/dir3/")); + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "/dir1/dir2/dir3")); + TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3", "/dir1/dir2/dir3/")); +} + +} // anonymous namespace + + +/* ///////////////////////////// end of file //////////////////////////// */ + diff --git a/test/unit/parse.C/CMakeLists.txt b/test/unit/parse.C/CMakeLists.txt new file mode 100644 index 0000000..9df7afb --- /dev/null +++ b/test/unit/parse.C/CMakeLists.txt @@ -0,0 +1,2 @@ +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +define_automated_test_program(test.unit.parse.C entry.c) diff --git a/test/unit/parse.C/entry.c b/test/unit/parse.C/entry.c new file mode 100644 index 0000000..4e2e714 --- /dev/null +++ b/test/unit/parse.C/entry.c @@ -0,0 +1,2183 @@ +/* ///////////////////////////////////////////////////////////////////////// + * File: test/unit/parse.C/entry.c + * + * Purpose: Unit-tests the libpath C parse API. + * + * Created: 9th November 2012 + * Updated: 14th October 2026 + * + * ////////////////////////////////////////////////////////////////////// */ + + +/* ///////////////////////////////////////////////////////////////////////// + * includes + */ + +/* ///////////////////////////////////// + * test component header file include(s) + */ + +#include + +/* ///////////////////////////////////// + * general includes + */ + +/* xTests header files */ +#include +#if _XTESTS_VER < 0x00150000 +# error This code requires xTests 0.21.0, or later +#endif + +/* STLSoft header files */ +#include + +/* Standard C header files */ +#include +#include + + +/* ///////////////////////////////////////////////////////////////////////// + * forward declarations + */ + +static void test_empty(void); +static void test_1_dot(void); +static void test_2_dots(void); +static void test_3_dots(void); +static void test_4_dots(void); +static void test_5_dots(void); +static void test_rooted_1_dot(void); +static void test_rooted_2_dots(void); +static void test_rooted_3_dots(void); +static void test_rooted_4_dots(void); + +static void test_filename_with_trailing_dot(void); +static void test_filename_with_trailing_dots(void); +static void test_stem_only(void); +static void test_filename(void); +static void test_extension_only(void); + +static void test_rooted_1_stem(void); +static void test_rooted_1_dir_1_stem(void); +static void test_rooted_1_dir_trailing_slash(void); +static void test_rooted_2_dirs_trailing_slash(void); +static void test_rooted_6_dirs_trailing_slash(void); +static void test_rooted_6_dirs_and_filename(void); +static void test_rooted_6_dirs_and_stem(void); +static void test_slash_only(void); +static void test_filename_multiple_dots(void); + +static void test_Windows_backslash_only(void); +static void test_Windows_backslash_rooted_1_stem(void); +static void test_Windows_volume_and_backslash_root(void); +static void test_Windows_volume_and_backslash_rooted_1_stem(void); +static void test_Windows_volume_and_backslash_rooted_6_dirs_and_filename(void); +static void test_Windows_volume_and_slash_root(void); +static void test_Windows_slash_rooted_1_stem(void); +static void test_Windows_volume_and_slash_rooted_6_dirs_and_filename(void); + +static void test_Windows_UNC_share(void); +static void test_Windows_UNC_share_and_entry(void); +static void test_Windows_UNC_share_and_6_dirs_and_filename(void); +static void test_Windows_UNC_share_and_6_dirs_and_filename_altslashes(void); +static void test_Windows_UNC_share_and_6_dirs_and_filename_altslashes_2(void); + +static void test_Windows_driveletterrelative_and_stem(void); +static void test_Windows_driveletterrelative_and_6_dirs_and_filename(void); +static void test_Windows_driveletterrelative_and_6_dirs_and_filename_altslashes(void); +static void test_Windows_driveletterrelative_and_6_dirs_and_dotsdir_altslashes(void); +static void test_rooted_1_dir_1_stem_extraslashes(void); + +static void test_bad_characters(void); +static void test_Windows_bad_characters(void); + +static void test_1_component_with_libpath_ParseOption_AssumeDirectory(void); +static void test_2_components_with_libpath_ParseOption_AssumeDirectory(void); +static void test_2_components_with_last_2dotsdir_with_libpath_ParseOption_AssumeDirectory(void); +static void test_2_components_with_last_1dotsdir_with_libpath_ParseOption_AssumeDirectory(void); + +static void test_Windows_UNC_share_trailing_backslash(void); +static void test_Windows_UNC_share_trailing_slash(void); +static void test_Windows_UNC_share_with_charwise_steps(void); + + +/* ///////////////////////////////////////////////////////////////////////// + * main() + */ + +int main(int argc, char* argv[]) +{ + int retCode = EXIT_SUCCESS; + int verbosity = 2; + + XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); + + if (XTESTS_START_RUNNER("test.unit.parse.C", verbosity)) + { + XTESTS_RUN_CASE(test_empty); + XTESTS_RUN_CASE(test_1_dot); + XTESTS_RUN_CASE(test_2_dots); + XTESTS_RUN_CASE(test_3_dots); + XTESTS_RUN_CASE(test_4_dots); + XTESTS_RUN_CASE(test_5_dots); + + XTESTS_RUN_CASE(test_rooted_1_dot); + XTESTS_RUN_CASE(test_rooted_2_dots); + XTESTS_RUN_CASE(test_rooted_3_dots); + XTESTS_RUN_CASE(test_rooted_4_dots); + + XTESTS_RUN_CASE(test_filename_with_trailing_dot); + XTESTS_RUN_CASE(test_filename_with_trailing_dots); + XTESTS_RUN_CASE(test_stem_only); + XTESTS_RUN_CASE(test_filename); + XTESTS_RUN_CASE(test_extension_only); + + XTESTS_RUN_CASE(test_rooted_1_stem); + XTESTS_RUN_CASE(test_rooted_1_dir_1_stem); + XTESTS_RUN_CASE(test_rooted_1_dir_trailing_slash); + XTESTS_RUN_CASE(test_rooted_2_dirs_trailing_slash); + XTESTS_RUN_CASE(test_rooted_6_dirs_trailing_slash); + XTESTS_RUN_CASE(test_rooted_6_dirs_and_filename); + XTESTS_RUN_CASE(test_rooted_6_dirs_and_stem); + XTESTS_RUN_CASE(test_slash_only); + XTESTS_RUN_CASE(test_filename_multiple_dots); + + XTESTS_RUN_CASE(test_Windows_backslash_only); + XTESTS_RUN_CASE(test_Windows_backslash_rooted_1_stem); + XTESTS_RUN_CASE(test_Windows_volume_and_backslash_root); + XTESTS_RUN_CASE(test_Windows_volume_and_backslash_rooted_1_stem); + XTESTS_RUN_CASE(test_Windows_volume_and_backslash_rooted_6_dirs_and_filename); + XTESTS_RUN_CASE(test_Windows_volume_and_slash_root); + XTESTS_RUN_CASE(test_Windows_slash_rooted_1_stem); + XTESTS_RUN_CASE(test_Windows_volume_and_slash_rooted_6_dirs_and_filename); + + XTESTS_RUN_CASE(test_Windows_UNC_share); + XTESTS_RUN_CASE(test_Windows_UNC_share_and_entry); + XTESTS_RUN_CASE(test_Windows_UNC_share_and_6_dirs_and_filename); + XTESTS_RUN_CASE(test_Windows_UNC_share_and_6_dirs_and_filename_altslashes); + XTESTS_RUN_CASE(test_Windows_UNC_share_and_6_dirs_and_filename_altslashes_2); + + XTESTS_RUN_CASE(test_Windows_driveletterrelative_and_stem); + XTESTS_RUN_CASE(test_Windows_driveletterrelative_and_6_dirs_and_filename); + XTESTS_RUN_CASE(test_Windows_driveletterrelative_and_6_dirs_and_filename_altslashes); + XTESTS_RUN_CASE(test_Windows_driveletterrelative_and_6_dirs_and_dotsdir_altslashes); + XTESTS_RUN_CASE(test_rooted_1_dir_1_stem_extraslashes); + XTESTS_RUN_CASE(test_bad_characters); + + XTESTS_RUN_CASE(test_Windows_bad_characters); + + XTESTS_RUN_CASE(test_1_component_with_libpath_ParseOption_AssumeDirectory); + XTESTS_RUN_CASE(test_2_components_with_libpath_ParseOption_AssumeDirectory); + XTESTS_RUN_CASE(test_2_components_with_last_2dotsdir_with_libpath_ParseOption_AssumeDirectory); + XTESTS_RUN_CASE(test_2_components_with_last_1dotsdir_with_libpath_ParseOption_AssumeDirectory); + + XTESTS_RUN_CASE(test_Windows_UNC_share_trailing_backslash); + XTESTS_RUN_CASE(test_Windows_UNC_share_trailing_slash); + XTESTS_RUN_CASE(test_Windows_UNC_share_with_charwise_steps); + + XTESTS_PRINT_RESULTS(); + + XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); + } + + return retCode; +} + + +/* ///////////////////////////////////////////////////////////////////////// + * test function implementations + */ + +#ifdef __cplusplus + libpath_size_t const NUM_DP_ELEMENTS = 10; +#else /* ? __cplusplus */ +# define NUM_DP_ELEMENTS (10) +#endif /* __cplusplus */ + +static void test_empty(void) +{ + char const input[] = ""; + + libpath_ParseResult_t r; + LIBPATH_RC rc; + libpath_StringSlice_t directoryPartSlices[1]; + libpath_size_t firstBadCharOffset; + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_NoPathSpecified, rc); + TEST_INT_EQ(0, firstBadCharOffset); + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_NoPathSpecified, rc); + TEST_INT_EQ(0, firstBadCharOffset); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); + TEST_INT_EQ(0u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(0u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); +} + +static void test_1_dot(void) +{ + char const input[] = "."; + + libpath_ParseResult_t r; + LIBPATH_RC rc; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + libpath_size_t firstBadCharOffset; + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(SIZE_MAX, firstBadCharOffset); + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(SIZE_MAX, firstBadCharOffset); + + TEST_INT_EQ(1u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(1u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(1u, r.entryNamePart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", r.entryNamePart); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", r.entryStemPart); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +} + +static void test_2_dots(void) +{ + char const input[] = ".."; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(2u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(2u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(2u, r.entryNamePart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", r.entryNamePart); + TEST_INT_EQ(2u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", r.entryStemPart); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +} + +static void test_3_dots(void) +{ + char const input[] = "..."; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("...", r.entryNamePart); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("...", r.entryStemPart); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +} + +static void test_4_dots(void) +{ + char const input[] = "...."; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(4u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(4u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(4u, r.entryNamePart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("....", r.entryNamePart); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("....", r.entryStemPart); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +} + +static void test_5_dots(void) +{ + char const input[] = "....."; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(5u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(5u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(5u, r.entryNamePart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL(".....", r.entryNamePart); + TEST_INT_EQ(5u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL(".....", r.entryStemPart); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +} + +static void test_rooted_1_dot(void) +{ + char const input[] = "/."; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(2u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(2u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, directoryPartSlices[0].len); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(1u, r.entryNamePart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", r.entryNamePart); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", r.entryStemPart); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_rooted_2_dots(void) +{ + char const input[] = "/.."; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(2u, r.entryNamePart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", r.entryNamePart); + TEST_INT_EQ(2u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", r.entryStemPart); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_rooted_3_dots(void) +{ + char const input[] = "/..."; + + libpath_ParseResult_t r; + LIBPATH_RC rc; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(4u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(4u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("...", r.entryNamePart); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("...", r.entryStemPart); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_rooted_4_dots(void) +{ + char const input[] = "/...."; + + libpath_ParseResult_t r; + LIBPATH_RC rc; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + libpath_size_t firstBadCharOffset; + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(SIZE_MAX, firstBadCharOffset); + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(SIZE_MAX, firstBadCharOffset); + + TEST_INT_EQ(5u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(5u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(4u, r.entryNamePart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("....", r.entryNamePart); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("....", r.entryStemPart); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_filename_with_trailing_dot(void) +{ + char const input[] = "..abc.def."; + + libpath_ParseResult_t r; + LIBPATH_RC rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, 0, LIBPATH_LF_nullptr, LIBPATH_LF_nullptr); + + // TODO: define failure result code + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(10u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(10u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(10u, r.entryNamePart.len); + TEST_INT_EQ(10u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); +} + +static void test_filename_with_trailing_dots(void) +{ + char const input[] = "..abc.def.."; + + libpath_ParseResult_t r; + LIBPATH_RC rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, 0, LIBPATH_LF_nullptr, LIBPATH_LF_nullptr); + + // TODO: define failure result code + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(11u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(11u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(11u, r.entryNamePart.len); + TEST_INT_EQ(11u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); +} + +static void test_stem_only(void) +{ + char const input[] = "abc"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +} + +static void test_filename(void) +{ + char const input[] = "a.c"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_INT_EQ(2u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +} + +static void test_extension_only(void) +{ + char const input[] = ".bc"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(3u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +} + +static void test_rooted_1_stem(void) +{ + char const input[] = "/abc"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(4u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(4u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_rooted_1_dir_1_stem(void) +{ + char const input[] = "/dir/abc"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(8u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(8u, r.fullPath.len); + TEST_INT_EQ(5u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_rooted_1_dir_trailing_slash(void) +{ + char const input[] = "/dir/"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(5u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(5u, r.fullPath.len); + TEST_INT_EQ(5u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_rooted_2_dirs_trailing_slash(void) +{ + char const input[] = "/dir/dir2/"; + + libpath_ParseResult_t r; + LIBPATH_RC rc; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(10u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(10u, r.fullPath.len); + TEST_INT_EQ(10u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(9u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); + TEST_INT_EQ(5u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir2/", directoryPartSlices[1]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ + + directoryPartSlices[1].len = 1234; + directoryPartSlices[1].ptr = stlsoft_reinterpret_cast(char*, 1234); + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, 1, &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(10u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(10u, r.fullPath.len); + TEST_INT_EQ(10u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(9u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + + TEST_INT_EQ(1234u, directoryPartSlices[1].len); + TEST_PTR_EQ(stlsoft_reinterpret_cast(char*, 1234), directoryPartSlices[1].ptr); + + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_rooted_6_dirs_trailing_slash(void) +{ + char const input[] = "/directory1/directory2/dir3/dir4/d5/d6/"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(39u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(39u, r.fullPath.len); + TEST_INT_EQ(39u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_rooted_6_dirs_and_filename(void) +{ + char const input[] = "/directory1/directory2/dir3/dir4/d5/d6/file.ext"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(47u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(47u, r.fullPath.len); + TEST_INT_EQ(39u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_rooted_6_dirs_and_stem(void) +{ + char const input[] = "/1/2/3/4/5/6/f"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(14u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(14u, r.fullPath.len); + TEST_INT_EQ(13u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(12u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(2u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("1/", directoryPartSlices[0]); + TEST_INT_EQ(2u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("2/", directoryPartSlices[1]); + TEST_INT_EQ(2u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("3/", directoryPartSlices[2]); + TEST_INT_EQ(2u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("4/", directoryPartSlices[3]); + TEST_INT_EQ(2u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("5/", directoryPartSlices[4]); + TEST_INT_EQ(2u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("6/", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(1u, r.entryNamePart.len); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_slash_only(void) +{ + char const input[] = "/"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(1u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(1u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_filename_multiple_dots(void) +{ + char const input[] = "this.is.a.more.complex.file.ext"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(31u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(31u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(31u, r.entryNamePart.len); + TEST_INT_EQ(27u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +} + +static void test_Windows_backslash_only(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(1u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(1u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); + TEST_INT_EQ(0u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_backslash_rooted_1_stem(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\abc"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(4u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(4u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); + TEST_INT_EQ(0u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_volume_and_backslash_root(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:\\"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(3u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_volume_and_backslash_rooted_1_stem(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:\\abc"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(3u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_volume_and_backslash_rooted_6_dirs_and_filename(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:\\directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(49u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(49u, r.fullPath.len); + TEST_INT_EQ(41u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_volume_and_slash_root(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:/"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(3u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_slash_rooted_1_stem(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:/abc"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(3u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_volume_and_slash_rooted_6_dirs_and_filename(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:/directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(49u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(49u, r.fullPath.len); + TEST_INT_EQ(41u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_UNC_share(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(20u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(20u, r.fullPath.len); + TEST_INT_EQ(20u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_UNC_share_and_entry(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\abc"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(23u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(23u, r.fullPath.len); + TEST_INT_EQ(20u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_UNC_share_and_6_dirs_and_filename(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(66u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(66u, r.fullPath.len); + TEST_INT_EQ(58u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_UNC_share_and_6_dirs_and_filename_altslashes(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\directory1/directory2\\dir3/dir4\\d5/d6\\file.ext"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(66u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(66u, r.fullPath.len); + TEST_INT_EQ(58u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_UNC_share_and_6_dirs_and_filename_altslashes_2(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share/directory1\\directory2/dir3\\dir4/d5\\d6/file.ext"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(66u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(66u, r.fullPath.len); + TEST_INT_EQ(58u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_driveletterrelative_and_stem(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:abc"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(5u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(5u, r.fullPath.len); + TEST_INT_EQ(2u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(2u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_driveletterrelative_and_6_dirs_and_filename(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(48u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(48u, r.fullPath.len); + TEST_INT_EQ(40u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(2u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_driveletterrelative_and_6_dirs_and_filename_altslashes(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:directory1/directory2\\dir3/dir4\\d5/d6\\file.ext"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(48u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(48u, r.fullPath.len); + TEST_INT_EQ(40u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(2u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_driveletterrelative_and_6_dirs_and_dotsdir_altslashes(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:directory1/directory2\\dir3/dir4\\d5/d6\\."; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(41u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(41u, r.fullPath.len); + TEST_INT_EQ(40u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(2u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(1u, r.entryNamePart.len); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_rooted_1_dir_1_stem_extraslashes(void) +{ + char const input[] = "/dir//abc"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(9u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(9u, r.fullPath.len); + TEST_INT_EQ(6u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(5u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(5u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir//", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_bad_characters(void) +{ + static char const bad_chars[] = + { + '|' + , '<' + , '>' + , '?' + , '*' +#ifdef LIBPATH_OS_IS_WINDOWS + , ';' +#else + , ':' +#endif + }; + char const input_template[] = "/this/is/going/to/be/a.bad.path"; + + { libpath_size_t i; for (i = 0; i != STLSOFT_NUM_ELEMENTS(bad_chars); ++i) + { + { libpath_size_t j; for (j = 0; j != STLSOFT_NUM_ELEMENTS(input_template) - 1; ++j) + { + libpath_ParseResult_t r; + LIBPATH_RC rc; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + libpath_size_t firstBadCharOffset; + + char input[STLSOFT_NUM_ELEMENTS(input_template)]; + + STLSOFT_STATIC_ASSERT(sizeof(input) == sizeof(input_template)); + + memcpy(input, input_template, sizeof(input)); + + input[j] = bad_chars[i]; + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(j, firstBadCharOffset); + + rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(31u, r.input.len); + TEST_INT_EQ(j, firstBadCharOffset); + }} + }} +} + +static void test_Windows_bad_characters(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + + libpath_ParseResult_t r; + LIBPATH_RC rc; + libpath_size_t firstBadCharOffset; + + + rc = libpath_Parse_ParsePathFromCStyleString(":C\\dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(0u, firstBadCharOffset); + + + rc = libpath_Parse_ParsePathFromCStyleString("C:\\dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(15u, r.input.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("C\\:dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(2u, firstBadCharOffset); + + + rc = libpath_Parse_ParsePathFromCStyleString("C\\d:ir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(3u, firstBadCharOffset); + + + rc = libpath_Parse_ParsePathFromCStyleString("C\\di:r\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(4u, firstBadCharOffset); + + + rc = libpath_Parse_ParsePathFromCStyleString("C\\dir:\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(5u, firstBadCharOffset); + + + + rc = libpath_Parse_ParsePathFromCStyleString("\\:Cdir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(1u, firstBadCharOffset); +#endif +} + +static void test_1_component_with_libpath_ParseOption_AssumeDirectory(void) +{ + libpath_ParseResult_t r; + LIBPATH_RC rc; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + + rc = libpath_Parse_ParsePathFromCStyleString("abc", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(4u, r.input.len); + TEST_INT_EQ(4u, r.fullPath.len); + TEST_INT_EQ(4u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(3u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(3u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(3u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(4u, r.input.len); + TEST_INT_EQ(4u, r.fullPath.len); + TEST_INT_EQ(4u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); +} + +static void test_2_components_with_libpath_ParseOption_AssumeDirectory(void) +{ + libpath_ParseResult_t r; + LIBPATH_RC rc; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/def", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(7u, r.input.len); + TEST_INT_EQ(7u, r.fullPath.len); + TEST_INT_EQ(4u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/def/", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(8u, r.input.len); + TEST_INT_EQ(8u, r.fullPath.len); + TEST_INT_EQ(8u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(8u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(4u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("def/", directoryPartSlices[1]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/def", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(7u, r.input.len); + TEST_INT_EQ(7u, r.fullPath.len); + TEST_INT_EQ(7u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(7u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(3u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("def", directoryPartSlices[1]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/def/", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(8u, r.input.len); + TEST_INT_EQ(8u, r.fullPath.len); + TEST_INT_EQ(8u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(8u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(4u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("def/", directoryPartSlices[1]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + +} + +static void test_2_components_with_last_2dotsdir_with_libpath_ParseOption_AssumeDirectory(void) +{ + libpath_ParseResult_t r; + LIBPATH_RC rc; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/..", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(4u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(2u, r.entryNamePart.len); + TEST_INT_EQ(2u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/../", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(7u, r.input.len); + TEST_INT_EQ(7u, r.fullPath.len); + TEST_INT_EQ(7u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(7u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(3u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("../", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/..", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(6u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(6u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(2u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/../", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(7u, r.input.len); + TEST_INT_EQ(7u, r.fullPath.len); + TEST_INT_EQ(7u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(7u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(3u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("../", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); +} + +static void test_2_components_with_last_1dotsdir_with_libpath_ParseOption_AssumeDirectory(void) +{ + libpath_ParseResult_t r; + LIBPATH_RC rc; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/.", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(5u, r.input.len); + TEST_INT_EQ(5u, r.fullPath.len); + TEST_INT_EQ(4u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(1u, r.entryNamePart.len); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/./", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(6u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(6u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(2u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("./", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/.", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(5u, r.input.len); + TEST_INT_EQ(5u, r.fullPath.len); + TEST_INT_EQ(5u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(5u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(1u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = libpath_Parse_ParsePathFromCStyleString("abc/./", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(6u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(6u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(2u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("./", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); +} + +static void test_Windows_UNC_share_trailing_backslash(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(20u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(20u, r.fullPath.len); + TEST_INT_EQ(20u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_UNC_share_trailing_slash(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share/"; + + libpath_ParseResult_t r; + libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(20u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(20u, r.fullPath.len); + TEST_INT_EQ(20u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_Windows_UNC_share_with_charwise_steps(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\"; + libpath_size_t const cch = STLSOFT_NUM_ELEMENTS(input) - 1; + + { libpath_size_t i; for (i = 0; i <= cch; ++i) + { + libpath_ParseResult_t r; + LIBPATH_RC const rc = libpath_Parse_ParsePathFromStringPtrAndLen(input, i, 0, &r, 0, LIBPATH_LF_nullptr, LIBPATH_LF_nullptr); + + if (1 == i || + cch == i) + { + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(i, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(i, r.fullPath.len); + TEST_INT_EQ(i, r.locationPart.len); + TEST_INT_EQ(i, r.rootPart.len); + if (cch == i) + { + TEST_INT_EQ(20u, r.volumePart.len); + } + else + { + TEST_INT_EQ(0u, r.volumePart.len); + } + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); + if (cch == i) + { + TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); + } + else + { + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); + } + } + else + { + if (0 == i) + { + TEST_ENUM_EQ(libpath_ResultCode_NoPathSpecified, rc); + TEST_INT_EQ(i, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + } + else + { + TEST_ENUM_EQ(libpath_ResultCode_InvalidRoot, rc); + TEST_INT_EQ(i, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + } + + TEST_INT_EQ(0u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(0u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); + TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); + } + }} +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + + +/* ///////////////////////////// end of file //////////////////////////// */ + diff --git a/test/unit/parse/CMakeLists.txt b/test/unit/parse/CMakeLists.txt new file mode 100644 index 0000000..5129fc8 --- /dev/null +++ b/test/unit/parse/CMakeLists.txt @@ -0,0 +1,2 @@ +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +define_automated_test_program(test.unit.parse entry.cpp) diff --git a/test/unit/parse/entry.cpp b/test/unit/parse/entry.cpp new file mode 100644 index 0000000..302b62a --- /dev/null +++ b/test/unit/parse/entry.cpp @@ -0,0 +1,2528 @@ +/* ///////////////////////////////////////////////////////////////////////// + * File: test/unit/parse/entry.cpp + * + * Purpose: Unit-tests the libpath C++ parse API. + * + * Created: 9th November 2012 + * Updated: 14th October 2026 + * + * ////////////////////////////////////////////////////////////////////// */ + + +/* ///////////////////////////////////////////////////////////////////////// + * includes + */ + +/* ///////////////////////////////////// + * test component header file include(s) + */ + +#include + +/* ///////////////////////////////////// + * general includes + */ + +/* xTests header files */ +#include +#if _XTESTS_VER < 0x00150000 +# error This code requires xTests 0.21.0, or later +#endif + +/* STLSoft header files */ +#include + +/* Standard C header files */ +#include + + +/* ///////////////////////////////////////////////////////////////////////// + * forward declarations + */ + +static void test_1_0(void); +static void test_1_1(void); +static void test_1_2(void); +static void test_1_3(void); +static void test_1_4(void); + +static void test_1_6(void); +static void test_1_7(void); +static void test_1_8(void); + +static void test_1_10(void); +static void test_1_11(void); +static void test_1_12(void); + +static void test_1_14(void); +static void test_1_15(void); +static void test_1_16(void); +static void test_1_17(void); +static void test_1_18(void); +static void test_1_19(void); +static void test_1_20(void); +static void test_1_21(void); +static void test_1_22(void); + +static void test_1_30(void); +static void test_1_31(void); +static void test_1_32(void); +static void test_1_33(void); +static void test_1_34(void); +static void test_1_35(void); +static void test_1_36(void); +static void test_1_37(void); + +static void test_1_40(void); +static void test_1_41(void); +static void test_1_42(void); +static void test_1_43(void); +static void test_1_44(void); + +static void test_1_50(void); +static void test_1_51(void); +static void test_1_52(void); +static void test_1_53(void); +static void test_1_54(void); +static void test_1_55(void); + +static void test_1_60(void); +static void test_1_61(void); + +static void test_1_70(void); +static void test_1_71(void); +static void test_1_72(void); +static void test_1_73(void); + +static void test_1_80(void); +static void test_1_81(void); +static void test_1_82(void); + + +/* ///////////////////////////////////////////////////////////////////////// + * main + */ + +int main(int argc, char* argv[]) +{ + int retCode = EXIT_SUCCESS; + int verbosity = 2; + + XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); + + if (XTESTS_START_RUNNER("test.unit.parse", verbosity)) + { + XTESTS_RUN_CASE(test_1_0); + XTESTS_RUN_CASE(test_1_1); + XTESTS_RUN_CASE(test_1_2); + XTESTS_RUN_CASE(test_1_3); + XTESTS_RUN_CASE(test_1_4); + + XTESTS_RUN_CASE(test_1_6); + XTESTS_RUN_CASE(test_1_7); + XTESTS_RUN_CASE(test_1_8); + + XTESTS_RUN_CASE(test_1_10); + XTESTS_RUN_CASE(test_1_11); + XTESTS_RUN_CASE(test_1_12); + + XTESTS_RUN_CASE(test_1_14); + XTESTS_RUN_CASE(test_1_15); + XTESTS_RUN_CASE(test_1_16); + XTESTS_RUN_CASE(test_1_17); + XTESTS_RUN_CASE(test_1_18); + XTESTS_RUN_CASE(test_1_19); + XTESTS_RUN_CASE(test_1_20); + XTESTS_RUN_CASE(test_1_21); + XTESTS_RUN_CASE(test_1_22); + + XTESTS_RUN_CASE(test_1_30); + XTESTS_RUN_CASE(test_1_31); + XTESTS_RUN_CASE(test_1_32); + XTESTS_RUN_CASE(test_1_33); + XTESTS_RUN_CASE(test_1_34); + XTESTS_RUN_CASE(test_1_35); + XTESTS_RUN_CASE(test_1_36); + XTESTS_RUN_CASE(test_1_37); + + XTESTS_RUN_CASE(test_1_40); + XTESTS_RUN_CASE(test_1_41); + XTESTS_RUN_CASE(test_1_42); + XTESTS_RUN_CASE(test_1_43); + XTESTS_RUN_CASE(test_1_44); + + XTESTS_RUN_CASE(test_1_50); + XTESTS_RUN_CASE(test_1_51); + XTESTS_RUN_CASE(test_1_52); + XTESTS_RUN_CASE(test_1_53); + XTESTS_RUN_CASE(test_1_54); + XTESTS_RUN_CASE(test_1_55); + + XTESTS_RUN_CASE(test_1_60); + XTESTS_RUN_CASE(test_1_61); + + XTESTS_RUN_CASE(test_1_70); + XTESTS_RUN_CASE(test_1_71); + XTESTS_RUN_CASE(test_1_72); + XTESTS_RUN_CASE(test_1_73); + + XTESTS_RUN_CASE(test_1_80); + XTESTS_RUN_CASE(test_1_81); + XTESTS_RUN_CASE(test_1_82); + + XTESTS_PRINT_RESULTS(); + + XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); + } + + return retCode; +} + + +/* ///////////////////////////////////////////////////////////////////////// + * test function implementations + */ + +using ::libpath::StringSlice_t; + +typedef ::libpath::parsing::PathDescriptor_t ParseResult_t; + +using ::libpath::parsing::parse_path_from_cstyle_string; +using ::libpath::parsing::parse_path_from_string_ptr_and_len; + +using ::libpath::parsing::is_absolute; +using ::libpath::parsing::is_rooted; + + +#ifdef __cplusplus + + const libpath_size_t NUM_DP_ELEMENTS = 10; +#else /* ? __cplusplus */ + +# define NUM_DP_ELEMENTS (10) +#endif /* __cplusplus */ + + +static void test_1_0(void) +{ + char const input[] = ""; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[1]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_NoPathSpecified, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_NoPathSpecified, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_NoPathSpecified, rc); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); + TEST_INT_EQ(0u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(0u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); +} + +static void test_1_1(void) +{ + char const input[] = "."; + + ParseResult_t r; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(1u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(1u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(1u, r.entryNamePart.len); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +} + +static void test_1_2(void) +{ + char const input[] = ".."; + + ParseResult_t r; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(2u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(2u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(2u, r.entryNamePart.len); + TEST_INT_EQ(2u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +} + +static void test_1_3(void) +{ + char const input[] = "/."; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(2u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(2u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, directoryPartSlices[0].len); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(1u, r.entryNamePart.len); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_4(void) +{ + char const input[] = "/.."; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(2u, r.entryNamePart.len); + TEST_INT_EQ(2u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_6(void) +{ + char const input[] = "..."; + + ParseResult_t r; + LIBPATH_RC rc = parse_path_from_cstyle_string(input, 0, &r, 0, LIBPATH_LF_nullptr); + + // TODO: define failure result code + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); +} + +static void test_1_7(void) +{ + char const input[] = "....."; + + ParseResult_t r; + LIBPATH_RC rc = parse_path_from_cstyle_string(input, 0, &r, 0, LIBPATH_LF_nullptr); + + // TODO: define failure result code + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(5u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(5u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(5u, r.entryNamePart.len); + TEST_INT_EQ(5u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); +} + +static void test_1_8(void) +{ + char const input[] = "..abc.def.."; + + ParseResult_t r; + LIBPATH_RC rc = parse_path_from_cstyle_string(input, 0, &r, 0, LIBPATH_LF_nullptr); + + // TODO: define failure result code + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(11u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(11u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(11u, r.entryNamePart.len); + TEST_INT_EQ(11u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); +} + +static void test_1_10(void) +{ + char const input[] = "abc"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +} + +static void test_1_11(void) +{ + char const input[] = "a.c"; + + ParseResult_t r; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + LIBPATH_RC const rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_INT_EQ(2u, r.entryExtensionPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL(".c", r.entryExtensionPart); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +} + +static void test_1_12(void) +{ + char const input[] = ".bc"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(3u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +} + +static void test_1_14(void) +{ + char const input[] = "/abc"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(4u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(4u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("/", r.locationPart); + TEST_INT_EQ(1u, r.rootPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("/", r.rootPart); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc", r.entryStemPart); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_15(void) +{ + char const input[] = "/dir/abc"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(8u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(8u, r.fullPath.len); + TEST_INT_EQ(5u, r.locationPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("/dir/", r.locationPart); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc", r.entryStemPart); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_16(void) +{ + char const input[] = "/dir/"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(5u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(5u, r.fullPath.len); + TEST_INT_EQ(5u, r.locationPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("/dir/", r.locationPart); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_17(void) +{ + char const input[] = "/dir/dir2/"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(10u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(10u, r.fullPath.len); + TEST_INT_EQ(10u, r.locationPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("/dir/dir2/", r.locationPart); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(9u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); + TEST_INT_EQ(5u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir2/", directoryPartSlices[1]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ + + directoryPartSlices[1].len = 1234; + directoryPartSlices[1].ptr = reinterpret_cast(1234); + + rc = parse_path_from_cstyle_string(input, 0, &r, 1, &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(10u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(10u, r.fullPath.len); + TEST_INT_EQ(10u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(9u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + + TEST_INT_EQ(1234u, directoryPartSlices[1].len); + TEST_PTR_EQ(reinterpret_cast(1234), directoryPartSlices[1].ptr); + + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_18(void) +{ + char const input[] = "/directory1/directory2/dir3/dir4/d5/d6/"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(39u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(39u, r.fullPath.len); + TEST_INT_EQ(39u, r.locationPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("/directory1/directory2/dir3/dir4/d5/d6/", r.locationPart); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_19(void) +{ + char const input[] = "/directory1/directory2/dir3/dir4/d5/d6/file.ext"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(47u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(47u, r.fullPath.len); + TEST_INT_EQ(39u, r.locationPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("/directory1/directory2/dir3/dir4/d5/d6/", r.locationPart); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("file", r.entryStemPart); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL(".ext", r.entryExtensionPart); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_20(void) +{ + char const input[] = "/1/2/3/4/5/6/f"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(14u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(14u, r.fullPath.len); + TEST_INT_EQ(13u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(12u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(2u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("1/", directoryPartSlices[0]); + TEST_INT_EQ(2u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("2/", directoryPartSlices[1]); + TEST_INT_EQ(2u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("3/", directoryPartSlices[2]); + TEST_INT_EQ(2u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("4/", directoryPartSlices[3]); + TEST_INT_EQ(2u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("5/", directoryPartSlices[4]); + TEST_INT_EQ(2u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("6/", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(1u, r.entryNamePart.len); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_21(void) +{ + char const input[] = "/"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(1u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(1u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_22(void) +{ + char const input[] = "this.is.a.more.complex.file.ext"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(31u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(31u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(31u, r.entryNamePart.len); + TEST_INT_EQ(27u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +} + +static void test_1_30(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(1u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(1u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); + TEST_INT_EQ(0u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_31(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\abc"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(4u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(4u, r.fullPath.len); + TEST_INT_EQ(1u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); + TEST_INT_EQ(0u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_32(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:\\"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(3u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_33(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:\\abc"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(3u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_34(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:\\directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(49u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(49u, r.fullPath.len); + TEST_INT_EQ(41u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_35(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:/"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(3u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_36(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:/abc"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(3u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_37(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:/directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(49u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(49u, r.fullPath.len); + TEST_INT_EQ(41u, r.locationPart.len); + TEST_INT_EQ(3u, r.rootPart.len); + TEST_INT_EQ(3u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_40(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(20u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(20u, r.fullPath.len); + TEST_INT_EQ(20u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_41(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\abc"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(23u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(23u, r.fullPath.len); + TEST_INT_EQ(20u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_42(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(66u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(66u, r.fullPath.len); + TEST_INT_EQ(58u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_43(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\directory1/directory2\\dir3/dir4\\d5/d6\\file.ext"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(66u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(66u, r.fullPath.len); + TEST_INT_EQ(58u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_44(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share/directory1\\directory2/dir3\\dir4/d5\\d6/file.ext"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(66u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(66u, r.fullPath.len); + TEST_INT_EQ(58u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_50(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:abc"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(5u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(5u, r.fullPath.len); + TEST_INT_EQ(2u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(2u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_51(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(48u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(48u, r.fullPath.len); + TEST_INT_EQ(40u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(2u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_52(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:directory1/directory2\\dir3/dir4\\d5/d6\\file.ext"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(48u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(48u, r.fullPath.len); + TEST_INT_EQ(40u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(2u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(8u, r.entryNamePart.len); + TEST_INT_EQ(4u, r.entryStemPart.len); + TEST_INT_EQ(4u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_53(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "C:directory1/directory2\\dir3/dir4\\d5/d6\\."; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(41u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(41u, r.fullPath.len); + TEST_INT_EQ(40u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(2u, r.volumePart.len); + TEST_INT_EQ(38u, r.directoryPart.len); + TEST_INT_EQ(6u, r.numDirectoryParts); + TEST_INT_EQ(11u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); + TEST_INT_EQ(11u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); + TEST_INT_EQ(5u, directoryPartSlices[2].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); + TEST_INT_EQ(5u, directoryPartSlices[3].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); + TEST_INT_EQ(3u, directoryPartSlices[4].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); + TEST_INT_EQ(3u, directoryPartSlices[5].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(1u, r.entryNamePart.len); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_54(void) +{ + char const input[] = "/dir//abc"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(9u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(9u, r.fullPath.len); + TEST_INT_EQ(6u, r.locationPart.len); + TEST_INT_EQ(1u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(5u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(5u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir//", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_55(void) +{ + char const input[] = "dir/abc"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(7u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(7u, r.fullPath.len); + TEST_INT_EQ(4u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_INT_EQ(0u, r.volumePart.len); +#endif + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + TEST_INT_EQ(3u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(is_rooted(r)); +#ifdef LIBPATH_OS_IS_WINDOWS + TEST_BOOLEAN_FALSE(is_absolute(r)); +#else /* ? LIBPATH_OS_IS_WINDOWS */ + TEST_BOOLEAN_FALSE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_60(void) +{ + static char const bad_chars[] = + { + '|' + , '<' + , '>' + , '?' + , '*' +#ifdef LIBPATH_OS_IS_WINDOWS + , ';' +#else + , ':' +#endif + }; + char const input_template[] = "/this/is/going/to/be/a.bad.path"; + + { for (libpath_size_t i = 0; i != STLSOFT_NUM_ELEMENTS(bad_chars); ++i) + { + { for (libpath_size_t j = 0; j != STLSOFT_NUM_ELEMENTS(input_template) - 1; ++j) + { + char input[STLSOFT_NUM_ELEMENTS(input_template)]; + + STLSOFT_STATIC_ASSERT(sizeof(input) == sizeof(input_template)); + + memcpy(input, input_template, sizeof(input)); + + input[j] = bad_chars[i]; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + libpath_size_t firstBadCharOffset; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], &firstBadCharOffset); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices, &firstBadCharOffset); +#endif + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(31u, r.input.len); + TEST_INT_EQ(j, firstBadCharOffset); + }} + }} +} + +static void test_1_61(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + ParseResult_t r; + LIBPATH_RC rc; + libpath_size_t firstBadCharOffset; + + + rc = parse_path_from_cstyle_string(":C\\dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(0u, firstBadCharOffset); + + + rc = parse_path_from_cstyle_string("C:\\dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(15u, r.input.len); + + + rc = parse_path_from_cstyle_string("C\\:dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(2u, firstBadCharOffset); + + + rc = parse_path_from_cstyle_string("C\\d:ir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(3u, firstBadCharOffset); + + + rc = parse_path_from_cstyle_string("C\\di:r\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(4u, firstBadCharOffset); + + + rc = parse_path_from_cstyle_string("C\\dir:\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(5u, firstBadCharOffset); + + + rc = parse_path_from_cstyle_string("\\:Cdir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); + + TEST_ENUM_EQ(libpath_ResultCode_BadPathCharacter, rc); + TEST_INT_EQ(15u, r.input.len); + TEST_INT_EQ(1u, firstBadCharOffset); + + +#endif +} + +static void test_1_70(void) +{ + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + + rc = parse_path_from_cstyle_string("abc", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + + + rc = parse_path_from_cstyle_string("abc/", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(4u, r.input.len); + TEST_INT_EQ(4u, r.fullPath.len); + TEST_INT_EQ(4u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = parse_path_from_cstyle_string("abc", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(3u, r.input.len); + TEST_INT_EQ(3u, r.fullPath.len); + TEST_INT_EQ(3u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(3u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(3u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = parse_path_from_cstyle_string("abc/", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(4u, r.input.len); + TEST_INT_EQ(4u, r.fullPath.len); + TEST_INT_EQ(4u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + +} + +static void test_1_71(void) +{ + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + + rc = parse_path_from_cstyle_string("abc/def", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(7u, r.input.len); + TEST_INT_EQ(7u, r.fullPath.len); + TEST_INT_EQ(4u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(3u, r.entryNamePart.len); + + + rc = parse_path_from_cstyle_string("abc/def/", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(8u, r.input.len); + TEST_INT_EQ(8u, r.fullPath.len); + TEST_INT_EQ(8u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(8u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(4u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("def/", directoryPartSlices[1]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = parse_path_from_cstyle_string("abc/def", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(7u, r.input.len); + TEST_INT_EQ(7u, r.fullPath.len); + TEST_INT_EQ(7u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(7u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(3u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("def", directoryPartSlices[1]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = parse_path_from_cstyle_string("abc/def/", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(8u, r.input.len); + TEST_INT_EQ(8u, r.fullPath.len); + TEST_INT_EQ(8u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(8u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(4u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("def/", directoryPartSlices[1]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + +} + +static void test_1_72(void) +{ + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + + rc = parse_path_from_cstyle_string("abc/..", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(4u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(2u, r.entryNamePart.len); + TEST_INT_EQ(2u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + + rc = parse_path_from_cstyle_string("abc/../", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(7u, r.input.len); + TEST_INT_EQ(7u, r.fullPath.len); + TEST_INT_EQ(7u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(7u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(3u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("../", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = parse_path_from_cstyle_string("abc/..", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(6u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(6u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(2u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = parse_path_from_cstyle_string("abc/../", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(7u, r.input.len); + TEST_INT_EQ(7u, r.fullPath.len); + TEST_INT_EQ(7u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(7u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(3u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("../", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + +} + +static void test_1_73(void) +{ + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + + rc = parse_path_from_cstyle_string("abc/.", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(5u, r.input.len); + TEST_INT_EQ(5u, r.fullPath.len); + TEST_INT_EQ(4u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(4u, r.directoryPart.len); + TEST_INT_EQ(1u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(1u, r.entryNamePart.len); + TEST_INT_EQ(1u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + + rc = parse_path_from_cstyle_string("abc/./", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(6u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(6u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(2u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("./", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = parse_path_from_cstyle_string("abc/.", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(5u, r.input.len); + TEST_INT_EQ(5u, r.fullPath.len); + TEST_INT_EQ(5u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(5u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(1u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + + rc = parse_path_from_cstyle_string("abc/./", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(6u, r.input.len); + TEST_INT_EQ(6u, r.fullPath.len); + TEST_INT_EQ(6u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(6u, r.directoryPart.len); + TEST_INT_EQ(2u, r.numDirectoryParts); + TEST_INT_EQ(4u, directoryPartSlices[0].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); + TEST_INT_EQ(2u, directoryPartSlices[1].len); + TEST_MULTIBYTE_STRING_SLICE_EQUAL("./", directoryPartSlices[1]); + TEST_INT_EQ(1u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + + +} + +static void test_1_80(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(20u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(20u, r.fullPath.len); + TEST_INT_EQ(20u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_81(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share/"; + + ParseResult_t r; + LIBPATH_RC rc; + StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; + + rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + +#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT + + rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); +#endif + + rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); + + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(20u, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(20u, r.fullPath.len); + TEST_INT_EQ(20u, r.locationPart.len); + TEST_INT_EQ(20u, r.rootPart.len); + TEST_INT_EQ(20u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + TEST_BOOLEAN_TRUE(is_absolute(r)); +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + +static void test_1_82(void) +{ +#ifdef LIBPATH_OS_IS_WINDOWS + char const input[] = "\\\\192.168.0.1\\share\\"; + libpath_size_t const cch = STLSOFT_NUM_ELEMENTS(input) - 1; + + { for (libpath_size_t i = 0; i <= cch; ++i) + { + ParseResult_t r; + LIBPATH_RC rc; + + rc = parse_path_from_string_ptr_and_len(input, i, 0, &r, 0, LIBPATH_LF_nullptr); + + if (1 == i || + cch == i) + { + TEST_ENUM_EQ(libpath_ResultCode_Success, rc); + TEST_INT_EQ(i, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + TEST_INT_EQ(i, r.fullPath.len); + TEST_INT_EQ(i, r.locationPart.len); + TEST_INT_EQ(i, r.rootPart.len); + if (cch == i) + { + TEST_INT_EQ(20u, r.volumePart.len); + } + else + { + TEST_INT_EQ(0u, r.volumePart.len); + } + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_TRUE(is_rooted(r)); + if (cch == i) + { + TEST_BOOLEAN_TRUE(is_absolute(r)); + } + else + { + TEST_BOOLEAN_FALSE(is_absolute(r)); + } + } + else + { + if (0 == i) + { + TEST_ENUM_EQ(libpath_ResultCode_NoPathSpecified, rc); + TEST_INT_EQ(i, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + } + else + { + TEST_ENUM_EQ(libpath_ResultCode_InvalidRoot, rc); + TEST_INT_EQ(i, r.input.len); + TEST_MS_EQ_N(input, r.input.ptr, r.input.len); + } + + TEST_INT_EQ(0u, r.fullPath.len); + TEST_INT_EQ(0u, r.locationPart.len); + TEST_INT_EQ(0u, r.rootPart.len); + TEST_INT_EQ(0u, r.volumePart.len); + TEST_INT_EQ(0u, r.directoryPart.len); + TEST_INT_EQ(0u, r.numDirectoryParts); + TEST_INT_EQ(0u, r.numDotsDirectoryParts); + TEST_INT_EQ(0u, r.entryNamePart.len); + TEST_INT_EQ(0u, r.entryStemPart.len); + TEST_INT_EQ(0u, r.entryExtensionPart.len); + + TEST_BOOLEAN_FALSE(is_rooted(r)); + TEST_BOOLEAN_FALSE(is_absolute(r)); + } + }} +#endif /* LIBPATH_OS_IS_WINDOWS */ +} + + +/* ///////////////////////////// end of file //////////////////////////// */ + diff --git a/test/unit/shim-strings/CMakeLists.txt b/test/unit/shim-strings/CMakeLists.txt new file mode 100644 index 0000000..1c2a75b --- /dev/null +++ b/test/unit/shim-strings/CMakeLists.txt @@ -0,0 +1,2 @@ +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +define_automated_test_program(test.unit.shim-strings entry.cpp) diff --git a/test/unit/shim-strings/entry.cpp b/test/unit/shim-strings/entry.cpp new file mode 100644 index 0000000..578d287 --- /dev/null +++ b/test/unit/shim-strings/entry.cpp @@ -0,0 +1,104 @@ +/* ///////////////////////////////////////////////////////////////////////// + * File: test/unit/shim-strings/entry.cpp + * + * Purpose: Unit-tests the libpath string shims. + * + * Created: 11th February 2024 + * Updated: 14th October 2026 + * + * ////////////////////////////////////////////////////////////////////// */ + + +/* ///////////////////////////////////////////////////////////////////////// + * includes + */ + +/* ///////////////////////////////////// + * test component header file include(s) + */ + +#include + +/* ///////////////////////////////////// + * general includes + */ + +/* xTests header files */ +#include +#if _XTESTS_VER < 0x00150000 +# error This code requires xTests 0.21.0, or later +#endif + +/* STLSoft header files */ +#include +#include + +/* Standard C header files */ +#include + + +/* ///////////////////////////////////////////////////////////////////////// + * forward declarations + */ + +static void test_rc_known_values(void); + + +/* ///////////////////////////////////////////////////////////////////////// + * main + */ + +int main(int argc, char* argv[]) +{ + int retCode = EXIT_SUCCESS; + int verbosity = 2; + + XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); + + if (XTESTS_START_RUNNER("test.unit.shim-strings", verbosity)) + { + XTESTS_RUN_CASE(test_rc_known_values); + + XTESTS_PRINT_RESULTS(); + + XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); + } + + return retCode; +} + + +/* ///////////////////////////////////////////////////////////////////////// + * test function implementations + */ + +static void test_rc_known_values() +{ + TEST_MS_EQ("operation is not supported", stlsoft::sas_to_string(LIBPATH_RC_OF(UnsupportedOperation))); + + TEST_MS_EQ("unexpected condition", stlsoft::sas_to_string(LIBPATH_RC_OF(UnexpectedCondition))); + + TEST_MS_EQ("out of memory", stlsoft::sas_to_string(LIBPATH_RC_OF(OutOfMemory))); + + TEST_MS_EQ("no path specified", stlsoft::sas_to_string(LIBPATH_RC_OF(NoPathSpecified))); + + TEST_MS_EQ("bad path character", stlsoft::sas_to_string(LIBPATH_RC_OF(BadPathCharacter))); + + TEST_MS_EQ("option not supported", stlsoft::sas_to_string(LIBPATH_RC_OF(OptionNotSupported))); + + TEST_MS_EQ("invalid root", stlsoft::sas_to_string(LIBPATH_RC_OF(InvalidRoot))); + + TEST_MS_EQ("a reserved parameter that is reserved for future use must have the value 0 or NULL", stlsoft::sas_to_string(LIBPATH_RC_OF(ParameterIsReservedAndMustBeZero))); + + TEST_MS_EQ("first/only path parameter is invalid", stlsoft::sas_to_string(LIBPATH_RC_OF(FirstPathInvalid))); + + TEST_MS_EQ("second path parameter is invalid", stlsoft::sas_to_string(LIBPATH_RC_OF(SecondPathInvalid))); + + TEST_MS_EQ("working directory path parameter is invalid", stlsoft::sas_to_string(LIBPATH_RC_OF(WorkingDirectoryPathInvalid))); + + TEST_MS_EQ("operation completed successfully", stlsoft::sas_to_string(LIBPATH_RC_OF(Success))); +} + + +/* ///////////////////////////// end of file //////////////////////////// */ + diff --git a/test/unit/test.unit.compare.1.c/CMakeLists.txt b/test/unit/test.unit.compare.1.c/CMakeLists.txt deleted file mode 100644 index 1d75fbf..0000000 --- a/test/unit/test.unit.compare.1.c/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten -define_automated_test_program(test.unit.compare.1.c test.unit.compare.1.c.c) diff --git a/test/unit/test.unit.compare.1.c/test.unit.compare.1.c.c b/test/unit/test.unit.compare.1.c/test.unit.compare.1.c.c deleted file mode 100644 index 3885948..0000000 --- a/test/unit/test.unit.compare.1.c/test.unit.compare.1.c.c +++ /dev/null @@ -1,758 +0,0 @@ -/* ///////////////////////////////////////////////////////////////////////// - * File: test.unit.compare.1.c.c - * - * Purpose: Implementation file for the test.unit.compare.1.c project. - * - * Created: 28th March 2013 - * Updated: 15th March 2025 - * - * ////////////////////////////////////////////////////////////////////// */ - - -/* ///////////////////////////////////////////////////////////////////////// - * includes - */ - -/* ///////////////////////////////////// - * test component header file include(s) - */ - -#include - -/* ///////////////////////////////////// - * general includes - */ - -/* xTests header files */ -#include - -/* STLSoft header files */ -#include - -/* Standard C header files */ -#include -#include -#include - - -/* ///////////////////////////////////////////////////////////////////////// - * forward declarations - */ - -static void test_1_0(void); -static void test_1_1(void); -static void test_1_2(void); -static void test_1_3(void); -static void test_1_4(void); -static void test_1_5(void); -static void test_1_6(void); -static void test_1_7(void); -static void test_1_8(void); -static void test_1_9(void); -static void test_1_10(void); -static void test_1_11(void); -static void test_1_12(void); -static void test_1_13(void); -static void test_1_14(void); -static void test_1_15(void); -static void test_1_16(void); -static void test_1_17(void); - - -/* ///////////////////////////////////////////////////////////////////////// - * helper functions - */ - -int main(int argc, char* argv[]) -{ - int retCode = EXIT_SUCCESS; - int verbosity = 2; - - XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); - - if (XTESTS_START_RUNNER("test.unit.compare.1.c", verbosity)) - { - XTESTS_RUN_CASE(test_1_0); - XTESTS_RUN_CASE(test_1_1); - XTESTS_RUN_CASE(test_1_2); - XTESTS_RUN_CASE(test_1_3); - XTESTS_RUN_CASE(test_1_4); - XTESTS_RUN_CASE(test_1_5); - XTESTS_RUN_CASE(test_1_6); - XTESTS_RUN_CASE(test_1_7); - XTESTS_RUN_CASE(test_1_8); - XTESTS_RUN_CASE(test_1_9); - XTESTS_RUN_CASE(test_1_10); - XTESTS_RUN_CASE(test_1_11); - XTESTS_RUN_CASE(test_1_12); - XTESTS_RUN_CASE(test_1_13); - XTESTS_RUN_CASE(test_1_14); - XTESTS_RUN_CASE(test_1_15); - XTESTS_RUN_CASE(test_1_16); - XTESTS_RUN_CASE(test_1_17); - - XTESTS_PRINT_RESULTS(); - - XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); - } - - return retCode; -} - - -/* ///////////////////////////////////////////////////////////////////////// - * test function implementations - */ - -int -compare_paths( - char const* lhs -, char const* rhs -, char const* cwd -, char const* mem -) -{ - libpath_sint32_t flags = 0; - libpath_WorkingDirectoryContext_t ctxt; - int result; - LIBPATH_RC rc; - - STLSOFT_SUPPRESS_UNUSED(mem); - - ctxt.mechanism = libpath_WorkingDirectoryContextMechanism_CStyleString; - ctxt.details.cwd_css = cwd; - - rc = libpath_Compare_ComparePathsAsCStyleStrings( - lhs - , rhs - , flags - , &ctxt - , LIBPATH_LF_nullptr - , &result - ); - - if (LIBPATH_RC_OF(Success) != rc) - { - XTESTS_TEST_FAIL_WITH_QUALIFIER("call to `libpath_Compare_ComparePathsAsCStyleStrings()` failed", ""); - } - - return result; -} - - -static void test_1_0(void) -{ - // Just entry parts - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("file.ext", "file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("fil1.ext", "fil2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("fil2.ext", "fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("...", "...", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("...", "....", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("....", "...", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("file.ext", "FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("fil1.ext", "fil2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("FIL2.EXT", "FIL1.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_1(void) -{ - // Just rooted entry parts - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/file.ext", "/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/fil1.ext", "/fil2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/fil2.ext", "/fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/file.ext", "/FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\file.ext", "/FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/file.ext", "\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\file.ext", "\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/fil1.ext", "/FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "/FIL2.EXT", "/fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\fil1.ext", "/FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\FIL2.EXT", "/fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/fil1.ext", "\\FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "/FIL2.EXT", "\\fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\fil1.ext", "\\FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\FIL2.EXT", "\\fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_2(void) -{ - // Windows-rooted entry parts - -#ifdef LIBPATH_OS_IS_WINDOWS - - // case of entry-part - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "C:/file.ext", "C:/FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\file.ext", "C:/FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "C:/file.ext", "C:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\file.ext", "C:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "C:/fil1.ext", "C:/FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "C:/FIL2.EXT", "C:/fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\fil1.ext", "C:/FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\FIL2.EXT", "C:/fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "C:/fil1.ext", "C:\\FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "C:/FIL2.EXT", "C:\\fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\fil1.ext", "C:\\FIL2.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\FIL2.EXT", "C:\\fil1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - - // case of volume part - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\file.ext", "C:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\file.ext", "c:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("c:\\file.ext", "C:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("c:\\file.ext", "c:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - - // different volumes - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\file.ext", "D:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\file.ext", "d:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("c:\\file.ext", "D:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("c:\\file.ext", "d:\\FILE.EXT", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -#endif -} - -static void test_1_3(void) -{ - // Just directory parts - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/", "dir2/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir2/", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/", "DIR1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("DIR1/", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("DIR1/", "DIR1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/", "dir1\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1\\", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1\\", "dir1\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/", "DIR2/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("DIR2/", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/", "DIR2\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("DIR2/", "dir1\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\", "DIR2/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("DIR2\\", "dir1/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\", "DIR2\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("DIR2\\", "dir1\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_4(void) -{ - // Just single dots dir - 1-dot - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".", ".", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".", "./", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./", ".", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./", "./", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".", ".", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".", ".\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".\\", ".", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./", ".\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".\\", "./", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".\\", ".\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_5(void) -{ - // Just single dots dir - 2-dot - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..", "../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("../", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("../", "../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..", "..\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..\\", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("../", "..\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..\\", "../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..\\", "..\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_6(void) -{ - // mixed dots entities - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".", ".", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("...", "...", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths(".", "..", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("..", "...", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); // '...' is a file; '..' is a directory - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("...", "....", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("....", ".....", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -} - -static void test_1_7(void) -{ - // root directory - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/", "/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/", "\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\", "/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\", "\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_8(void) -{ - // more complex relative paths - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file.ext", "dir1/dir3/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1/dir3/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file.ext", "dir1/dir21/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1/dir21/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -} - -static void test_1_9(void) -{ - // absolute vs relative - no cwd - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file.ext", "/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/file.ext", "file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file.ext", "/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/dir1/file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file.ext", "/dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/dir1/dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/", "abcdefghijklmnopqrstuvwxyz.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file.ext", "C:\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\file.ext", "file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\file.ext", "dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "X:\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("X:\\", "abcdefghijklmnopqrstuvwxyz.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_10(void) -{ - // absolute vs rooted - no cwd - -#ifdef LIBPATH_OS_IS_WINDOWS - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\file.ext", "C:\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\file.ext", "\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\file.ext", "\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\dir2\\file.ext", "\\dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\abcdefghijklmnopqrstuvwxyz.ext", "X:\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("X:\\", "\\abcdefghijklmnopqrstuvwxyz.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_11(void) -{ - // absolute vs relative - cwd - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/file1.ext", "file1.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file2.ext", "/", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/dir1/dir2/file1.ext", "file1.ext", "/dir1/dir2/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/dir1/dir2/file1.ext", "file2.ext", "/dir1/dir2/", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/dir1/dir2/file1.ext", "dir2/file1.ext", "/dir1/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/dir1/dir2/file1.ext", "dir2/file2.ext", "/dir1/", LIBPATH_LF_nullptr)); - -#if LIBPATH_VER >= 0x00040000 - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/dir1/dir2/file1.ext", "file1.ext", "//dir1//dir2/", LIBPATH_LF_nullptr)); -#endif - - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file2.ext", "/", LIBPATH_LF_nullptr)); - - - - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file2.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/file1.ext", "file1.ext", "/", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("file.ext", "/file.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/file.ext", "file.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file.ext", "/dir1/file.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/dir1/file.ext", "dir1/file.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/file.ext", "/dir1/dir2/file.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/dir1/dir2/file.ext", "dir1/dir2/file.ext", "/", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "/", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/", "abcdefghijklmnopqrstuvwxyz.ext", "/", LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_WINDOWS - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/file1.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file2.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "/file2.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file1.ext", "C:\\dir1\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file2.ext", "C:\\dir1\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file2.ext", "file1.ext", "C:\\dir1\\", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "C:/file1.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "C:/file1.ext", "file2.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "C:/file2.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "D:/file1.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "D:/file1.ext", "file2.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "D:/file2.ext", "file1.ext", "C:\\", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file.ext", "C:\\file.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\file.ext", "file.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\file.ext", "C:\\dir1\\file.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\file.ext", "dir1\\file.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext", "/", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "X:\\", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("X:\\", "abcdefghijklmnopqrstuvwxyz.ext", "/", LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_12(void) -{ - // paths that need canonicalising - - // file1.ext <=> file1.ext - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("file1.ext", "file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("file1.ext", "dir1/../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/../file1.ext", "file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./file1.ext", "dir1/dir2/../../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/../../file1.ext", "./file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./file1.ext", "dir1/../dir2/../dir3/../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/../dir2/../dir3/../file1.ext", "./file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - // dir1/file1.ext <=> dir1/file1.ext - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "dir1/./file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/./file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "./dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./dir1/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "dir1/././././././././././././././././././././././././././././././././file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/././././././././././././././././././././././././././././././././file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "dir1/dir2/../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/../file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - // dir1/dir2/file1.ext <=> dir1/dir2/file1.ext - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/file1.ext", "dir1/./dir2/./file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/./dir2/./file1.ext", "dir1/dir2/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/dir3/../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - // d1/d2/d3/d4/d5/file1.ext <=> d1/d2/d3/d4/d5/file1.ext - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "./d1/./d2/./d3/./d4/./d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./d1/./d2/./d3/./d4/./d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext", "d1/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - - // file1.ext <=> file2.ext - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file1.ext", "file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file1.ext", "dir1/../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/../file1.ext", "file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("./file1.ext", "dir1/dir2/../../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/../../file1.ext", "./file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("./file1.ext", "dir1/../dir2/../dir3/../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/../dir2/../dir3/../file1.ext", "./file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - // dir1/file1.ext <=> dir1/file2.ext - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "dir1/./file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/./file1.ext", "dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "./dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("./dir1/file1.ext", "dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "dir1/././././././././././././././././././././././././././././././././file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/././././././././././././././././././././././././././././././././file1.ext", "dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "dir1/dir2/../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/../file1.ext", "dir1/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - // dir1/dir2/file1.ext <=> dir1/dir2/file2.ext - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file1.ext", "dir1/./dir2/./file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/./dir2/./file1.ext", "dir1/dir2/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/dir3/../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - // d1/d2/d3/d4/d5/file1.ext <=> d1/d2/d3/d4/d5/file2.ext - XTESTS_TEST_INTEGER_LESS(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "./d1/./d2/./d3/./d4/./d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("./d1/./d2/./d3/./d4/./d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext", "d1/d2/d3/d4/d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - -} - -static void test_1_13(void) -{ - // trailing dots - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/..", "dir1/dir2/../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/..", "dir1/dir3/../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir3/..", "dir1/dir2/../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/..", "dir4/dir3/../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir4/dir3/..", "dir1/dir2/../", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/.", "dir1/dir2/./", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -} - -static void test_1_14(void) -{ - // sliding [rel / cwd] - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d5/file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d6/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d5/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d4/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d3/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d2/d2/d3/d4/d5/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file1.ext", "/d1", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file2.ext", "/d1", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d6/file1.ext", "/d1", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d5/d5/file1.ext", "/d1", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d4/d4/d5/file1.ext", "/d1", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d3/d4/d5/file1.ext", "/d1", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file1.ext", "/d2", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d1/d2", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file2.ext", "/d1/d2", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d6/file1.ext", "/d1/d2", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d5/d5/file1.ext", "/d1/d2", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d4/d5/file1.ext", "/d1/d2", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d1/d3", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d2/d2", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d2/d3", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file2.ext", "/d1/d2/d3", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d6/file1.ext", "/d1/d2/d3", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/d5/file1.ext", "/d1/d2/d3", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d2/d4", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d3/d3", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d2/d2/d3", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d3/d4", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file2.ext", "/d1/d2/d3/d4", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d6/file1.ext", "/d1/d2/d3/d4", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d3/d5", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d4/d4", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d3/d3/d4", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d2/d2/d3/d4", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d4/d5", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file2.ext", "/d1/d2/d3/d4/d5", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d4/d6", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d5/d5", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d4/d4/d5", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d3/d3/d4/d5", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d2/d2/d3/d4/d5", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d5/d6", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file2.ext", "/d1/d2/d3/d4/d5/d6", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d5/d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d6/d6", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d5/d5/d6", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d4/d4/d5/d6", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d3/d3/d4/d5/d6", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d2/d2/d3/d4/d5/d6", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d6/d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file2.ext", "/d1/d2/d3/d4/d5/d6/d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d6/d8", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d7/d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d6/d6/d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d5/d5/d6/d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d4/d4/d5/d6/d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d3/d3/d4/d5/d6/d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d2/d2/d3/d4/d5/d6/d7", LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_WINDOWS - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file2.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d8", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d7\\d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d6\\d6\\d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d5\\d5\\d6\\d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d4\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d3\\d3\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d2\\d2\\d3\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "D:\\d1\\d2\\d3\\d4\\d5\\d6\\d7", LIBPATH_LF_nullptr)); - -#endif -} - -static void test_1_15(void) -{ - // UNC roots - -#ifdef LIBPATH_OS_IS_WINDOWS - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\\\server1\\share1/dir1\\file1.ext", "\\\\server1\\share1\\dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1\\dir1\\file2.ext", "\\\\server1\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir2\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1\\dir2\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share2\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share2\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server2\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server2\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -#endif -} - -static void test_1_16(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file1.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file2.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1\\file2.ext", "C:\\dir1\\file1.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\file1.ext", "C:\\dir2\\file1.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir2\\file1.ext", "C:\\dir1\\file1.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\file1.ext", "D:\\dir1\\file1.ext", "C:\\", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file1.ext", "D:\\", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file1.ext", "C:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file2.ext", "C:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\dir1\\file2.ext", "C:\\dir1\\file1.ext", "C:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\dir1\\file1.ext", "C:\\dir2\\file1.ext", "C:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\dir2\\file1.ext", "C:\\dir1\\file1.ext", "C:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\dir1\\file1.ext", "D:\\dir1\\file1.ext", "C:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file1.ext", "D:", LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_17(void) -{ - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file1.ext", "file2.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("file2.ext", "file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "dir2/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir2/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/dir1/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_WINDOWS - - // absolute, rooted, and relative paths - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:/dir1/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:/dir1/file1.ext", "/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:/dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "C:/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - - // relative paths with volumes - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext", "D:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "C:dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext", "D:", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "D:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "D:/dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1/file2.ext", "C:/dir1/file1.ext", "C:/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir2/file1.ext", "C:/dir1/file1.ext", "C:/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file2.ext", "C:/dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir2/file1.ext", "C:/dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "C:/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "D:/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "D:/dir1/file1.ext", "C:/", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file1.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file1.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file2.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:dir1/file1.ext", "C:/dir2/file1.ext", "/", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir1/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir1", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:file1.ext", "C:/dir1/file2.ext", "/dir1", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:file2.ext", "C:/dir1/file1.ext", "/dir1", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:file1.ext", "C:/dir2/file1.ext", "/dir1", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir2", LIBPATH_LF_nullptr)); - - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext", "C:/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "C:dir1/file1.ext", "/", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext", "C:", LIBPATH_LF_nullptr)); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "file1.ext", "dir1", LIBPATH_LF_nullptr)); -#endif -} - - -/* ///////////////////////////// end of file //////////////////////////// */ - diff --git a/test/unit/test.unit.compare.1/CMakeLists.txt b/test/unit/test.unit.compare.1/CMakeLists.txt deleted file mode 100644 index 11bdb25..0000000 --- a/test/unit/test.unit.compare.1/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten -define_automated_test_program(test.unit.compare.1 test.unit.compare.1.cpp) diff --git a/test/unit/test.unit.compare.1/test.unit.compare.1.cpp b/test/unit/test.unit.compare.1/test.unit.compare.1.cpp deleted file mode 100644 index 2b0100e..0000000 --- a/test/unit/test.unit.compare.1/test.unit.compare.1.cpp +++ /dev/null @@ -1,777 +0,0 @@ -/* ///////////////////////////////////////////////////////////////////////// - * File: test.unit.compare.1.cpp - * - * Purpose: Implementation file for the test.unit.compare.1 project. - * - * Created: 17th February 2013 - * Updated: 15th March 2025 - * - * ////////////////////////////////////////////////////////////////////// */ - - -/* ///////////////////////////////////////////////////////////////////////// - * includes - */ - -/* ///////////////////////////////////// - * test component header file include(s) - */ - -#include - -/* ///////////////////////////////////// - * general includes - */ - -/* xTests header files */ -#include - -/* STLSoft header files */ -#include - -/* Standard C++ header files */ -#include -#include - -/* Standard C header files */ -#include -#include -#include - - -/* ///////////////////////////////////////////////////////////////////////// - * forward declarations - */ - -namespace -{ - - static void test_compare_filenames(void); - static void test_compare_slash_rooted_filenames(void); - static void test_compare_Windows_drive_rooted_filenames(void); - static void test_compare_relative_directory(void); - static void test_compare_dots_directory(void); - static void test_compare_2dotsdir(void); - static void test_compare_mixed_dots_directory(void); - static void test_compare_slash(void); - static void test_compare_2_dirs_and_filename(void); - static void test_compare_slash_rooted_filename(void); - static void test_Windows_mixed_rooted_paths(void); - static void test_mixed_with_root_pwd(void); - static void test_noncanonical_paths(void); - static void test_noncanonical_paths_trailing_dots(void); - static void test_sliding_rel_and_cwd(void); - static void test_compare_UNC_rooted_paths(void); - static void test_Windows_mixed_pwd(void); - static void test_mixed_comparisons(void); -} // anonymous namespace - - -/* ///////////////////////////////////////////////////////////////////////// - * helper functions - */ - -int main(int argc, char* argv[]) -{ - int retCode = EXIT_SUCCESS; - int verbosity = 2; - - XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); - - if (XTESTS_START_RUNNER("test.unit.compare.1", verbosity)) - { - XTESTS_RUN_CASE(test_compare_filenames); - XTESTS_RUN_CASE(test_compare_slash_rooted_filenames); - XTESTS_RUN_CASE(test_compare_Windows_drive_rooted_filenames); - XTESTS_RUN_CASE(test_compare_relative_directory); - XTESTS_RUN_CASE(test_compare_dots_directory); - XTESTS_RUN_CASE(test_compare_2dotsdir); - XTESTS_RUN_CASE(test_compare_mixed_dots_directory); - XTESTS_RUN_CASE(test_compare_slash); - XTESTS_RUN_CASE(test_compare_2_dirs_and_filename); - XTESTS_RUN_CASE(test_compare_slash_rooted_filename); - XTESTS_RUN_CASE(test_Windows_mixed_rooted_paths); - XTESTS_RUN_CASE(test_mixed_with_root_pwd); - XTESTS_RUN_CASE(test_noncanonical_paths); - XTESTS_RUN_CASE(test_noncanonical_paths_trailing_dots); - XTESTS_RUN_CASE(test_sliding_rel_and_cwd); - XTESTS_RUN_CASE(test_compare_UNC_rooted_paths); - XTESTS_RUN_CASE(test_Windows_mixed_pwd); - XTESTS_RUN_CASE(test_mixed_comparisons); - - XTESTS_PRINT_RESULTS(); - - XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); - } - - return retCode; -} - - -/* ///////////////////////////////////////////////////////////////////////// - * test function implementations - */ - -namespace -{ -// using libpath::comparing::compare_paths; - - inline - int - compare_paths( - char const* lhs - , char const* rhs - , char const* cwd = LIBPATH_LF_nullptr - , char const* /*mem*/ = LIBPATH_LF_nullptr - ) - { - libpath_sint32_t flags = 0; - libpath_WorkingDirectoryContext_t ctxt; - int result; - - ctxt.mechanism = libpath_WorkingDirectoryContextMechanism_CStyleString; - ctxt.details.cwd_css = cwd; - - LIBPATH_RC rc = libpath_Compare_ComparePathsAsCStyleStrings( - lhs - , rhs - , flags - , &ctxt - , LIBPATH_LF_nullptr - , &result - ); - - switch (rc) - { - case LIBPATH_RC_OF(FirstPathInvalid): - case LIBPATH_RC_OF(SecondPathInvalid): - case LIBPATH_RC_OF(WorkingDirectoryPathInvalid): - - break; - default: - - break; - } - - if (LIBPATH_RC_FAILURE(rc)) - { - return INT_MIN; - } - - return result; - } - - - -static void test_compare_filenames(void) -{ - // Just entry parts - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("file.ext", "file.ext")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("fil1.ext", "fil2.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("fil2.ext", "fil1.ext")); - - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("...", "...")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("...", "....")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("....", "...")); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("file.ext", "FILE.EXT")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("fil1.ext", "fil2.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("FIL2.EXT", "FIL1.EXT")); -#endif -} - -static void test_compare_slash_rooted_filenames(void) -{ - // Just rooted entry parts - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/file.ext", "/file.ext")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/fil1.ext", "/fil2.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/fil2.ext", "/fil1.ext")); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/file.ext", "/FILE.EXT")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\file.ext", "/FILE.EXT")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/file.ext", "\\FILE.EXT")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\file.ext", "\\FILE.EXT")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/fil1.ext", "/FIL2.EXT")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "/FIL2.EXT", "/fil1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\fil1.ext", "/FIL2.EXT")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\FIL2.EXT", "/fil1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/fil1.ext", "\\FIL2.EXT")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "/FIL2.EXT", "\\fil1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\fil1.ext", "\\FIL2.EXT")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\FIL2.EXT", "\\fil1.ext")); -#endif -} - -static void test_compare_Windows_drive_rooted_filenames(void) -{ - // Windows-rooted entry parts - -#ifdef LIBPATH_OS_IS_WINDOWS - - // case of entry-part - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "C:/file.ext", "C:/FILE.EXT")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\file.ext", "C:/FILE.EXT")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "C:/file.ext", "C:\\FILE.EXT")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\file.ext", "C:\\FILE.EXT")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "C:/fil1.ext", "C:/FIL2.EXT")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "C:/FIL2.EXT", "C:/fil1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\fil1.ext", "C:/FIL2.EXT")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\FIL2.EXT", "C:/fil1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "C:/fil1.ext", "C:\\FIL2.EXT")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "C:/FIL2.EXT", "C:\\fil1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\fil1.ext", "C:\\FIL2.EXT")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\FIL2.EXT", "C:\\fil1.ext")); - - - // case of volume part - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\file.ext", "C:\\FILE.EXT")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\file.ext", "c:\\FILE.EXT")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("c:\\file.ext", "C:\\FILE.EXT")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("c:\\file.ext", "c:\\FILE.EXT")); - - - // different volumes - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\file.ext", "D:\\FILE.EXT")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\file.ext", "d:\\FILE.EXT")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("c:\\file.ext", "D:\\FILE.EXT")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("c:\\file.ext", "d:\\FILE.EXT")); - -#endif -} - -static void test_compare_relative_directory(void) -{ - // Just directory parts - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/", "dir1/")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/", "dir2/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir2/", "dir1/")); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/", "DIR1/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("DIR1/", "dir1/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("DIR1/", "DIR1/")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/", "dir1/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/", "dir1\\")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1\\", "dir1/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1\\", "dir1\\")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/", "DIR2/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("DIR2/", "dir1/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/", "DIR2\\")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("DIR2/", "dir1\\")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\", "DIR2/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("DIR2\\", "dir1/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\", "DIR2\\")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("DIR2\\", "dir1\\")); -#endif -} - -static void test_compare_dots_directory(void) -{ - // Just single dots dir - 1-dot - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".", ".")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".", "./")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./", ".")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./", "./")); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".", ".")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".", ".\\")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".\\", ".")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./", ".\\")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".\\", "./")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".\\", ".\\")); -#endif -} - -static void test_compare_2dotsdir(void) -{ - // Just single dots dir - 2-dot - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..", "..")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..", "../")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("../", "..")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("../", "../")); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..", "..")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..", "..\\")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..\\", "..")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("../", "..\\")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..\\", "../")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..\\", "..\\")); -#endif -} - -static void test_compare_mixed_dots_directory(void) -{ - // mixed dots entities - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths(".", ".")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("..", "..")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("...", "...")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths(".", "..")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("..", "...")); // '...' is a file; '..' is a directory - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("...", "....")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("....", ".....")); -} - -static void test_compare_slash(void) -{ - // root directory - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/", "/")); - -#ifdef LIBPATH_OS_IS_UNIX -#endif - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/", "\\")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\", "/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\", "\\")); -#endif -} - -static void test_compare_2_dirs_and_filename(void) -{ - // more complex relative paths - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file.ext", "dir1/dir3/file.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1/dir3/file.ext", "dir1/dir2/file.ext")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file.ext", "dir1/dir21/file.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1/dir21/file.ext", "dir1/dir2/file.ext")); -} - -static void test_compare_slash_rooted_filename(void) -{ - // absolute vs relative - no cwd - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file.ext", "/file.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/file.ext", "file.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file.ext", "/dir1/file.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/dir1/file.ext", "dir1/file.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file.ext", "/dir1/dir2/file.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/dir1/dir2/file.ext", "dir1/dir2/file.ext")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/", "abcdefghijklmnopqrstuvwxyz.ext")); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file.ext", "C:\\file.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\file.ext", "file.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\file.ext", "C:\\dir1\\file.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\file.ext", "dir1\\file.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "X:\\")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("X:\\", "abcdefghijklmnopqrstuvwxyz.ext")); -#endif -} - -static void test_Windows_mixed_rooted_paths(void) -{ - // absolute vs rooted - no cwd - -#ifdef LIBPATH_OS_IS_WINDOWS - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\file.ext", "C:\\file.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\file.ext", "\\file.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\dir1\\file.ext", "C:\\dir1\\file.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\file.ext", "\\dir1\\file.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\dir2\\file.ext", "\\dir1\\dir2\\file.ext")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\abcdefghijklmnopqrstuvwxyz.ext", "X:\\")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("X:\\", "\\abcdefghijklmnopqrstuvwxyz.ext")); -#endif -} - -static void test_mixed_with_root_pwd(void) -{ - // absolute vs relative - cwd - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/file1.ext", "file1.ext", "/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file2.ext", "/")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/dir1/dir2/file1.ext", "file1.ext", "/dir1/dir2/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/dir1/dir2/file1.ext", "file2.ext", "/dir1/dir2/")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/dir1/dir2/file1.ext", "dir2/file1.ext", "/dir1/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/dir1/dir2/file1.ext", "dir2/file2.ext", "/dir1/")); - -#if LIBPATH_VER >= 0x00040000 - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/dir1/dir2/file1.ext", "file1.ext", "//dir1//dir2/")); -#endif - - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file2.ext", "/")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file2.ext", "/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/file1.ext", "file1.ext", "/")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("file.ext", "/file.ext", "/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/file.ext", "file.ext", "/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file.ext", "/dir1/file.ext", "/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/dir1/file.ext", "dir1/file.ext", "/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/file.ext", "/dir1/dir2/file.ext", "/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/dir1/dir2/file.ext", "dir1/dir2/file.ext", "/")); - - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "/", "/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/", "abcdefghijklmnopqrstuvwxyz.ext", "/")); - -#ifdef LIBPATH_OS_IS_WINDOWS - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "/file1.ext", "file1.ext", "C:\\")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file2.ext", "C:\\")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "/file2.ext", "file1.ext", "C:\\")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file1.ext", "C:\\dir1\\")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file1.ext", "file2.ext", "C:\\dir1\\")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "/file2.ext", "file1.ext", "C:\\dir1\\")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths( "C:/file1.ext", "file1.ext", "C:\\")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths( "C:/file1.ext", "file2.ext", "C:\\")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "C:/file2.ext", "file1.ext", "C:\\")); - - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "D:/file1.ext", "file1.ext", "C:\\")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "D:/file1.ext", "file2.ext", "C:\\")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths( "D:/file2.ext", "file1.ext", "C:\\")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file.ext", "C:\\file.ext", "/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\file.ext", "file.ext", "/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\file.ext", "C:\\dir1\\file.ext", "/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\file.ext", "dir1\\file.ext", "/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\dir2\\file.ext", "C:\\dir1\\dir2\\file.ext", "/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:\\dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext", "/")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("abcdefghijklmnopqrstuvwxyz.ext", "X:\\", "/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("X:\\", "abcdefghijklmnopqrstuvwxyz.ext", "/")); -#endif -} - -static void test_noncanonical_paths(void) -{ - // paths that need canonicalising - - // file1.ext <=> file1.ext - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("file1.ext", "file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("file1.ext", "dir1/../file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/../file1.ext", "file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./file1.ext", "dir1/dir2/../../file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/../../file1.ext", "./file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./file1.ext", "dir1/../dir2/../dir3/../file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/../dir2/../dir3/../file1.ext", "./file1.ext")); - - // dir1/file1.ext <=> dir1/file1.ext - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "dir1/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "dir1/./file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/./file1.ext", "dir1/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "./dir1/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./dir1/file1.ext", "dir1/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "dir1/././././././././././././././././././././././././././././././././file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/././././././././././././././././././././././././././././././././file1.ext", "dir1/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "dir1/dir2/../file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/../file1.ext", "dir1/file1.ext")); - - // dir1/dir2/file1.ext <=> dir1/dir2/file1.ext - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/file1.ext", "dir1/./dir2/./file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/./dir2/./file1.ext", "dir1/dir2/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/dir3/../file1.ext")); - - // d1/d2/d3/d4/d5/file1.ext <=> d1/d2/d3/d4/d5/file1.ext - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "./d1/./d2/./d3/./d4/./d5/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("./d1/./d2/./d3/./d4/./d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext", "d1/d2/d3/d4/d5/file1.ext")); - - - // file1.ext <=> file2.ext - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file1.ext", "file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file1.ext", "dir1/../file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/../file1.ext", "file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("./file1.ext", "dir1/dir2/../../file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/../../file1.ext", "./file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("./file1.ext", "dir1/../dir2/../dir3/../file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/../dir2/../dir3/../file1.ext", "./file2.ext")); - - // dir1/file1.ext <=> dir1/file2.ext - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "dir1/file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "dir1/./file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/./file1.ext", "dir1/file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "./dir1/file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("./dir1/file1.ext", "dir1/file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "dir1/././././././././././././././././././././././././././././././././file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/././././././././././././././././././././././././././././././././file1.ext", "dir1/file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "dir1/dir2/../file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/../file1.ext", "dir1/file2.ext")); - - // dir1/dir2/file1.ext <=> dir1/dir2/file2.ext - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file1.ext", "dir1/./dir2/./file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/./dir2/./file1.ext", "dir1/dir2/file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/file1.ext", "dir1/dir2/dir3/../file2.ext")); - - // d1/d2/d3/d4/d5/file1.ext <=> d1/d2/d3/d4/d5/file2.ext - XTESTS_TEST_INTEGER_LESS(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "./d1/./d2/./d3/./d4/./d5/file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("./d1/./d2/./d3/./d4/./d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("d1/d2/d3/d4/d5/file1.ext", "d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("d1/d2/d3/d4/d5/d6/d7/d8/d9/../../../../file1.ext", "d1/d2/d3/d4/d5/file2.ext")); -} - -static void test_noncanonical_paths_trailing_dots(void) -{ - // trailing dots - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/..", "dir1/dir2/../")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/..", "dir1/dir3/../")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir3/..", "dir1/dir2/../")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/dir2/..", "dir4/dir3/../")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir4/dir3/..", "dir1/dir2/../")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/dir2/.", "dir1/dir2/./")); -} - -static void test_sliding_rel_and_cwd(void) -{ - // sliding [rel / cwd] - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d5/file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d5/file2.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d4/d6/file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d3/d5/d5/file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d2/d4/d4/d5/file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d1/d3/d3/d4/d5/file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "/d2/d2/d3/d4/d5/file1.ext")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file1.ext", "/d1")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file2.ext", "/d1")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d6/file1.ext", "/d1")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d5/d5/file1.ext", "/d1")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d4/d4/d5/file1.ext", "/d1")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d3/d4/d5/file1.ext", "/d1")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d2/d3/d4/d5/file1.ext", "/d2")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d1/d2")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file2.ext", "/d1/d2")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d6/file1.ext", "/d1/d2")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d5/d5/file1.ext", "/d1/d2")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d4/d5/file1.ext", "/d1/d2")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d1/d3")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d3/d4/d5/file1.ext", "/d2/d2")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d2/d3")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file2.ext", "/d1/d2/d3")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d6/file1.ext", "/d1/d2/d3")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/d5/file1.ext", "/d1/d2/d3")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d2/d4")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d1/d3/d3")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d4/d5/file1.ext", "/d2/d2/d3")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d3/d4")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file2.ext", "/d1/d2/d3/d4")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d6/file1.ext", "/d1/d2/d3/d4")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d3/d5")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d2/d4/d4")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d1/d3/d3/d4")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "d5/file1.ext", "/d2/d2/d3/d4")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d4/d5")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file2.ext", "/d1/d2/d3/d4/d5")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d4/d6")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d3/d5/d5")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d2/d4/d4/d5")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d1/d3/d3/d4/d5")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "file1.ext", "/d2/d2/d3/d4/d5")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d5/d6")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file2.ext", "/d1/d2/d3/d4/d5/d6")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d5/d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d4/d6/d6")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d3/d5/d5/d6")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d2/d4/d4/d5/d6")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d1/d3/d3/d4/d5/d6")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../file1.ext", "/d2/d2/d3/d4/d5/d6")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d6/d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file2.ext", "/d1/d2/d3/d4/d5/d6/d7")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d6/d8")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d5/d7/d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d4/d6/d6/d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d3/d5/d5/d6/d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d2/d4/d4/d5/d6/d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d1/d3/d3/d4/d5/d6/d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/d1/d2/d3/d4/d5/file1.ext", "../../file1.ext", "/d2/d2/d3/d4/d5/d6/d7")); - -#ifdef LIBPATH_OS_IS_WINDOWS - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file2.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d7")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d6\\d8")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d5\\d7\\d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d4\\d6\\d6\\d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d3\\d5\\d5\\d6\\d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d2\\d4\\d4\\d5\\d6\\d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d1\\d3\\d3\\d4\\d5\\d6\\d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "C:\\d2\\d2\\d3\\d4\\d5\\d6\\d7")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:\\d1\\d2\\d3\\d4\\d5\\file1.ext", "..\\..\\file1.ext", "D:\\d1\\d2\\d3\\d4\\d5\\d6\\d7")); -#endif -} - -static void test_compare_UNC_rooted_paths(void) -{ - // UNC roots - -#ifdef LIBPATH_OS_IS_WINDOWS - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\\\server1\\share1/dir1\\file1.ext", "\\\\server1\\share1\\dir1/file1.ext")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file2.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1\\dir1\\file2.ext", "\\\\server1\\share1\\dir1\\file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir2\\file1.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1\\dir2\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server1\\share2\\dir1\\file1.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share2\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\\\server1\\share1\\dir1\\file1.ext", "\\\\server2\\share1\\dir1\\file1.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server2\\share1\\dir1\\file1.ext", "\\\\server1\\share1\\dir1\\file1.ext")); - -#endif -} - -static void test_Windows_mixed_pwd(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file1.ext", "C:\\")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file2.ext", "C:\\")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1\\file2.ext", "C:\\dir1\\file1.ext", "C:\\")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\file1.ext", "C:\\dir2\\file1.ext", "C:\\")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir2\\file1.ext", "C:\\dir1\\file1.ext", "C:\\")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1\\file1.ext", "D:\\dir1\\file1.ext", "C:\\")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1\\file1.ext", "C:\\dir1\\file1.ext", "D:\\")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file1.ext", "C:")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file2.ext", "C:")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\dir1\\file2.ext", "C:\\dir1\\file1.ext", "C:")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\dir1\\file1.ext", "C:\\dir2\\file1.ext", "C:")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\dir2\\file1.ext", "C:\\dir1\\file1.ext", "C:")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("\\dir1\\file1.ext", "D:\\dir1\\file1.ext", "C:")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\dir1\\file1.ext", "C:\\dir1\\file1.ext", "D:")); -#endif -} - -static void test_mixed_comparisons(void) -{ - XTESTS_TEST_INTEGER_LESS(0, compare_paths("file1.ext", "file2.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("file2.ext", "file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "dir2/file1.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir2/file1.ext", "dir1/file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "/dir1/file1.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/dir1/file1.ext", "dir1/file1.ext")); - -#ifdef LIBPATH_OS_IS_WINDOWS - - // absolute, rooted, and relative paths - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:/dir1/file1.ext", "dir1/file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:/dir1/file1.ext", "/dir1/file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("/dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "/dir1/file1.ext")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:/dir1/file1.ext", "\\\\server1\\share1/dir1/file1.ext")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "C:/dir1/file1.ext")); - - - // relative paths with volumes - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext", "C:")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:dir1/file1.ext", "C:dir1/file1.ext", "D:")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "C:dir1/file1.ext", "C:")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext", "C:")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("/dir1/file1.ext", "C:/dir1/file1.ext", "D:")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "C:")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "D:")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "D:/dir1/file1.ext", "C:")); - - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1/file2.ext", "C:/dir1/file1.ext", "C:/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir2/file1.ext", "C:/dir1/file1.ext", "C:/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file2.ext", "C:/dir1/file1.ext", "C:")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir2/file1.ext", "C:/dir1/file1.ext", "C:")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "C:/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("dir1/file1.ext", "C:/dir1/file1.ext", "D:/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("dir1/file1.ext", "D:/dir1/file1.ext", "C:/")); - - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file1.ext")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file1.ext", "/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:dir1/file1.ext", "C:/dir1/file2.ext", "/")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:dir1/file1.ext", "C:/dir2/file1.ext", "/")); - - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir1/")); - XTESTS_TEST_INTEGER_EQUAL(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir1")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:file1.ext", "C:/dir1/file2.ext", "/dir1")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:file2.ext", "C:/dir1/file1.ext", "/dir1")); - XTESTS_TEST_INTEGER_LESS(0, compare_paths("C:file1.ext", "C:/dir2/file1.ext", "/dir1")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("C:file1.ext", "C:/dir1/file1.ext", "/dir2")); - - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext", "C:/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "C:dir1/file1.ext", "/")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "dir1/file1.ext", "C:")); - XTESTS_TEST_INTEGER_GREATER(0, compare_paths("\\\\server1\\share1/dir1/file1.ext", "file1.ext", "dir1")); -#endif -} - -} // anonymous namespace - - -/* ///////////////////////////// end of file //////////////////////////// */ - diff --git a/test/unit/test.unit.equal.1.c/CMakeLists.txt b/test/unit/test.unit.equal.1.c/CMakeLists.txt deleted file mode 100644 index 44134d1..0000000 --- a/test/unit/test.unit.equal.1.c/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten -define_automated_test_program(test.unit.equal.1.c test.unit.equal.1.c.c) diff --git a/test/unit/test.unit.equal.1.c/test.unit.equal.1.c.c b/test/unit/test.unit.equal.1.c/test.unit.equal.1.c.c deleted file mode 100644 index f8d7e46..0000000 --- a/test/unit/test.unit.equal.1.c/test.unit.equal.1.c.c +++ /dev/null @@ -1,475 +0,0 @@ -/* ///////////////////////////////////////////////////////////////////////// - * File: test.unit.equal.1.c.c - * - * Purpose: Implementation file for the test.unit.equal.1.c project. - * - * Created: 28th March 2013 - * Updated: 19th October 2024 - * - * ////////////////////////////////////////////////////////////////////// */ - - -/* ///////////////////////////////////////////////////////////////////////// - * includes - */ - -/* ///////////////////////////////////// - * test component header file include(s) - */ - -#include - -/* ///////////////////////////////////// - * general includes - */ - -/* xTests header files */ -#include - -/* STLSoft header files */ -#include - -/* Standard C header files */ -#include -#include -#include -#include - - -/* ///////////////////////////////////////////////////////////////////////// - * forward declarations - */ - -static void test_1_0(void); -static void test_1_1(void); -static void test_1_2(void); -static void test_1_3(void); -static void test_1_4(void); -static void test_1_5(void); -static void test_1_6(void); -static void test_1_7(void); -static void test_1_8(void); -static void test_1_9(void); -static void test_1_10(void); -static void test_1_11(void); - -static void test_1_20(void); - -static void test_1_30(void); -static void test_1_31(void); -static void test_1_32(void); -static void test_1_33(void); - -static void test_1_40(void); -static void test_1_41(void); -static void test_1_42(void); -static void test_1_43(void); -static void test_1_44(void); -static void test_1_45(void); - -static void test_1_50(void); - - -/* ///////////////////////////////////////////////////////////////////////// - * helper functions - */ - -int main(int argc, char* argv[]) -{ - int retCode = EXIT_SUCCESS; - int verbosity = 2; - - XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); - - if (XTESTS_START_RUNNER("test.unit.equal.1.c", verbosity)) - { - XTESTS_RUN_CASE(test_1_0); - XTESTS_RUN_CASE(test_1_1); - XTESTS_RUN_CASE(test_1_2); - XTESTS_RUN_CASE(test_1_3); - XTESTS_RUN_CASE(test_1_4); - XTESTS_RUN_CASE(test_1_5); - XTESTS_RUN_CASE(test_1_6); - XTESTS_RUN_CASE(test_1_7); - XTESTS_RUN_CASE(test_1_8); - XTESTS_RUN_CASE(test_1_9); - XTESTS_RUN_CASE(test_1_10); - XTESTS_RUN_CASE(test_1_11); - - XTESTS_RUN_CASE(test_1_20); - - XTESTS_RUN_CASE(test_1_30); - XTESTS_RUN_CASE(test_1_31); - XTESTS_RUN_CASE(test_1_32); - XTESTS_RUN_CASE(test_1_33); - - XTESTS_RUN_CASE(test_1_40); - XTESTS_RUN_CASE(test_1_41); - XTESTS_RUN_CASE(test_1_42); - XTESTS_RUN_CASE(test_1_43); - XTESTS_RUN_CASE(test_1_44); - XTESTS_RUN_CASE(test_1_45); - - XTESTS_RUN_CASE(test_1_50); - - XTESTS_PRINT_RESULTS(); - - XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); - } - - return retCode; -} - - -/* ///////////////////////////////////////////////////////////////////////// - * test function implementations - */ - -static -bool -path_equals( - char const* lhs -, char const* rhs -, char const* cwd /* = LIBPATH_LF_nullptr */ -, char const* mem /* = LIBPATH_LF_nullptr */ -) -{ - libpath_sint32_t flags = 0; - libpath_WorkingDirectoryContext_t ctxt; - int result; - LIBPATH_RC rc; - - STLSOFT_SUPPRESS_UNUSED(mem); - - ctxt.mechanism = libpath_WorkingDirectoryContextMechanism_CStyleString; - ctxt.details.cwd_css = cwd; - - rc = libpath_Equate_EquatePathsAsCStyleStrings( - lhs - , rhs - , flags - , &ctxt - , LIBPATH_LF_nullptr - , &result - ); - - switch (rc) - { - case LIBPATH_RC_OF(FirstPathInvalid): - case LIBPATH_RC_OF(SecondPathInvalid): - case LIBPATH_RC_OF(WorkingDirectoryPathInvalid): - - break; - default: - - break; - } - - return (LIBPATH_RC_OF(Success) == rc) && (0 != result); -} - - -static void test_1_0(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("", "", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -} - -static void test_1_1(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("", "a", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("a", "", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -} - -static void test_1_2(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("file", "file", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("fil1", "fil2", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -} - -static void test_1_3(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("file.ext", "file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("file.ex1", "file.ex2", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -} - -static void test_1_4(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\file.ext", "dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_5(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1\\file.ext", "dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1\\file.ext", "dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_6(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/dir2/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/dir3/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/./file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "./dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/././././././././././././././././././././././././././././././././././././././././././././././file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/dir2/../dir3/../dir4/../dir5/../dir6/../dir7/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/dir2/dir3/dir4/dir5/dir6/dir7/../../../../../../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("../dir1/dir2/../file.ext", "../dir1/dir2/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -} - -static void test_1_7(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/dir2/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/dir3/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/./file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "./dir9/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/././././././././././././././././././././././././././././././././././././././././././././././file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir9/dir2/../dir3/../dir4/../dir5/../dir6/../dir7/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir9/dir2/dir3/dir4/dir5/dir6/dir7/../../../../../../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("../dir1/dir2/../file.ext", "../dir9/dir2/../file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -} - -static void test_1_8(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/../../file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "../dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -} - -static void test_1_9(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "C:\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_10(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share1\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share2\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server2\\share1\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server10\\share10\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_11(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1/dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1\\dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1/dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1\\dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1/dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1\\dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1\\dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_20(void) -{ - // Trailing slashes - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("abc.def", "abc.def", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("abc.def/", "abc.def", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("abc.def", "abc.def/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("abc.def\\", "abc.def", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("abc.def", "abc.def\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif - XTESTS_TEST_BOOLEAN_TRUE(path_equals("abc.def/", "abc.def/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("abc.def\\", "abc.def/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("abc.def/", "abc.def\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("abc.def\\", "abc.def\\", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif - -} - -static void test_1_30(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir2", LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir8", LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir2/dir3/..", LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir4/.././file.ext", "/./dir1/dir2/dir3/dir4//..", LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/../file.ext", ".././file.ext", "/dir1/dir2/dir3/dir4", LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", ".././file.ext", "/dir1/dir2/dir3/dir4", LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/../file.ext", ".././../file.ext", "/dir1/dir2/dir3/dir4", LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/dir4/dir5/file.ext", "file.ext", "/dir1/dir2/dir3/dir4/dir5", LIBPATH_LF_nullptr)); -} - -static void test_1_31(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "dir3", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "dir3", "/dir1/dir2", LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/", "dir3/", "/dir1/dir2", LIBPATH_LF_nullptr)); -} - -static void test_1_32(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_33(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "dir1/file.ext", "/", LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "C:\\dir1\\file.ext", "C:/", LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("\\dir1/file.ext", "C:\\dir1\\file.ext", "C:", LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_40(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("\\dir1\\file.ext", "\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("\\dir1\\file.ext", "/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_41(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "c:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("c:\\dir1\\file.ext", "C:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("c:\\dir1\\file.ext", "c:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "c:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("c:/dir1/file.ext", "C:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("c:/dir1/file.ext", "c:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:/dir1/file.ext", "D:\\dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:/dir1/file.ext", "D:/dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:dir1\\file.ext", "C:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:dir1\\file.ext", "C:dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:dir1/file.ext", "C:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:dir1/file.ext", "C:dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:dir1\\file.ext", "D:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:dir1\\file.ext", "D:dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:dir1/file.ext", "D:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:dir1/file.ext", "D:dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_42(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/file.ext", "dir1/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "dir1/file.ext", "/", LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "c:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "c:dir1\\file.ext", "/", LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "d:dir1\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "d:dir1\\file.ext", "/", LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_43(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "dir2/file.ext", "/dir1", LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir2\\file.ext", "/dir1", LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir2\\file.ext", "\\dir1\\", LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_44(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "dir2/file.ext", "/dir1/dir2/dir3/./../..", LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir2\\file.ext", "/dir1/dir2/dir3/./../..", LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir2\\file.ext", "\\dir1\\dir2\\dir3\\.\\..\\..", LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_45(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/dir3/./../../dir2/file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "./../../dir2/file.ext", "/dir1/dir2/dir3/", LIBPATH_LF_nullptr)); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\dir3\\.\\..\\..\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:.\\..\\..\\dir2\\file.ext", "/dir1/dir2/dir3", LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\dir3\\.\\..\\..\\dir2\\file.ext", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:.\\..\\..\\dir2\\file.ext", "\\dir1\\dir2\\dir3", LIBPATH_LF_nullptr)); -#endif -} - -static void test_1_50(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/", "/dir1/dir2/dir3/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "/dir1/dir2/dir3", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3", "/dir1/dir2/dir3/", LIBPATH_LF_nullptr, LIBPATH_LF_nullptr)); -} - - -/* ///////////////////////////// end of file //////////////////////////// */ - diff --git a/test/unit/test.unit.equal.1/CMakeLists.txt b/test/unit/test.unit.equal.1/CMakeLists.txt deleted file mode 100644 index 5bb7f0d..0000000 --- a/test/unit/test.unit.equal.1/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten -define_automated_test_program(test.unit.equal.1 test.unit.equal.1.cpp) diff --git a/test/unit/test.unit.equal.1/test.unit.equal.1.cpp b/test/unit/test.unit.equal.1/test.unit.equal.1.cpp deleted file mode 100644 index 4a79582..0000000 --- a/test/unit/test.unit.equal.1/test.unit.equal.1.cpp +++ /dev/null @@ -1,487 +0,0 @@ -/* ///////////////////////////////////////////////////////////////////////// - * File: test.unit.equal.1.cpp - * - * Purpose: Implementation file for the test.unit.equal.1 project. - * - * Created: 9th November 2012 - * Updated: 19th October 2024 - * - * ////////////////////////////////////////////////////////////////////// */ - - -/* ///////////////////////////////////////////////////////////////////////// - * includes - */ - -/* ///////////////////////////////////// - * test component header file include(s) - */ - -#include - -#include - -/* ///////////////////////////////////// - * general includes - */ - -/* xTests header files */ -#include - -/* STLSoft header files */ -#include - -/* Standard C++ header files */ -#include -#include - -/* Standard C header files */ -#include -#include -#include - - -/* ///////////////////////////////////////////////////////////////////////// - * forward declarations - */ - -namespace -{ - - static void test_1_0(void); - static void test_1_1(void); - static void test_1_2(void); - static void test_1_3(void); - static void test_1_4(void); - static void test_1_5(void); - static void test_1_6(void); - static void test_1_7(void); - static void test_1_8(void); - static void test_1_9(void); - static void test_1_10(void); - static void test_1_11(void); - - static void test_1_20(void); - - static void test_1_30(void); - static void test_1_31(void); - static void test_1_32(void); - static void test_1_33(void); - - static void test_1_40(void); - static void test_1_41(void); - static void test_1_42(void); - static void test_1_43(void); - static void test_1_44(void); - static void test_1_45(void); - - static void test_1_50(void); -} // anonymous namespace - - -/* ///////////////////////////////////////////////////////////////////////// - * helper functions - */ - -int main(int argc, char* argv[]) -{ - int retCode = EXIT_SUCCESS; - int verbosity = 2; - - XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); - - if (XTESTS_START_RUNNER("test.unit.equal.1", verbosity)) - { - XTESTS_RUN_CASE(test_1_0); - XTESTS_RUN_CASE(test_1_1); - XTESTS_RUN_CASE(test_1_2); - XTESTS_RUN_CASE(test_1_3); - XTESTS_RUN_CASE(test_1_4); - XTESTS_RUN_CASE(test_1_5); - XTESTS_RUN_CASE(test_1_6); - XTESTS_RUN_CASE(test_1_7); - XTESTS_RUN_CASE(test_1_8); - XTESTS_RUN_CASE(test_1_9); - XTESTS_RUN_CASE(test_1_10); - XTESTS_RUN_CASE(test_1_11); - - XTESTS_RUN_CASE(test_1_20); - - XTESTS_RUN_CASE(test_1_30); - XTESTS_RUN_CASE(test_1_31); - XTESTS_RUN_CASE(test_1_32); - XTESTS_RUN_CASE(test_1_33); - - XTESTS_RUN_CASE(test_1_40); - XTESTS_RUN_CASE(test_1_41); - XTESTS_RUN_CASE(test_1_42); - XTESTS_RUN_CASE(test_1_43); - XTESTS_RUN_CASE(test_1_44); - XTESTS_RUN_CASE(test_1_45); - - XTESTS_RUN_CASE(test_1_50); - - XTESTS_PRINT_RESULTS(); - - XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); - } - - return retCode; -} - - -/* ///////////////////////////////////////////////////////////////////////// - * test function implementations - */ - -namespace -{ - - inline - bool - path_equals( - char const* lhs - , char const* rhs - , char const* cwd = LIBPATH_LF_nullptr - , char const* /*mem*/ = LIBPATH_LF_nullptr - ) - { - libpath_sint32_t flags = 0; - libpath_WorkingDirectoryContext_t ctxt; - libpath_truthy_t result; - - ctxt.mechanism = libpath_WorkingDirectoryContextMechanism_CStyleString; - ctxt.details.cwd_css = cwd; - - LIBPATH_RC rc = libpath_Equate_EquatePathsAsCStyleStrings( - lhs - , rhs - , flags - , &ctxt - , LIBPATH_LF_nullptr - , &result - ); - - switch (rc) - { - case LIBPATH_RC_OF(FirstPathInvalid): - case LIBPATH_RC_OF(SecondPathInvalid): - case LIBPATH_RC_OF(WorkingDirectoryPathInvalid): - - break; - default: - - break; - } - - - return (LIBPATH_RC_OF(Success) == rc) && (result); - } - - -static void test_1_0(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("", "")); -} - -static void test_1_1(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("", "a")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("a", "")); -} - -static void test_1_2(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("file", "file")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("fil1", "fil2")); -} - -static void test_1_3(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("file.ext", "file.ext")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("file.ex1", "file.ex2")); -} - -static void test_1_4(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/file.ext")); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\file.ext", "dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\file.ext", "dir1/file.ext")); -#endif -} - -static void test_1_5(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir2/file.ext")); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1\\file.ext", "dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1\\file.ext", "dir2/file.ext")); -#endif -} - -static void test_1_6(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/dir2/../file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/dir3/../file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/./file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "./dir1/file.ext")); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/../file.ext", "dir1/././././././././././././././././././././././././././././././././././././././././././././././file.ext")); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/dir2/../dir3/../dir4/../dir5/../dir6/../dir7/../file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "dir1/dir2/dir3/dir4/dir5/dir6/dir7/../../../../../../file.ext")); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("../dir1/dir2/../file.ext", "../dir1/dir2/../file.ext")); -} - -static void test_1_7(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/dir2/../file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/dir3/../file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/./file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "./dir9/file.ext")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/dir2/../file.ext", "dir9/././././././././././././././././././././././././././././././././././././././././././././././file.ext")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir9/dir2/../dir3/../dir4/../dir5/../dir6/../dir7/../file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "dir9/dir2/dir3/dir4/dir5/dir6/dir7/../../../../../../file.ext")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("../dir1/dir2/../file.ext", "../dir9/dir2/../file.ext")); -} - -static void test_1_8(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/../../file.ext", "dir1/file.ext")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "../dir1/file.ext")); -} - -static void test_1_9(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "C:\\dir2\\file.ext")); -#endif -} - -static void test_1_10(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share1\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share1\\dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server1\\share2\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server2\\share1\\dir1\\file.ext")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("\\\\server1\\share1\\dir1\\file.ext", "\\\\server10\\share10\\dir1\\file.ext")); -#endif -} - -static void test_1_11(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2/file.ext")); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1/dir2/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1/dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1\\dir2/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2\\file.ext", "dir1\\dir2\\file.ext")); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1/dir2/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1/dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1\\dir2/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1\\dir2/file.ext", "dir1\\dir2\\file.ext")); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1/dir2/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1/dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1\\dir2/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2\\file.ext", "dir1\\dir2\\file.ext")); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1/dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1\\dir2/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/dir2/file.ext", "dir1\\dir2\\file.ext")); -#endif -} - -static void test_1_20(void) -{ - // Trailing slashes - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("abc.def", "abc.def")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("abc.def/", "abc.def")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("abc.def", "abc.def/")); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("abc.def\\", "abc.def")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("abc.def", "abc.def\\")); -#endif - XTESTS_TEST_BOOLEAN_TRUE(path_equals("abc.def/", "abc.def/")); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("abc.def\\", "abc.def/")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("abc.def/", "abc.def\\")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("abc.def\\", "abc.def\\")); -#endif - -} - -static void test_1_30(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir2")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir8")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir3/file.ext", "/dir1/dir2/dir3/..")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", "dir4/.././file.ext", "/./dir1/dir2/dir3/dir4//..")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/../file.ext", ".././file.ext", "/dir1/dir2/dir3/dir4")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/file.ext", ".././file.ext", "/dir1/dir2/dir3/dir4")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/../file.ext", ".././../file.ext", "/dir1/dir2/dir3/dir4")); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/dir4/dir5/file.ext", "file.ext", "/dir1/dir2/dir3/dir4/dir5")); -} - -static void test_1_31(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "dir3", LIBPATH_LF_nullptr)); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "dir3", "/dir1/dir2")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/", "dir3/", "/dir1/dir2")); -} - -static void test_1_32(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/file.ext", "dir1/file.ext")); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("dir1/file.ext", "C:\\dir1\\file.ext")); -#endif -} - -static void test_1_33(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "dir1/file.ext", "/")); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("dir1/file.ext", "C:\\dir1\\file.ext", "C:/")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("\\dir1/file.ext", "C:\\dir1\\file.ext", "C:")); -#endif -} - -static void test_1_40(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "/dir1/file.ext")); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("\\dir1\\file.ext", "\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("\\dir1\\file.ext", "/dir1/file.ext")); -#endif -} - -static void test_1_41(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:/dir1/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:/dir1/file.ext")); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "C:\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "c:\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("c:\\dir1\\file.ext", "C:\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("c:\\dir1\\file.ext", "c:\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "C:/dir1/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:/dir1/file.ext", "c:/dir1/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("c:/dir1/file.ext", "C:/dir1/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("c:/dir1/file.ext", "c:/dir1/file.ext")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "D:/dir1/file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:/dir1/file.ext", "D:\\dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:/dir1/file.ext", "D:/dir1/file.ext")); - - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:dir1\\file.ext", "C:dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:dir1\\file.ext", "C:dir1/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:dir1/file.ext", "C:dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:dir1/file.ext", "C:dir1/file.ext")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:dir1\\file.ext", "D:dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:dir1\\file.ext", "D:dir1/file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:dir1/file.ext", "D:dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:dir1/file.ext", "D:dir1/file.ext")); -#endif -} - -static void test_1_42(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/file.ext", "dir1/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/file.ext", "dir1/file.ext", "/")); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "c:dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\file.ext", "c:dir1\\file.ext", "/")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "d:dir1\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\file.ext", "d:dir1\\file.ext", "/")); -#endif -} - -static void test_1_43(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "dir2/file.ext", "/dir1")); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir2\\file.ext", "/dir1")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir2\\file.ext", "\\dir1\\")); -#endif -} - -static void test_1_44(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "dir2/file.ext", "/dir1/dir2/dir3/./../..")); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir2\\file.ext", "/dir1/dir2/dir3/./../..")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir2\\file.ext", "\\dir1\\dir2\\dir3\\.\\..\\..")); -#endif -} - -static void test_1_45(void) -{ - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/file.ext", "dir1/dir2/dir3/./../../dir2/file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/file.ext", "./../../dir2/file.ext", "/dir1/dir2/dir3/")); - -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "c:dir1\\dir2\\dir3\\.\\..\\..\\dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_TRUE(path_equals("C:\\dir1\\dir2\\file.ext", "c:.\\..\\..\\dir2\\file.ext", "/dir1/dir2/dir3")); - - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:dir1\\dir2\\dir3\\.\\..\\..\\dir2\\file.ext")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("C:\\dir1\\dir2\\file.ext", "d:.\\..\\..\\dir2\\file.ext", "\\dir1\\dir2\\dir3")); -#endif -} - -static void test_1_50(void) -{ - XTESTS_TEST_BOOLEAN_TRUE(path_equals("/dir1/dir2/dir3/", "/dir1/dir2/dir3/")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3/", "/dir1/dir2/dir3")); - XTESTS_TEST_BOOLEAN_FALSE(path_equals("/dir1/dir2/dir3", "/dir1/dir2/dir3/")); -} - -} // anonymous namespace - - -/* ///////////////////////////// end of file //////////////////////////// */ - diff --git a/test/unit/test.unit.parse.1/test.unit.parse.1.cpp b/test/unit/test.unit.parse.1/test.unit.parse.1.cpp deleted file mode 100644 index b03aa2c..0000000 --- a/test/unit/test.unit.parse.1/test.unit.parse.1.cpp +++ /dev/null @@ -1,2528 +0,0 @@ -/* ///////////////////////////////////////////////////////////////////////// - * File: test.unit.parse.1.cpp - * - * Purpose: Implementation file for the test.unit.parse.1 project. - * - * Created: 9th November 2012 - * Updated: 15th March 2025 - * - * ////////////////////////////////////////////////////////////////////// */ - - -/* ///////////////////////////////////////////////////////////////////////// - * includes - */ - -/* ///////////////////////////////////// - * test component header file include(s) - */ - -#include - -/* ///////////////////////////////////// - * general includes - */ - -/* xTests header files */ -#include -#if _XTESTS_VER < 0x00150000 -# error This code requires xTests 0.21.0, or later -#endif - -/* STLSoft header files */ -#include - -/* Standard C header files */ -#include - - -/* ///////////////////////////////////////////////////////////////////////// - * forward declarations - */ - -static void test_1_0(void); -static void test_1_1(void); -static void test_1_2(void); -static void test_1_3(void); -static void test_1_4(void); - -static void test_1_6(void); -static void test_1_7(void); -static void test_1_8(void); - -static void test_1_10(void); -static void test_1_11(void); -static void test_1_12(void); - -static void test_1_14(void); -static void test_1_15(void); -static void test_1_16(void); -static void test_1_17(void); -static void test_1_18(void); -static void test_1_19(void); -static void test_1_20(void); -static void test_1_21(void); -static void test_1_22(void); - -static void test_1_30(void); -static void test_1_31(void); -static void test_1_32(void); -static void test_1_33(void); -static void test_1_34(void); -static void test_1_35(void); -static void test_1_36(void); -static void test_1_37(void); - -static void test_1_40(void); -static void test_1_41(void); -static void test_1_42(void); -static void test_1_43(void); -static void test_1_44(void); - -static void test_1_50(void); -static void test_1_51(void); -static void test_1_52(void); -static void test_1_53(void); -static void test_1_54(void); -static void test_1_55(void); - -static void test_1_60(void); -static void test_1_61(void); - -static void test_1_70(void); -static void test_1_71(void); -static void test_1_72(void); -static void test_1_73(void); - -static void test_1_80(void); -static void test_1_81(void); -static void test_1_82(void); - - -/* ///////////////////////////////////////////////////////////////////////// - * main - */ - -int main(int argc, char* argv[]) -{ - int retCode = EXIT_SUCCESS; - int verbosity = 2; - - XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); - - if (XTESTS_START_RUNNER("test.unit.parse.1", verbosity)) - { - XTESTS_RUN_CASE(test_1_0); - XTESTS_RUN_CASE(test_1_1); - XTESTS_RUN_CASE(test_1_2); - XTESTS_RUN_CASE(test_1_3); - XTESTS_RUN_CASE(test_1_4); - - XTESTS_RUN_CASE(test_1_6); - XTESTS_RUN_CASE(test_1_7); - XTESTS_RUN_CASE(test_1_8); - - XTESTS_RUN_CASE(test_1_10); - XTESTS_RUN_CASE(test_1_11); - XTESTS_RUN_CASE(test_1_12); - - XTESTS_RUN_CASE(test_1_14); - XTESTS_RUN_CASE(test_1_15); - XTESTS_RUN_CASE(test_1_16); - XTESTS_RUN_CASE(test_1_17); - XTESTS_RUN_CASE(test_1_18); - XTESTS_RUN_CASE(test_1_19); - XTESTS_RUN_CASE(test_1_20); - XTESTS_RUN_CASE(test_1_21); - XTESTS_RUN_CASE(test_1_22); - - XTESTS_RUN_CASE(test_1_30); - XTESTS_RUN_CASE(test_1_31); - XTESTS_RUN_CASE(test_1_32); - XTESTS_RUN_CASE(test_1_33); - XTESTS_RUN_CASE(test_1_34); - XTESTS_RUN_CASE(test_1_35); - XTESTS_RUN_CASE(test_1_36); - XTESTS_RUN_CASE(test_1_37); - - XTESTS_RUN_CASE(test_1_40); - XTESTS_RUN_CASE(test_1_41); - XTESTS_RUN_CASE(test_1_42); - XTESTS_RUN_CASE(test_1_43); - XTESTS_RUN_CASE(test_1_44); - - XTESTS_RUN_CASE(test_1_50); - XTESTS_RUN_CASE(test_1_51); - XTESTS_RUN_CASE(test_1_52); - XTESTS_RUN_CASE(test_1_53); - XTESTS_RUN_CASE(test_1_54); - XTESTS_RUN_CASE(test_1_55); - - XTESTS_RUN_CASE(test_1_60); - XTESTS_RUN_CASE(test_1_61); - - XTESTS_RUN_CASE(test_1_70); - XTESTS_RUN_CASE(test_1_71); - XTESTS_RUN_CASE(test_1_72); - XTESTS_RUN_CASE(test_1_73); - - XTESTS_RUN_CASE(test_1_80); - XTESTS_RUN_CASE(test_1_81); - XTESTS_RUN_CASE(test_1_82); - - XTESTS_PRINT_RESULTS(); - - XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); - } - - return retCode; -} - - -/* ///////////////////////////////////////////////////////////////////////// - * test function implementations - */ - -using ::libpath::StringSlice_t; - -typedef ::libpath::parsing::PathDescriptor_t ParseResult_t; - -using ::libpath::parsing::parse_path_from_cstyle_string; -using ::libpath::parsing::parse_path_from_string_ptr_and_len; - -using ::libpath::parsing::is_absolute; -using ::libpath::parsing::is_rooted; - - -#ifdef __cplusplus - - const libpath_size_t NUM_DP_ELEMENTS = 10; -#else /* ? __cplusplus */ - -# define NUM_DP_ELEMENTS (10) -#endif /* __cplusplus */ - - -static void test_1_0(void) -{ - char const input[] = ""; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[1]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_NoPathSpecified, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_NoPathSpecified, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_NoPathSpecified, rc); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); - XTESTS_TEST_INTEGER_EQUAL(0u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); -} - -static void test_1_1(void) -{ - char const input[] = "."; - - ParseResult_t r; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(1u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -} - -static void test_1_2(void) -{ - char const input[] = ".."; - - ParseResult_t r; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(2u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -} - -static void test_1_3(void) -{ - char const input[] = "/."; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(2u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, directoryPartSlices[0].len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_4(void) -{ - char const input[] = "/.."; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_6(void) -{ - char const input[] = "..."; - - ParseResult_t r; - LIBPATH_RC rc = parse_path_from_cstyle_string(input, 0, &r, 0, LIBPATH_LF_nullptr); - - // TODO: define failure result code - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); -} - -static void test_1_7(void) -{ - char const input[] = "....."; - - ParseResult_t r; - LIBPATH_RC rc = parse_path_from_cstyle_string(input, 0, &r, 0, LIBPATH_LF_nullptr); - - // TODO: define failure result code - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(5u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(5u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); -} - -static void test_1_8(void) -{ - char const input[] = "..abc.def.."; - - ParseResult_t r; - LIBPATH_RC rc = parse_path_from_cstyle_string(input, 0, &r, 0, LIBPATH_LF_nullptr); - - // TODO: define failure result code - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(11u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(11u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(11u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); -} - -static void test_1_10(void) -{ - char const input[] = "abc"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -} - -static void test_1_11(void) -{ - char const input[] = "a.c"; - - ParseResult_t r; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryExtensionPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL(".c", r.entryExtensionPart); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -} - -static void test_1_12(void) -{ - char const input[] = ".bc"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -} - -static void test_1_14(void) -{ - char const input[] = "/abc"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(4u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("/", r.locationPart); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("/", r.rootPart); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_15(void) -{ - char const input[] = "/dir/abc"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(8u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.locationPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("/dir/", r.locationPart); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_16(void) -{ - char const input[] = "/dir/"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(5u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.locationPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("/dir/", r.locationPart); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_17(void) -{ - char const input[] = "/dir/dir2/"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(10u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(10u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(10u, r.locationPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("/dir/dir2/", r.locationPart); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(9u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir2/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ - - directoryPartSlices[1].len = 1234; - directoryPartSlices[1].ptr = reinterpret_cast(1234); - - rc = parse_path_from_cstyle_string(input, 0, &r, 1, &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(10u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(10u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(10u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(9u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - - XTESTS_TEST_INTEGER_EQUAL(1234u, directoryPartSlices[1].len); - XTESTS_TEST_POINTER_EQUAL(reinterpret_cast(1234), directoryPartSlices[1].ptr); - - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_18(void) -{ - char const input[] = "/directory1/directory2/dir3/dir4/d5/d6/"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(39u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(39u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(39u, r.locationPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("/directory1/directory2/dir3/dir4/d5/d6/", r.locationPart); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_19(void) -{ - char const input[] = "/directory1/directory2/dir3/dir4/d5/d6/file.ext"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(47u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(47u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(39u, r.locationPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("/directory1/directory2/dir3/dir4/d5/d6/", r.locationPart); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("file", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL(".ext", r.entryExtensionPart); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_20(void) -{ - char const input[] = "/1/2/3/4/5/6/f"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(14u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(14u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(13u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(12u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("2/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("4/", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("6/", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_21(void) -{ - char const input[] = "/"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(1u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_22(void) -{ - char const input[] = "this.is.a.more.complex.file.ext"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(31u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(31u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(31u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(27u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -} - -static void test_1_30(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(1u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_31(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\abc"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(4u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_32(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:\\"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_33(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:\\abc"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_34(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:\\directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(49u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(49u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(41u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_35(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:/"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_36(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:/abc"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_37(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:/directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(49u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(49u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(41u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_40(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(20u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_41(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\abc"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(23u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(23u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_42(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(66u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(66u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(58u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_43(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\directory1/directory2\\dir3/dir4\\d5/d6\\file.ext"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(66u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(66u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(58u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_44(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share/directory1\\directory2/dir3\\dir4/d5\\d6/file.ext"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(66u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(66u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(58u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_50(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:abc"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(5u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_51(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(48u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(48u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(40u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_52(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:directory1/directory2\\dir3/dir4\\d5/d6\\file.ext"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(48u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(48u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(40u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_53(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:directory1/directory2\\dir3/dir4\\d5/d6\\."; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(41u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(41u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(40u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_54(void) -{ - char const input[] = "/dir//abc"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(9u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(9u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(5u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir//", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_55(void) -{ - char const input[] = "dir/abc"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(7u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_60(void) -{ - static char const bad_chars[] = - { - '|' - , '<' - , '>' - , '?' - , '*' -#ifdef LIBPATH_OS_IS_WINDOWS - , ';' -#else - , ':' -#endif - }; - char const input_template[] = "/this/is/going/to/be/a.bad.path"; - - { for (libpath_size_t i = 0; i != STLSOFT_NUM_ELEMENTS(bad_chars); ++i) - { - { for (libpath_size_t j = 0; j != STLSOFT_NUM_ELEMENTS(input_template) - 1; ++j) - { - char input[STLSOFT_NUM_ELEMENTS(input_template)]; - - STLSOFT_STATIC_ASSERT(sizeof(input) == sizeof(input_template)); - - memcpy(input, input_template, sizeof(input)); - - input[j] = bad_chars[i]; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - libpath_size_t firstBadCharOffset; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], &firstBadCharOffset); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices, &firstBadCharOffset); -#endif - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(31u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(j, firstBadCharOffset); - }} - }} -} - -static void test_1_61(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - ParseResult_t r; - LIBPATH_RC rc; - libpath_size_t firstBadCharOffset; - - - rc = parse_path_from_cstyle_string(":C\\dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(0u, firstBadCharOffset); - - - rc = parse_path_from_cstyle_string("C:\\dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - - - rc = parse_path_from_cstyle_string("C\\:dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(2u, firstBadCharOffset); - - - rc = parse_path_from_cstyle_string("C\\d:ir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, firstBadCharOffset); - - - rc = parse_path_from_cstyle_string("C\\di:r\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, firstBadCharOffset); - - - rc = parse_path_from_cstyle_string("C\\dir:\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, firstBadCharOffset); - - - rc = parse_path_from_cstyle_string("\\:Cdir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(1u, firstBadCharOffset); - - -#endif -} - -static void test_1_70(void) -{ - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - - rc = parse_path_from_cstyle_string("abc", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - - - rc = parse_path_from_cstyle_string("abc/", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(4u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = parse_path_from_cstyle_string("abc", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = parse_path_from_cstyle_string("abc/", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(4u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - -} - -static void test_1_71(void) -{ - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - - rc = parse_path_from_cstyle_string("abc/def", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(7u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - - - rc = parse_path_from_cstyle_string("abc/def/", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(8u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("def/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = parse_path_from_cstyle_string("abc/def", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(7u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("def", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = parse_path_from_cstyle_string("abc/def/", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(8u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("def/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - -} - -static void test_1_72(void) -{ - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - - rc = parse_path_from_cstyle_string("abc/..", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - - rc = parse_path_from_cstyle_string("abc/../", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(7u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("../", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = parse_path_from_cstyle_string("abc/..", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = parse_path_from_cstyle_string("abc/../", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(7u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("../", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - -} - -static void test_1_73(void) -{ - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - - rc = parse_path_from_cstyle_string("abc/.", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(5u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - - rc = parse_path_from_cstyle_string("abc/./", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("./", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = parse_path_from_cstyle_string("abc/.", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(5u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(1u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = parse_path_from_cstyle_string("abc/./", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("./", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - -} - -static void test_1_80(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(20u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_81(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share/"; - - ParseResult_t r; - LIBPATH_RC rc; - StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = parse_path_from_cstyle_string(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - -#ifdef LIBPATH_STATIC_ARRAY_SIZE_DETERMINATION_SUPPORT - - rc = parse_path_from_cstyle_string(input, 0, &r, directoryPartSlices); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); -#endif - - rc = parse_path_from_cstyle_string(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0]); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(20u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_1_82(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\"; - libpath_size_t const cch = STLSOFT_NUM_ELEMENTS(input) - 1; - - { for (libpath_size_t i = 0; i <= cch; ++i) - { - ParseResult_t r; - LIBPATH_RC rc; - - rc = parse_path_from_string_ptr_and_len(input, i, 0, &r, 0, LIBPATH_LF_nullptr); - - if (1 == i || - cch == i) - { - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(i, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(i, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(i, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(i, r.rootPart.len); - if (cch == i) - { - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - } - else - { - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); - } - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(is_rooted(r)); - if (cch == i) - { - XTESTS_TEST_BOOLEAN_TRUE(is_absolute(r)); - } - else - { - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); - } - } - else - { - if (0 == i) - { - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_NoPathSpecified, rc); - XTESTS_TEST_INTEGER_EQUAL(i, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - } - else - { - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_InvalidRoot, rc); - XTESTS_TEST_INTEGER_EQUAL(i, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - } - - XTESTS_TEST_INTEGER_EQUAL(0u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(is_rooted(r)); - XTESTS_TEST_BOOLEAN_FALSE(is_absolute(r)); - } - }} -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - - -/* ///////////////////////////// end of file //////////////////////////// */ - diff --git a/test/unit/test.unit.parse.c/test.unit.parse.c.c b/test/unit/test.unit.parse.c/test.unit.parse.c.c deleted file mode 100644 index 9a92642..0000000 --- a/test/unit/test.unit.parse.c/test.unit.parse.c.c +++ /dev/null @@ -1,2183 +0,0 @@ -/* ///////////////////////////////////////////////////////////////////////// - * File: test.unit.parse.c.c - * - * Purpose: Implementation file for the test.unit.parse.c project. - * - * Created: 9th November 2012 - * Updated: 15th March 2025 - * - * ////////////////////////////////////////////////////////////////////// */ - - -/* ///////////////////////////////////////////////////////////////////////// - * includes - */ - -/* ///////////////////////////////////// - * test component header file include(s) - */ - -#include - -/* ///////////////////////////////////// - * general includes - */ - -/* xTests header files */ -#include -#if _XTESTS_VER < 0x00150000 -# error This code requires xTests 0.21.0, or later -#endif - -/* STLSoft header files */ -#include - -/* Standard C header files */ -#include -#include - - -/* ///////////////////////////////////////////////////////////////////////// - * forward declarations - */ - -static void test_empty(void); -static void test_1_dot(void); -static void test_2_dots(void); -static void test_3_dots(void); -static void test_4_dots(void); -static void test_5_dots(void); -static void test_rooted_1_dot(void); -static void test_rooted_2_dots(void); -static void test_rooted_3_dots(void); -static void test_rooted_4_dots(void); - -static void test_filename_with_trailing_dot(void); -static void test_filename_with_trailing_dots(void); -static void test_stem_only(void); -static void test_filename(void); -static void test_extension_only(void); - -static void test_rooted_1_stem(void); -static void test_rooted_1_dir_1_stem(void); -static void test_rooted_1_dir_trailing_slash(void); -static void test_rooted_2_dirs_trailing_slash(void); -static void test_rooted_6_dirs_trailing_slash(void); -static void test_rooted_6_dirs_and_filename(void); -static void test_rooted_6_dirs_and_stem(void); -static void test_slash_only(void); -static void test_filename_multiple_dots(void); - -static void test_Windows_backslash_only(void); -static void test_Windows_backslash_rooted_1_stem(void); -static void test_Windows_volume_and_backslash_root(void); -static void test_Windows_volume_and_backslash_rooted_1_stem(void); -static void test_Windows_volume_and_backslash_rooted_6_dirs_and_filename(void); -static void test_Windows_volume_and_slash_root(void); -static void test_Windows_slash_rooted_1_stem(void); -static void test_Windows_volume_and_slash_rooted_6_dirs_and_filename(void); - -static void test_Windows_UNC_share(void); -static void test_Windows_UNC_share_and_entry(void); -static void test_Windows_UNC_share_and_6_dirs_and_filename(void); -static void test_Windows_UNC_share_and_6_dirs_and_filename_altslashes(void); -static void test_Windows_UNC_share_and_6_dirs_and_filename_altslashes_2(void); - -static void test_Windows_driveletterrelative_and_stem(void); -static void test_Windows_driveletterrelative_and_6_dirs_and_filename(void); -static void test_Windows_driveletterrelative_and_6_dirs_and_filename_altslashes(void); -static void test_Windows_driveletterrelative_and_6_dirs_and_dotsdir_altslashes(void); -static void test_rooted_1_dir_1_stem_extraslashes(void); - -static void test_bad_characters(void); -static void test_Windows_bad_characters(void); - -static void test_1_component_with_libpath_ParseOption_AssumeDirectory(void); -static void test_2_components_with_libpath_ParseOption_AssumeDirectory(void); -static void test_2_components_with_last_2dotsdir_with_libpath_ParseOption_AssumeDirectory(void); -static void test_2_components_with_last_1dotsdir_with_libpath_ParseOption_AssumeDirectory(void); - -static void test_Windows_UNC_share_trailing_backslash(void); -static void test_Windows_UNC_share_trailing_slash(void); -static void test_Windows_UNC_share_with_charwise_steps(void); - - -/* ///////////////////////////////////////////////////////////////////////// - * main() - */ - -int main(int argc, char* argv[]) -{ - int retCode = EXIT_SUCCESS; - int verbosity = 2; - - XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); - - if (XTESTS_START_RUNNER("test.unit.parse.c", verbosity)) - { - XTESTS_RUN_CASE(test_empty); - XTESTS_RUN_CASE(test_1_dot); - XTESTS_RUN_CASE(test_2_dots); - XTESTS_RUN_CASE(test_3_dots); - XTESTS_RUN_CASE(test_4_dots); - XTESTS_RUN_CASE(test_5_dots); - - XTESTS_RUN_CASE(test_rooted_1_dot); - XTESTS_RUN_CASE(test_rooted_2_dots); - XTESTS_RUN_CASE(test_rooted_3_dots); - XTESTS_RUN_CASE(test_rooted_4_dots); - - XTESTS_RUN_CASE(test_filename_with_trailing_dot); - XTESTS_RUN_CASE(test_filename_with_trailing_dots); - XTESTS_RUN_CASE(test_stem_only); - XTESTS_RUN_CASE(test_filename); - XTESTS_RUN_CASE(test_extension_only); - - XTESTS_RUN_CASE(test_rooted_1_stem); - XTESTS_RUN_CASE(test_rooted_1_dir_1_stem); - XTESTS_RUN_CASE(test_rooted_1_dir_trailing_slash); - XTESTS_RUN_CASE(test_rooted_2_dirs_trailing_slash); - XTESTS_RUN_CASE(test_rooted_6_dirs_trailing_slash); - XTESTS_RUN_CASE(test_rooted_6_dirs_and_filename); - XTESTS_RUN_CASE(test_rooted_6_dirs_and_stem); - XTESTS_RUN_CASE(test_slash_only); - XTESTS_RUN_CASE(test_filename_multiple_dots); - - XTESTS_RUN_CASE(test_Windows_backslash_only); - XTESTS_RUN_CASE(test_Windows_backslash_rooted_1_stem); - XTESTS_RUN_CASE(test_Windows_volume_and_backslash_root); - XTESTS_RUN_CASE(test_Windows_volume_and_backslash_rooted_1_stem); - XTESTS_RUN_CASE(test_Windows_volume_and_backslash_rooted_6_dirs_and_filename); - XTESTS_RUN_CASE(test_Windows_volume_and_slash_root); - XTESTS_RUN_CASE(test_Windows_slash_rooted_1_stem); - XTESTS_RUN_CASE(test_Windows_volume_and_slash_rooted_6_dirs_and_filename); - - XTESTS_RUN_CASE(test_Windows_UNC_share); - XTESTS_RUN_CASE(test_Windows_UNC_share_and_entry); - XTESTS_RUN_CASE(test_Windows_UNC_share_and_6_dirs_and_filename); - XTESTS_RUN_CASE(test_Windows_UNC_share_and_6_dirs_and_filename_altslashes); - XTESTS_RUN_CASE(test_Windows_UNC_share_and_6_dirs_and_filename_altslashes_2); - - XTESTS_RUN_CASE(test_Windows_driveletterrelative_and_stem); - XTESTS_RUN_CASE(test_Windows_driveletterrelative_and_6_dirs_and_filename); - XTESTS_RUN_CASE(test_Windows_driveletterrelative_and_6_dirs_and_filename_altslashes); - XTESTS_RUN_CASE(test_Windows_driveletterrelative_and_6_dirs_and_dotsdir_altslashes); - XTESTS_RUN_CASE(test_rooted_1_dir_1_stem_extraslashes); - XTESTS_RUN_CASE(test_bad_characters); - - XTESTS_RUN_CASE(test_Windows_bad_characters); - - XTESTS_RUN_CASE(test_1_component_with_libpath_ParseOption_AssumeDirectory); - XTESTS_RUN_CASE(test_2_components_with_libpath_ParseOption_AssumeDirectory); - XTESTS_RUN_CASE(test_2_components_with_last_2dotsdir_with_libpath_ParseOption_AssumeDirectory); - XTESTS_RUN_CASE(test_2_components_with_last_1dotsdir_with_libpath_ParseOption_AssumeDirectory); - - XTESTS_RUN_CASE(test_Windows_UNC_share_trailing_backslash); - XTESTS_RUN_CASE(test_Windows_UNC_share_trailing_slash); - XTESTS_RUN_CASE(test_Windows_UNC_share_with_charwise_steps); - - XTESTS_PRINT_RESULTS(); - - XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); - } - - return retCode; -} - - -/* ///////////////////////////////////////////////////////////////////////// - * test function implementations - */ - -#ifdef __cplusplus - libpath_size_t const NUM_DP_ELEMENTS = 10; -#else /* ? __cplusplus */ -# define NUM_DP_ELEMENTS (10) -#endif /* __cplusplus */ - -static void test_empty(void) -{ - char const input[] = ""; - - libpath_ParseResult_t r; - LIBPATH_RC rc; - libpath_StringSlice_t directoryPartSlices[1]; - libpath_size_t firstBadCharOffset; - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_NoPathSpecified, rc); - XTESTS_TEST_INTEGER_EQUAL(0, firstBadCharOffset); - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_NoPathSpecified, rc); - XTESTS_TEST_INTEGER_EQUAL(0, firstBadCharOffset); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); - XTESTS_TEST_INTEGER_EQUAL(0u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); -} - -static void test_1_dot(void) -{ - char const input[] = "."; - - libpath_ParseResult_t r; - LIBPATH_RC rc; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - libpath_size_t firstBadCharOffset; - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(SIZE_MAX, firstBadCharOffset); - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(SIZE_MAX, firstBadCharOffset); - - XTESTS_TEST_INTEGER_EQUAL(1u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryNamePart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", r.entryNamePart); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -} - -static void test_2_dots(void) -{ - char const input[] = ".."; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(2u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryNamePart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", r.entryNamePart); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -} - -static void test_3_dots(void) -{ - char const input[] = "..."; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("...", r.entryNamePart); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("...", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -} - -static void test_4_dots(void) -{ - char const input[] = "...."; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(4u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryNamePart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("....", r.entryNamePart); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("....", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -} - -static void test_5_dots(void) -{ - char const input[] = "....."; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(5u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(5u, r.entryNamePart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL(".....", r.entryNamePart); - XTESTS_TEST_INTEGER_EQUAL(5u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL(".....", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -} - -static void test_rooted_1_dot(void) -{ - char const input[] = "/."; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(2u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, directoryPartSlices[0].len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryNamePart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", r.entryNamePart); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_rooted_2_dots(void) -{ - char const input[] = "/.."; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryNamePart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", r.entryNamePart); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_rooted_3_dots(void) -{ - char const input[] = "/..."; - - libpath_ParseResult_t r; - LIBPATH_RC rc; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(4u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("...", r.entryNamePart); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("...", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_rooted_4_dots(void) -{ - char const input[] = "/...."; - - libpath_ParseResult_t r; - LIBPATH_RC rc; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - libpath_size_t firstBadCharOffset; - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(SIZE_MAX, firstBadCharOffset); - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(SIZE_MAX, firstBadCharOffset); - - XTESTS_TEST_INTEGER_EQUAL(5u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryNamePart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("....", r.entryNamePart); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("....", r.entryStemPart); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_filename_with_trailing_dot(void) -{ - char const input[] = "..abc.def."; - - libpath_ParseResult_t r; - LIBPATH_RC rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, 0, LIBPATH_LF_nullptr, LIBPATH_LF_nullptr); - - // TODO: define failure result code - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(10u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(10u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(10u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(10u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); -} - -static void test_filename_with_trailing_dots(void) -{ - char const input[] = "..abc.def.."; - - libpath_ParseResult_t r; - LIBPATH_RC rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, 0, LIBPATH_LF_nullptr, LIBPATH_LF_nullptr); - - // TODO: define failure result code - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(11u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(11u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(11u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); -} - -static void test_stem_only(void) -{ - char const input[] = "abc"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -} - -static void test_filename(void) -{ - char const input[] = "a.c"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -} - -static void test_extension_only(void) -{ - char const input[] = ".bc"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -} - -static void test_rooted_1_stem(void) -{ - char const input[] = "/abc"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(4u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_rooted_1_dir_1_stem(void) -{ - char const input[] = "/dir/abc"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(8u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_rooted_1_dir_trailing_slash(void) -{ - char const input[] = "/dir/"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(5u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_rooted_2_dirs_trailing_slash(void) -{ - char const input[] = "/dir/dir2/"; - - libpath_ParseResult_t r; - LIBPATH_RC rc; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(10u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(10u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(10u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(9u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir2/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ - - directoryPartSlices[1].len = 1234; - directoryPartSlices[1].ptr = stlsoft_reinterpret_cast(char*, 1234); - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, 1, &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(10u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(10u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(10u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(9u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - - XTESTS_TEST_INTEGER_EQUAL(1234u, directoryPartSlices[1].len); - XTESTS_TEST_POINTER_EQUAL(stlsoft_reinterpret_cast(char*, 1234), directoryPartSlices[1].ptr); - - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_rooted_6_dirs_trailing_slash(void) -{ - char const input[] = "/directory1/directory2/dir3/dir4/d5/d6/"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(39u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(39u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(39u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_rooted_6_dirs_and_filename(void) -{ - char const input[] = "/directory1/directory2/dir3/dir4/d5/d6/file.ext"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(47u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(47u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(39u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_rooted_6_dirs_and_stem(void) -{ - char const input[] = "/1/2/3/4/5/6/f"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(14u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(14u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(13u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(12u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("2/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("4/", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("6/", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_slash_only(void) -{ - char const input[] = "/"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(1u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_filename_multiple_dots(void) -{ - char const input[] = "this.is.a.more.complex.file.ext"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(31u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(31u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(31u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(27u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -} - -static void test_Windows_backslash_only(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(1u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_backslash_rooted_1_stem(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\abc"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(4u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_volume_and_backslash_root(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:\\"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_volume_and_backslash_rooted_1_stem(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:\\abc"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_volume_and_backslash_rooted_6_dirs_and_filename(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:\\directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(49u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(49u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(41u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_volume_and_slash_root(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:/"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_slash_rooted_1_stem(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:/abc"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_volume_and_slash_rooted_6_dirs_and_filename(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:/directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(49u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(49u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(41u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_UNC_share(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(20u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_UNC_share_and_entry(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\abc"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(23u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(23u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_UNC_share_and_6_dirs_and_filename(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(66u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(66u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(58u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_UNC_share_and_6_dirs_and_filename_altslashes(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\directory1/directory2\\dir3/dir4\\d5/d6\\file.ext"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(66u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(66u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(58u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_UNC_share_and_6_dirs_and_filename_altslashes_2(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share/directory1\\directory2/dir3\\dir4/d5\\d6/file.ext"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(66u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(66u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(58u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4/", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6/", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_driveletterrelative_and_stem(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:abc"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(5u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_driveletterrelative_and_6_dirs_and_filename(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:directory1\\directory2\\dir3\\dir4\\d5\\d6\\file.ext"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(48u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(48u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(40u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1\\", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3\\", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5\\", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_driveletterrelative_and_6_dirs_and_filename_altslashes(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:directory1/directory2\\dir3/dir4\\d5/d6\\file.ext"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(48u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(48u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(40u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(8u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_driveletterrelative_and_6_dirs_and_dotsdir_altslashes(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "C:directory1/directory2\\dir3/dir4\\d5/d6\\."; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(41u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(41u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(40u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(38u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory1/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(11u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("directory2\\", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[2].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir3/", directoryPartSlices[2]); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[3].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir4\\", directoryPartSlices[3]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[4].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d5/", directoryPartSlices[4]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[5].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("d6\\", directoryPartSlices[5]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_rooted_1_dir_1_stem_extraslashes(void) -{ - char const input[] = "/dir//abc"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(9u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(9u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.rootPart.len); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); -#endif - XTESTS_TEST_INTEGER_EQUAL(5u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(5u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("dir//", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); -#ifdef LIBPATH_OS_IS_WINDOWS - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); -#else /* ? LIBPATH_OS_IS_WINDOWS */ - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_bad_characters(void) -{ - static char const bad_chars[] = - { - '|' - , '<' - , '>' - , '?' - , '*' -#ifdef LIBPATH_OS_IS_WINDOWS - , ';' -#else - , ':' -#endif - }; - char const input_template[] = "/this/is/going/to/be/a.bad.path"; - - { libpath_size_t i; for (i = 0; i != STLSOFT_NUM_ELEMENTS(bad_chars); ++i) - { - { libpath_size_t j; for (j = 0; j != STLSOFT_NUM_ELEMENTS(input_template) - 1; ++j) - { - libpath_ParseResult_t r; - LIBPATH_RC rc; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - libpath_size_t firstBadCharOffset; - - char input[STLSOFT_NUM_ELEMENTS(input_template)]; - - STLSOFT_STATIC_ASSERT(sizeof(input) == sizeof(input_template)); - - memcpy(input, input_template, sizeof(input)); - - input[j] = bad_chars[i]; - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, LIBPATH_LF_nullptr, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(j, firstBadCharOffset); - - rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(31u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(j, firstBadCharOffset); - }} - }} -} - -static void test_Windows_bad_characters(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - - libpath_ParseResult_t r; - LIBPATH_RC rc; - libpath_size_t firstBadCharOffset; - - - rc = libpath_Parse_ParsePathFromCStyleString(":C\\dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(0u, &firstBadCharOffset); - - - rc = libpath_Parse_ParsePathFromCStyleString("C:\\dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("C\\:dir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(2u, &firstBadCharOffset); - - - rc = libpath_Parse_ParsePathFromCStyleString("C\\d:ir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, &firstBadCharOffset); - - - rc = libpath_Parse_ParsePathFromCStyleString("C\\di:r\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, &firstBadCharOffset); - - - rc = libpath_Parse_ParsePathFromCStyleString("C\\dir:\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, &firstBadCharOffset); - - - - rc = libpath_Parse_ParsePathFromCStyleString("\\:Cdir\\file.ext", 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_BadPathCharacter, rc); - XTESTS_TEST_INTEGER_EQUAL(15u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(1u, &firstBadCharOffset); -#endif -} - -static void test_1_component_with_libpath_ParseOption_AssumeDirectory(void) -{ - libpath_ParseResult_t r; - LIBPATH_RC rc; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - - rc = libpath_Parse_ParsePathFromCStyleString("abc", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(4u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(3u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(3u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(4u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); -} - -static void test_2_components_with_libpath_ParseOption_AssumeDirectory(void) -{ - libpath_ParseResult_t r; - LIBPATH_RC rc; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/def", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(7u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(3u, r.entryNamePart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/def/", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(8u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("def/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/def", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(7u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("def", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/def/", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(8u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(8u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("def/", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - -} - -static void test_2_components_with_last_2dotsdir_with_libpath_ParseOption_AssumeDirectory(void) -{ - libpath_ParseResult_t r; - LIBPATH_RC rc; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/..", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/../", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(7u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("../", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/..", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("..", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/../", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(7u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(7u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(3u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("../", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); -} - -static void test_2_components_with_last_1dotsdir_with_libpath_ParseOption_AssumeDirectory(void) -{ - libpath_ParseResult_t r; - LIBPATH_RC rc; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/.", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(5u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(4u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(1u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/./", 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("./", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/.", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(5u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(5u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(1u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL(".", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - - - rc = libpath_Parse_ParsePathFromCStyleString("abc/./", libpath_ParseOption_AssumeDirectory, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(6u, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(6u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(2u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(4u, directoryPartSlices[0].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("abc/", directoryPartSlices[0]); - XTESTS_TEST_INTEGER_EQUAL(2u, directoryPartSlices[1].len); - XTESTS_TEST_MULTIBYTE_STRING_SLICE_EQUAL("./", directoryPartSlices[1]); - XTESTS_TEST_INTEGER_EQUAL(1u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); -} - -static void test_Windows_UNC_share_trailing_backslash(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(20u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_UNC_share_trailing_slash(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share/"; - - libpath_ParseResult_t r; - libpath_StringSlice_t directoryPartSlices[NUM_DP_ELEMENTS]; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromCStyleString(input, 0, &r, STLSOFT_NUM_ELEMENTS(directoryPartSlices), &directoryPartSlices[0], LIBPATH_LF_nullptr); - - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(20u, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - -static void test_Windows_UNC_share_with_charwise_steps(void) -{ -#ifdef LIBPATH_OS_IS_WINDOWS - char const input[] = "\\\\192.168.0.1\\share\\"; - libpath_size_t const cch = STLSOFT_NUM_ELEMENTS(input) - 1; - - { libpath_size_t i; for (i = 0; i <= cch; ++i) - { - libpath_ParseResult_t r; - LIBPATH_RC const rc = libpath_Parse_ParsePathFromStringPtrAndLen(input, i, 0, &r, 0, LIBPATH_LF_nullptr, &firstBadCharOffset); - - if (1 == i || - cch == i) - { - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_Success, rc); - XTESTS_TEST_INTEGER_EQUAL(i, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - XTESTS_TEST_INTEGER_EQUAL(i, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(i, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(i, r.rootPart.len); - if (cch == i) - { - XTESTS_TEST_INTEGER_EQUAL(20u, r.volumePart.len); - } - else - { - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); - } - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathRooted(&r)); - if (cch == i) - { - XTESTS_TEST_BOOLEAN_TRUE(libpath_ParseResult_IsPathAbsolute(&r)); - } - else - { - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); - } - } - else - { - if (0 == i) - { - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_NoPathSpecified, rc); - XTESTS_TEST_INTEGER_EQUAL(i, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - } - else - { - XTESTS_TEST_ENUM_EQUAL(libpath_ResultCode_InvalidRoot, rc); - XTESTS_TEST_INTEGER_EQUAL(i, r.input.len); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(input, r.input.ptr, r.input.len); - } - - XTESTS_TEST_INTEGER_EQUAL(0u, r.fullPath.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.locationPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.rootPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.volumePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.directoryPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.numDotsDirectoryParts); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryNamePart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryStemPart.len); - XTESTS_TEST_INTEGER_EQUAL(0u, r.entryExtensionPart.len); - - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathRooted(&r)); - XTESTS_TEST_BOOLEAN_FALSE(libpath_ParseResult_IsPathAbsolute(&r)); - } - }} -#endif /* LIBPATH_OS_IS_WINDOWS */ -} - - -/* ///////////////////////////// end of file //////////////////////////// */ - diff --git a/test/unit/test.unit.shim_strings/CMakeLists.txt b/test/unit/test.unit.shim_strings/CMakeLists.txt deleted file mode 100644 index 8154455..0000000 --- a/test/unit/test.unit.shim_strings/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten -define_automated_test_program(test.unit.shim_strings test.unit.shim_strings.cpp) diff --git a/test/unit/test.unit.shim_strings/test.unit.shim_strings.cpp b/test/unit/test.unit.shim_strings/test.unit.shim_strings.cpp deleted file mode 100644 index 273dda5..0000000 --- a/test/unit/test.unit.shim_strings/test.unit.shim_strings.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* ///////////////////////////////////////////////////////////////////////// - * File: test.unit.shim_strings.cpp - * - * Purpose: Unit-test for shim-strings. - * - * Created: 11th February 2024 - * Updated: 19th October 2024 - * - * ////////////////////////////////////////////////////////////////////// */ - - -/* ///////////////////////////////////////////////////////////////////////// - * includes - */ - -/* ///////////////////////////////////// - * test component header file include(s) - */ - -#include - -/* ///////////////////////////////////// - * general includes - */ - -/* xTests header files */ -#include -#if _XTESTS_VER < 0x00150000 -# error This code requires xTests 0.21.0, or later -#endif - -/* STLSoft header files */ -#include -#include - -/* Standard C header files */ -#include - - -/* ///////////////////////////////////////////////////////////////////////// - * forward declarations - */ - -static void test_rc_known_values(void); - - -/* ///////////////////////////////////////////////////////////////////////// - * main - */ - -int main(int argc, char* argv[]) -{ - int retCode = EXIT_SUCCESS; - int verbosity = 2; - - XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); - - if (XTESTS_START_RUNNER("test.unit.shim_strings", verbosity)) - { - XTESTS_RUN_CASE(test_rc_known_values); - - XTESTS_PRINT_RESULTS(); - - XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode); - } - - return retCode; -} - - -/* ///////////////////////////////////////////////////////////////////////// - * test function implementations - */ - -static void test_rc_known_values() -{ - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("operation is not supported", stlsoft::sas_to_string(LIBPATH_RC_OF(UnsupportedOperation))); - - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("unexpected condition", stlsoft::sas_to_string(LIBPATH_RC_OF(UnexpectedCondition))); - - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("out of memory", stlsoft::sas_to_string(LIBPATH_RC_OF(OutOfMemory))); - - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("no path specified", stlsoft::sas_to_string(LIBPATH_RC_OF(NoPathSpecified))); - - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("bad path character", stlsoft::sas_to_string(LIBPATH_RC_OF(BadPathCharacter))); - - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("option not supported", stlsoft::sas_to_string(LIBPATH_RC_OF(OptionNotSupported))); - - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("invalid root", stlsoft::sas_to_string(LIBPATH_RC_OF(InvalidRoot))); - - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("a reserved parameter that is reserved for future use must have the value 0 or NULL", stlsoft::sas_to_string(LIBPATH_RC_OF(ParameterIsReservedAndMustBeZero))); - - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("first/only path parameter is invalid", stlsoft::sas_to_string(LIBPATH_RC_OF(FirstPathInvalid))); - - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("second path parameter is invalid", stlsoft::sas_to_string(LIBPATH_RC_OF(SecondPathInvalid))); - - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("working directory path parameter is invalid", stlsoft::sas_to_string(LIBPATH_RC_OF(WorkingDirectoryPathInvalid))); - - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("operation completed successfully", stlsoft::sas_to_string(LIBPATH_RC_OF(Success))); -} - - -/* ///////////////////////////// end of file //////////////////////////// */ - diff --git a/test/unit/test.unit.type_strings/CMakeLists.txt b/test/unit/test.unit.type_strings/CMakeLists.txt deleted file mode 100644 index b2cadb9..0000000 --- a/test/unit/test.unit.type_strings/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten -define_automated_test_program(test.unit.type_strings test.unit.type_strings.cpp) diff --git a/test/unit/type-strings/CMakeLists.txt b/test/unit/type-strings/CMakeLists.txt new file mode 100644 index 0000000..996082e --- /dev/null +++ b/test/unit/type-strings/CMakeLists.txt @@ -0,0 +1,2 @@ +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +define_automated_test_program(test.unit.type-strings entry.cpp) diff --git a/test/unit/test.unit.type_strings/test.unit.type_strings.cpp b/test/unit/type-strings/entry.cpp similarity index 77% rename from test/unit/test.unit.type_strings/test.unit.type_strings.cpp rename to test/unit/type-strings/entry.cpp index b4bd176..68a57b5 100644 --- a/test/unit/test.unit.type_strings/test.unit.type_strings.cpp +++ b/test/unit/type-strings/entry.cpp @@ -1,10 +1,10 @@ /* ///////////////////////////////////////////////////////////////////////// - * File: test.unit.type_strings.cpp + * File: test/unit/type-strings/entry.cpp * - * Purpose: Unit-test for shim-strings. + * Purpose: Unit-tests the libpath type-string facilities. * * Created: 11th February 2024 - * Updated: 19th October 2024 + * Updated: 14th October 2026 * * ////////////////////////////////////////////////////////////////////// */ @@ -24,7 +24,7 @@ */ /* xTests header files */ -#include +#include #if _XTESTS_VER < 0x00150000 # error This code requires xTests 0.21.0, or later #endif @@ -58,7 +58,7 @@ int main(int argc, char* argv[]) XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity); - if (XTESTS_START_RUNNER("test.unit.type_strings", verbosity)) + if (XTESTS_START_RUNNER("test.unit.type-strings", verbosity)) { XTESTS_RUN_CASE(test_rc_known_values); XTESTS_RUN_CASE(test_rcx_known_values); @@ -82,84 +82,84 @@ static void test_rc_known_values() LIBPATH_RC const rc = LIBPATH_RC_OF(UnsupportedOperation); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("operation is not supported", s); + TEST_MS_EQ("operation is not supported", s); } { LIBPATH_RC const rc = LIBPATH_RC_OF(UnexpectedCondition); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("unexpected condition", s); + TEST_MS_EQ("unexpected condition", s); } { LIBPATH_RC const rc = LIBPATH_RC_OF(OutOfMemory); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("out of memory", s); + TEST_MS_EQ("out of memory", s); } { LIBPATH_RC const rc = LIBPATH_RC_OF(NoPathSpecified); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("no path specified", s); + TEST_MS_EQ("no path specified", s); } { LIBPATH_RC const rc = LIBPATH_RC_OF(BadPathCharacter); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("bad path character", s); + TEST_MS_EQ("bad path character", s); } { LIBPATH_RC const rc = LIBPATH_RC_OF(OptionNotSupported); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("option not supported", s); + TEST_MS_EQ("option not supported", s); } { LIBPATH_RC const rc = LIBPATH_RC_OF(InvalidRoot); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("invalid root", s); + TEST_MS_EQ("invalid root", s); } { LIBPATH_RC const rc = LIBPATH_RC_OF(ParameterIsReservedAndMustBeZero); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("a reserved parameter that is reserved for future use must have the value 0 or NULL", s); + TEST_MS_EQ("a reserved parameter that is reserved for future use must have the value 0 or NULL", s); } { LIBPATH_RC const rc = LIBPATH_RC_OF(FirstPathInvalid); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("first/only path parameter is invalid", s); + TEST_MS_EQ("first/only path parameter is invalid", s); } { LIBPATH_RC const rc = LIBPATH_RC_OF(SecondPathInvalid); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("second path parameter is invalid", s); + TEST_MS_EQ("second path parameter is invalid", s); } { LIBPATH_RC const rc = LIBPATH_RC_OF(WorkingDirectoryPathInvalid); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("working directory path parameter is invalid", s); + TEST_MS_EQ("working directory path parameter is invalid", s); } { LIBPATH_RC const rc = LIBPATH_RC_OF(Success); std::string const s = std::string(libpath_rc_getStringPtr(rc), libpath_rc_getStringLen(rc)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("operation completed successfully", s); + TEST_MS_EQ("operation completed successfully", s); } } @@ -169,7 +169,7 @@ static void test_rcx_known_values() LIBPATH_RCX const rcx = LIBPATH_RCX_OF(Success); std::string const s = std::string(libpath_rcx_getStringPtr(rcx), libpath_rcx_getStringLen(rcx)); - XTESTS_TEST_MULTIBYTE_STRING_EQUAL("operation completed successfully", s); + TEST_MS_EQ("operation completed successfully", s); } } diff --git a/test/unit/version/CMakeLists.txt b/test/unit/version/CMakeLists.txt new file mode 100644 index 0000000..ce99fd4 --- /dev/null +++ b/test/unit/version/CMakeLists.txt @@ -0,0 +1,2 @@ +# SIS:AUTO_GENERATED: Remove this line if you edit the file, otherwise it will be overwritten +define_automated_test_program(test.unit.version entry.c) diff --git a/test/unit/test.unit.version/test.unit.version.c b/test/unit/version/entry.c similarity index 66% rename from test/unit/test.unit.version/test.unit.version.c rename to test/unit/version/entry.c index 0ad5e92..a4ecd8b 100644 --- a/test/unit/test.unit.version/test.unit.version.c +++ b/test/unit/version/entry.c @@ -1,10 +1,10 @@ /* ///////////////////////////////////////////////////////////////////////// - * File: test.unit.version.c + * File: test/unit/version/entry.c * - * Purpose: Unit-test the library version macros. + * Purpose: Unit-tests the library version macros. * * Created: 8th February 2024 - * Updated: 19th October 2024 + * Updated: 14th October 2026 * * ////////////////////////////////////////////////////////////////////// */ @@ -24,7 +24,7 @@ */ /* xTests header files */ -#include +#include /* STLSoft header files */ #include @@ -71,15 +71,17 @@ int main(int argc, char* argv[]) static void test_version(void) { - unsigned const major = (LIBPATH_VER >> 24) & 0xff; - unsigned const minor = (LIBPATH_VER >> 16) & 0xff; - unsigned const patch = (LIBPATH_VER >> 8) & 0xff; - unsigned const ab = (LIBPATH_VER >> 0) & 0xff; - - XTESTS_TEST_INTEGER_EQUAL_EXACT(LIBPATH_VER_MAJOR, major); - XTESTS_TEST_INTEGER_EQUAL_EXACT(LIBPATH_VER_MINOR, minor); - XTESTS_TEST_INTEGER_EQUAL_EXACT(LIBPATH_VER_REVISION, patch); - XTESTS_TEST_INTEGER_EQUAL_EXACT(LIBPATH_VER_ALPHABETA, ab); + unsigned const major = (LIBPATH_VER >> 24) & 0xff; + unsigned const minor = (LIBPATH_VER >> 16) & 0xff; + unsigned const patch = (LIBPATH_VER >> 8) & 0xff; + unsigned const relstatus = (LIBPATH_VER >> 0) & 0xff; + + TEST_INTEGER_EQUAL_EXACT(LIBPATH_VER_MAJOR, major); + TEST_INTEGER_EQUAL_EXACT(LIBPATH_VER_MINOR, minor); + TEST_INTEGER_EQUAL_EXACT(LIBPATH_VER_PATCH, patch); + TEST_INTEGER_EQUAL_EXACT(LIBPATH_VER_REVISION, patch); + TEST_INTEGER_EQUAL_EXACT(LIBPATH_VER_RELSTATUS, relstatus); + TEST_INTEGER_EQUAL_EXACT(LIBPATH_VER_ALPHABETA, relstatus); }