aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLexi Winter <lexi@hemlock.eden.le-fay.org>2025-03-29 07:34:00 +0000
committerLexi Winter <lexi@hemlock.eden.le-fay.org>2025-03-29 07:34:00 +0000
commitb48e5ad9b57372c7904dfaa8e10bfe5c527149a7 (patch)
tree1cb4430c856fc56608ed7bb8bcbcfdd631b76a41
parent7c2c7527da2a1ab06b31e8b86f041b0fd3376d34 (diff)
downloadlibnvxx-b48e5ad9b57372c7904dfaa8e10bfe5c527149a7.tar.gz
libnvxx-b48e5ad9b57372c7904dfaa8e10bfe5c527149a7.tar.bz2
add tests for operator bool, and add an empty check
-rw-r--r--libnvxx/const_nv_list.cc2
-rw-r--r--libnvxx/nvxx.32
-rw-r--r--libnvxx/tests/nvxx_basic.cc28
3 files changed, 30 insertions, 2 deletions
diff --git a/libnvxx/const_nv_list.cc b/libnvxx/const_nv_list.cc
index 2c2465f..2cff900 100644
--- a/libnvxx/const_nv_list.cc
+++ b/libnvxx/const_nv_list.cc
@@ -108,7 +108,7 @@ __const_nv_list::in_array() const noexcept
__const_nv_list::operator bool() const noexcept
{
- return (::nvlist_error(__m_nv) == 0);
+ return ((__m_nv != nullptr) && (::nvlist_error(__m_nv) == 0));
}
void
diff --git a/libnvxx/nvxx.3 b/libnvxx/nvxx.3
index 904eabe..37db659 100644
--- a/libnvxx/nvxx.3
+++ b/libnvxx/nvxx.3
@@ -487,7 +487,7 @@ The
.Fn "operator bool"
member function returns
.Dv false
-if the nvlist is in an error state, otherwise
+if the nvlist is in the empty state or an error state, otherwise
.Dv true .
.Pp
The
diff --git a/libnvxx/tests/nvxx_basic.cc b/libnvxx/tests/nvxx_basic.cc
index 835d2b2..dbca98c 100644
--- a/libnvxx/tests/nvxx_basic.cc
+++ b/libnvxx/tests/nvxx_basic.cc
@@ -345,6 +345,30 @@ TEST_CASE(nvxx_flags_error)
}
/*
+ * operator bool
+ */
+
+TEST_CASE(nvxx_operator_bool)
+{
+ auto nvl = bsd::nv_list(NV_FLAG_IGNORE_CASE);
+
+ ATF_REQUIRE_EQ(true, static_cast<bool>(nvl));
+}
+
+TEST_CASE(nvxx_operator_bool_empty)
+{
+ auto cnv = bsd::const_nv_list();
+ ATF_REQUIRE_EQ(false, static_cast<bool>(cnv));
+}
+
+TEST_CASE(nvxx_operator_bool_error)
+{
+ auto nvl = bsd::nv_list();
+ nvl.set_error(std::errc::invalid_argument);
+ ATF_REQUIRE_EQ(false, static_cast<bool>(nvl));
+}
+
+/*
* empty
*/
@@ -2073,6 +2097,10 @@ ATF_INIT_TEST_CASES(tcs)
ATF_ADD_TEST_CASE(tcs, nvxx_empty_empty);
ATF_ADD_TEST_CASE(tcs, nvxx_empty_error);
+ ATF_ADD_TEST_CASE(tcs, nvxx_operator_bool);
+ ATF_ADD_TEST_CASE(tcs, nvxx_operator_bool_empty);
+ ATF_ADD_TEST_CASE(tcs, nvxx_operator_bool_error);
+
ATF_ADD_TEST_CASE(tcs, nvxx_pack);
ATF_ADD_TEST_CASE(tcs, nvxx_pack_error);
ATF_ADD_TEST_CASE(tcs, nvxx_pack_empty);