1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
From 530c3bbb89c0115d58ba7bcc4dd7d15d0182e259 Mon Sep 17 00:00:00 2001
From: Thomas Braun <thomas.braun@byte-physics.de>
Date: Thu, 1 May 2025 14:29:28 +0200
Subject: [PATCH 5/5] Attribute::set_upd_properties: Handle no database case
gracefully
When trying to set the attribute configuration without database, we used
to crash inside Attribute::db_access as the returned pointer from get_database() was not valid.
We now skip the database update similiar to what is done in
DeviceImpl::set_attribute_config.
---
src/include/tango/server/attribute_templ.h | 5 ++-
tests/CMakeLists.txt | 1 +
tests/catch2_attr_conf_event.cpp | 51 ++++++++++++++++++++++
3 files changed, 56 insertions(+), 1 deletion(-)
create mode 100644 tests/catch2_attr_conf_event.cpp
diff --git a/lib/cpp/src/include/tango/server/attribute_templ.h b/lib/cpp/src/include/tango/server/attribute_templ.h
index b05843a26..e5e98888d 100644
--- a/lib/cpp/src/include/tango/server/attribute_templ.h
+++ b/lib/cpp/src/include/tango/server/attribute_templ.h
@@ -1357,7 +1357,10 @@ void Attribute::set_upd_properties(const T &conf, const std::string &dev_name, b
try
{
- upd_database(v_db);
+ if(Tango::Util::instance()->use_db())
+ {
+ upd_database(v_db);
+ }
}
catch(DevFailed &)
{
diff --git a/lib/cpp/tests/CMakeLists.txt b/lib/cpp/tests/CMakeLists.txt
index 64b957559..83db6fe97 100644
--- a/lib/cpp/tests/CMakeLists.txt
+++ b/lib/cpp/tests/CMakeLists.txt
@@ -309,6 +309,7 @@ tango_catch2_tests_create(
catch2_alarm.cpp
catch2_attr_manip.cpp
catch2_attr_proxy.cpp
+ catch2_attr_conf_event.cpp
catch2_attr_polling.cpp
catch2_cmd_polling.cpp
catch2_connection.cpp
diff --git a/lib/cpp/tests/catch2_attr_conf_event.cpp b/lib/cpp/tests/catch2_attr_conf_event.cpp
new file mode 100644
index 000000000..aea73316b
--- /dev/null
+++ b/lib/cpp/tests/catch2_attr_conf_event.cpp
@@ -0,0 +1,51 @@
+#include "catch2_common.h"
+
+static constexpr double k_initial_value{1.1234};
+
+template <class Base>
+class AttrConfEventData : public Base
+{
+ public:
+ using Base::Base;
+
+ void init_device() override { }
+
+ void read_attr(Tango::Attribute &att) override
+ {
+ att.set_value(&attr_dq_double);
+ }
+
+ static void attribute_factory(std::vector<Tango::Attr *> &attrs)
+ {
+ attrs.push_back(new TangoTest::AutoAttr<&AttrConfEventData::read_attr>("double_attr", Tango::DEV_DOUBLE));
+ }
+
+ private:
+ Tango::DevDouble attr_dq_double{k_initial_value};
+};
+
+TANGO_TEST_AUTO_DEV_TMPL_INSTANTIATE(AttrConfEventData, 1)
+
+SCENARIO("Setting AttributeConfig works without database")
+{
+ int idlver = GENERATE(TangoTest::idlversion(1));
+ GIVEN("a device proxy to a simple IDLv" << idlver << " device")
+ {
+ TangoTest::Context ctx{"double_attr", "AttrConfEventData", idlver};
+ auto device = ctx.get_proxy();
+
+ REQUIRE(idlver == device->get_idl_version());
+
+ THEN("we can change the attribute configuration")
+ {
+ std::string attr{"double_attr"};
+ auto ai = device->attribute_query(attr);
+ ai.events.ch_event.abs_change = "33333";
+ ai.events.ch_event.rel_change = "99.99";
+
+ Tango::AttributeInfoListEx ail;
+ ail.push_back(ai);
+ REQUIRE_NOTHROW(device->set_attribute_config(ail));
+ }
+ }
+}
--
2.39.5
|