Skip to content

test(libc): cover strlcpy and case-insensitive comparisons - #1490

Closed
cubersu wants to merge 1 commit into
boykopovar:mainfrom
cubersu:test/libc-strlcpy-strcasecmp
Closed

cubersu wants to merge 1 commit into
boykopovar:mainfrom
cubersu:test/libc-strlcpy-strcasecmp

Conversation

@cubersu

@cubersu cubersu commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What

Adds behavioural tests for three libc exports that had no coverage: strlcpy, strcasecmp and strncasecmp (Strings.cpp). Test-only change, no implementation changes.

  • strlcpy: return value is the source length in every case; truncation keeps size - 1 bytes plus the terminator; exact fit and one-byte overflow; size 1 writes only the terminator; size 0 leaves the destination untouched; no padding past the terminator.
  • strcasecmp / strncasecmp: equality across case, sign of the result for ordered and prefix strings, comparison after lowering ("A" vs "["), unsigned comparison of bytes above 0x7f, n of 0, stopping at n, and n larger than both strings.

Expected values follow FreeBSD strlcpy(3) and POSIX strcasecmp in the C locale. Only the sign of comparison results is checked.

strncpy_s is left out on purpose: #1336 already adds tests for it in the same file.

Tested

Linux (Ubuntu 24.04, GCC 13.3), ctest -R guest_strings. Each new check was also confirmed to fail against a deliberately broken implementation (off-by-one in strlcpy, inverted strcasecmp sign, comparison without tolower, strncasecmp ignoring n). Windows not tested. tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01ULF8vCbJFyzxVsW3SfiWC5

@popcoder565

Copy link
Copy Markdown
Contributor

Tested on Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, Intel Core i7-12700H (20 logical CPUs). I merged it onto main 73ac9ef together with #1477, #1482 and #1490 to share one build.

Tested with AI assistance (Claude Code).

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: the tests pass on main and no fix or title comes with them. If a title shows strlcpy or strcasecmp behaving differently from the console, reopen with that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants