From 7c2c7527da2a1ab06b31e8b86f041b0fd3376d34 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Sat, 29 Mar 2025 07:30:28 +0000 Subject: add tests for empty() --- libnvxx/const_nv_list.cc | 2 +- libnvxx/nvxx_base.h | 2 +- libnvxx/tests/nvxx_basic.cc | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/libnvxx/const_nv_list.cc b/libnvxx/const_nv_list.cc index e27554f..2c2465f 100644 --- a/libnvxx/const_nv_list.cc +++ b/libnvxx/const_nv_list.cc @@ -87,7 +87,7 @@ __const_nv_list::exists(std::string_view key) const bool -__const_nv_list::empty() const noexcept +__const_nv_list::empty() const { __throw_if_error(); return (::nvlist_empty(__m_nv)); diff --git a/libnvxx/nvxx_base.h b/libnvxx/nvxx_base.h index 7c12921..43e53cf 100644 --- a/libnvxx/nvxx_base.h +++ b/libnvxx/nvxx_base.h @@ -138,7 +138,7 @@ struct __const_nv_list : virtual __nv_list_base { /* * Returns true if this nvlist is empty (contains no values). */ - [[nodiscard]] bool empty() const noexcept; + [[nodiscard]] bool empty() const; /* * Return the flags used to create this nv_list. diff --git a/libnvxx/tests/nvxx_basic.cc b/libnvxx/tests/nvxx_basic.cc index edd9937..835d2b2 100644 --- a/libnvxx/tests/nvxx_basic.cc +++ b/libnvxx/tests/nvxx_basic.cc @@ -344,6 +344,38 @@ TEST_CASE(nvxx_flags_error) ATF_REQUIRE_THROW(bsd::nv_error_state, (void)nvl.flags()); } +/* + * empty + */ + +TEST_CASE(nvxx_empty) +{ + using namespace std::literals; + auto constexpr key = "test"sv; + auto constexpr value = 42u; + + auto nvl = bsd::nv_list(); + ATF_REQUIRE_EQ(true, nvl.empty()); + + nvl.add_number(key, value); + ATF_REQUIRE_EQ(false, nvl.empty()); +} + +TEST_CASE(nvxx_empty_empty) +{ + auto cnv = bsd::const_nv_list(); + + ATF_REQUIRE_THROW(std::logic_error, (void)cnv.empty()); +} + +TEST_CASE(nvxx_empty_error) +{ + auto nvl = bsd::nv_list(); + nvl.set_error(std::errc::invalid_argument); + + ATF_REQUIRE_THROW(bsd::nv_error_state, (void)nvl.empty()); +} + /* * pack/unpack */ @@ -2037,6 +2069,10 @@ ATF_INIT_TEST_CASES(tcs) ATF_ADD_TEST_CASE(tcs, nvxx_flags_empty); ATF_ADD_TEST_CASE(tcs, nvxx_flags_error); + ATF_ADD_TEST_CASE(tcs, nvxx_empty); + ATF_ADD_TEST_CASE(tcs, nvxx_empty_empty); + ATF_ADD_TEST_CASE(tcs, nvxx_empty_error); + ATF_ADD_TEST_CASE(tcs, nvxx_pack); ATF_ADD_TEST_CASE(tcs, nvxx_pack_error); ATF_ADD_TEST_CASE(tcs, nvxx_pack_empty); -- cgit v1.2.3