diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-09-26 16:22:09 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-09-29 15:17:47 +0200 |
commit | 66eedce71f10c30712f34732157e4dcdfcb49090 (patch) | |
tree | 912ca181175c8bde690eda218d4051a4604bbcff /tools/qa | |
parent | 43d3f3a2d1f5a3dcfbd42368c4e86e24b80c6cbb (diff) |
Move Rectangle,Point,Size serialization to GenericTypeSerializer
Change-Id: Iae489fc31b13b836e1df5327ba2fa07e0325907a
Reviewed-on: https://gerrit.libreoffice.org/79793
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'tools/qa')
-rw-r--r-- | tools/qa/cppunit/test_GenericTypeSerializer.cxx | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tools/qa/cppunit/test_GenericTypeSerializer.cxx b/tools/qa/cppunit/test_GenericTypeSerializer.cxx new file mode 100644 index 000000000000..24d1497f92d2 --- /dev/null +++ b/tools/qa/cppunit/test_GenericTypeSerializer.cxx @@ -0,0 +1,101 @@ +/* -*- 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 <tools/GenericTypeSerializer.hxx> +#include <tools/stream.hxx> +#include <tools/gen.hxx> + +namespace tools +{ +class GenericTypeSerializerTest : public CppUnit::TestFixture +{ +public: + void testRoundtripPoint() + { + Point aPoint(20, 50); + SvMemoryStream aStream; + GenericTypeSerializer aSerializer(aStream); + aSerializer.writePoint(aPoint); + aStream.Seek(STREAM_SEEK_TO_BEGIN); + Point aReadPoint; + aSerializer.readPoint(aReadPoint); + CPPUNIT_ASSERT_EQUAL(aPoint, aReadPoint); + } + + void testRoundtripSize() + { + Size aSize(40, 80); + SvMemoryStream aStream; + GenericTypeSerializer aSerializer(aStream); + aSerializer.writeSize(aSize); + aStream.Seek(STREAM_SEEK_TO_BEGIN); + Size aReadSize; + aSerializer.readSize(aReadSize); + CPPUNIT_ASSERT_EQUAL(aSize, aReadSize); + } + + void testRoundtripRectangle() + { + { + Rectangle aRectangle; + CPPUNIT_ASSERT(aRectangle.IsEmpty()); + SvMemoryStream aStream; + aStream.Seek(STREAM_SEEK_TO_BEGIN); + GenericTypeSerializer aSerializer(aStream); + aSerializer.writeRectangle(aRectangle); + aStream.Seek(STREAM_SEEK_TO_BEGIN); + // Need to set the rectangle to non-empty, so it will be set to empty later + Rectangle aReadRectangle(Point(20, 50), Size(10, 30)); + aSerializer.readRectangle(aReadRectangle); + CPPUNIT_ASSERT(aRectangle.IsEmpty()); + } + + { + Rectangle aRectangle(Point(20, 50), Size(10, 30)); + SvMemoryStream aStream; + aStream.Seek(STREAM_SEEK_TO_BEGIN); + GenericTypeSerializer aSerializer(aStream); + aSerializer.writeRectangle(aRectangle); + aStream.Seek(STREAM_SEEK_TO_BEGIN); + Rectangle aReadRectangle; + aSerializer.readRectangle(aReadRectangle); + CPPUNIT_ASSERT_EQUAL(aRectangle.Top(), aReadRectangle.Top()); + CPPUNIT_ASSERT_EQUAL(aRectangle.Left(), aReadRectangle.Left()); + CPPUNIT_ASSERT_EQUAL(aRectangle.Right(), aReadRectangle.Right()); + CPPUNIT_ASSERT_EQUAL(aRectangle.Bottom(), aReadRectangle.Bottom()); + } + } + + CPPUNIT_TEST_SUITE(GenericTypeSerializerTest); + CPPUNIT_TEST(testRoundtripPoint); + CPPUNIT_TEST(testRoundtripSize); + CPPUNIT_TEST(testRoundtripRectangle); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(GenericTypeSerializerTest); + +} // namespace tools + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |