1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppunit/TestFixture.h>
21 #include <cppunit/extensions/HelperMacros.h>
23 #include <basegfx/vector/b2dsize.hxx>
27 class B2DSizeTest
: public CppUnit::TestFixture
30 void testOperatorAddition()
32 B2DSize
aSize(4.0, 8.0);
33 aSize
+= { 2.0, 3.0 };
35 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.0, aSize
.getWidth(), 1e-2);
36 CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, aSize
.getHeight(), 1e-2);
39 void testOperatorSubstraction()
41 B2DSize
aSize(4.0, 8.0);
42 aSize
-= { 2.0, 3.0 };
44 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, aSize
.getWidth(), 1e-2);
45 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, aSize
.getHeight(), 1e-2);
48 void testOperatorMultiply()
50 B2DSize
aSize(4.0, 8.0);
51 aSize
*= { 2.0, 3.0 };
53 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.0, aSize
.getWidth(), 1e-2);
54 CPPUNIT_ASSERT_DOUBLES_EQUAL(24.0, aSize
.getHeight(), 1e-2);
58 CPPUNIT_ASSERT_DOUBLES_EQUAL(16.0, aSize
.getWidth(), 1e-2);
59 CPPUNIT_ASSERT_DOUBLES_EQUAL(48.0, aSize
.getHeight(), 1e-2);
62 void testOperatorDivide()
64 B2DSize
aSize(4.0, 8.0);
65 aSize
/= { 2.0, 8.0 };
67 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, aSize
.getWidth(), 1e-2);
68 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, aSize
.getHeight(), 1e-2);
71 void testOperatorEqualUnequal()
73 B2DSize
aSize(4.0, 8.0);
74 B2DSize aSize2
= aSize
;
76 CPPUNIT_ASSERT_EQUAL(true, aSize
== aSize
);
77 CPPUNIT_ASSERT_EQUAL(true, aSize
== aSize2
);
78 CPPUNIT_ASSERT_EQUAL(true, aSize
== B2DSize(4.0, 8.0));
79 CPPUNIT_ASSERT_EQUAL(false, aSize
== B2DSize(4.0, 7.99));
80 CPPUNIT_ASSERT_EQUAL(false, aSize
== B2DSize(3.99, 8.0));
83 void testOperatorMinus()
85 B2DSize aSizeMinus
= -B2DSize(4.0, 8.0);
86 CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.0, aSizeMinus
.getWidth(), 1e-2);
87 CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.0, aSizeMinus
.getHeight(), 1e-2);
89 B2DSize aSizeZero
= -B2DSize(0.0, 0.0);
90 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aSizeZero
.getWidth(), 1e-2);
91 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aSizeZero
.getHeight(), 1e-2);
94 CPPUNIT_TEST_SUITE(B2DSizeTest
);
95 CPPUNIT_TEST(testOperatorAddition
);
96 CPPUNIT_TEST(testOperatorSubstraction
);
97 CPPUNIT_TEST(testOperatorMultiply
);
98 CPPUNIT_TEST(testOperatorDivide
);
99 CPPUNIT_TEST(testOperatorEqualUnequal
);
100 CPPUNIT_TEST(testOperatorMinus
);
101 CPPUNIT_TEST_SUITE_END();
104 } // namespace basegfx
106 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::B2DSizeTest
);
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */