Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / printing / units_unittest.cc
blobfe160b3f405096496b51a1ec3a0420cfdc88d56e
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "printing/units.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "testing/gtest/include/gtest/gtest-spi.h"
9 namespace printing {
11 TEST(UnitsTest, Convertions) {
12 EXPECT_EQ(100, ConvertUnit(100, 100, 100));
13 EXPECT_EQ(-100, ConvertUnit(-100, 100, 100));
14 EXPECT_EQ(0, ConvertUnit(0, 100, 100));
15 EXPECT_EQ(99, ConvertUnit(99, 100, 100));
16 EXPECT_EQ(101, ConvertUnit(101, 100, 100));
17 EXPECT_EQ(99900, ConvertUnit(999, 10, 1000));
18 EXPECT_EQ(100100, ConvertUnit(1001, 10, 1000));
20 // Rounding.
21 EXPECT_EQ(10, ConvertUnit(999, 1000, 10));
22 EXPECT_EQ(10, ConvertUnit(950, 1000, 10));
23 EXPECT_EQ(9, ConvertUnit(949, 1000, 10));
24 EXPECT_EQ(10, ConvertUnit(1001, 1000, 10));
25 EXPECT_EQ(10, ConvertUnit(1049, 1000, 10));
26 EXPECT_EQ(11, ConvertUnit(1050, 1000, 10));
27 EXPECT_EQ(-10, ConvertUnit(-999, 1000, 10));
28 EXPECT_EQ(-10, ConvertUnit(-950, 1000, 10));
29 EXPECT_EQ(-9, ConvertUnit(-949, 1000, 10));
30 EXPECT_EQ(-10, ConvertUnit(-1001, 1000, 10));
31 EXPECT_EQ(-10, ConvertUnit(-1049, 1000, 10));
32 EXPECT_EQ(-11, ConvertUnit(-1050, 1000, 10));
34 EXPECT_EQ(0, ConvertUnit(2, 1000000000, 1));
35 EXPECT_EQ(2000000000, ConvertUnit(2, 1, 1000000000));
36 EXPECT_EQ(4000000000U,
37 static_cast<unsigned int>(ConvertUnit(2, 1, 2000000000)));
39 EXPECT_EQ(100, ConvertUnitDouble(100, 100, 100));
40 EXPECT_EQ(-100, ConvertUnitDouble(-100, 100, 100));
41 EXPECT_EQ(0, ConvertUnitDouble(0, 100, 100));
42 EXPECT_DOUBLE_EQ(0.000002, ConvertUnitDouble(2, 1000, 0.001));
43 EXPECT_EQ(2000000, ConvertUnitDouble(2, 0.001, 1000));
45 EXPECT_EQ(kHundrethsMMPerInch, ConvertMilliInchToHundredThousanthMeter(1000));
46 EXPECT_EQ(-kHundrethsMMPerInch,
47 ConvertMilliInchToHundredThousanthMeter(-1000));
48 EXPECT_EQ(0, ConvertMilliInchToHundredThousanthMeter(0));
49 EXPECT_EQ(1000, ConvertHundredThousanthMeterToMilliInch(kHundrethsMMPerInch));
50 EXPECT_EQ(-1000,
51 ConvertHundredThousanthMeterToMilliInch(-kHundrethsMMPerInch));
52 EXPECT_EQ(0, ConvertHundredThousanthMeterToMilliInch(0));
54 EXPECT_EQ(8.25, ConvertPixelsToPointDouble(11.0));
55 // Round down.
56 EXPECT_EQ(8, ConvertPixelsToPoint(11));
57 EXPECT_EQ(7.5, ConvertPixelsToPointDouble(10.0));
58 // Round up.
59 EXPECT_EQ(8, ConvertPixelsToPoint(10));
60 EXPECT_EQ(0, ConvertPixelsToPoint(0));
63 } // namespace printing