htmlparser.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/html/htmlparser.cpp
  3. // Purpose: wxHtmlParser tests
  4. // Author: Vadim Zeitlin
  5. // Created: 2011-01-13
  6. // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
  7. ///////////////////////////////////////////////////////////////////////////////
  8. // ----------------------------------------------------------------------------
  9. // headers
  10. // ----------------------------------------------------------------------------
  11. #include "testprec.h"
  12. #if wxUSE_HTML
  13. #ifdef __BORLANDC__
  14. #pragma hdrstop
  15. #endif
  16. #ifndef WX_PRECOMP
  17. #endif // WX_PRECOMP
  18. #include "wx/html/htmlpars.h"
  19. // ----------------------------------------------------------------------------
  20. // test class
  21. // ----------------------------------------------------------------------------
  22. class HtmlParserTestCase : public CppUnit::TestCase
  23. {
  24. public:
  25. HtmlParserTestCase() { }
  26. private:
  27. CPPUNIT_TEST_SUITE( HtmlParserTestCase );
  28. CPPUNIT_TEST( Invalid );
  29. CPPUNIT_TEST_SUITE_END();
  30. void Invalid();
  31. wxDECLARE_NO_COPY_CLASS(HtmlParserTestCase);
  32. };
  33. // register in the unnamed registry so that these tests are run by default
  34. CPPUNIT_TEST_SUITE_REGISTRATION( HtmlParserTestCase );
  35. // also include in its own registry so that these tests can be run alone
  36. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HtmlParserTestCase, "HtmlParserTestCase" );
  37. // ----------------------------------------------------------------------------
  38. // tests themselves
  39. // ----------------------------------------------------------------------------
  40. // Test that parsing invalid HTML simply fails but doesn't crash for example.
  41. void HtmlParserTestCase::Invalid()
  42. {
  43. class NullParser : public wxHtmlParser
  44. {
  45. public:
  46. virtual wxObject *GetProduct() { return NULL; }
  47. protected:
  48. virtual void AddText(const wxString& WXUNUSED(txt)) { }
  49. };
  50. NullParser p;
  51. p.Parse("<");
  52. p.Parse("<foo");
  53. p.Parse("<!--");
  54. p.Parse("<!---");
  55. }
  56. #endif //wxUSE_HTML