Bump version to 6.4-15
[LibreOffice.git] / tools / qa / cppunit / test_GenericTypeSerializer.cxx
blob24d1497f92d2fa24a950debcfab9047aeae5e411
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sal/types.h>
22 #include <cppunit/TestFixture.h>
23 #include <cppunit/extensions/HelperMacros.h>
25 #include <tools/GenericTypeSerializer.hxx>
26 #include <tools/stream.hxx>
27 #include <tools/gen.hxx>
29 namespace tools
31 class GenericTypeSerializerTest : public CppUnit::TestFixture
33 public:
34 void testRoundtripPoint()
36 Point aPoint(20, 50);
37 SvMemoryStream aStream;
38 GenericTypeSerializer aSerializer(aStream);
39 aSerializer.writePoint(aPoint);
40 aStream.Seek(STREAM_SEEK_TO_BEGIN);
41 Point aReadPoint;
42 aSerializer.readPoint(aReadPoint);
43 CPPUNIT_ASSERT_EQUAL(aPoint, aReadPoint);
46 void testRoundtripSize()
48 Size aSize(40, 80);
49 SvMemoryStream aStream;
50 GenericTypeSerializer aSerializer(aStream);
51 aSerializer.writeSize(aSize);
52 aStream.Seek(STREAM_SEEK_TO_BEGIN);
53 Size aReadSize;
54 aSerializer.readSize(aReadSize);
55 CPPUNIT_ASSERT_EQUAL(aSize, aReadSize);
58 void testRoundtripRectangle()
61 Rectangle aRectangle;
62 CPPUNIT_ASSERT(aRectangle.IsEmpty());
63 SvMemoryStream aStream;
64 aStream.Seek(STREAM_SEEK_TO_BEGIN);
65 GenericTypeSerializer aSerializer(aStream);
66 aSerializer.writeRectangle(aRectangle);
67 aStream.Seek(STREAM_SEEK_TO_BEGIN);
68 // Need to set the rectangle to non-empty, so it will be set to empty later
69 Rectangle aReadRectangle(Point(20, 50), Size(10, 30));
70 aSerializer.readRectangle(aReadRectangle);
71 CPPUNIT_ASSERT(aRectangle.IsEmpty());
75 Rectangle aRectangle(Point(20, 50), Size(10, 30));
76 SvMemoryStream aStream;
77 aStream.Seek(STREAM_SEEK_TO_BEGIN);
78 GenericTypeSerializer aSerializer(aStream);
79 aSerializer.writeRectangle(aRectangle);
80 aStream.Seek(STREAM_SEEK_TO_BEGIN);
81 Rectangle aReadRectangle;
82 aSerializer.readRectangle(aReadRectangle);
83 CPPUNIT_ASSERT_EQUAL(aRectangle.Top(), aReadRectangle.Top());
84 CPPUNIT_ASSERT_EQUAL(aRectangle.Left(), aReadRectangle.Left());
85 CPPUNIT_ASSERT_EQUAL(aRectangle.Right(), aReadRectangle.Right());
86 CPPUNIT_ASSERT_EQUAL(aRectangle.Bottom(), aReadRectangle.Bottom());
90 CPPUNIT_TEST_SUITE(GenericTypeSerializerTest);
91 CPPUNIT_TEST(testRoundtripPoint);
92 CPPUNIT_TEST(testRoundtripSize);
93 CPPUNIT_TEST(testRoundtripRectangle);
94 CPPUNIT_TEST_SUITE_END();
97 CPPUNIT_TEST_SUITE_REGISTRATION(GenericTypeSerializerTest);
99 } // namespace tools
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */