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>
43 typedef std::list< std::string > StringList;
45 BOOST_AUTO_TEST_SUITE(stringfunc)
47 BOOST_AUTO_TEST_CASE(smart_html_entites1)
49 string output = smart_html_entities("Test");
51 BOOST_CHECK_EQUAL(string("Test"), output);
54 BOOST_AUTO_TEST_CASE(smart_html_entites2)
56 string output = smart_html_entities("Täst");
58 BOOST_CHECK_EQUAL(string("Täst"), output);
61 BOOST_AUTO_TEST_CASE(smart_html_entites3)
63 string output = smart_html_entities("<>");
65 BOOST_CHECK_EQUAL(string("<>"), output);
68 BOOST_AUTO_TEST_CASE(smart_html_entites4)
70 string output = smart_html_entities("<ümlaut>");
72 BOOST_CHECK_EQUAL(string("<ümlaut>"), output);
75 BOOST_AUTO_TEST_CASE(smart_html_entites5)
77 string output = smart_html_entities("Test<ümlaut>Blä");
79 BOOST_CHECK_EQUAL(string("Test<ümlaut>Blä"), output);
82 BOOST_AUTO_TEST_CASE(smart_html_entites6)
84 string output = smart_html_entities("System > Einstellungen");
86 BOOST_CHECK_EQUAL(string("System > Einstellungen"), output);
89 BOOST_AUTO_TEST_CASE(smart_html_entites7)
91 string output = smart_html_entities("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">\"System > Einstellungen\"</a>. Oder etwa nicht?");
93 BOOST_CHECK_EQUAL(string("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">"System > Einstellungen"</a>. Oder etwa nicht?"), output);
96 BOOST_AUTO_TEST_CASE(strip_html_tags1)
98 string output = strip_html_tags("Was für ein schöner Tag, finden Sie nicht?");
100 BOOST_CHECK_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
103 BOOST_AUTO_TEST_CASE(strip_html_tags2)
105 string output = strip_html_tags("Was für ein <a href=\"wikipedia\" target=\"new\">schöner Tag</a>, finden Sie nicht?");
107 BOOST_CHECK_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
112 BOOST_AUTO_TEST_CASE(html_entities1)
114 string output = html_entities("\xC3\xA4\xC3\xB6\xC3\xBC");
115 BOOST_CHECK_EQUAL(string("äöü"), output);
118 BOOST_AUTO_TEST_CASE(html_entities2)
120 string output = html_entities("\xC3\xA5 \xC3\xB5 \xC3\xBF");
121 BOOST_CHECK_EQUAL(string("å õ ÿ"), output);
124 BOOST_AUTO_TEST_CASE(html_entities3)
126 string output = html_entities("\xC4\x8E \xE0\xBC\xB1 \xE8\x82\x88");
127 BOOST_CHECK_EQUAL(string("Ď ༱ 肈"), output);
132 BOOST_AUTO_TEST_CASE(nice_unit_format1)
134 const int64_t two_bytes = 2;
136 string output = nice_unit_format(two_bytes, LongUnitFormat, UnitBase1000);
137 BOOST_CHECK_EQUAL(string("2.00 Bytes"), output);
139 output = nice_unit_format(two_bytes);
140 BOOST_CHECK_EQUAL(string("2.0 B"), output);
143 BOOST_AUTO_TEST_CASE(nice_unit_format2)
145 const int64_t two_kilobytes = 2000;
147 string output = nice_unit_format(two_kilobytes, LongUnitFormat, UnitBase1000);
148 BOOST_CHECK_EQUAL(string("2.00 KBytes"), output);
150 output = nice_unit_format(two_kilobytes);
151 BOOST_CHECK_EQUAL(string("2.0 KB"), output);
153 output = nice_unit_format(boost::numeric_cast<double>(two_kilobytes), LongUnitFormat, UnitBase1000);
154 BOOST_CHECK_EQUAL(string("2.00 KBytes"), output);
156 output = nice_unit_format(boost::numeric_cast<double>(two_kilobytes));
157 BOOST_CHECK_EQUAL(string("2.0 KB"), output);
159 const int64_t two_and_half_kilobytes = 2500;
161 output = nice_unit_format(two_and_half_kilobytes, LongUnitFormat, UnitBase1000);
162 BOOST_CHECK_EQUAL(string("2.50 KBytes"), output);
164 output = nice_unit_format(two_and_half_kilobytes);
165 BOOST_CHECK_EQUAL(string("2.4 KB"), output);
167 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_kilobytes), LongUnitFormat, UnitBase1000);
168 BOOST_CHECK_EQUAL(string("2.50 KBytes"), output);
170 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_kilobytes));
171 BOOST_CHECK_EQUAL(string("2.4 KB"), output);
174 BOOST_AUTO_TEST_CASE(nice_unit_format3)
176 const int64_t two_megabytes = 2000000;
178 string output = nice_unit_format(two_megabytes, LongUnitFormat, UnitBase1000);
179 BOOST_CHECK_EQUAL(string("2.00 MBytes"), output);
181 output = nice_unit_format(two_megabytes);
182 BOOST_CHECK_EQUAL(string("1.9 MB"), output);
184 output = nice_unit_format(boost::numeric_cast<double>(two_megabytes), LongUnitFormat, UnitBase1000);
185 BOOST_CHECK_EQUAL(string("2.00 MBytes"), output);
187 output = nice_unit_format(boost::numeric_cast<double>(two_megabytes));
188 BOOST_CHECK_EQUAL(string("1.9 MB"), output);
190 const int64_t two_and_half_megabytes = 2500000;
192 output = nice_unit_format(two_and_half_megabytes, LongUnitFormat, UnitBase1000);
193 BOOST_CHECK_EQUAL(string("2.50 MBytes"), output);
195 output = nice_unit_format(two_and_half_megabytes);
196 BOOST_CHECK_EQUAL(string("2.4 MB"), output);
198 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_megabytes), LongUnitFormat, UnitBase1000);
199 BOOST_CHECK_EQUAL(string("2.50 MBytes"), output);
201 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_megabytes));
202 BOOST_CHECK_EQUAL(string("2.4 MB"), output);
206 BOOST_AUTO_TEST_CASE(nice_unit_format4)
208 const int64_t two_gigabytes = 2000000000LL;
210 string output = nice_unit_format(two_gigabytes, LongUnitFormat, UnitBase1000);
211 BOOST_CHECK_EQUAL(string("2.00 GBytes"), output);
213 output = nice_unit_format(two_gigabytes);
214 BOOST_CHECK_EQUAL(string("1.9 GB"), output);
216 output = nice_unit_format(boost::numeric_cast<double>(two_gigabytes), LongUnitFormat, UnitBase1000);
217 BOOST_CHECK_EQUAL(string("2.00 GBytes"), output);
219 output = nice_unit_format(boost::numeric_cast<double>(two_gigabytes));
220 BOOST_CHECK_EQUAL(string("1.9 GB"), output);
222 const int64_t two_and_half_gigabytes = 2500000000LL;
224 output = nice_unit_format(two_and_half_gigabytes, LongUnitFormat, UnitBase1000);
225 BOOST_CHECK_EQUAL(string("2.50 GBytes"), output);
227 output = nice_unit_format(two_and_half_gigabytes);
228 BOOST_CHECK_EQUAL(string("2.3 GB"), output);
230 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_gigabytes), LongUnitFormat, UnitBase1000);
231 BOOST_CHECK_EQUAL(string("2.50 GBytes"), output);
233 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_gigabytes));
234 BOOST_CHECK_EQUAL(string("2.3 GB"), output);
237 BOOST_AUTO_TEST_CASE(nice_unit_format5)
239 const int64_t two_terabytes = 2000000000000LL;
241 string output = nice_unit_format(two_terabytes, LongUnitFormat, UnitBase1000);
242 BOOST_CHECK_EQUAL(string("2.00 TBytes"), output);
244 output = nice_unit_format(two_terabytes);
245 BOOST_CHECK_EQUAL(string("1.8 TB"), output);
247 output = nice_unit_format(boost::numeric_cast<double>(two_terabytes), LongUnitFormat, UnitBase1000);
248 BOOST_CHECK_EQUAL(string("2.00 TBytes"), output);
250 output = nice_unit_format(boost::numeric_cast<double>(two_terabytes));
251 BOOST_CHECK_EQUAL(string("1.8 TB"), output);
253 const int64_t two_and_half_terabytes = 2500000000000LL;
255 output = nice_unit_format(two_and_half_terabytes, LongUnitFormat, UnitBase1000);
256 BOOST_CHECK_EQUAL(string("2.50 TBytes"), output);
258 output = nice_unit_format(two_and_half_terabytes);
259 BOOST_CHECK_EQUAL(string("2.3 TB"), output);
261 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_terabytes), LongUnitFormat, UnitBase1000);
262 BOOST_CHECK_EQUAL(string("2.50 TBytes"), output);
264 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_terabytes));
265 BOOST_CHECK_EQUAL(string("2.3 TB"), output);
268 BOOST_AUTO_TEST_CASE(nice_unit_format6)
270 const int64_t two_petabytes = 2000000000000000LL;
272 string output = nice_unit_format(two_petabytes, LongUnitFormat, UnitBase1000);
273 BOOST_CHECK_EQUAL(string("2.00 PBytes"), output);
275 output = nice_unit_format(two_petabytes);
276 BOOST_CHECK_EQUAL(string("1.8 PB"), output);
278 output = nice_unit_format(boost::numeric_cast<double>(two_petabytes), LongUnitFormat, UnitBase1000);
279 BOOST_CHECK_EQUAL(string("2.00 PBytes"), output);
281 output = nice_unit_format(boost::numeric_cast<double>(two_petabytes));
282 BOOST_CHECK_EQUAL(string("1.8 PB"), output);
284 const int64_t two_and_half_petabytes = 2500000000000000LL;
286 output = nice_unit_format(two_and_half_petabytes, LongUnitFormat, UnitBase1000);
287 BOOST_CHECK_EQUAL(string("2.50 PBytes"), output);
289 output = nice_unit_format(two_and_half_petabytes);
290 BOOST_CHECK_EQUAL(string("2.2 PB"), output);
292 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_petabytes), LongUnitFormat, UnitBase1000);
293 BOOST_CHECK_EQUAL(string("2.50 PBytes"), output);
295 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_petabytes));
296 BOOST_CHECK_EQUAL(string("2.2 PB"), output);
299 BOOST_AUTO_TEST_CASE(nice_unit_format7)
301 const int64_t two_exabytes = 2000000000000000000LL;
303 string output = nice_unit_format(two_exabytes, LongUnitFormat, UnitBase1000);
304 BOOST_CHECK_EQUAL(string("2000.00 PBytes"), output);
306 output = nice_unit_format(two_exabytes);
307 BOOST_CHECK_EQUAL(string("1776.4 PB"), output);
309 output = nice_unit_format(boost::numeric_cast<double>(two_exabytes), LongUnitFormat, UnitBase1000);
310 BOOST_CHECK_EQUAL(string("2000.00 PBytes"), output);
312 output = nice_unit_format(boost::numeric_cast<double>(two_exabytes));
313 BOOST_CHECK_EQUAL(string("1776.4 PB"), output);
315 const int64_t two_and_half_exabytes = 2500000000000000000LL;
317 output = nice_unit_format(two_and_half_exabytes, LongUnitFormat, UnitBase1000);
318 BOOST_CHECK_EQUAL(string("2500.00 PBytes"), output);
320 output = nice_unit_format(two_and_half_exabytes);
321 BOOST_CHECK_EQUAL(string("2220.4 PB"), output);
323 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_exabytes), LongUnitFormat, UnitBase1000);
324 BOOST_CHECK_EQUAL(string("2500.00 PBytes"), output);
326 output = nice_unit_format(boost::numeric_cast<double>(two_and_half_exabytes));
327 BOOST_CHECK_EQUAL(string("2220.4 PB"), output);
330 BOOST_AUTO_TEST_CASE(nice_unit_format8)
332 const int64_t max_representable_64bits_number = 9223372036854775807LL;
334 string output = nice_unit_format(max_representable_64bits_number, LongUnitFormat, UnitBase1000);
335 BOOST_CHECK_EQUAL(string("9223.40 PBytes"), output);
337 output = nice_unit_format(max_representable_64bits_number);
338 BOOST_CHECK_EQUAL(string("8192.0 PB"), output);
341 double val = boost::numeric_cast<double>(max_representable_64bits_number);
342 BOOST_MESSAGE("val as int64 is " << max_representable_64bits_number << " and as double is " << val);
343 BOOST_MESSAGE("val rounded is " << round(val));
344 BOOST_CHECK_EQUAL(val, round(val));
345 BOOST_MESSAGE("half as int64 is " << boost::numeric_cast<int64_t>(round(val/2))); // ok
346 BOOST_MESSAGE("cast back is " << boost::numeric_cast<int64_t>(round(val))); // throws a positive overflow
347 output = nice_unit_format(boost::numeric_cast<double>(max_representable_64bits_number), LongUnitFormat, UnitBase1000);
348 BOOST_CHECK_EQUAL(string("9223.40 PBytes"), output);
350 output = nice_unit_format(boost::numeric_cast<double>(max_representable_64bits_number));
351 BOOST_CHECK_EQUAL(string("8192.0 PB"), output);
355 BOOST_AUTO_TEST_CASE(TestTrim)
359 BOOST_CHECK_EQUAL( std::string("s1"), s );
363 BOOST_CHECK_EQUAL( std::string("s2"), s );
367 BOOST_CHECK_EQUAL( std::string("s3"), s );
371 BOOST_CHECK_EQUAL( std::string("s4:s4"), s);
373 /* non modifying version */
376 BOOST_CHECK_EQUAL( std::string("s1"), trim(s) );
379 BOOST_CHECK_EQUAL( std::string("s2"), trim(s) );
380 BOOST_CHECK_EQUAL( std::string(" s2"), s );
383 BOOST_CHECK_EQUAL( std::string("s3"), trim(s) );
384 BOOST_CHECK_EQUAL( std::string("s3 "), s );
387 BOOST_CHECK_EQUAL( std::string("s4:s4"), trim(s,":+-a") );
392 BOOST_AUTO_TEST_CASE(TestChomp)
397 BOOST_CHECK_EQUAL( std::string("s1"), s );
401 BOOST_CHECK_EQUAL( std::string("s2"), s );
405 BOOST_CHECK_EQUAL( std::string("s3"), s );
409 BOOST_CHECK_EQUAL( std::string(":s4:"), s);
411 /* non modifiying versions */
414 BOOST_CHECK_EQUAL( std::string("s1"), chomp(s) );
417 BOOST_CHECK_EQUAL( std::string("s2"), chomp(s) );
418 BOOST_CHECK_EQUAL( std::string("s2\n"), s);
421 BOOST_CHECK_EQUAL( std::string("s3"), chomp(s,":") );
422 BOOST_CHECK_EQUAL( std::string("s3:"), s);
425 BOOST_CHECK_EQUAL( std::string(":s4:"), chomp(s,"s:") );
426 BOOST_CHECK_EQUAL( std::string(":s4::"), s);
431 BOOST_AUTO_TEST_CASE(TestSuffixFuncs)
433 std::string s1("12.cpp");
435 BOOST_CHECK_EQUAL( true, has_suffix(s1,".cpp") );
436 BOOST_CHECK_EQUAL( true, has_suffix(s1,"pp") );
437 BOOST_CHECK_EQUAL( false, has_suffix(s1,"hpp") );
438 BOOST_CHECK_EQUAL( false, has_suffix(s1,"cp") );
439 BOOST_CHECK_EQUAL( false, has_suffix(s1,"") );
441 std::string s1c1= remove_suffix(s1,".cpp");
442 BOOST_CHECK_EQUAL( std::string("12"), s1c1 );
444 std::string s1c2= remove_suffix(s1,"p");
445 BOOST_CHECK_EQUAL( std::string("12.cp"), s1c2 );
447 std::string s1c3= remove_suffix(s1,"cp");
448 BOOST_CHECK_EQUAL( std::string("12.cpp"), s1c3 );
450 std::string s2(".cpp");
451 BOOST_CHECK_EQUAL( true, has_suffix(s2,".cpp") );
453 std::string s2c1= remove_suffix(s2,".cpp");
454 BOOST_CHECK_EQUAL( std::string(""), s2c1 );
456 } // eo TestSuffixFuncs()
460 BOOST_AUTO_TEST_CASE(TestPrefixFuncs)
462 std::string s1("12.cpp");
464 BOOST_CHECK_EQUAL( true, has_prefix(s1,"12") );
465 BOOST_CHECK_EQUAL( true, has_prefix(s1, "1") );
466 BOOST_CHECK_EQUAL( false, has_prefix(s1, "2") );
467 BOOST_CHECK_EQUAL( false, has_prefix(s1, "") );
469 std::string s1c1= remove_prefix(s1, "12");
470 BOOST_CHECK_EQUAL( std::string(".cpp"), s1c1);
471 } // eo TestPrefixFuncs()
475 BOOST_AUTO_TEST_CASE(TestLowerUpperFuncs)
477 std::string u1("CASE CONVERSION TEST..");
478 std::string l1("case conversion test..");
480 std::string test1(l1);
483 BOOST_CHECK_EQUAL( u1, test1 );
486 BOOST_CHECK_EQUAL( l1, test1 );
489 BOOST_CHECK_EQUAL( u1, to_upper(l1) );
490 BOOST_CHECK_EQUAL( l1, to_lower(u1) );
491 } // eo TestLowerUpper
495 BOOST_AUTO_TEST_CASE(PairSplit1)
498 get_push_back_filler(str_list)
499 ("a=11")("a= 11")("a =11 ")("a = 11 ")(" a = 11 ")
501 BOOST_CHECK_EQUAL( 5u, str_list.size() );
502 for(StringList::iterator it= str_list.begin();
503 it != str_list.end();
506 std::string key, value;
507 bool res= pair_split( *it, key, value);
509 BOOST_CHECK_EQUAL( true , res );
510 BOOST_CHECK_EQUAL( std::string("a"), key );
511 BOOST_CHECK_EQUAL( std::string("11"), value );
514 std::string key, value;
517 res= pair_split(" 1 : 2 ", key, value, ':');
518 BOOST_CHECK_EQUAL( true, res );
519 BOOST_CHECK_EQUAL( std::string("1"), key);
520 BOOST_CHECK_EQUAL( std::string("2"), value);
525 BOOST_AUTO_TEST_CASE(SplitString1)
537 split_string(block, list1, "\n");
538 // since the blocks ends with \n we should have 6 lines (the last one empty):
539 BOOST_CHECK_EQUAL( 6u, list1.size() );
540 BOOST_CHECK_EQUAL( std::string(), list1.back() );
541 BOOST_CHECK_EQUAL( std::string("Zeile 1"), list1.front() );
545 split_string(block, list2, "\n", true);
547 // now we omitted empty lines, now we should have only 4 lines left:
548 BOOST_CHECK_EQUAL( 4u, list2.size() );
549 BOOST_CHECK_EQUAL( std::string("Zeile 5"), list2.back() );
550 BOOST_CHECK_EQUAL( std::string("Zeile 1"), list2.front() );
552 list2= split_string(block, "\n", true, "+-");
554 // again, we omitted empty lines, but also trimmed away leading and trailing "+" and "-"
555 BOOST_CHECK_EQUAL( 4u, list2.size() );
556 BOOST_CHECK_EQUAL( std::string("Zeile 5"), list2.back() );
557 BOOST_CHECK_EQUAL( std::string("Zeile 1"), list2.front() );
558 BOOST_CHECK_EQUAL( std::string("Zeile-2"), *(++list2.begin()) );
563 BOOST_AUTO_TEST_CASE(SplitString2)
565 std::string line("172.16.0.0/16 dev eth0 scope link src 172.16.1.111");
569 split_string(line, list1, " ", true, Whitespaces);
571 BOOST_CHECK_EQUAL( 7u, list1.size() );
577 BOOST_AUTO_TEST_CASE(SplitStringEmpty)
579 std::string line("");
583 split_string(line, list1, " ", true, Whitespaces);
585 BOOST_CHECK_EQUAL( 0u, list1.size() );
586 } // eo SplitStringEmpty
589 BOOST_AUTO_TEST_CASE(SplitStringDelimiterOnly)
591 std::string line(" ");
595 split_string(line, list1, " ", true, Whitespaces);
597 BOOST_CHECK_EQUAL( 0u, list1.size() );
598 } // eo SplitStringDelimiterOnly
602 BOOST_AUTO_TEST_CASE(JoinString1)
604 std::list< std::string > parts;
605 get_push_back_filler(parts)("1")("2")("drei");
607 std::string joined_string= join_string(parts,"/");
608 // we should have slashes between the strings:
609 BOOST_CHECK_EQUAL( std::string("1/2/drei") , joined_string );
611 parts.push_back( std::string() );
612 joined_string= join_string(parts,"/");
613 // now we should have an additional trailing slash:
614 BOOST_CHECK_EQUAL( std::string("1/2/drei/") , joined_string );
616 parts.push_front( std::string() );
617 joined_string= join_string(parts,"/");
618 // now we should have an additional leading slash:
619 BOOST_CHECK_EQUAL( std::string("/1/2/drei/") , joined_string );
624 BOOST_AUTO_TEST_CASE(JoinStringVector)
626 std::vector< std::string > parts;
627 get_push_back_filler(parts)("1")("2")("drei");
629 std::string joined_string= join_string(parts,"/");
630 // we should have slashes between the strings:
631 BOOST_CHECK_EQUAL( std::string("1/2/drei") , joined_string );
633 parts.push_back( std::string() );
634 joined_string= join_string(parts,"/");
635 // now we should have an additional trailing slash:
636 BOOST_CHECK_EQUAL( std::string("1/2/drei/") , joined_string );
638 parts.insert(parts.begin(), "");
639 joined_string= join_string(parts,"/");
640 // now we should have an additional leading slash:
641 BOOST_CHECK_EQUAL( std::string("/1/2/drei/") , joined_string );
643 } // eo JoinStringVector
646 BOOST_AUTO_TEST_CASE(ConversionStringInt)
648 std::string s1("24");
649 std::string s1x("25x");
653 i1= string_to<int>(s1);
654 BOOST_CHECK_EQUAL( 24, i1 );
655 i1= string_to<int>(s1x);
656 BOOST_CHECK_EQUAL( 25, i1 );
658 res= string_to<int>(s1,i1);
659 BOOST_CHECK_EQUAL( true, res );
660 BOOST_CHECK_EQUAL( 24, i1 );
662 res= string_to<int>(s1x,i1);
663 BOOST_CHECK_EQUAL( false, res );
665 std::string ss1= to_string( 24 );
666 BOOST_CHECK_EQUAL( std::string("24"), ss1);
668 } // eo ConversionStringInt()
672 BOOST_AUTO_TEST_CASE(HexBinaryConversion)
674 std::string hex1("49324E");
675 std::string bin1("I2N");
677 BOOST_CHECK_EQUAL( hex1, convert_binary_to_hex(bin1,true) );
678 BOOST_CHECK_EQUAL( bin1, convert_hex_to_binary(hex1) );
679 BOOST_CHECK_EQUAL( to_lower(hex1), convert_binary_to_hex(bin1) );
681 std::string hex2("0001");
682 std::string hex2a("00 01");
683 std::string hex2b("00:01");
684 std::string bin2("\0\1",2);
686 BOOST_CHECK_EQUAL( hex2, convert_binary_to_hex(bin2) );
687 BOOST_CHECK_EQUAL( bin2, convert_hex_to_binary(hex2) );
688 BOOST_CHECK_EQUAL( bin2, convert_hex_to_binary(hex2a) );
689 BOOST_CHECK_EQUAL( bin2, convert_hex_to_binary(hex2b) );
691 BOOST_REQUIRE_THROW( convert_hex_to_binary("01 kein hex"), std::runtime_error);
692 } // eo HexConversion()
694 BOOST_AUTO_TEST_CASE(HexIntConversion)
696 BOOST_CHECK_EQUAL( 255 , hex_string_to<uint32_t>("ff") );
697 BOOST_CHECK_EQUAL( 18866985 , hex_string_to<uint32_t>("11FE329") );
698 BOOST_CHECK_EQUAL( 44 , hex_string_to<uint32_t>("0x2C") );
701 BOOST_AUTO_TEST_CASE(sanitize_for_logging1)
703 string output = sanitize_for_logging("normaler string ohne aerger");
705 BOOST_CHECK_EQUAL(string("normaler string ohne aerger"), output);
708 BOOST_AUTO_TEST_CASE(sanitize_for_logging2)
710 string to_test="fiese";
711 to_test.push_back(0);
714 string output = sanitize_for_logging(to_test);
716 BOOST_CHECK_EQUAL(string("fiese?null"), output);
719 BOOST_AUTO_TEST_CASE(sanitize_for_logging3)
721 string output = sanitize_for_logging("läuter ümlaute utf8");
723 BOOST_CHECK_EQUAL(string("l??uter ??mlaute utf8"), output);
726 BOOST_AUTO_TEST_SUITE_END()