Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions components/idfxx_console/src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,13 @@ void repl::_stop_and_delete() noexcept {
if (_handle != nullptr) {
auto err = esp_console_stop_repl(_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to stop REPL: %s", make_error_code(err).message().c_str());
auto msg = make_error_code(err).message();
ESP_LOGE(TAG, "Failed to stop REPL: %s", msg.c_str());
}
err = _handle->del(_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to delete REPL: %s", make_error_code(err).message().c_str());
auto msg = make_error_code(err).message();
ESP_LOGE(TAG, "Failed to delete REPL: %s", msg.c_str());
}
}
}
Expand Down
36 changes: 24 additions & 12 deletions components/idfxx_core/tests/cpu_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ static_assert(static_cast<unsigned int>(core_id::core_1) == 1);
// to_string

TEST_CASE("to_string(core_id) outputs CORE_0", "[idfxx][cpu]") {
TEST_ASSERT_EQUAL_STRING("CORE_0", to_string(core_id::core_0).c_str());
auto s = to_string(core_id::core_0);
TEST_ASSERT_EQUAL_STRING("CORE_0", s.c_str());
}

#if SOC_CPU_CORES_NUM > 1
TEST_CASE("to_string(core_id) outputs CORE_1", "[idfxx][cpu]") {
TEST_ASSERT_EQUAL_STRING("CORE_1", to_string(core_id::core_1).c_str());
auto s = to_string(core_id::core_1);
TEST_ASSERT_EQUAL_STRING("CORE_1", s.c_str());
}
#endif

TEST_CASE("to_string(core_id) handles unknown values", "[idfxx][cpu]") {
auto unknown = static_cast<core_id>(99);
TEST_ASSERT_EQUAL_STRING("unknown(99)", to_string(unknown).c_str());
auto s = to_string(unknown);
TEST_ASSERT_EQUAL_STRING("unknown(99)", s.c_str());
}

// =============================================================================
Expand All @@ -67,36 +70,45 @@ static_assert(std::is_convertible_v<unsigned int, task_priority>);
// =============================================================================

TEST_CASE("to_string(task_priority) outputs value", "[idfxx][cpu]") {
TEST_ASSERT_EQUAL_STRING("0", to_string(task_priority{0}).c_str());
TEST_ASSERT_EQUAL_STRING("5", to_string(task_priority{5}).c_str());
TEST_ASSERT_EQUAL_STRING("24", to_string(task_priority{24}).c_str());
auto s = to_string(task_priority{0});
TEST_ASSERT_EQUAL_STRING("0", s.c_str());
s = to_string(task_priority{5});
TEST_ASSERT_EQUAL_STRING("5", s.c_str());
s = to_string(task_priority{24});
TEST_ASSERT_EQUAL_STRING("24", s.c_str());
}

#ifdef CONFIG_IDFXX_STD_FORMAT
// Formatter
static_assert(std::formattable<core_id, char>);

TEST_CASE("core_id formatter outputs CORE_0", "[idfxx][cpu]") {
TEST_ASSERT_EQUAL_STRING("CORE_0", std::format("{}", core_id::core_0).c_str());
auto s = std::format("{}", core_id::core_0);
TEST_ASSERT_EQUAL_STRING("CORE_0", s.c_str());
}

#if SOC_CPU_CORES_NUM > 1
TEST_CASE("core_id formatter outputs CORE_1", "[idfxx][cpu]") {
TEST_ASSERT_EQUAL_STRING("CORE_1", std::format("{}", core_id::core_1).c_str());
auto s = std::format("{}", core_id::core_1);
TEST_ASSERT_EQUAL_STRING("CORE_1", s.c_str());
}
#endif

TEST_CASE("core_id formatter handles unknown values", "[idfxx][cpu]") {
auto unknown = static_cast<core_id>(99);
TEST_ASSERT_EQUAL_STRING("unknown(99)", std::format("{}", unknown).c_str());
auto s = std::format("{}", unknown);
TEST_ASSERT_EQUAL_STRING("unknown(99)", s.c_str());
}

