X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ftest_html_parser.cpp;h=370ff725354d1d9b31c21a78a08347332b1bd2df;hb=dd17e564b39fa38a3d611853a3b13dacdff3d070;hp=f0ab6416f22808d47c2cc86d626654db839b74a3;hpb=8bcd4c3e063e932b2f80f9491ec0af66d3da5c2e;p=metaproxy-moved-to-github.git
diff --git a/src/test_html_parser.cpp b/src/test_html_parser.cpp
index f0ab641..370ff72 100644
--- a/src/test_html_parser.cpp
+++ b/src/test_html_parser.cpp
@@ -35,64 +35,205 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
using namespace boost::unit_test;
namespace mp = metaproxy_1;
-class MyEvent : public mp::HTMLParserEvent {
- public:
- std::string out;
- void openTagStart(const char *name)
- {
- out += "<";
- out += name;
- }
-
- void attribute(const char *tagName,
- const char *name, const char *value, int val_len)
+class MyEvent : public mp::HTMLParserEvent
+{
+public:
+ std::string out;
+ 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 *sep) {
+ out += " ";
+ out.append(attr, attr_len);
+ if (value)
{
- out += " ";
- out += name;
- out += "=\"";
+ out += "=";
+ out += sep;
out.append(value, val_len);
- out += "\"";
+ out += sep;
}
+ }
+ void anyTagEnd(const char *tag, int tag_len, int close_it) {
+ if (close_it)
+ out += "/";
+ out += ">";
+ }
+ void closeTag(const char *tag, int tag_len) {
+ out += "";
+ out.append(tag, tag_len);
+ }
+ void text(const char *value, int len) {
+ out.append(value, len);
+ }
+};
+
+BOOST_AUTO_TEST_CASE( test_html_parser_1 )
+{
+ try
+ {
+ mp::HTMLParser hp;
+ const char* html =
+ "
some text"
+ "
";
+ const char* expected =
+ "some text"
+ "
";
+ MyEvent e;
+ hp.set_verbose(0);
+ hp.parse(e, html);
- void anyTagEnd(const char *name, int close_it)
+ BOOST_CHECK_EQUAL(std::string(expected), e.out);
+ if (std::string(expected) != e.out)
{
- if (close_it)
- out += "/";
- out += ">";
+ std::cout << "Expected" << std::endl;
+ std::cout << expected << std::endl;
+ std::cout << "Got" << std::endl;
+ std::cout << e.out << std::endl;
}
-
- void closeTag(const char *name)
+ }
+ catch (std::exception & e)
+ {
+ std::cout << e.what();
+ std::cout << std::endl;
+ BOOST_CHECK (false);
+ }
+}
+
+BOOST_AUTO_TEST_CASE( test_html_parser_2 )
+{
+ try
+ {
+ mp::HTMLParser hp;
+ const char* html =
+ "\n"
+ "\n"
+ " \n"
+ " YAZ 4.2.60\n"
+ " \n"
+ " \n"
+ " YAZ 4.2.60
\n"
+ " Error: 404
\n"
+ " Description: Not Found
\n"
+ " \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)
{
- out += "";
- out += name;
+ std::cout << "Expected" << std::endl;
+ std::cout << expected << std::endl;
+ std::cout << "Got" << std::endl;
+ std::cout << e.out << std::endl;
}
-
- void text(const char *value, int len)
+ }
+ 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);
+
+ BOOST_CHECK_EQUAL(std::string(expected), e.out);
+ if (std::string(expected) != e.out)
{
- out.append(value, len);
+ 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_AUTO_TEST_CASE( test_html_parser_1 )
+ 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 =
- "some text"
- "
";
- const char* expected =
- "some text"
- "
";
+ const char* html =
+ "";
+
+ const char* expected = html;
MyEvent e;
+ hp.set_verbose(0);
hp.parse(e, html);
- std::cout << expected << 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;