From: Francis Dupont Date: Sat, 20 Jul 2019 19:14:54 +0000 (+0200) Subject: [742-new-libyang-and-sysrepo-versions] Updated to the 0.7.8 value API X-Git-Tag: Kea-1.6.1~10^2~105 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6776a829f90768225ea794145e522560d26fe959;p=thirdparty%2Fkea.git [742-new-libyang-and-sysrepo-versions] Updated to the 0.7.8 value API --- diff --git a/src/lib/yang/tests/translator_database_unittests.cc b/src/lib/yang/tests/translator_database_unittests.cc index 3e8e3c43ce..bf71051a03 100644 --- a/src/lib/yang/tests/translator_database_unittests.cc +++ b/src/lib/yang/tests/translator_database_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 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 @@ -62,7 +62,11 @@ TEST_F(TranslatorDatabaseTest, get) { S_Val s_type(new Val("memfile")); EXPECT_NO_THROW(sess_->set_item(xtype.c_str(), s_type)); uint32_t li = 3600; +#ifdef HAVE_POST_0_7_7_SYSREPO + S_Val s_interval(new Val(li)); +#else S_Val s_interval(new Val(li, SR_UINT32_T)); +#endif EXPECT_NO_THROW(sess_->set_item(xinterval.c_str(), s_interval)); // Get empty. @@ -120,7 +124,11 @@ TEST_F(TranslatorDatabaseTest, setEmpty) { S_Val s_type(new Val("memfile")); EXPECT_NO_THROW(sess_->set_item(xtype.c_str(), s_type)); uint32_t li = 3600; +#ifdef HAVE_POST_0_7_7_SYSREPO + S_Val s_interval(new Val(li)); +#else S_Val s_interval(new Val(li, SR_UINT32_T)); +#endif EXPECT_NO_THROW(sess_->set_item(xinterval.c_str(), s_interval)); // Reset to empty. @@ -181,7 +189,11 @@ TEST_F(TranslatorDatabasesTest, get) { S_Val s_host(new Val("localhost")); EXPECT_NO_THROW(sess_->set_item(xhost.c_str(), s_host)); uint16_t mport = 3306; +#ifdef HAVE_POST_0_7_7_SYSREPO + S_Val s_port(new Val(mport)); +#else S_Val s_port(new Val(mport, SR_UINT16_T)); +#endif EXPECT_NO_THROW(sess_->set_item(xport.c_str(), s_port)); // Get empty. @@ -277,7 +289,11 @@ TEST_F(TranslatorDatabasesTest, setEmpty) { S_Val s_host(new Val("localhost")); EXPECT_NO_THROW(sess_->set_item(xhost.c_str(), s_host)); uint16_t mport = 3306; +#ifdef HAVE_POST_0_7_7_SYSREPO + S_Val s_port(new Val(mport)); +#else S_Val s_port(new Val(mport, SR_UINT16_T)); +#endif EXPECT_NO_THROW(sess_->set_item(xport.c_str(), s_port)); // Reset to empty. @@ -311,7 +327,11 @@ TEST_F(TranslatorDatabasesTest, setEmpties) { S_Val s_host(new Val("localhost")); EXPECT_NO_THROW(sess_->set_item(xhost.c_str(), s_host)); uint16_t mport = 3306; +#ifdef HAVE_POST_0_7_7_SYSREPO + S_Val s_port(new Val(mport)); +#else S_Val s_port(new Val(mport, SR_UINT16_T)); +#endif EXPECT_NO_THROW(sess_->set_item(xport.c_str(), s_port)); // Reset to empty. diff --git a/src/lib/yang/tests/translator_logger_unittests.cc b/src/lib/yang/tests/translator_logger_unittests.cc index 1de5e8f07f..cc8100a8e0 100644 --- a/src/lib/yang/tests/translator_logger_unittests.cc +++ b/src/lib/yang/tests/translator_logger_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 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 @@ -65,7 +65,11 @@ TEST_F(TranslatorLoggersTest, get) { S_Val s_severity(new Val("WARN", SR_ENUM_T)); EXPECT_NO_THROW(sess_->set_item(xseverity.c_str(), s_severity)); uint32_t max_ver = 10; +#ifdef HAVE_POST_0_7_7_SYSREPO + S_Val s_maxver(new Val(max_ver)); +#else S_Val s_maxver(new Val(max_ver, SR_UINT32_T)); +#endif EXPECT_NO_THROW(sess_->set_item(xmaxver.c_str(), s_maxver)); // Get empty. diff --git a/src/lib/yang/tests/translator_pd_pool_unittests.cc b/src/lib/yang/tests/translator_pd_pool_unittests.cc index 55583296bc..1be28b16c8 100644 --- a/src/lib/yang/tests/translator_pd_pool_unittests.cc +++ b/src/lib/yang/tests/translator_pd_pool_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 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 @@ -89,7 +89,11 @@ TEST_F(TranslatorPdPoolsTest, getIetf) { EXPECT_NO_THROW(sess_->set_item(prefix.c_str(), s_prefix)); const string& length = xpath + "/prefix-length"; uint8_t len = 56; +#ifdef HAVE_POST_0_7_7_SYSREPO + S_Val s_length(new Val(len)); +#else S_Val s_length(new Val(len, SR_UINT8_T)); +#endif EXPECT_NO_THROW(sess_->set_item(length.c_str(), s_length)); // Get the pool. @@ -128,7 +132,11 @@ TEST_F(TranslatorPdPoolsTest, getKea) { spool << xpath + "/pd-pool[prefix='" << prefix << "']"; const string& x_delegated = spool.str() + "/delegated-len"; uint8_t dl = 64; +#ifdef HAVE_POST_0_7_7_SYSREPO + S_Val s_delegated(new Val(dl)); +#else S_Val s_delegated(new Val(dl, SR_UINT8_T)); +#endif EXPECT_NO_THROW(sess_->set_item(x_delegated.c_str(), s_delegated)); // Get the pool. @@ -332,7 +340,11 @@ TEST_F(TranslatorPdPoolsTest, getListKea) { spool << xpath + "/pd-pool[prefix='" << prefix << "']"; const string& x_delegated = spool.str() + "/delegated-len"; uint8_t dl = 64; +#ifdef HAVE_POST_0_7_7_SYSREPO + S_Val s_delegated(new Val(dl)); +#else S_Val s_delegated(new Val(dl, SR_UINT8_T)); +#endif EXPECT_NO_THROW(sess_->set_item(x_delegated.c_str(), s_delegated)); // Create the second pd-pool 2001:db8:0:2000::/56 @@ -341,7 +353,11 @@ TEST_F(TranslatorPdPoolsTest, getListKea) { spool2 << xpath + "/pd-pool[prefix='" << prefix2 << "']"; const string& x_delegated2 = spool2.str() + "/delegated-len"; uint8_t dl2 = 60; +#ifdef HAVE_POST_0_7_7_SYSREPO + S_Val s_delegated2(new Val(dl2)); +#else S_Val s_delegated2(new Val(dl2, SR_UINT8_T)); +#endif EXPECT_NO_THROW(sess_->set_item(x_delegated2.c_str(), s_delegated2)); diff --git a/src/lib/yang/tests/translator_unittests.cc b/src/lib/yang/tests/translator_unittests.cc index ddf314e1b7..14ee74cdc4 100644 --- a/src/lib/yang/tests/translator_unittests.cc +++ b/src/lib/yang/tests/translator_unittests.cc @@ -61,7 +61,11 @@ TEST(TranslatorBasicTest, valueFrom) { // Unsigned 8 bit integer. uint8_t u8(123); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u8)); +#else s_val.reset(new Val(u8, SR_UINT8_T)); +#endif EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val)); ASSERT_TRUE(elem); ASSERT_EQ(Element::integer, elem->getType()); @@ -70,7 +74,11 @@ TEST(TranslatorBasicTest, valueFrom) { // Unsigned 16 bit integer. uint16_t u16(12345); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u16)); +#else s_val.reset(new Val(u16, SR_UINT16_T)); +#endif EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val)); ASSERT_TRUE(elem); ASSERT_EQ(Element::integer, elem->getType()); @@ -79,7 +87,11 @@ TEST(TranslatorBasicTest, valueFrom) { // Unsigned 32 bit integer. uint32_t u32(123456789); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u32)); +#else s_val.reset(new Val(u32, SR_UINT32_T)); +#endif EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val)); ASSERT_TRUE(elem); ASSERT_EQ(Element::integer, elem->getType()); @@ -88,7 +100,11 @@ TEST(TranslatorBasicTest, valueFrom) { // Signed 8 bit integer. int8_t s8(-123); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(s8)); +#else s_val.reset(new Val(s8, SR_INT8_T)); +#endif EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val)); ASSERT_TRUE(elem); ASSERT_EQ(Element::integer, elem->getType()); @@ -97,7 +113,11 @@ TEST(TranslatorBasicTest, valueFrom) { // Signed 16 bit integer. int16_t s16(-12345); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(s16)); +#else s_val.reset(new Val(s16, SR_INT16_T)); +#endif EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val)); ASSERT_TRUE(elem); ASSERT_EQ(Element::integer, elem->getType()); @@ -106,7 +126,11 @@ TEST(TranslatorBasicTest, valueFrom) { // Signed 32 bit integer. int32_t s32(-123456789); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(s32)); +#else s_val.reset(new Val(s32, SR_INT32_T)); +#endif EXPECT_NO_THROW(elem = TranslatorBasic::value(s_val)); ASSERT_TRUE(elem); ASSERT_EQ(Element::integer, elem->getType()); @@ -191,7 +215,11 @@ TEST(TranslatorBasicTest, getItem) { // Unsigned 8 bit integer. xpath = "/keatest-module:main/ui8"; uint8_t u8(8); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u8)); +#else s_val.reset(new Val(u8, SR_UINT8_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); EXPECT_NO_THROW(elem = t_obj->getItem(xpath)); ASSERT_TRUE(elem); @@ -202,7 +230,11 @@ TEST(TranslatorBasicTest, getItem) { // Unsigned 16 bit integer. xpath = "/keatest-module:main/ui16"; uint16_t u16(16); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u16)); +#else s_val.reset(new Val(u16, SR_UINT16_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); EXPECT_NO_THROW(elem = t_obj->getItem(xpath)); ASSERT_TRUE(elem); @@ -213,7 +245,11 @@ TEST(TranslatorBasicTest, getItem) { // Unsigned 32 bit integer. xpath = "/keatest-module:main/ui32"; uint32_t u32(32); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u32)); +#else s_val.reset(new Val(u32, SR_UINT32_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); EXPECT_NO_THROW(elem = t_obj->getItem(xpath)); ASSERT_TRUE(elem); @@ -224,7 +260,11 @@ TEST(TranslatorBasicTest, getItem) { // Signed 8 bit integer. xpath = "/keatest-module:main/i8"; int8_t s8(8); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(s8)); +#else s_val.reset(new Val(s8, SR_INT8_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); EXPECT_NO_THROW(elem = t_obj->getItem(xpath)); ASSERT_TRUE(elem); @@ -235,7 +275,11 @@ TEST(TranslatorBasicTest, getItem) { // Signed 16 bit integer. xpath = "/keatest-module:main/i16"; int16_t s16(16); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(s16)); +#else s_val.reset(new Val(s16, SR_INT16_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); EXPECT_NO_THROW(elem = t_obj->getItem(xpath)); ASSERT_TRUE(elem); @@ -246,7 +290,11 @@ TEST(TranslatorBasicTest, getItem) { // Signed 32 bit integer. xpath = "/keatest-module:main/i32"; int32_t s32(32); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(s32)); +#else s_val.reset(new Val(s32, SR_INT32_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); EXPECT_NO_THROW(elem = t_obj->getItem(xpath)); ASSERT_TRUE(elem); @@ -294,13 +342,25 @@ TEST(TranslatorBasicTest, getItem) { // Leaf-list: 1, 2 and 3. u8 = 1; +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u8)); +#else s_val.reset(new Val(u8, SR_UINT8_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); u8 = 2; +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u8)); +#else s_val.reset(new Val(u8, SR_UINT8_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); u8 = 3; +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u8)); +#else s_val.reset(new Val(u8, SR_UINT8_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); EXPECT_NO_THROW(elem = t_obj->getItems(xpath)); ASSERT_TRUE(elem); diff --git a/src/lib/yang/tests/translator_utils_unittests.cc b/src/lib/yang/tests/translator_utils_unittests.cc index 938028bb69..2bd374009d 100644 --- a/src/lib/yang/tests/translator_utils_unittests.cc +++ b/src/lib/yang/tests/translator_utils_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 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 @@ -84,32 +84,56 @@ TEST(YangReprTest, getTest) { xpath = "/keatest-module:main/ui8"; uint8_t u8(8); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u8)); +#else s_val.reset(new Val(u8, SR_UINT8_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); xpath = "/keatest-module:main/ui16"; uint16_t u16(16); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u16)); +#else s_val.reset(new Val(u16, SR_UINT16_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); xpath = "/keatest-module:main/ui32"; uint32_t u32(32); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u32)); +#else s_val.reset(new Val(u32, SR_UINT32_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); xpath = "/keatest-module:main/i8"; int8_t s8(8); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(s8)); +#else s_val.reset(new Val(s8, SR_INT8_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); xpath = "/keatest-module:main/i16"; int16_t s16(16); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(s16)); +#else s_val.reset(new Val(s16, SR_INT16_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); xpath = "/keatest-module:main/i32"; int32_t s32(32); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(s32)); +#else s_val.reset(new Val(s32, SR_INT32_T)); +#endif EXPECT_NO_THROW(sess->set_item(xpath.c_str(), s_val)); xpath = "/keatest-module:main/id_ref"; diff --git a/src/lib/yang/testutils/translator_test.cc b/src/lib/yang/testutils/translator_test.cc index bf542ccb6b..3418413648 100644 --- a/src/lib/yang/testutils/translator_test.cc +++ b/src/lib/yang/testutils/translator_test.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 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 @@ -187,7 +187,11 @@ YangRepr::set(const Tree& tree, S_Session session) const { case SR_UINT8_T: try { uint8_t u8 = boost::lexical_cast(item.value_); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u8)); +#else s_val.reset(new Val(u8, SR_UINT8_T)); +#endif } catch (const boost::bad_lexical_cast&) { isc_throw(BadValue, "'" << item.value_ << "' not an uint8"); @@ -197,7 +201,11 @@ YangRepr::set(const Tree& tree, S_Session session) const { case SR_UINT16_T: try { uint16_t u16 = boost::lexical_cast(item.value_); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u16)); +#else s_val.reset(new Val(u16, SR_UINT16_T)); +#endif } catch (const boost::bad_lexical_cast&) { isc_throw(BadValue, "'" << item.value_ << "' not an uint16"); @@ -207,7 +215,11 @@ YangRepr::set(const Tree& tree, S_Session session) const { case SR_UINT32_T: try { uint32_t u32 = boost::lexical_cast(item.value_); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(u32)); +#else s_val.reset(new Val(u32, SR_UINT32_T)); +#endif } catch (const boost::bad_lexical_cast&) { isc_throw(BadValue, "'" << item.value_ << "' not an uint32"); @@ -217,7 +229,11 @@ YangRepr::set(const Tree& tree, S_Session session) const { case SR_INT8_T: try { int8_t i8 = boost::lexical_cast(item.value_); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(i8)); +#else s_val.reset(new Val(i8, SR_INT8_T)); +#endif } catch (const boost::bad_lexical_cast&) { isc_throw(BadValue, "'" << item.value_ << "' not an int8"); @@ -227,7 +243,11 @@ YangRepr::set(const Tree& tree, S_Session session) const { case SR_INT16_T: try { int16_t i16 = boost::lexical_cast(item.value_); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(i16)); +#else s_val.reset(new Val(i16, SR_INT16_T)); +#endif } catch (const boost::bad_lexical_cast&) { isc_throw(BadValue, "'" << item.value_ << "' not an int16"); @@ -237,7 +257,11 @@ YangRepr::set(const Tree& tree, S_Session session) const { case SR_INT32_T: try { int32_t i32 = boost::lexical_cast(item.value_); +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(i32)); +#else s_val.reset(new Val(i32, SR_INT32_T)); +#endif } catch (const boost::bad_lexical_cast&) { isc_throw(BadValue, "'" << item.value_ << "' not an int32"); diff --git a/src/lib/yang/translator.cc b/src/lib/yang/translator.cc index d2983ccd49..aa5cc0ec5b 100644 --- a/src/lib/yang/translator.cc +++ b/src/lib/yang/translator.cc @@ -186,7 +186,11 @@ TranslatorBasic::value(ConstElementPtr elem, sr_type_t type) { "value for an integer called with not an integer: " << elem->str()); } +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(static_cast(elem->intValue()))); +#else s_val.reset(new Val(static_cast(elem->intValue()), type)); +#endif break; case SR_UINT16_T: @@ -195,7 +199,11 @@ TranslatorBasic::value(ConstElementPtr elem, sr_type_t type) { "value for an integer called with not an integer: " << elem->str()); } +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(static_cast(elem->intValue()))); +#else s_val.reset(new Val(static_cast(elem->intValue()), type)); +#endif break; case SR_UINT32_T: @@ -204,7 +212,11 @@ TranslatorBasic::value(ConstElementPtr elem, sr_type_t type) { "value for an integer called with not an integer: " << elem->str()); } +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(static_cast(elem->intValue()))); +#else s_val.reset(new Val(static_cast(elem->intValue()), type)); +#endif break; case SR_INT8_T: @@ -213,7 +225,11 @@ TranslatorBasic::value(ConstElementPtr elem, sr_type_t type) { "value for an integer called with not an integer: " << elem->str()); } +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(static_cast(elem->intValue()))); +#else s_val.reset(new Val(static_cast(elem->intValue()), type)); +#endif break; case SR_INT16_T: @@ -222,7 +238,11 @@ TranslatorBasic::value(ConstElementPtr elem, sr_type_t type) { "value for an integer called with not an integer: " << elem->str()); } +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(static_cast(elem->intValue()))); +#else s_val.reset(new Val(static_cast(elem->intValue()), type)); +#endif break; case SR_INT32_T: @@ -231,7 +251,11 @@ TranslatorBasic::value(ConstElementPtr elem, sr_type_t type) { "value for an integer called with not an integer: " << elem->str()); } +#ifdef HAVE_POST_0_7_7_SYSREPO + s_val.reset(new Val(static_cast(elem->intValue()))); +#else s_val.reset(new Val(static_cast(elem->intValue()), type)); +#endif break; case SR_BINARY_T: