diff options
| author | Lexi Winter <lexi@hemlock.eden.le-fay.org> | 2025-03-29 07:30:28 +0000 |
|---|---|---|
| committer | Lexi Winter <lexi@hemlock.eden.le-fay.org> | 2025-03-29 07:30:28 +0000 |
| commit | 7c2c7527da2a1ab06b31e8b86f041b0fd3376d34 (patch) | |
| tree | 47844a2313c02454fca925688a55a4120c4a31de /libnvxx | |
| parent | 9d36060ce292f27a6427f87d71a45ed93e171bb8 (diff) | |
| download | libnvxx-7c2c7527da2a1ab06b31e8b86f041b0fd3376d34.tar.gz libnvxx-7c2c7527da2a1ab06b31e8b86f041b0fd3376d34.tar.bz2 | |
add tests for empty()
Diffstat (limited to 'libnvxx')
| -rw-r--r-- | libnvxx/const_nv_list.cc | 2 | ||||
| -rw-r--r-- | libnvxx/nvxx_base.h | 2 | ||||
| -rw-r--r-- | 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 @@ -345,6 +345,38 @@ TEST_CASE(nvxx_flags_error) } /* + * 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); |
