summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2018-05-12 19:57:19 +1000
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-05-16 09:07:14 +0200
commit99dbaba70afb91ed3961f9ff627c35bf54d66bef (patch)
treef9d6ec2dd1ce8d90a561f89c8bfe9a604578b915 /tools
parent8611689f0df73daeebb261b0c06c8a1727c17fe3 (diff)
tools: test Pair
Change-Id: I03e48c134ec9b8fc53c247ced231f209e1205cb1 Reviewed-on: https://gerrit.libreoffice.org/54189 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'tools')
-rw-r--r--tools/CppunitTest_tools_test.mk1
-rw-r--r--tools/Library_tl.mk1
-rw-r--r--tools/qa/cppunit/test_pair.cxx126
-rw-r--r--tools/source/generic/pair.cxx28
4 files changed, 156 insertions, 0 deletions
diff --git a/tools/CppunitTest_tools_test.mk b/tools/CppunitTest_tools_test.mk
index 7cf5657e68ec..ad393f8347c6 100644
--- a/tools/CppunitTest_tools_test.mk
+++ b/tools/CppunitTest_tools_test.mk
@@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,tools_test, \
tools/qa/cppunit/test_minmax \
tools/qa/cppunit/test_100mm2twips \
tools/qa/cppunit/test_fround \
+ tools/qa/cppunit/test_pair \
))
$(eval $(call gb_CppunitTest_use_sdk_api,tools_test))
diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk
index c524a38084aa..539bee3e5b2a 100644
--- a/tools/Library_tl.mk
+++ b/tools/Library_tl.mk
@@ -57,6 +57,7 @@ $(eval $(call gb_Library_add_exception_objects,tl,\
tools/source/generic/config \
tools/source/generic/fract \
tools/source/generic/gen \
+ tools/source/generic/pair \
tools/source/generic/line \
tools/source/generic/point \
tools/source/generic/poly \
diff --git a/tools/qa/cppunit/test_pair.cxx b/tools/qa/cppunit/test_pair.cxx
new file mode 100644
index 000000000000..31812963f754
--- /dev/null
+++ b/tools/qa/cppunit/test_pair.cxx
@@ -0,0 +1,126 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/types.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <tools/stream.hxx>
+#include <tools/Pair.hxx>
+
+namespace tools
+{
+class PairTest : public CppUnit::TestFixture
+{
+public:
+ void testPair()
+ {
+ long nExpectedA = 0;
+ long nExpectedB = 0;
+ long nActualA = 0;
+ long nActualB = 0;
+
+ {
+ Pair aPair;
+ nActualA = aPair.A();
+ nActualB = aPair.B();
+
+ CPPUNIT_ASSERT_EQUAL(nExpectedA, nActualA);
+ CPPUNIT_ASSERT_EQUAL(nExpectedB, nActualB);
+ }
+
+ {
+ Pair aPair(1, 2);
+ nExpectedA = 1;
+ nExpectedB = 2;
+ nActualA = aPair.A();
+ nActualB = aPair.B();
+
+ CPPUNIT_ASSERT_EQUAL(nExpectedA, nActualA);
+ CPPUNIT_ASSERT_EQUAL(nExpectedB, nActualB);
+ }
+ }
+
+ void testToString()
+ {
+ OString sExpectedString("1, 2");
+ Pair aPair(1, 2);
+ CPPUNIT_ASSERT_EQUAL(sExpectedString, aPair.toString());
+ }
+
+ void testReadStream()
+ {
+ TestPair* pData = new TestPair(1, 2);
+ SvMemoryStream aMemStm(pData, 8, StreamMode::READ);
+
+ Pair aPair;
+ ReadPair(aMemStm, aPair);
+
+ sal_Int32 nExpectedA = 1;
+ sal_Int32 nExpectedB = 2;
+ sal_Int32 nActualA = aPair.A();
+ sal_Int32 nActualB = aPair.B();
+
+ CPPUNIT_ASSERT_EQUAL(nExpectedA, nActualA);
+ CPPUNIT_ASSERT_EQUAL(nExpectedB, nActualB);
+ }
+
+ void testWriteStream()
+ {
+ SvMemoryStream aMemStm;
+
+ WritePair(aMemStm, Pair(1, 2));
+
+ Pair aPair;
+ aMemStm.Seek(0); // reset to the beginning of the stream
+ ReadPair(aMemStm, aPair);
+
+ sal_Int32 nExpectedA = 1;
+ sal_Int32 nExpectedB = 2;
+ sal_Int32 nActualA = aPair.A();
+ sal_Int32 nActualB = aPair.B();
+
+ CPPUNIT_ASSERT_EQUAL(nExpectedA, nActualA);
+ CPPUNIT_ASSERT_EQUAL(nExpectedB, nActualB);
+ }
+
+ CPPUNIT_TEST_SUITE(PairTest);
+ CPPUNIT_TEST(testPair);
+ CPPUNIT_TEST(testToString);
+ CPPUNIT_TEST(testReadStream);
+ CPPUNIT_TEST(testWriteStream);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ struct TestPair
+ {
+ sal_Int32 mnA;
+ sal_Int32 mnB;
+
+ TestPair(sal_Int32 nA, sal_Int32 nB)
+ : mnA(nA)
+ , mnB(nB){};
+ };
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PairTest);
+} // namespace tools
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/source/generic/pair.cxx b/tools/source/generic/pair.cxx
new file mode 100644
index 000000000000..6e998592ce5d
--- /dev/null
+++ b/tools/source/generic/pair.cxx
@@ -0,0 +1,28 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <tools/gen.hxx>
+#include <tools/Pair.hxx>
+
+SvStream& ReadPair(SvStream& rIStream, Point& v) { return ReadPair(rIStream, v.toPair()); }
+SvStream& WritePair(SvStream& rOStream, const Point& v) { return WritePair(rOStream, v.toPair()); }
+SvStream& ReadPair(SvStream& rIStream, Size& v) { return ReadPair(rIStream, v.toPair()); }
+SvStream& WritePair(SvStream& rOStream, const Size& v) { return WritePair(rOStream, v.toPair()); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */