BlockCssPropertyTest.C 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include <boost/test/unit_test.hpp>
  2. #include <boost/assign/list_of.hpp>
  3. #include <Wt/Render/Block.h>
  4. #include <Wt/Render/CssParser.h>
  5. #include <boost/version.hpp>
  6. #if !defined(WT_NO_SPIRIT) && BOOST_VERSION >= 104700
  7. # define CSS_PARSER
  8. #endif
  9. #ifdef CSS_PARSER
  10. using namespace boost::assign;
  11. const Wt::Render::Block* childBlock2(const Wt::Render::Block* parent,
  12. const std::vector<int>& indexes)
  13. {
  14. const Wt::Render::Block* block = parent;
  15. for(std::vector<int>::const_iterator iter = indexes.begin();
  16. iter != indexes.end(); ++iter)
  17. {
  18. block = block->children().at(*iter);
  19. }
  20. return block;
  21. }
  22. Wt::rapidxml::xml_document<>* createXHtml2(const char * xhtml)
  23. {
  24. Wt::rapidxml::xml_document<>* doc = new Wt::rapidxml::xml_document<>();
  25. char *cxhtml = doc->allocate_string(xhtml);
  26. doc->parse<Wt::rapidxml::parse_xhtml_entity_translation>(cxhtml);
  27. return doc;
  28. }
  29. BOOST_AUTO_TEST_CASE( BlockCssProperty_test1 )
  30. {
  31. Wt::rapidxml::xml_document<>* doc = createXHtml2(
  32. "<h2>"
  33. "<h3>"
  34. "</h3>"
  35. "</h2>"
  36. "<h1>"
  37. "<h2>"
  38. "<h3>"
  39. "<h4>"
  40. "</h4>"
  41. "</h3>"
  42. "</h2>"
  43. "</h1>");
  44. Wt::Render::StyleSheet* style = Wt::Render::CssParser().parse(
  45. "h1{border: 1px}"
  46. "h2{border: 2px}"
  47. "h1 h2{border: 12px }"
  48. "h1 h2{border-right: 120px }"
  49. "h2{border: 20px}"
  50. "h1{color: blue}"
  51. );
  52. BOOST_REQUIRE( style );
  53. Wt::Render::Block b(doc, 0);
  54. b.setStyleSheet(style);
  55. // h1 color == "blue"
  56. BOOST_REQUIRE(childBlock2(&b, list_of(1))
  57. ->cssProperty(Wt::PropertyStyleColor) == "blue");
  58. // h1 border-left == 1px
  59. BOOST_REQUIRE(childBlock2(&b, list_of(1))
  60. ->cssProperty(Wt::PropertyStyleBorderLeft) == "1px");
  61. // h1/h2 border-left == 12px
  62. BOOST_REQUIRE(childBlock2(&b, list_of(1)(0))
  63. ->cssProperty(Wt::PropertyStyleBorderLeft) == "12px");
  64. // h2 border-left == 20px
  65. BOOST_REQUIRE(childBlock2(&b, list_of(0))
  66. ->cssProperty(Wt::PropertyStyleBorderLeft) == "20px");
  67. // h1/h2 border-right == 120px
  68. BOOST_REQUIRE(childBlock2(&b, list_of(1)(0))
  69. ->cssProperty(Wt::PropertyStyleBorderRight) == "120px");
  70. delete style;
  71. delete doc;
  72. }
  73. #endif // CSS_PARSER