File indexing completed on 2024-04-21 04:34:22
0001 /* This file is part of the TikZKit project. 0002 * 0003 * Copyright (C) 2014 Dominik Haumann <dhaumann@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU Library General Public License as published 0007 * by the Free Software Foundation, either version 2 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, see 0017 * <http://www.gnu.org/licenses/>. 0018 */ 0019 #include "TestPos.h" 0020 0021 #include <QtTest/QTest> 0022 0023 #include <tikz/core/Pos.h> 0024 0025 QTEST_MAIN(PosTest) 0026 0027 void PosTest::initTestCase() 0028 { 0029 } 0030 0031 void PosTest::cleanupTestCase() 0032 { 0033 } 0034 0035 void PosTest::testPos() 0036 { 0037 tikz::Pos pos; 0038 0039 // test initial value 0040 QCOMPARE(pos.x(), tikz::Value(0.0)); 0041 QCOMPARE(pos.y(), tikz::Value(0.0)); 0042 QCOMPARE(tikz::toString(pos.x().unit()), tikz::toString(tikz::Unit::Point)); 0043 QCOMPARE(tikz::toString(pos.y().unit()), tikz::toString(tikz::Unit::Point)); 0044 QCOMPARE(pos.toString(), QString("(0pt, 0pt)")); 0045 } 0046 0047 void PosTest::testFromString() 0048 { 0049 tikz::Pos pos; 0050 0051 // test "0pt" 0052 QCOMPARE(pos, tikz::Pos::fromString("(0pt, 0pt)")); 0053 QCOMPARE(pos, tikz::Pos::fromString("(0pt,0pt)")); 0054 QCOMPARE(pos, tikz::Pos::fromString("(0, 0)")); 0055 QCOMPARE(pos, tikz::Pos::fromString("(0,0)")); 0056 0057 pos = tikz::Pos(3.0_cm, 5.0_cm); 0058 QCOMPARE(pos.x(), 3.0_cm); 0059 QCOMPARE(pos.y(), 5.0_cm); 0060 QCOMPARE(pos, tikz::Pos::fromString("(3cm, 5cm)")); 0061 QCOMPARE(pos, tikz::Pos::fromString("(3cm, 5cm)").convertTo(tikz::Unit::Point)); 0062 QCOMPARE(pos, tikz::Pos::fromString("(3cm, 5cm)").convertTo(tikz::Unit::Millimeter)); 0063 QCOMPARE(pos, tikz::Pos::fromString("(3cm, 5cm)").convertTo(tikz::Unit::Centimeter)); 0064 QCOMPARE(pos, tikz::Pos::fromString("(3cm, 5cm)").convertTo(tikz::Unit::Inch)); 0065 } 0066 0067 // kate: indent-width 4; replace-tabs on;