aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLexi Winter <lexi@hemlock.eden.le-fay.org>2025-03-29 05:53:48 +0000
committerLexi Winter <lexi@hemlock.eden.le-fay.org>2025-03-29 05:53:48 +0000
commit61fc4a0aec687a4e52608f90c3613c41dc12ab5a (patch)
tree3b76bebcd3bb5203ac3b273deefd1d9195f8f0e2
parent624e051bb3244cda572c1d932108bc75116ddfb2 (diff)
downloadlibnvxx-61fc4a0aec687a4e52608f90c3613c41dc12ab5a.tar.gz
libnvxx-61fc4a0aec687a4e52608f90c3613c41dc12ab5a.tar.bz2
add more constructor tests
-rw-r--r--libnvxx/const_nv_list.cc1
-rw-r--r--libnvxx/nv_list.cc2
-rw-r--r--libnvxx/tests/nvxx_basic.cc120
3 files changed, 121 insertions, 2 deletions
diff --git a/libnvxx/const_nv_list.cc b/libnvxx/const_nv_list.cc
index 4f6504f..22d3771 100644
--- a/libnvxx/const_nv_list.cc
+++ b/libnvxx/const_nv_list.cc
@@ -54,6 +54,7 @@ const_nv_list::operator=(nv_list const &other) noexcept
::nvlist_t const *
const_nv_list::ptr() const
{
+ __throw_if_null();
return (__m_nv);
}
diff --git a/libnvxx/nv_list.cc b/libnvxx/nv_list.cc
index 3d8c0a1..03916d9 100644
--- a/libnvxx/nv_list.cc
+++ b/libnvxx/nv_list.cc
@@ -82,12 +82,14 @@ nv_list::operator=(nv_list &&other) noexcept
::nvlist_t *
nv_list::ptr()
{
+ __throw_if_null();
return (__m_nv);
}
::nvlist_t const *
nv_list::ptr() const
{
+ __throw_if_null();
return (__m_nv);
}
diff --git a/libnvxx/tests/nvxx_basic.cc b/libnvxx/tests/nvxx_basic.cc
index a552ad1..b428611 100644
--- a/libnvxx/tests/nvxx_basic.cc
+++ b/libnvxx/tests/nvxx_basic.cc
@@ -23,9 +23,115 @@
* constructor tests
*/
-TEST_CASE(nvxx_ctor_default)
+TEST_CASE(nvxx_nv_list_ctor_default)
{
auto nvl = bsd::nv_list();
+ ATF_REQUIRE_EQ(true, (nvl.ptr() != nullptr));
+}
+
+TEST_CASE(nvxx_nv_list_ctor_nvlist_t)
+{
+ auto nv = ::nvlist_create(0);
+ ATF_REQUIRE_EQ(true, nv != nullptr);
+
+ auto nvl = bsd::nv_list(nv);
+ ATF_REQUIRE_EQ(true, nvl.ptr() == nv);
+}
+
+TEST_CASE(nvxx_nv_list_ctor_const_nv_list)
+{
+ using namespace std::literals;
+ auto constexpr key = "test"sv;
+ auto constexpr value = 42;
+
+ auto nvl = bsd::nv_list();
+ nvl.add_number(key, value);
+
+ auto cnv = bsd::const_nv_list(nvl);
+ ATF_REQUIRE_EQ(true, nvl.ptr() == cnv.ptr());
+
+ auto nvl2 = bsd::nv_list(cnv);
+ ATF_REQUIRE_EQ(true, (cnv.ptr() != nvl2.ptr()));
+ ATF_REQUIRE_EQ(value, nvl2.get_number(key));
+}
+
+TEST_CASE(nvxx_nv_list_ctor_copy)
+{
+ using namespace std::literals;
+ auto constexpr key = "test"sv;
+ auto constexpr value = 42;
+
+ auto nvl = bsd::nv_list();
+ nvl.add_number(key, value);
+
+ auto nvl2 = bsd::nv_list(nvl);
+
+ ATF_REQUIRE_EQ(true, (nvl.ptr() != nvl2.ptr()));
+ ATF_REQUIRE_EQ(value, nvl.get_number(key));
+ ATF_REQUIRE_EQ(value, nvl2.get_number(key));
+}
+
+TEST_CASE(nvxx_nv_list_ctor_move)
+{
+ using namespace std::literals;
+ auto constexpr key = "test"sv;
+ auto constexpr value = 42;
+
+ auto nvl = bsd::nv_list();
+ nvl.add_number(key, value);
+
+ auto nvl2 = bsd::nv_list(std::move(nvl));
+
+ ATF_REQUIRE_THROW(std::logic_error, nvl.ptr());
+
+ ATF_REQUIRE_EQ(value, nvl2.get_number(key));
+}
+
+TEST_CASE(nvxx_const_nv_list_ctor_default)
+{
+ auto nvl = bsd::const_nv_list();
+ ATF_REQUIRE_THROW(std::logic_error, nvl.ptr());
+}
+
+TEST_CASE(nvxx_const_nv_list_ctor_nv_list)
+{
+ using namespace std::literals;
+ auto constexpr key = "test"sv;
+ auto constexpr value = 42;
+
+ auto nvl = bsd::nv_list();
+ nvl.add_number(key, value);
+
+ auto cnv = bsd::const_nv_list(nvl);
+
+ ATF_REQUIRE_EQ(nvl.ptr(), cnv.ptr());
+ ATF_REQUIRE_EQ(value, cnv.get_number(key));
+}
+
+TEST_CASE(nvxx_const_nv_list_ctor_nvlist_t)
+{
+ auto nv = ::nvlist_create(0);
+ ATF_REQUIRE_EQ(true, nv != nullptr);
+
+ auto cnv = bsd::const_nv_list(nv);
+ ATF_REQUIRE_EQ(true, cnv.ptr() == nv);
+}
+
+TEST_CASE(nvxx_const_nv_list_ctor_copy)
+{
+ using namespace std::literals;
+ auto constexpr key = "test"sv;
+ auto constexpr value = 42;
+
+ auto nvl = bsd::nv_list();
+ nvl.add_number(key, value);
+
+ auto cnv1 = bsd::const_nv_list(nvl);
+ auto cnv2 = bsd::const_nv_list(cnv1);
+
+ ATF_REQUIRE_EQ(cnv1.ptr(), cnv2.ptr());
+ ATF_REQUIRE_EQ(value, cnv1.get_number(key));
+ ATF_REQUIRE_EQ(value, cnv2.get_number(key));
}
/*
@@ -1564,7 +1670,17 @@ TEST_CASE(nvxx_add_binary_range)
ATF_INIT_TEST_CASES(tcs)
{
- ATF_ADD_TEST_CASE(tcs, nvxx_ctor_default);
+ ATF_ADD_TEST_CASE(tcs, nvxx_nv_list_ctor_default);
+ ATF_ADD_TEST_CASE(tcs, nvxx_nv_list_ctor_const_nv_list);
+ ATF_ADD_TEST_CASE(tcs, nvxx_nv_list_ctor_nvlist_t);
+ ATF_ADD_TEST_CASE(tcs, nvxx_nv_list_ctor_copy);
+ ATF_ADD_TEST_CASE(tcs, nvxx_nv_list_ctor_move);
+
+ ATF_ADD_TEST_CASE(tcs, nvxx_const_nv_list_ctor_default);
+ ATF_ADD_TEST_CASE(tcs, nvxx_const_nv_list_ctor_copy);
+ ATF_ADD_TEST_CASE(tcs, nvxx_const_nv_list_ctor_nv_list);
+ ATF_ADD_TEST_CASE(tcs, nvxx_const_nv_list_ctor_nvlist_t);
+
ATF_ADD_TEST_CASE(tcs, nvxx_ignore_case);
ATF_ADD_TEST_CASE(tcs, nvxx_set_error);