2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
20 /***************************************************************************
21 * Copyright (C) 2006-2011 by Intra2net AG *
23 ***************************************************************************/
25 // #include <iostream>
29 // #include <stdexcept>
31 #define BOOST_TEST_DYN_LINK
32 #include <boost/test/unit_test.hpp>
33 #include <boost/numeric/conversion/cast.hpp>
35 #include <stringfunc.hxx>
36 #include <containerfunc.hpp>
42 typedef std::list< std::string > StringList;
44 BOOST_AUTO_TEST_SUITE(stringfunc)
46 BOOST_AUTO_TEST_CASE(smart_html_entites1)
48 string output = smart_html_entities("Test");
50 BOOST_CHECK_EQUAL(string("Test"), output);
53 BOOST_AUTO_TEST_CASE(smart_html_entites2)
55 string output = smart_html_entities("Täst");
57 BOOST_CHECK_EQUAL(string("Täst"), output);
60 BOOST_AUTO_TEST_CASE(smart_html_entites3)
62 string output = smart_html_entities("<>");
64 BOOST_CHECK_EQUAL(string("<>"), output);
67 BOOST_AUTO_TEST_CASE(smart_html_entites4)
69 string output = smart_html_entities("<ümlaut>");
71 BOOST_CHECK_EQUAL(string("<ümlaut>"), output);
74 BOOST_AUTO_TEST_CASE(smart_html_entites5)
76 string output = smart_html_entities("Test<ümlaut>Blä");
78 BOOST_CHECK_EQUAL(string("Test<ümlaut>Blä"), output);
81 BOOST_AUTO_TEST_CASE(smart_html_entites6)
83 string output = smart_html_entities("System > Einstellungen");
85 BOOST_CHECK_EQUAL(string("System > Einstellungen"), output);
88 BOOST_AUTO_TEST_CASE(smart_html_entites7)
90 string output = smart_html_entities("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">\"System > Einstellungen\"</a>. Oder etwa nicht?");
92 BOOST_CHECK_EQUAL(string("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">"System > Einstellungen"</a>. Oder etwa nicht?"), output);
95 BOOST_AUTO_TEST_CASE(strip_html_tags1)
97 string output = strip_html_tags("Was für ein schöner Tag, finden Sie nicht?");
99 BOOST_CHECK_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
102 BOOST_AUTO_TEST_CASE(strip_html_tags2)
104 string output = strip_html_tags("Was für ein <a href=\"wikipedia\" target=\"new\">schöner Tag</a>, finden Sie nicht?");
106 BOOST_CHECK_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
111 BOOST_AUTO_TEST_CASE(html_entities1)
113 string output = html_entities("\xC3\xA4\xC3\xB6\xC3\xBC");
114 BOOST_CHECK_EQUAL(string("äöü"), output);
117 BOOST_AUTO_TEST_CASE(html_entities2)
119 string output = html_entities("\xC3\xA5 \xC3\xB5 \xC3\xBF");
120 BOOST_CHECK_EQUAL(string("å õ ÿ"), output);
123 BOOST_AUTO_TEST_CASE(html_entities3)
125 string output = html_entities("\xC4\x8E \xE0\xBC\xB1 \xE8\x82\x88");
126 BOOST_CHECK_EQUAL(string("Ď ༱ 肈"), output);
131 BOOST_AUTO_TEST_CASE(nice_unit_format1)
133 const int64_t two_bytes = 2;
135 string output = nice_unit_format(two_bytes, LongUnitFormat, UnitBase1000);
136 BOOST_CHECK_EQUAL(string("2.00 Bytes"), output);
138 output = nice_unit_format(two_bytes);
139 BOOST_CHECK_EQUAL(string("2.0 B"), output);
142 BOOST_AUTO_TEST_CASE(nice_unit_format2)
144 const int64_t two_kilobytes = 2000;
146 string output = nice_unit_format(two_kilobytes, LongUnitFormat, UnitBase1000);
147 BOOST_CHECK_EQUAL(string("2.00 KBytes"), output);
149 output = nice_unit_format(two_kilobytes);
150 BOOST_CHECK_EQUAL(string("2.0 KB"), output);
152 output = nice_unit_format(boost::numeric_cast<double>(two_kilobytes), LongUnitFormat, UnitBase1000);
153 BOOST_CHECK_EQUAL(string("2.00 KBytes"), output);
155 output = nice_unit_format(boost::numeric_cast<double>(two_kilobytes));
156 BOOST_CHECK_EQUAL(string("2.0 KB"), output);
158 const int64_t two_and_half_kilobytes = 2500;
160 output = nice_unit_format(two_and_half_kilobytes, LongUnitFormat, UnitBase1000);
161 BOOST_CHECK_EQUAL(string("2.50 KBytes"), output);
163 output = nice_unit_format(two_and_half_kilobytes);
164 BOOST_CHECK_EQUAL(string("2.4 KB"), output);
166 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_kilobytes), LongUnitFormat, UnitBase1000);
167 BOOST_CHECK_EQUAL(string("2.50 KBytes"), output);
169 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_kilobytes));
170 BOOST_CHECK_EQUAL(string("2.4 KB"), output);
173 BOOST_AUTO_TEST_CASE(nice_unit_format3)
175 const int64_t two_megabytes = 2000000;
177 string output = nice_unit_format(two_megabytes, LongUnitFormat, UnitBase1000);
178 BOOST_CHECK_EQUAL(string("2.00 MBytes"), output);
180 output = nice_unit_format(two_megabytes);
181 BOOST_CHECK_EQUAL(string("1.9 MB"), output);
183 output = nice_unit_format(boost::numeric_cast<double>(two_megabytes), LongUnitFormat, UnitBase1000);
184 BOOST_CHECK_EQUAL(string("2.00 MBytes"), output);
186 output = nice_unit_format(boost::numeric_cast<double>(two_megabytes));
187 BOOST_CHECK_EQUAL(string("1.9 MB"), output);
189 const int64_t two_and_half_megabytes = 2500000;
191 output = nice_unit_format(two_and_half_megabytes, LongUnitFormat, UnitBase1000);
192 BOOST_CHECK_EQUAL(string("2.50 MBytes"), output);
194 output = nice_unit_format(two_and_half_megabytes);
195 BOOST_CHECK_EQUAL(string("2.4 MB"), output);
197 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_megabytes), LongUnitFormat, UnitBase1000);
198 BOOST_CHECK_EQUAL(string("2.50 MBytes"), output);
200 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_megabytes));
201 BOOST_CHECK_EQUAL(string("2.4 MB"), output);
205 BOOST_AUTO_TEST_CASE(nice_unit_format4)
207 const int64_t two_gigabytes = 2000000000LL;
209 string output = nice_unit_format(two_gigabytes, LongUnitFormat, UnitBase1000);
210 BOOST_CHECK_EQUAL(string("2.00 GBytes"), output);
212 output = nice_unit_format(two_gigabytes);
213 BOOST_CHECK_EQUAL(string("1.9 GB"), output);
215 output = nice_unit_format(boost::numeric_cast<double>(two_gigabytes), LongUnitFormat, UnitBase1000);
216 BOOST_CHECK_EQUAL(string("2.00 GBytes"), output);
218 output = nice_unit_format(boost::numeric_cast<double>(two_gigabytes));
219 BOOST_CHECK_EQUAL(string("1.9 GB"), output);
221 const int64_t two_and_half_gigabytes = 2500000000LL;
223 output = nice_unit_format(two_and_half_gigabytes, LongUnitFormat, UnitBase1000);
224 BOOST_CHECK_EQUAL(string("2.50 GBytes"), output);
226 output = nice_unit_format(two_and_half_gigabytes);
227 BOOST_CHECK_EQUAL(string("2.3 GB"), output);
229 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_gigabytes), LongUnitFormat, UnitBase1000);
230 BOOST_CHECK_EQUAL(string("2.50 GBytes"), output);
232 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_gigabytes));
233 BOOST_CHECK_EQUAL(string("2.3 GB"), output);
236 BOOST_AUTO_TEST_CASE(nice_unit_format5)
238 const int64_t two_terabytes = 2000000000000LL;
240 string output = nice_unit_format(two_terabytes, LongUnitFormat, UnitBase1000);
241 BOOST_CHECK_EQUAL(string("2.00 TBytes"), output);
243 output = nice_unit_format(two_terabytes);
244 BOOST_CHECK_EQUAL(string("1.8 TB"), output);
246 output = nice_unit_format(boost::numeric_cast<double>(two_terabytes), LongUnitFormat, UnitBase1000);
247 BOOST_CHECK_EQUAL(string("2.00 TBytes"), output);
249 output = nice_unit_format(boost::numeric_cast<double>(two_terabytes));
250 BOOST_CHECK_EQUAL(string("1.8 TB"), output);
252 const int64_t two_and_half_terabytes = 2500000000000LL;
254 output = nice_unit_format(two_and_half_terabytes, LongUnitFormat, UnitBase1000);
255 BOOST_CHECK_EQUAL(string("2.50 TBytes"), output);
257 output = nice_unit_format(two_and_half_terabytes);
258 BOOST_CHECK_EQUAL(string("2.3 TB"), output);
260 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_terabytes), LongUnitFormat, UnitBase1000);
261 BOOST_CHECK_EQUAL(string("2.50 TBytes"), output);
263 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_terabytes));
264 BOOST_CHECK_EQUAL(string("2.3 TB"), output);
267 BOOST_AUTO_TEST_CASE(nice_unit_format6)
269 const int64_t two_petabytes = 2000000000000000LL;
271 string output = nice_unit_format(two_petabytes, LongUnitFormat, UnitBase1000);
272 BOOST_CHECK_EQUAL(string("2.00 PBytes"), output);
274 output = nice_unit_format(two_petabytes);
275 BOOST_CHECK_EQUAL(string("1.8 PB"), output);
277 output = nice_unit_format(boost::numeric_cast<double>(two_petabytes), LongUnitFormat, UnitBase1000);
278 BOOST_CHECK_EQUAL(string("2.00 PBytes"), output);
280 output = nice_unit_format(boost::numeric_cast<double>(two_petabytes));
281 BOOST_CHECK_EQUAL(string("1.8 PB"), output);
283 const int64_t two_and_half_petabytes = 2500000000000000LL;
285 output = nice_unit_format(two_and_half_petabytes, LongUnitFormat, UnitBase1000);
286 BOOST_CHECK_EQUAL(string("2.50 PBytes"), output);
288 output = nice_unit_format(two_and_half_petabytes);
289 BOOST_CHECK_EQUAL(string("2.2 PB"), output);
291 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_petabytes), LongUnitFormat, UnitBase1000);
292 BOOST_CHECK_EQUAL(string("2.50 PBytes"), output);
294 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_petabytes));
295 BOOST_CHECK_EQUAL(string("2.2 PB"), output);
298 BOOST_AUTO_TEST_CASE(nice_unit_format7)
300 const int64_t two_exabytes = 2000000000000000000LL;
302 string output = nice_unit_format(two_exabytes, LongUnitFormat, UnitBase1000);
303 BOOST_CHECK_EQUAL(string("2000.00 PBytes"), output);
305 output = nice_unit_format(two_exabytes);
306 BOOST_CHECK_EQUAL(string("1776.4 PB"), output);
308 output = nice_unit_format(boost::numeric_cast<double>(two_exabytes), LongUnitFormat, UnitBase1000);
309 BOOST_CHECK_EQUAL(string("2000.00 PBytes"), output);
311 output = nice_unit_format(boost::numeric_cast<double>(two_exabytes));
312 BOOST_CHECK_EQUAL(string("1776.4 PB"), output);
314 const int64_t two_and_half_exabytes = 2500000000000000000LL;
316 output = nice_unit_format(two_and_half_exabytes, LongUnitFormat, UnitBase1000);
317 BOOST_CHECK_EQUAL(string("2500.00 PBytes"), output);
319 output = nice_unit_format(two_and_half_exabytes);
320 BOOST_CHECK_EQUAL(string("2220.4 PB"), output);
322 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_exabytes), LongUnitFormat, UnitBase1000);
323 BOOST_CHECK_EQUAL(string("2500.00 PBytes"), output);
325 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_exabytes));
326 BOOST_CHECK_EQUAL(string("2220.4 PB"), output);
329 BOOST_AUTO_TEST_CASE(nice_unit_format8)
331 const int64_t max_representable_64bits_number = 9223372036854775807LL;
333 string output = nice_unit_format(max_representable_64bits_number, LongUnitFormat, UnitBase1000);
334 BOOST_CHECK_EQUAL(string("9223.40 PBytes"), output);
336 output = nice_unit_format(max_representable_64bits_number);
337 BOOST_CHECK_EQUAL(string("8192.0 PB"), output);
340 double val = boost::numeric_cast<double>(max_representable_64bits_number);
341 BOOST_MESSAGE("val as int64 is " << max_representable_64bits_number << " and as double is " << val);
342 BOOST_MESSAGE("val rounded is " << round(val));
343 BOOST_CHECK_EQUAL(val, round(val));
344 BOOST_MESSAGE("half as int64 is " << boost::numeric_cast<int64_t>(round(val/2))); // ok
345 BOOST_MESSAGE("cast back is " << boost::numeric_cast<int64_t>(round(val))); // throws a positive overflow
346 output = nice_unit_format(boost::numeric_cast<double>(max_representable_64bits_number), LongUnitFormat, UnitBase1000);
347 BOOST_CHECK_EQUAL(string("9223.40 PBytes"), output);
349 output = nice_unit_format(boost::numeric_cast<double>(max_representable_64bits_number));
350 BOOST_CHECK_EQUAL(string("8192.0 PB"), output);
354 BOOST_AUTO_TEST_CASE(TestTrim)
358 BOOST_CHECK_EQUAL( std::string("s1"), s );
362 BOOST_CHECK_EQUAL( std::string("s2"), s );
366 BOOST_CHECK_EQUAL( std::string("s3"), s );
370 BOOST_CHECK_EQUAL( std::string("s4:s4"), s);
372 /* non modifying version */
375 BOOST_CHECK_EQUAL( std::string("s1"), trim(s) );
378 BOOST_CHECK_EQUAL( std::string("s2"), trim(s) );
379 BOOST_CHECK_EQUAL( std::string(" s2"), s );
382 BOOST_CHECK_EQUAL( std::string("s3"), trim(s) );
383 BOOST_CHECK_EQUAL( std::string("s3 "), s );
386 BOOST_CHECK_EQUAL( std::string("s4:s4"), trim(s,":+-a") );
391 BOOST_AUTO_TEST_CASE(TestChomp)
396 BOOST_CHECK_EQUAL( std::string("s1"), s );
400 BOOST_CHECK_EQUAL( std::string("s2"), s );
404 BOOST_CHECK_EQUAL( std::string("s3"), s );
408 BOOST_CHECK_EQUAL( std::string(":s4:"), s);
410 /* non modifiying versions */
413 BOOST_CHECK_EQUAL( std::string("s1"), chomp(s) );
416 BOOST_CHECK_EQUAL( std::string("s2"), chomp(s) );
417 BOOST_CHECK_EQUAL( std::string("s2\n"), s);
420 BOOST_CHECK_EQUAL( std::string("s3"), chomp(s,":") );
421 BOOST_CHECK_EQUAL( std::string("s3:"), s);
424 BOOST_CHECK_EQUAL( std::string(":s4:"), chomp(s,"s:") );
425 BOOST_CHECK_EQUAL( std::string(":s4::"), s);
430 BOOST_AUTO_TEST_CASE(TestSuffixFuncs)
432 std::string s1("12.cpp");
434 BOOST_CHECK_EQUAL( true, has_suffix(s1,".cpp") );
435 BOOST_CHECK_EQUAL( true, has_suffix(s1,"pp") );
436 BOOST_CHECK_EQUAL( false, has_suffix(s1,"hpp") );
437 BOOST_CHECK_EQUAL( false, has_suffix(s1,"cp") );
438 BOOST_CHECK_EQUAL( false, has_suffix(s1,"") );
440 std::string s1c1= remove_suffix(s1,".cpp");
441 BOOST_CHECK_EQUAL( std::string("12"), s1c1 );
443 std::string s1c2= remove_suffix(s1,"p");
444 BOOST_CHECK_EQUAL( std::string("12.cp"), s1c2 );
446 std::string s1c3= remove_suffix(s1,"cp");
447 BOOST_CHECK_EQUAL( std::string("12.cpp"), s1c3 );
449 std::string s2(".cpp");
450 BOOST_CHECK_EQUAL( true, has_suffix(s2,".cpp") );
452 std::string s2c1= remove_suffix(s2,".cpp");
453 BOOST_CHECK_EQUAL( std::string(""), s2c1 );
455 } // eo TestSuffixFuncs()
459 BOOST_AUTO_TEST_CASE(TestPrefixFuncs)
461 std::string s1("12.cpp");
463 BOOST_CHECK_EQUAL( true, has_prefix(s1,"12") );
464 BOOST_CHECK_EQUAL( true, has_prefix(s1, "1") );
465 BOOST_CHECK_EQUAL( false, has_prefix(s1, "2") );
466 BOOST_CHECK_EQUAL( false, has_prefix(s1, "") );
468 std::string s1c1= remove_prefix(s1, "12");
469 BOOST_CHECK_EQUAL( std::string(".cpp"), s1c1);
470 } // eo TestPrefixFuncs()
474 BOOST_AUTO_TEST_CASE(TestLowerUpperFuncs)
476 std::string u1("CASE CONVERSION TEST..");
477 std::string l1("case conversion test..");
479 std::string test1(l1);
482 BOOST_CHECK_EQUAL( u1, test1 );
485 BOOST_CHECK_EQUAL( l1, test1 );
488 BOOST_CHECK_EQUAL( u1, to_upper(l1) );
489 BOOST_CHECK_EQUAL( l1, to_lower(u1) );
490 } // eo TestLowerUpper
494 BOOST_AUTO_TEST_CASE(PairSplit1)
497 get_push_back_filler(str_list)
498 ("a=11")("a= 11")("a =11 ")("a = 11 ")(" a = 11 ")
500 BOOST_CHECK_EQUAL( 5u, str_list.size() );
501 for(StringList::iterator it= str_list.begin();
502 it != str_list.end();
505 std::string key, value;
506 bool res= pair_split( *it, key, value);
508 BOOST_CHECK_EQUAL( true , res );
509 BOOST_CHECK_EQUAL( std::string("a"), key );
510 BOOST_CHECK_EQUAL( std::string("11"), value );
513 std::string key, value;
516 res= pair_split(" 1 : 2 ", key, value, ':');
517 BOOST_CHECK_EQUAL( true, res );
518 BOOST_CHECK_EQUAL( std::string("1"), key);
519 BOOST_CHECK_EQUAL( std::string("2"), value);
524 BOOST_AUTO_TEST_CASE(SplitString1)
536 split_string(block, list1, "\n");
537 // since the blocks ends with \n we should have 6 lines (the last one empty):
538 BOOST_CHECK_EQUAL( 6u, list1.size() );
539 BOOST_CHECK_EQUAL( std::string(), list1.back() );
540 BOOST_CHECK_EQUAL( std::string("Zeile 1"), list1.front() );
544 split_string(block, list2, "\n", true);
546 // now we omitted empty lines, now we should have only 4 lines left:
547 BOOST_CHECK_EQUAL( 4u, list2.size() );
548 BOOST_CHECK_EQUAL( std::string("Zeile 5"), list2.back() );
549 BOOST_CHECK_EQUAL( std::string("Zeile 1"), list2.front() );
551 list2= split_string(block, "\n", true, "+-");
553 // again, we omitted empty lines, but also trimmed away leading and trailing "+" and "-"
554 BOOST_CHECK_EQUAL( 4u, list2.size() );
555 BOOST_CHECK_EQUAL( std::string("Zeile 5"), list2.back() );
556 BOOST_CHECK_EQUAL( std::string("Zeile 1"), list2.front() );
557 BOOST_CHECK_EQUAL( std::string("Zeile-2"), *(++list2.begin()) );
562 BOOST_AUTO_TEST_CASE(SplitString2)
564 std::string line("172.16.0.0/16 dev eth0 scope link src 172.16.1.111");
568 split_string(line, list1, " ", true, Whitespaces);
570 BOOST_CHECK_EQUAL( 7u, list1.size() );
576 BOOST_AUTO_TEST_CASE(SplitStringEmpty)
578 std::string line("");
582 split_string(line, list1, " ", true, Whitespaces);
584 BOOST_CHECK_EQUAL( 0u, list1.size() );
585 } // eo SplitStringEmpty
588 BOOST_AUTO_TEST_CASE(SplitStringDelimiterOnly)
590 std::string line(" ");
594 split_string(line, list1, " ", true, Whitespaces);
596 BOOST_CHECK_EQUAL( 0u, list1.size() );
597 } // eo SplitStringDelimiterOnly
601 BOOST_AUTO_TEST_CASE(JoinString1)
603 std::list< std::string > parts;
604 get_push_back_filler(parts)("1")("2")("drei");
606 std::string joined_string= join_string(parts,"/");
607 // we should have slashes between the strings:
608 BOOST_CHECK_EQUAL( std::string("1/2/drei") , joined_string );
610 parts.push_back( std::string() );
611 joined_string= join_string(parts,"/");
612 // now we should have an additional trailing slash:
613 BOOST_CHECK_EQUAL( std::string("1/2/drei/") , joined_string );
615 parts.push_front( std::string() );
616 joined_string= join_string(parts,"/");
617 // now we should have an additional leading slash:
618 BOOST_CHECK_EQUAL( std::string("/1/2/drei/") , joined_string );
624 BOOST_AUTO_TEST_CASE(ConversionStringInt)
626 std::string s1("24");
627 std::string s1x("25x");
631 i1= string_to<int>(s1);
632 BOOST_CHECK_EQUAL( 24, i1 );
633 i1= string_to<int>(s1x);
634 BOOST_CHECK_EQUAL( 25, i1 );
636 res= string_to<int>(s1,i1);
637 BOOST_CHECK_EQUAL( true, res );
638 BOOST_CHECK_EQUAL( 24, i1 );
640 res= string_to<int>(s1x,i1);
641 BOOST_CHECK_EQUAL( false, res );
643 std::string ss1= to_string( 24 );
644 BOOST_CHECK_EQUAL( std::string("24"), ss1);
646 } // eo ConversionStringInt()
650 BOOST_AUTO_TEST_CASE(HexBinaryConversion)
652 std::string hex1("49324E");
653 std::string bin1("I2N");
655 BOOST_CHECK_EQUAL( hex1, convert_binary_to_hex(bin1,true) );
656 BOOST_CHECK_EQUAL( bin1, convert_hex_to_binary(hex1) );
657 BOOST_CHECK_EQUAL( to_lower(hex1), convert_binary_to_hex(bin1) );
659 std::string hex2("0001");
660 std::string hex2a("00 01");
661 std::string hex2b("00:01");
662 std::string bin2("\0\1",2);
664 BOOST_CHECK_EQUAL( hex2, convert_binary_to_hex(bin2) );
665 BOOST_CHECK_EQUAL( bin2, convert_hex_to_binary(hex2) );
666 BOOST_CHECK_EQUAL( bin2, convert_hex_to_binary(hex2a) );
667 BOOST_CHECK_EQUAL( bin2, convert_hex_to_binary(hex2b) );
669 BOOST_REQUIRE_THROW( convert_hex_to_binary("01 kein hex"), std::runtime_error);
670 } // eo HexConversion()
672 BOOST_AUTO_TEST_CASE(HexIntConversion)
674 BOOST_CHECK_EQUAL( 255 , hex_string_to<uint32_t>("ff") );
675 BOOST_CHECK_EQUAL( 18866985 , hex_string_to<uint32_t>("11FE329") );
676 BOOST_CHECK_EQUAL( 44 , hex_string_to<uint32_t>("0x2C") );
679 BOOST_AUTO_TEST_CASE(sanitize_for_logging1)
681 string output = sanitize_for_logging("normaler string ohne aerger");
683 BOOST_CHECK_EQUAL(string("normaler string ohne aerger"), output);
686 BOOST_AUTO_TEST_CASE(sanitize_for_logging2)
688 string to_test="fiese";
689 to_test.push_back(0);
692 string output = sanitize_for_logging(to_test);
694 BOOST_CHECK_EQUAL(string("fiese?null"), output);
697 BOOST_AUTO_TEST_CASE(sanitize_for_logging3)
699 string output = sanitize_for_logging("läuter ümlaute utf8");
701 BOOST_CHECK_EQUAL(string("l??uter ??mlaute utf8"), output);
704 BOOST_AUTO_TEST_SUITE_END()