X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ftest_html_parser.cpp;h=370ff725354d1d9b31c21a78a08347332b1bd2df;hb=dd17e564b39fa38a3d611853a3b13dacdff3d070;hp=6f5c134464cb7f65bcef93375f66199cb9939882;hpb=288111986392ffbd733d71cd964f49437b899bdb;p=metaproxy-moved-to-github.git
diff --git a/src/test_html_parser.cpp b/src/test_html_parser.cpp
index 6f5c134..370ff72 100644
--- a/src/test_html_parser.cpp
+++ b/src/test_html_parser.cpp
@@ -49,10 +49,13 @@ public:
const char *value, int val_len, const char *sep) {
out += " ";
out.append(attr, attr_len);
- out += "=";
- out += sep;
- out.append(value, val_len);
- out += sep;
+ if (value)
+ {
+ out += "=";
+ out += sep;
+ out.append(value, val_len);
+ out += sep;
+ }
}
void anyTagEnd(const char *tag, int tag_len, int close_it) {
if (close_it)
@@ -80,14 +83,17 @@ BOOST_AUTO_TEST_CASE( test_html_parser_1 )
"
some text"
"
";
MyEvent e;
- hp.set_verbose(1);
+ hp.set_verbose(0);
hp.parse(e, html);
- std::cout << "Expected" << std::endl;
- std::cout << expected << std::endl;
- std::cout << "Got" << std::endl;
- std::cout << e.out << std::endl;
BOOST_CHECK_EQUAL(std::string(expected), e.out);
+ if (std::string(expected) != e.out)
+ {
+ std::cout << "Expected" << std::endl;
+ std::cout << expected << std::endl;
+ std::cout << "Got" << std::endl;
+ std::cout << e.out << std::endl;
+ }
}
catch (std::exception & e)
{
@@ -102,7 +108,7 @@ BOOST_AUTO_TEST_CASE( test_html_parser_2 )
try
{
mp::HTMLParser hp;
- const char* html =
+ const char* html =
"\n"
"\n"
" \n"
@@ -117,17 +123,19 @@ BOOST_AUTO_TEST_CASE( test_html_parser_2 )
const char* expected = html;
MyEvent e;
- hp.set_verbose(1);
+ hp.set_verbose(0);
hp.parse(e, html);
- std::cout << "Expected" << std::endl;
- std::cout << expected << std::endl;
- std::cout << "Got" << std::endl;
- std::cout << e.out << std::endl;
-
BOOST_CHECK_EQUAL(std::string(expected), e.out);
+ if (std::string(expected) != e.out)
+ {
+ std::cout << "Expected" << std::endl;
+ std::cout << expected << std::endl;
+ std::cout << "Got" << std::endl;
+ std::cout << e.out << std::endl;
+ }
}
- catch (std::exception & e)
+ catch (std::exception & e)
{
std::cout << e.what();
std::cout << std::endl;
@@ -152,17 +160,19 @@ BOOST_AUTO_TEST_CASE( test_html_parser_3 )
const char* expected = html;
MyEvent e;
- hp.set_verbose(1);
+ hp.set_verbose(0);
hp.parse(e, html);
- std::cout << "Expected" << std::endl;
- std::cout << expected << std::endl;
- std::cout << "Got" << std::endl;
- std::cout << e.out << std::endl;
-
BOOST_CHECK_EQUAL(std::string(expected), e.out);
+ if (std::string(expected) != e.out)
+ {
+ std::cout << "Expected" << std::endl;
+ std::cout << expected << std::endl;
+ std::cout << "Got" << std::endl;
+ std::cout << e.out << std::endl;
+ }
}
- catch (std::exception & e)
+ catch (std::exception & e)
{
std::cout << e.what();
std::cout << std::endl;
@@ -170,37 +180,67 @@ BOOST_AUTO_TEST_CASE( test_html_parser_3 )
}
}
-#if 0
-// null ptr exception
BOOST_AUTO_TEST_CASE( test_html_parser_4 )
{
try
{
mp::HTMLParser hp;
const char* html =
- "<\"?xml version=\"1.0\" strandalone=\"no\"?>\n"
- "";
+ "\n"
+ "";
const char* expected = html;
MyEvent e;
- hp.set_verbose(1);
+ hp.set_verbose(0);
hp.parse(e, html);
- std::cout << "Expected" << std::endl;
- std::cout << expected << std::endl;
- std::cout << "Got" << std::endl;
- std::cout << e.out << std::endl;
+ BOOST_CHECK_EQUAL(std::string(expected), e.out);
+ if (std::string(expected) != e.out)
+ {
+ std::cout << "Expected" << std::endl;
+ std::cout << expected << std::endl;
+ std::cout << "Got" << std::endl;
+ std::cout << e.out << std::endl;
+ }
+ }
+ catch (std::exception & e)
+ {
+ std::cout << e.what();
+ std::cout << std::endl;
+ BOOST_CHECK (false);
+ }
+}
+
+BOOST_AUTO_TEST_CASE( test_html_parser_5 )
+{
+ try
+ {
+ mp::HTMLParser hp;
+ const char* html =
+ "";
+
+ const char* expected = html;
+ MyEvent e;
+ hp.set_verbose(0);
+ hp.parse(e, html);
BOOST_CHECK_EQUAL(std::string(expected), e.out);
+ if (std::string(expected) != e.out)
+ {
+ std::cout << "Expected" << std::endl;
+ std::cout << expected << std::endl;
+ std::cout << "Got" << std::endl;
+ std::cout << e.out << std::endl;
+ }
}
- catch (std::exception & e)
+ catch (std::exception & e)
{
std::cout << e.what();
std::cout << std::endl;
BOOST_CHECK (false);
}
}
-#endif
+
/*
* Local variables: