blob: d439a05832e09076b0755b7f0152bf02d95e970d [file] [log] [blame]
Tomaž Vajngerlc7474862022-09-08 11:12:27 +02001/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
Michael Meeksd037b812026-03-26 15:06:16 +00003 * This file is part of the Collabora Office project.
Tomaž Vajngerlc7474862022-09-08 11:12:27 +02004 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <cppunit/TestFixture.h>
21#include <cppunit/extensions/HelperMacros.h>
22
23#include <basegfx/vector/b2dsize.hxx>
24
25namespace basegfx
26{
27class B2DSizeTest : public CppUnit::TestFixture
28{
29public:
30 void testOperatorAddition()
31 {
32 B2DSize aSize(4.0, 8.0);
33 aSize += { 2.0, 3.0 };
34
35 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.0, aSize.getWidth(), 1e-2);
36 CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, aSize.getHeight(), 1e-2);
37 }
38
39 void testOperatorSubstraction()
40 {
41 B2DSize aSize(4.0, 8.0);
42 aSize -= { 2.0, 3.0 };
43
44 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, aSize.getWidth(), 1e-2);
45 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, aSize.getHeight(), 1e-2);
46 }
47
48 void testOperatorMultiply()
49 {
50 B2DSize aSize(4.0, 8.0);
51 aSize *= { 2.0, 3.0 };
52
53 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.0, aSize.getWidth(), 1e-2);
54 CPPUNIT_ASSERT_DOUBLES_EQUAL(24.0, aSize.getHeight(), 1e-2);
55
56 aSize *= 2.0;
57
58 CPPUNIT_ASSERT_DOUBLES_EQUAL(16.0, aSize.getWidth(), 1e-2);
59 CPPUNIT_ASSERT_DOUBLES_EQUAL(48.0, aSize.getHeight(), 1e-2);
60 }
61
62 void testOperatorDivide()
63 {
64 B2DSize aSize(4.0, 8.0);
65 aSize /= { 2.0, 8.0 };
66
67 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, aSize.getWidth(), 1e-2);
68 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, aSize.getHeight(), 1e-2);
69 }
70
71 void testOperatorEqualUnequal()
72 {
73 B2DSize aSize(4.0, 8.0);
74 B2DSize aSize2 = aSize;
75
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));
81 }
82
83 void testOperatorMinus()
84 {
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);
88
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);
92 }
93
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();
102};
103
104} // namespace basegfx
105
106CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::B2DSizeTest);
107
108/* vim:set shiftwidth=4 softtabstop=4 expandtab: */