From a84511619a8a056d1d9005feb9ba088565a6c091 Mon Sep 17 00:00:00 2001
From: Florent Lamiraux <florent@laas.fr>
Date: Mon, 21 Oct 2019 19:57:48 +0200
Subject: [PATCH] Fix DefaultCastRegisterer<std::string>::cast

  - when signal value contained a space, only the part before the space
    was stored in the signal.
  - add a test on this case.
---
 src/signal/signal-cast-helper.cpp |  3 +--
 tests/signal-ptr.cpp              | 17 +++++++++++++----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/signal/signal-cast-helper.cpp b/src/signal/signal-cast-helper.cpp
index 9b1323f..633ab5f 100644
--- a/src/signal/signal-cast-helper.cpp
+++ b/src/signal/signal-cast-helper.cpp
@@ -79,8 +79,7 @@ template <>
 inline boost::any DefaultCastRegisterer<std::string>::cast
 (std::istringstream &iss)
 {
-  std::string inst ("");
-  iss >> inst;
+  std::string inst (iss.str ());
   return inst;
 }
 
diff --git a/tests/signal-ptr.cpp b/tests/signal-ptr.cpp
index dfe54c9..a2fc5b5 100644
--- a/tests/signal-ptr.cpp
+++ b/tests/signal-ptr.cpp
@@ -92,12 +92,21 @@ BOOST_AUTO_TEST_CASE (plug_signal_string)
   Signal<std::string, int> outSig("output");
   SignalPtr<std::string, int> inSig (NULL, "input");
 
-  std::string str ("value");
+  std::string str ("two words");
   outSig.setConstant(str);
   inSig.plug (&outSig);
   inSig.recompute(1);
-  std::ostringstream os;
-  inSig.get (os);
-  std::string res (os.str ());
+  std::ostringstream os1;
+  inSig.get (os1);
+  std::string res (os1.str ());
+  BOOST_CHECK (res == str);
+
+  Signal<std::string, int> s ("signal");
+  std::ostringstream os2;
+  s.setConstant (str);
+  os2.clear ();
+  s.get (os2);
+  res = os2.str ();
+  std::cout << "res=" << res << std::endl;
   BOOST_CHECK (res == str);
 }
-- 
GitLab