WTextRendererTest.C 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <boost/test/unit_test.hpp>
  2. #include <Wt/Render/WTextRenderer>
  3. #include <iostream>
  4. #include <boost/version.hpp>
  5. #if !defined(WT_NO_SPIRIT) && BOOST_VERSION >= 104700
  6. # define CSS_PARSER
  7. #endif
  8. #ifdef CSS_PARSER
  9. class MyTextRenderer : public Wt::Render::WTextRenderer
  10. {
  11. virtual double pageWidth(int page) const{return 0;}
  12. virtual double pageHeight(int page) const{return 0;}
  13. virtual double margin(Wt::Side side) const{return 0;}
  14. virtual Wt::WPaintDevice *startPage(int page){return 0;}
  15. virtual void endPage(Wt::WPaintDevice *device){}
  16. virtual Wt::WPainter *getPainter(Wt::WPaintDevice *device){return 0;}
  17. };
  18. BOOST_AUTO_TEST_CASE( WTextRenderer_testStylesheet )
  19. {
  20. MyTextRenderer r;
  21. BOOST_REQUIRE( r.setStyleSheetText("h1{}") );
  22. BOOST_REQUIRE( r.setStyleSheetText("h1{}") );
  23. BOOST_REQUIRE( r.styleSheetText() == "h1{}" );
  24. BOOST_REQUIRE( r.setStyleSheetText("") );
  25. BOOST_REQUIRE( r.styleSheetText() == "" );
  26. BOOST_REQUIRE( r.setStyleSheetText("h1{}") );
  27. BOOST_REQUIRE( !r.setStyleSheetText("h1{} #1bla{}") );
  28. BOOST_REQUIRE( r.getStyleSheetParseErrors().size() );
  29. BOOST_REQUIRE( !r.setStyleSheetText("h1{} 1h{}") );
  30. BOOST_REQUIRE( r.getStyleSheetParseErrors().size() );
  31. BOOST_REQUIRE( r.styleSheetText() == "h1{}" );
  32. BOOST_REQUIRE( r.setStyleSheetText("h1{}") );
  33. BOOST_REQUIRE( !r.getStyleSheetParseErrors().size() );
  34. }
  35. #endif // CSS_PARSER