Fix NetconfAccess not treating bools as bools
Change-Id: I024040efe78dd46e1fd89bd8e22f4942e80c7854
diff --git a/src/netconf_access.cpp b/src/netconf_access.cpp
index 9974fca..13fec88 100644
--- a/src/netconf_access.cpp
+++ b/src/netconf_access.cpp
@@ -33,7 +33,7 @@
case LY_TYPE_UINT64:
return value->uint64();
case LY_TYPE_BOOL:
- return value->bln();
+ return bool(value->bln());
case LY_TYPE_STRING:
return std::string(value->string());
case LY_TYPE_ENUM:
diff --git a/src/utils.cpp b/src/utils.cpp
index 979bda4..672cd36 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -113,6 +113,14 @@
return data;
}
+ std::string operator()(const bool& data) const
+ {
+ if (data)
+ return "true";
+ else
+ return "false";
+ }
+
template <typename T>
std::string operator()(const T& data) const
{
diff --git a/submodules/dependencies b/submodules/dependencies
index 7b0a5a7..512c7bc 160000
--- a/submodules/dependencies
+++ b/submodules/dependencies
@@ -1 +1 @@
-Subproject commit 7b0a5a712febbeb0623f0d2b0b0d94ab2bf1bd40
+Subproject commit 512c7bcd2c0cb9d31ef5e22288d60aa426863329
diff --git a/tests/sysrepo.cpp b/tests/sysrepo.cpp
index c544cf3..7125a9a 100644
--- a/tests/sysrepo.cpp
+++ b/tests/sysrepo.cpp
@@ -17,13 +17,27 @@
#error "Unknown backend"
#endif
#include "sysrepo_subscription.hpp"
+#include "utils.hpp"
class MockRecorder : public Recorder {
public:
MAKE_MOCK3(write, void(const std::string&, const std::string&, const std::string&), override);
};
-TEST_CASE("setting values")
+namespace std {
+std::ostream& operator<<(std::ostream& s, const std::map<std::string, leaf_data_> map)
+{
+ s << std::endl
+ << "{";
+ for (const auto& it : map) {
+ s << "{\"" << it.first << "\", " << leafDataToString(it.second) << "}" << std::endl;
+ }
+ s << "}" << std::endl;
+ return s;
+}
+}
+
+TEST_CASE("setting/getting values")
{
trompeloeil::sequence seq1;
MockRecorder mock;
@@ -161,6 +175,17 @@
datastore.commitChanges();
}
}
+ SECTION("bool values get correctly represented as bools")
+ {
+ {
+ REQUIRE_CALL(mock, write("/example-schema:down", "", "true"));
+ datastore.setLeaf("/example-schema:down", bool{true});
+ datastore.commitChanges();
+ }
+
+ std::map<std::string, leaf_data_> expected{{"/example-schema:down", bool{true}}};
+ REQUIRE(datastore.getItems("/example-schema:down") == expected);
+ }
waitForCompletionAndBitMore(seq1);
}