X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ftest_html_parser.cpp;h=5ba7e5a29b39478ce52af1b63b71c1c00b8552e6;hb=973e85e353f85f6ad792f6e8a5bc5a4d75fb7da6;hp=c4ffe131d947afc0e99fa3393035dad8691bba44;hpb=3ef4df94516a136b7ee18ec8a45e740ef9e9dc05;p=metaproxy-moved-to-github.git
diff --git a/src/test_html_parser.cpp b/src/test_html_parser.cpp
index c4ffe13..5ba7e5a 100644
--- a/src/test_html_parser.cpp
+++ b/src/test_html_parser.cpp
@@ -1,5 +1,5 @@
/* This file is part of Metaproxy.
- Copyright (C) 2005-2013 Index Data
+ Copyright (C) Index Data
Metaproxy is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
@@ -42,16 +42,20 @@ public:
void openTagStart(const char *tag, int tag_len) {
out += "<";
out.append(tag, tag_len);
- }
-
+ }
+
void attribute(const char *tag, int tag_len,
const char *attr, int attr_len,
- const char *value, int val_len) {
+ const char *value, int val_len, const char *sep) {
out += " ";
out.append(attr, attr_len);
- out += "=\"";
- out.append(value, val_len);
- out += "\"";
+ 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)
@@ -67,28 +71,31 @@ public:
}
};
-
BOOST_AUTO_TEST_CASE( test_html_parser_1 )
{
try
{
mp::HTMLParser hp;
- const char* html =
+ const char* html =
"
some text"
"
";
- const char* expected =
- "some text"
- "
";
+ const char* expected =
+ "some text"
+ "
";
MyEvent e;
+ 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;
@@ -101,7 +108,7 @@ BOOST_AUTO_TEST_CASE( test_html_parser_2 )
try
{
mp::HTMLParser hp;
- const char* html =
+ const char* html =
"\n"
"\n"
" \n"
@@ -116,16 +123,179 @@ BOOST_AUTO_TEST_CASE( test_html_parser_2 )
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)
+ {
+ std::cout << e.what();
+ std::cout << std::endl;
+ BOOST_CHECK (false);
+ }
+}
+
+BOOST_AUTO_TEST_CASE( test_html_parser_3 )
+{
+ try
+ {
+ mp::HTMLParser hp;
+ const char* html =
+ "\n"
+ "\n"
+ " %local;\n"
+ "]>\n"
+ "";
+
+ const char* expected = html;
+ MyEvent e;
+ 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_4 )
+{
+ try
+ {
+ mp::HTMLParser hp;
+ const char* html =
+ "\n"
+ "";
+
+ 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)
+ {
+ 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)
+ {
+ std::cout << e.what();
+ std::cout << std::endl;
+ BOOST_CHECK (false);
+ }
+}
+
+BOOST_AUTO_TEST_CASE( test_html_parser_6 )
+{
+ 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)
+ {
+ std::cout << e.what();
+ std::cout << std::endl;
+ BOOST_CHECK (false);
+ }
+}
+
+BOOST_AUTO_TEST_CASE( test_html_parser_7 )
+{
+ try
+ {
+ mp::HTMLParser hp;
+ const char* html =
+ ""
+ "1>\nx=2;\n";
+
+ 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;