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