mirror of
https://github.com/izzy2lost/libultraship.git
synced 2026-10-26 11:44:27 -07:00
* test: add comprehensive test coverage for utility modules Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/a89625bd-3a8f-4c51-b418-4258f9c6c44a Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com> * chore: plan ResourceManager/ArchiveManager test additions Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/a89625bd-3a8f-4c51-b418-4258f9c6c44a Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com> * chore: plan maximum coverage test additions Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/a89625bd-3a8f-4c51-b418-4258f9c6c44a Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com> * test: add comprehensive coverage — glob, splitText, Path/DiskFile, resource types/factories, Archive self tests, ResourceLoader, ResourceManager helpers Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/a89625bd-3a8f-4c51-b418-4258f9c6c44a Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com> * test: address PR review suggestions and splitText leak Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/44c1e76b-581e-4593-b8bc-a60be4c0dd9f Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com> * Changes before error encountered Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/44c1e76b-581e-4593-b8bc-a60be4c0dd9f Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com> * style: apply clang-format to remaining test files Agent-Logs-Url: https://github.com/Kenix3/libultraship/sessions/1a9e1a9f-2efb-449b-91a3-8c8372053c64 Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Kenix3 <18299654+Kenix3@users.noreply.github.com>
113 lines
2.7 KiB
C++
113 lines
2.7 KiB
C++
#include <gtest/gtest.h>
|
|
#include <climits>
|
|
#include "ship/utils/stox.h"
|
|
|
|
// ============================================================
|
|
// stob — string to bool
|
|
// ============================================================
|
|
|
|
TEST(StobTest, IntegerOneIsTrue) {
|
|
EXPECT_TRUE(Ship::stob("1"));
|
|
}
|
|
|
|
TEST(StobTest, IntegerZeroIsFalse) {
|
|
EXPECT_FALSE(Ship::stob("0"));
|
|
}
|
|
|
|
TEST(StobTest, BoolAlphaTrue) {
|
|
EXPECT_TRUE(Ship::stob("true"));
|
|
}
|
|
|
|
TEST(StobTest, BoolAlphaFalse) {
|
|
EXPECT_FALSE(Ship::stob("false"));
|
|
}
|
|
|
|
TEST(StobTest, InvalidStringReturnsDefaultTrue) {
|
|
EXPECT_TRUE(Ship::stob("notabool", true));
|
|
}
|
|
|
|
TEST(StobTest, InvalidStringReturnsDefaultFalse) {
|
|
EXPECT_FALSE(Ship::stob("notabool", false));
|
|
}
|
|
|
|
TEST(StobTest, EmptyStringReturnsDefault) {
|
|
EXPECT_TRUE(Ship::stob("", true));
|
|
}
|
|
|
|
// ============================================================
|
|
// stoi — string to int32_t
|
|
// ============================================================
|
|
|
|
TEST(StoiTest, ParsesPositiveInt) {
|
|
EXPECT_EQ(Ship::stoi("42"), 42);
|
|
}
|
|
|
|
TEST(StoiTest, ParsesNegativeInt) {
|
|
EXPECT_EQ(Ship::stoi("-7"), -7);
|
|
}
|
|
|
|
TEST(StoiTest, ParsesZero) {
|
|
EXPECT_EQ(Ship::stoi("0"), 0);
|
|
}
|
|
|
|
TEST(StoiTest, InvalidStringReturnsDefault) {
|
|
EXPECT_EQ(Ship::stoi("abc", -99), -99);
|
|
}
|
|
|
|
TEST(StoiTest, EmptyStringReturnsDefault) {
|
|
EXPECT_EQ(Ship::stoi("", 5), 5);
|
|
}
|
|
|
|
TEST(StoiTest, OutOfRangeReturnsDefault) {
|
|
// Value larger than INT32_MAX
|
|
EXPECT_EQ(Ship::stoi("99999999999999999", 0), 0);
|
|
}
|
|
|
|
// ============================================================
|
|
// stof — string to float
|
|
// ============================================================
|
|
|
|
TEST(StofTest, ParsesPositiveFloat) {
|
|
EXPECT_FLOAT_EQ(Ship::stof("3.14"), 3.14f);
|
|
}
|
|
|
|
TEST(StofTest, ParsesNegativeFloat) {
|
|
EXPECT_FLOAT_EQ(Ship::stof("-1.5"), -1.5f);
|
|
}
|
|
|
|
TEST(StofTest, ParsesZero) {
|
|
EXPECT_FLOAT_EQ(Ship::stof("0.0"), 0.0f);
|
|
}
|
|
|
|
TEST(StofTest, InvalidStringReturnsDefault) {
|
|
EXPECT_FLOAT_EQ(Ship::stof("xyz", 2.0f), 2.0f);
|
|
}
|
|
|
|
TEST(StofTest, EmptyStringReturnsDefault) {
|
|
EXPECT_FLOAT_EQ(Ship::stof("", 1.0f), 1.0f);
|
|
}
|
|
|
|
// ============================================================
|
|
// stoll — string to int64_t
|
|
// ============================================================
|
|
|
|
TEST(StollTest, ParsesPositive) {
|
|
EXPECT_EQ(Ship::stoll("1234567890123"), 1234567890123LL);
|
|
}
|
|
|
|
TEST(StollTest, ParsesNegative) {
|
|
EXPECT_EQ(Ship::stoll("-9876543210"), -9876543210LL);
|
|
}
|
|
|
|
TEST(StollTest, ParsesZero) {
|
|
EXPECT_EQ(Ship::stoll("0"), 0LL);
|
|
}
|
|
|
|
TEST(StollTest, InvalidStringReturnsDefault) {
|
|
EXPECT_EQ(Ship::stoll("notanumber", -42LL), -42LL);
|
|
}
|
|
|
|
TEST(StollTest, EmptyStringReturnsDefault) {
|
|
EXPECT_EQ(Ship::stoll("", 7LL), 7LL);
|
|
}
|