]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1848] pgsql_cb_impl_unittest.cc added
authorTomek Mrugalski <tomek@isc.org>
Thu, 1 Jul 2021 14:25:27 +0000 (16:25 +0200)
committerTomek Mrugalski <tomek@isc.org>
Wed, 17 Nov 2021 14:35:18 +0000 (15:35 +0100)
src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_impl_unittest.cc [new file with mode: 0644]

diff --git a/src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_impl_unittest.cc b/src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_impl_unittest.cc
new file mode 100644 (file)
index 0000000..342174c
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright (C) 2021 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+#include <pgsql_cb_impl.h>
+#include <gtest/gtest.h>
+
+using namespace isc::db;
+using namespace isc::dhcp;
+
+namespace {
+
+// Test that the Postgres binding can be created from a triplet.
+TEST(PgSqlConfigBackendImplTest, createBindingFromTriplet) {
+    // Create a binding from an unspecified triplet.
+    auto binding = PgSqlConfigBackendImpl::createBinding(Triplet<uint32_t>());
+    // The binding pointer should be non-null but the type of the binding
+    // should be null.
+    ASSERT_TRUE(binding);
+    EXPECT_TRUE(binding->amNull());
+
+    // This time create a triplet encapsulating a number.
+    binding = PgSqlConfigBackendImpl::createBinding(Triplet<uint32_t>(123));
+    ASSERT_TRUE(binding);
+    // The binding type should be non-null.
+    ASSERT_FALSE(binding->amNull());
+    ASSERT_EQ(PsqlBindArray::TEXT_FMT, binding->getType());
+    // Check that the correct value was stored in the binding.
+    EXPECT_EQ(123, binding->getInteger<uint32_t>(0));
+}
+
+#if 0
+// Test that the triplet can be created from the Postgres binding.
+TEST(PgSqlConfigBackendImplTest, createTripletFromBinding) {
+    // Create a binding encapsulating a number and try to create a triplet
+    // from this binding.
+    MySqlBindingPtr binding = MySqlBinding::createInteger<uint32_t>(234);
+    Triplet<uint32_t> triplet;
+    ASSERT_NO_THROW(triplet = PgSqlConfigBackendImpl::createTriplet(binding));
+
+    // The triplet should be specified and equal to the value stored in the
+    // binding.
+    ASSERT_FALSE(triplet.unspecified());
+    EXPECT_EQ(234, triplet.get());
+
+    // Create a null binding and then use it to create a triplet.
+    binding = MySqlBinding::createNull();
+    ASSERT_NO_THROW(triplet = PgSqlConfigBackendImpl::createTriplet(binding));
+    // This time the triplet should be unspecified.
+    EXPECT_TRUE(triplet.unspecified());
+
+    // Finally, make sure that the null binding pointer is rejected.
+    EXPECT_THROW(PgSqlConfigBackendImpl::createTriplet(MySqlBindingPtr()),
+                 isc::Unexpected);
+}
+#endif
+
+}