1 /* 2 * Copyright (C) 2010 Emweb bv, Herent, Belgium. 3 * 4 * See the LICENSE file for terms of use. 5 */ 6 #include <boost/test/unit_test.hpp> 7 8 #include <Wt/WLength.h> 9 BOOST_AUTO_TEST_CASE(length_test_constructors)10BOOST_AUTO_TEST_CASE( length_test_constructors ) 11 { 12 //default constructor 13 { 14 Wt::WLength a; 15 BOOST_REQUIRE(a.isAuto()); 16 BOOST_REQUIRE(a.value() == -1); 17 BOOST_REQUIRE(a.unit() == Wt::LengthUnit::Pixel); 18 } 19 20 //double constructor 21 { 22 Wt::WLength d(50.0); 23 BOOST_REQUIRE(!d.isAuto()); 24 BOOST_REQUIRE(d.value() == 50.0); 25 BOOST_REQUIRE(d.unit() == Wt::LengthUnit::Pixel); 26 } 27 28 { 29 Wt::WLength d(99.0, Wt::LengthUnit::Centimeter); 30 BOOST_REQUIRE(!d.isAuto()); 31 BOOST_REQUIRE(d.value() == 99.0); 32 BOOST_REQUIRE(d.unit() == Wt::LengthUnit::Centimeter); 33 } 34 35 //int constructor 36 { 37 Wt::WLength i(10); 38 BOOST_REQUIRE(!i.isAuto()); 39 BOOST_REQUIRE(i.value() == 10.0); 40 BOOST_REQUIRE(i.unit() == Wt::LengthUnit::Pixel); 41 } 42 43 { 44 Wt::WLength i(10, Wt::LengthUnit::Centimeter); 45 BOOST_REQUIRE(!i.isAuto()); 46 BOOST_REQUIRE(i.value() == 10.0); 47 BOOST_REQUIRE(i.unit() == Wt::LengthUnit::Centimeter); 48 } 49 50 { 51 Wt::WLength i(0); 52 BOOST_REQUIRE(!i.isAuto()); 53 BOOST_REQUIRE(i.value() == 0.0); 54 BOOST_REQUIRE(i.unit() == Wt::LengthUnit::Pixel); 55 } 56 57 //string constructor 58 { 59 Wt::WLength s("10px"); 60 BOOST_REQUIRE(!s.isAuto()); 61 BOOST_REQUIRE(s.value() == 10.0); 62 BOOST_REQUIRE(s.unit() == Wt::LengthUnit::Pixel); 63 } 64 65 { 66 Wt::WLength s("15.2em"); 67 BOOST_REQUIRE(!s.isAuto()); 68 BOOST_REQUIRE(s.value() == 15.2); 69 BOOST_REQUIRE(s.unit() == Wt::LengthUnit::FontEm); 70 } 71 72 { 73 Wt::WLength s("15.2ex"); 74 BOOST_REQUIRE(!s.isAuto()); 75 BOOST_REQUIRE(s.value() == 15.2); 76 BOOST_REQUIRE(s.unit() == Wt::LengthUnit::FontEx); 77 } 78 79 { 80 Wt::WLength s("15.0in"); 81 BOOST_REQUIRE(!s.isAuto()); 82 BOOST_REQUIRE(s.value() == 15.0); 83 BOOST_REQUIRE(s.unit() == Wt::LengthUnit::Inch); 84 } 85 86 { 87 Wt::WLength s("15.0cm"); 88 BOOST_REQUIRE(!s.isAuto()); 89 BOOST_REQUIRE(s.value() == 15.0); 90 BOOST_REQUIRE(s.unit() == Wt::LengthUnit::Centimeter); 91 } 92 93 { 94 Wt::WLength s("15.0mm"); 95 BOOST_REQUIRE(!s.isAuto()); 96 BOOST_REQUIRE(s.value() == 15.0); 97 BOOST_REQUIRE(s.unit() == Wt::LengthUnit::Millimeter); 98 } 99 100 { 101 Wt::WLength s("15.0mm"); 102 BOOST_REQUIRE(!s.isAuto()); 103 BOOST_REQUIRE(s.value() == 15.0); 104 BOOST_REQUIRE(s.unit() == Wt::LengthUnit::Millimeter); 105 } 106 107 { 108 Wt::WLength s("15.0pt"); 109 BOOST_REQUIRE(!s.isAuto()); 110 BOOST_REQUIRE(s.value() == 15.0); 111 BOOST_REQUIRE(s.unit() == Wt::LengthUnit::Point); 112 } 113 114 { 115 Wt::WLength s("15.0pc"); 116 BOOST_REQUIRE(!s.isAuto()); 117 BOOST_REQUIRE(s.value() == 15.0); 118 BOOST_REQUIRE(s.unit() == Wt::LengthUnit::Pica); 119 } 120 121 { 122 Wt::WLength s("15.0%"); 123 BOOST_REQUIRE(!s.isAuto()); 124 BOOST_REQUIRE(s.value() == 15.0); 125 BOOST_REQUIRE(s.unit() == Wt::LengthUnit::Percentage); 126 } 127 128 //add some random empty chars 129 { 130 Wt::WLength s(" 15.0 px "); 131 BOOST_REQUIRE(!s.isAuto()); 132 BOOST_REQUIRE(s.value() == 15.0); 133 BOOST_REQUIRE(s.unit() == Wt::LengthUnit::Pixel); 134 } 135 136 //try to mess things up 137 { 138 Wt::WLength s("px"); 139 BOOST_REQUIRE(s.isAuto()); 140 } 141 142 { 143 Wt::WLength s("100pn"); 144 BOOST_REQUIRE(s.isAuto()); 145 } 146 } 147