// task_priority formatter
static_assert(std::formattable<task_priority, char>);

TEST_CASE("task_priority formatter outputs value", "[idfxx][cpu]") {
TEST_ASSERT_EQUAL_STRING("0", std::format("{}", task_priority{0}).c_str());
TEST_ASSERT_EQUAL_STRING("5", std::format("{}", task_priority{5}).c_str());
TEST_ASSERT_EQUAL_STRING("24", std::format("{}", task_priority{24}).c_str());
auto s = std::format("{}", task_priority{0});
TEST_ASSERT_EQUAL_STRING("0", s.c_str());
s = std::format("{}", task_priority{5});
TEST_ASSERT_EQUAL_STRING("5", s.c_str());
s = std::format("{}", task_priority{24});
TEST_ASSERT_EQUAL_STRING("24", s.c_str());
}
#endif // CONFIG_IDFXX_STD_FORMAT
3 changes: 2 additions & 1 deletion components/idfxx_core/tests/error_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ TEST_CASE("make_error_code from errc", "[idfxx][error]") {

TEST_ASSERT_EQUAL(std::to_underlying(errc::invalid_arg), ec.value());
TEST_ASSERT_EQUAL_STRING("idfxx::Error", ec.category().name());
TEST_ASSERT_EQUAL_STRING("Invalid argument", ec.message().c_str());
auto s = ec.message();
TEST_ASSERT_EQUAL_STRING("Invalid argument", s.c_str());
}

