Fix for paths test

This commit is contained in:
Ken Van Hoeylandt 2026-08-19 22:45:42 +02:00
parent 5ff98ab38c
commit 5cc815e99c
2 changed files with 14 additions and 14 deletions

View File

@ -7,20 +7,20 @@
#include <cstring>
#include <string>
TEST_CASE("paths_get_user_data_path returns a non-empty path") {
TEST_CASE("paths_get_data_path returns a non-empty path") {
char buffer[192];
CHECK_EQ(paths_get_user_data_path(buffer, sizeof(buffer)), ERROR_NONE);
CHECK_EQ(paths_get_data_path(buffer, sizeof(buffer)), ERROR_NONE);
CHECK_GT(std::strlen(buffer), 0);
}
TEST_CASE("paths_get_user_data_path reports overflow for a too-small buffer") {
TEST_CASE("paths_get_data_path reports overflow for a too-small buffer") {
char buffer[1];
CHECK_EQ(paths_get_user_data_path(buffer, sizeof(buffer)), ERROR_BUFFER_OVERFLOW);
CHECK_EQ(paths_get_data_path(buffer, sizeof(buffer)), ERROR_BUFFER_OVERFLOW);
}
TEST_CASE("service_paths_get_user_data_directory includes the service id") {
char root[192];
REQUIRE_EQ(paths_get_user_data_path(root, sizeof(root)), ERROR_NONE);
REQUIRE_EQ(paths_get_data_path(root, sizeof(root)), ERROR_NONE);
char buffer[224];
CHECK_EQ(service_paths_get_user_data_directory("my-service", buffer, sizeof(buffer)), ERROR_NONE);

View File

@ -4,28 +4,28 @@
#include <tactility/paths.h>
// The simulator target is never built with ESP_PLATFORM, so paths_get_user_data_path()
// The simulator target is never built with ESP_PLATFORM, so paths_get_data_path()
// always takes the fixed "data" path branch here, guarded by a buffer-size check.
TEST_CASE("paths_get_user_data_path succeeds when the buffer exactly fits") {
TEST_CASE("paths_get_data_path succeeds when the buffer exactly fits") {
char buffer[16] = { 0 };
CHECK_EQ(paths_get_user_data_path(buffer, sizeof(buffer)), ERROR_NONE);
CHECK_EQ(paths_get_data_path(buffer, sizeof(buffer)), ERROR_NONE);
CHECK_EQ(std::strcmp(buffer, "data"), 0);
}
TEST_CASE("paths_get_user_data_path succeeds with a buffer sized to exactly fit the string and terminator") {
TEST_CASE("paths_get_data_path succeeds with a buffer sized to exactly fit the string and terminator") {
char buffer[5] = { 0 }; // strlen("data") + 1
CHECK_EQ(paths_get_user_data_path(buffer, sizeof(buffer)), ERROR_NONE);
CHECK_EQ(paths_get_data_path(buffer, sizeof(buffer)), ERROR_NONE);
CHECK_EQ(std::strcmp(buffer, "data"), 0);
}
TEST_CASE("paths_get_user_data_path reports a buffer overflow when the buffer is one byte too small") {
TEST_CASE("paths_get_data_path reports a buffer overflow when the buffer is one byte too small") {
char buffer[4] = { 0 }; // strlen("data"), no room for the terminator
CHECK_EQ(paths_get_user_data_path(buffer, sizeof(buffer)), ERROR_BUFFER_OVERFLOW);
CHECK_EQ(paths_get_data_path(buffer, sizeof(buffer)), ERROR_BUFFER_OVERFLOW);
}
TEST_CASE("paths_get_user_data_path reports a buffer overflow for a zero-size buffer") {
TEST_CASE("paths_get_data_path reports a buffer overflow for a zero-size buffer") {
char buffer[1] = { 'x' };
CHECK_EQ(paths_get_user_data_path(buffer, 0), ERROR_BUFFER_OVERFLOW);
CHECK_EQ(paths_get_data_path(buffer, 0), ERROR_BUFFER_OVERFLOW);
CHECK_EQ(buffer[0], 'x'); // untouched
}