12 #include <boost/foreach.hpp>
13 #include <boost/format.hpp>
20 #define BOOST_TEST_MODULE signal_cast_registerer
22 #if BOOST_VERSION >= 105900
23 #include <boost/test/tools/output_test_stream.hpp>
25 #include <boost/test/output_test_stream.hpp>
27 #include <boost/test/unit_test.hpp>
30 using boost::test_tools::output_test_stream;
39 typedef std::pair<std::string, std::string> test_t;
40 std::vector<test_t> values;
42 values.push_back(std::make_pair(
"42.0",
"42"));
43 values.push_back(std::make_pair(
"42.5",
"42.5"));
44 values.push_back(std::make_pair(
"-12.",
"-12"));
48 values.push_back(std::make_pair(
"inf",
"inf"));
49 values.push_back(std::make_pair(
"-inf",
"-inf"));
50 values.push_back(std::make_pair(
"nan",
"nan"));
52 BOOST_FOREACH (
const test_t &test, values) {
54 std::istringstream value(test.first);
59 output_test_stream output;
61 BOOST_CHECK_EQUAL(output.str(), test.second);
66 output_test_stream output;
67 mySignal.
trace(output);
68 BOOST_CHECK_EQUAL(output.str(), test.second);
74 std::istringstream value(
"This is not a valid double.");
75 BOOST_CHECK_THROW(mySignal.
set(value), std::exception);
84 output_test_stream output;
85 output << myVectorSignal;
86 BOOST_CHECK(output.is_equal(
"Sig:vector (Type Cst)"));
89 for (
unsigned int i = 0; i < 5; ++i) {
90 Vector v = Vector::Unit(5, i);
91 std::ostringstream os;
93 std::istringstream ss(
"[5](" + os.str() +
")");
96 myVectorSignal.
set(ss);
99 output_test_stream output;
100 myVectorSignal.
get(output);
102 boost::format fmt(
"%d %d %d %d %d");
103 fmt % (i == 0) % (i == 1) % (i == 2) % (i == 3) % (i == 4);
105 BOOST_CHECK(output.is_equal(fmt.str()));
112 std::istringstream ss(
"test");
113 myVectorSignal.
set(ss);
115 std::cout <<
"Test passed : ss[0] != \"[\"";
120 std::istringstream ss(
"[test");
121 myVectorSignal.
set(ss);
123 std::cout <<
"Test passed : ss[1] != %i";
128 std::istringstream ss(
"[5[");
129 myVectorSignal.
set(ss);
131 std::cout <<
"Test passed : ss[2] != \"]\"";
136 std::istringstream ss(
"[5]test");
137 myVectorSignal.
set(ss);
139 std::cout <<
"Test passed : ss[3] != \"(\"";
144 std::istringstream ss(
"[5](1, ");
145 myVectorSignal.
set(ss);
147 std::cout <<
"Test passed : ss[4] != \" \" || \",\"";
152 std::istringstream ss(
"[5](1,2,3,4,5]");
153 myVectorSignal.
set(ss);
155 std::cout <<
"Test passed : ss[-1] != \")\"";
159 output_test_stream output;
160 myVectorSignal.
trace(output);
162 std::cout <<
"Test passed : ss[-1] != \")\"";
171 output_test_stream output;
172 output << myMatrixSignal;
173 BOOST_CHECK(output.is_equal(
"Sig:matrix (Type Cst)"));
180 std::istringstream ss(
"test");
181 myMatrixSignal.
set(ss);
183 std::cout <<
"Test passed : ss[0] != \"[\"";
188 std::istringstream ss(
"[test");
189 myMatrixSignal.
set(ss);
191 std::cout <<
"Test passed : ss[1] != %i";
196 std::istringstream ss(
"[5[");
197 myMatrixSignal.
set(ss);
199 std::cout <<
"Test passed : ss[2] != \",\"";
204 std::istringstream ss(
"[5,c");
205 myMatrixSignal.
set(ss);
207 std::cout <<
"Test passed : ss[3] != %i";
212 std::istringstream ss(
"[5,3[");
213 myMatrixSignal.
set(ss);
215 std::cout <<
"Test passed : ss[4] != \"]\"";
220 std::istringstream ss(
"[5,3]test");
221 myMatrixSignal.
set(ss);
223 std::cout <<
"Test passed : ss[5] != \"(\"";
228 std::istringstream ss(
"[5,3](test");
229 myMatrixSignal.
set(ss);
231 std::cout <<
"Test passed : ss[6] != \"(\"";
236 std::istringstream ss(
"[5,3]((1,");
237 myMatrixSignal.
set(ss);
239 std::cout <<
"Test passed : ss[8] != \" \" || \",\"";
244 std::istringstream ss(
"[5,3]((1,2,3]");
245 myMatrixSignal.
set(ss);
247 std::cout << (
"ss[6+n] != \")\"");
252 std::istringstream ss(
"[5,1]((1)(2)(3[");
253 myMatrixSignal.
set(ss);
255 std::cout <<
"Test passed : ss[5] != \")\"";
260 std::istringstream ss(
"[5,1]((1)(2)(3)[");
261 myMatrixSignal.
set(ss);
263 std::cout <<
"Test passed : ss[5] != \")\"";
268 std::istringstream ss(
"[3,1]((1)(2),(3)[");
269 myMatrixSignal.
set(ss);
271 std::cout <<
"Test passed : ss[5] != \")\" and ignore \",\"";