1 /// Unit tests for canvas::Element
2 #define BOOST_TEST_MODULE canvas
3 #include <BoostTestTargetConfig.h>
5 #include "CanvasElement.hxx"
6 #include "CanvasGroup.hxx"
8 namespace sc = simgear::canvas;
10 BOOST_AUTO_TEST_CASE( attr_data )
12 // http://www.w3.org/TR/html5/dom.html#attr-data-*
14 #define SG_CHECK_ATTR2PROP(attr, prop)\
15 BOOST_CHECK_EQUAL(sc::Element::attrToDataPropName(attr), prop)
17 // If name starts with "data-", for each "-" (U+002D) character in the name
18 // that is followed by a lowercase ASCII letter, remove the "-" (U+002D)
19 // character and replace the character that followed it by the same character
20 // converted to ASCII uppercase.
22 SG_CHECK_ATTR2PROP("no-data", "");
23 SG_CHECK_ATTR2PROP("data-blub", "blub");
24 SG_CHECK_ATTR2PROP("data-blub-x-y", "blubXY");
25 SG_CHECK_ATTR2PROP("data-blub-x-y-", "blubXY-");
27 #undef SG_CHECK_ATTR2PROP
29 #define SG_CHECK_PROP2ATTR(prop, attr)\
30 BOOST_CHECK_EQUAL(sc::Element::dataPropToAttrName(prop), attr)
32 // If name contains a "-" (U+002D) character followed by a lowercase ASCII
33 // letter, throw a SyntaxError exception (empty string) and abort these steps.
34 // For each uppercase ASCII letter in name, insert a "-" (U+002D) character
35 // before the character and replace the character with the same character
36 // converted to ASCII lowercase.
37 // Insert the string "data-" at the front of name.
39 SG_CHECK_PROP2ATTR("test", "data-test");
40 SG_CHECK_PROP2ATTR("testIt", "data-test-it");
41 SG_CHECK_PROP2ATTR("testIt-Hyphen", "data-test-it--hyphen");
42 SG_CHECK_PROP2ATTR("-test", "");
43 SG_CHECK_PROP2ATTR("test-", "data-test-");
45 #undef SG_CHECK_PROP2ATTR
47 SGPropertyNode_ptr node = new SGPropertyNode;
49 sc::Element::create<sc::Group>(sc::CanvasWeakPtr(), node);
51 el->setDataProp("myData", 3);
52 BOOST_CHECK_EQUAL( el->getDataProp<int>("myData"), 3 );
53 BOOST_CHECK_EQUAL( node->getIntValue("data-my-data"), 3 );