TEST_CASE("make_error_code from esp_err_t", "[idfxx][error]") {
Expand Down
18 changes: 12 additions & 6 deletions components/idfxx_core/tests/flags_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,17 +344,20 @@ TEST_CASE("free operator ~E produces flags", "[idfxx][flags]") {

TEST_CASE("to_string(flags) outputs hex for zero", "[idfxx][flags]") {
flags<test_flag> f;
TEST_ASSERT_EQUAL_STRING("0x0", to_string(f).c_str());
auto s = to_string(f);
TEST_ASSERT_EQUAL_STRING("0x0", s.c_str());
}

TEST_CASE("to_string(flags) outputs hex for single flag", "[idfxx][flags]") {
auto f = flags{test_flag::flag_a};
TEST_ASSERT_EQUAL_STRING("0x1", to_string(f).c_str());
auto s = to_string(f);
TEST_ASSERT_EQUAL_STRING("0x1", s.c_str());
}

TEST_CASE("to_string(flags) outputs hex for combined flags", "[idfxx][flags]") {
auto f = test_flag::flag_a | test_flag::flag_b | test_flag::flag_c;
TEST_ASSERT_EQUAL_STRING("0x7", to_string(f).c_str());
auto s = to_string(f);
TEST_ASSERT_EQUAL_STRING("0x7", s.c_str());
}

// =============================================================================
Expand All @@ -366,16 +369,19 @@ static_assert(std::formattable<flags<test_flag>, char>);

TEST_CASE("flags formatter outputs hex for zero", "[idfxx][flags]") {
flags<test_flag> f;
TEST_ASSERT_EQUAL_STRING("0x0", std::format("{}", f).c_str());
auto s = std::format("{}", f);
TEST_ASSERT_EQUAL_STRING("0x0", s.c_str());
}

TEST_CASE("flags formatter outputs hex for single flag", "[idfxx][flags]") {
auto f = flags{test_flag::flag_a};
TEST_ASSERT_EQUAL_STRING("0x1", std::format("{}", f).c_str());
auto s = std::format("{}", f);
TEST_ASSERT_EQUAL_STRING("0x1", s.c_str());
}

TEST_CASE("flags formatter outputs hex for combined flags", "[idfxx][flags]") {
auto f = test_flag::flag_a | test_flag::flag_b | test_flag::flag_c;
TEST_ASSERT_EQUAL_STRING("0x7", std::format("{}", f).c_str());
auto s = std::format("{}", f);
TEST_ASSERT_EQUAL_STRING("0x7", s.c_str());
}
#endif // CONFIG_IDFXX_STD_FORMAT
51 changes: 34 additions & 17 deletions components/idfxx_core/tests/net_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ TEST_CASE("ip4_addr equality", "[idfxx][net]") {
}

TEST_CASE("ip4_addr to_string edge cases", "[idfxx][net]") {
TEST_ASSERT_EQUAL_STRING("0.0.0.0", idfxx::to_string(idfxx::net::ip4_addr()).c_str());
TEST_ASSERT_EQUAL_STRING("255.255.255.255", idfxx::to_string(idfxx::net::ip4_addr(255, 255, 255, 255)).c_str());
TEST_ASSERT_EQUAL_STRING("1.0.0.0", idfxx::to_string(idfxx::net::ip4_addr(1, 0, 0, 0)).c_str());
TEST_ASSERT_EQUAL_STRING("0.0.0.1", idfxx::to_string(idfxx::net::ip4_addr(0, 0, 0, 1)).c_str());
auto s = idfxx::to_string(idfxx::net::ip4_addr());
TEST_ASSERT_EQUAL_STRING("0.0.0.0", s.c_str());
s = idfxx::to_string(idfxx::net::ip4_addr(255, 255, 255, 255));
TEST_ASSERT_EQUAL_STRING("255.255.255.255", s.c_str());
s = idfxx::to_string(idfxx::net::ip4_addr(1, 0, 0, 0));
TEST_ASSERT_EQUAL_STRING("1.0.0.0", s.c_str());
s = idfxx::to_string(idfxx::net::ip4_addr(0, 0, 0, 1));
TEST_ASSERT_EQUAL_STRING("0.0.0.1", s.c_str());
}

// =============================================================================
Expand Down Expand Up @@ -169,67 +173,78 @@ TEST_CASE("ip6 to_string all zeros", "[idfxx][net]") {

TEST_CASE("ip6 to_string loopback", "[idfxx][net]") {
auto addr = ip6_from_groups(0, 0, 0, 0, 0, 0, 0, 1);
TEST_ASSERT_EQUAL_STRING("::1", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("::1", s.c_str());
}

TEST_CASE("ip6 to_string full address no compression", "[idfxx][net]") {
auto addr = ip6_from_groups(0x2001, 0x0db8, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006);
TEST_ASSERT_EQUAL_STRING("2001:db8:1:2:3:4:5:6", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("2001:db8:1:2:3:4:5:6", s.c_str());
}

TEST_CASE("ip6 to_string leading zeros compressed", "[idfxx][net]") {
// ::1:2:3:4:5:6
auto addr = ip6_from_groups(0, 0, 1, 2, 3, 4, 5, 6);
TEST_ASSERT_EQUAL_STRING("::1:2:3:4:5:6", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("::1:2:3:4:5:6", s.c_str());
}

TEST_CASE("ip6 to_string trailing zeros compressed", "[idfxx][net]") {
// 2001:db8::
auto addr = ip6_from_groups(0x2001, 0x0db8, 0, 0, 0, 0, 0, 0);
TEST_ASSERT_EQUAL_STRING("2001:db8::", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("2001:db8::", s.c_str());
}

TEST_CASE("ip6 to_string middle zeros compressed", "[idfxx][net]") {
// 2001:db8::1
auto addr = ip6_from_groups(0x2001, 0x0db8, 0, 0, 0, 0, 0, 1);
TEST_ASSERT_EQUAL_STRING("2001:db8::1", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("2001:db8::1", s.c_str());
}

TEST_CASE("ip6 to_string link-local", "[idfxx][net]") {
// fe80::1
auto addr = ip6_from_groups(0xfe80, 0, 0, 0, 0, 0, 0, 1);
TEST_ASSERT_EQUAL_STRING("fe80::1", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("fe80::1", s.c_str());
}

TEST_CASE("ip6 to_string single zero group not compressed", "[idfxx][net]") {
// RFC 5952: a single zero group must NOT be compressed
// 2001:db8:0:1:2:3:4:5
auto addr = ip6_from_groups(0x2001, 0x0db8, 0, 1, 2, 3, 4, 5);
TEST_ASSERT_EQUAL_STRING("2001:db8:0:1:2:3:4:5", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("2001:db8:0:1:2:3:4:5", s.c_str());
}

TEST_CASE("ip6 to_string longest run wins", "[idfxx][net]") {
// 1:0:0:2:0:0:0:3 — longest run is groups 4-6 (length 3), not groups 1-2 (length 2)
auto addr = ip6_from_groups(1, 0, 0, 2, 0, 0, 0, 3);
TEST_ASSERT_EQUAL_STRING("1:0:0:2::3", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("1:0:0:2::3", s.c_str());
}

TEST_CASE("ip6 to_string first longest run wins tie", "[idfxx][net]") {
// RFC 5952: when two runs are equal length, the first one is compressed
// 1:0:0:2:3:0:0:4
auto addr = ip6_from_groups(1, 0, 0, 2, 3, 0, 0, 4);
TEST_ASSERT_EQUAL_STRING("1::2:3:0:0:4", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("1::2:3:0:0:4", s.c_str());
}

TEST_CASE("ip6 to_string multicast", "[idfxx][net]") {
// ff02::1
auto addr = ip6_from_groups(0xff02, 0, 0, 0, 0, 0, 0, 1);
TEST_ASSERT_EQUAL_STRING("ff02::1", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("ff02::1", s.c_str());
}

TEST_CASE("ip6 to_string all ones", "[idfxx][net]") {
auto addr = ip6_from_groups(0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff);
TEST_ASSERT_EQUAL_STRING("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", s.c_str());
}

TEST_CASE("ip6 to_string zone appended", "[idfxx][net]") {
Expand All @@ -241,13 +256,15 @@ TEST_CASE("ip6 to_string zone appended", "[idfxx][net]") {
TEST_CASE("ip6 to_string zeros at both ends prefer first", "[idfxx][net]") {
// 0:0:1:2:3:4:0:0 — both runs are length 2, first wins
auto addr = ip6_from_groups(0, 0, 1, 2, 3, 4, 0, 0);
TEST_ASSERT_EQUAL_STRING("::1:2:3:4:0:0", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("::1:2:3:4:0:0", s.c_str());
}

TEST_CASE("ip6 to_string groups after compression", "[idfxx][net]") {
// ff02::1:2
auto addr = ip6_from_groups(0xff02, 0, 0, 0, 0, 0, 1, 2);
TEST_ASSERT_EQUAL_STRING("ff02::1:2", idfxx::to_string(addr).c_str());
auto s = idfxx::to_string(addr);
TEST_ASSERT_EQUAL_STRING("ff02::1:2", s.c_str());
}

TEST_CASE("ip6 to_string lowercase hex", "[idfxx][net]") {
Expand Down
12 changes: 8 additions & 4 deletions components/idfxx_core/tests/system_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ TEST_CASE("to_string(reset_reason) returns non-empty for all values", "[idfxx][s
}

TEST_CASE("to_string(reset_reason::power_on) returns POWER_ON", "[idfxx][system]") {
TEST_ASSERT_EQUAL_STRING("POWER_ON", to_string(reset_reason::power_on).c_str());
auto s = to_string(reset_reason::power_on);
TEST_ASSERT_EQUAL_STRING("POWER_ON", s.c_str());
}

TEST_CASE("to_string(reset_reason) handles unknown values", "[idfxx][system]") {
auto unknown = static_cast<reset_reason>(99);
TEST_ASSERT_EQUAL_STRING("unknown(99)", to_string(unknown).c_str());
auto s = to_string(unknown);
TEST_ASSERT_EQUAL_STRING("unknown(99)", s.c_str());
}

// Heap info
Expand Down Expand Up @@ -108,11 +110,13 @@ TEST_CASE("unregister non-registered shutdown handler fails", "[idfxx][system]")
static_assert(std::formattable<reset_reason, char>);

TEST_CASE("reset_reason formatter outputs POWER_ON", "[idfxx][system]") {
TEST_ASSERT_EQUAL_STRING("POWER_ON", std::format("{}", reset_reason::power_on).c_str());
auto s = std::format("{}", reset_reason::power_on);
TEST_ASSERT_EQUAL_STRING("POWER_ON", s.c_str());
}

TEST_CASE("reset_reason formatter handles unknown values", "[idfxx][system]") {
auto unknown = static_cast<reset_reason>(99);
TEST_ASSERT_EQUAL_STRING("unknown(99)", std::format("{}", unknown).c_str());
auto s = std::format("{}", unknown);
TEST_ASSERT_EQUAL_STRING("unknown(99)", s.c_str());
}
#endif // CONFIG_IDFXX_STD_FORMAT
21 changes: 14 additions & 7 deletions components/idfxx_core/tests/uart_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,45 @@ static_assert(std::to_underlying(uart_port::lp_uart0) == LP_UART_NUM_0);
// to_string

TEST_CASE("to_string(uart_port) outputs UART0", "[idfxx][uart]") {
TEST_ASSERT_EQUAL_STRING("UART0", to_string(uart_port::uart0).c_str());
auto s = to_string(uart_port::uart0);
TEST_ASSERT_EQUAL_STRING("UART0", s.c_str());
}

TEST_CASE("to_string(uart_port) outputs UART1", "[idfxx][uart]") {
TEST_ASSERT_EQUAL_STRING("UART1", to_string(uart_port::uart1).c_str());
auto s = to_string(uart_port::uart1);
TEST_ASSERT_EQUAL_STRING("UART1", s.c_str());
}

#if SOC_UART_HP_NUM > 2
TEST_CASE("to_string(uart_port) outputs UART2", "[idfxx][uart]") {
TEST_ASSERT_EQUAL_STRING("UART2", to_string(uart_port::uart2).c_str());
auto s = to_string(uart_port::uart2);
TEST_ASSERT_EQUAL_STRING("UART2", s.c_str());
}
#endif

TEST_CASE("to_string(uart_port) handles unknown values", "[idfxx][uart]") {
auto unknown = static_cast<uart_port>(99);
TEST_ASSERT_EQUAL_STRING("unknown(99)", to_string(unknown).c_str());
auto s = to_string(unknown);
TEST_ASSERT_EQUAL_STRING("unknown(99)", s.c_str());
}

#ifdef CONFIG_IDFXX_STD_FORMAT
// Formatter
static_assert(std::formattable<uart_port, char>);

TEST_CASE("uart_port formatter outputs UART0", "[idfxx][uart]") {
TEST_ASSERT_EQUAL_STRING("UART0", std::format("{}", uart_port::uart0).c_str());
auto s = std::format("{}", uart_port::uart0);
TEST_ASSERT_EQUAL_STRING("UART0", s.c_str());
}

TEST_CASE("uart_port formatter outputs UART1", "[idfxx][uart]") {
TEST_ASSERT_EQUAL_STRING("UART1", std::format("{}", uart_port::uart1).c_str());
auto s = std::format("{}", uart_port::uart1);
TEST_ASSERT_EQUAL_STRING("UART1", s.c_str());
}

TEST_CASE("uart_port formatter handles unknown values", "[idfxx][uart]") {
auto unknown = static_cast<uart_port>(99);
TEST_ASSERT_EQUAL_STRING("unknown(99)", std::format("{}", unknown).c_str());
auto s = std::format("{}", unknown);
TEST_ASSERT_EQUAL_STRING("unknown(99)", s.c_str());
}
#endif // CONFIG_IDFXX_STD_FORMAT
Loading
Loading