tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / tools / qa / cppunit / test_GenericTypeSerializer.cxx
blobd378dd7c304d170452b50796e59f8657b777e0a1
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 void testRoundtripFraction()
93 Fraction aFraction(2, 5);
94 CPPUNIT_ASSERT_EQUAL(true, aFraction.IsValid());
95 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFraction.GetNumerator());
96 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aFraction.GetDenominator());
98 SvMemoryStream aStream;
99 aStream.Seek(STREAM_SEEK_TO_BEGIN);
100 GenericTypeSerializer aSerializer(aStream);
101 aSerializer.writeFraction(aFraction);
103 aStream.Seek(STREAM_SEEK_TO_BEGIN);
105 Fraction aReadFraction(1, 2);
106 aSerializer.readFraction(aReadFraction);
107 CPPUNIT_ASSERT_EQUAL(true, aReadFraction.IsValid());
108 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aReadFraction.GetNumerator());
109 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aReadFraction.GetDenominator());
112 Fraction aFraction(1, 0);
113 CPPUNIT_ASSERT_EQUAL(false, aFraction.IsValid());
114 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aFraction.GetNumerator());
115 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aFraction.GetDenominator());
117 SvMemoryStream aStream;
118 aStream.Seek(STREAM_SEEK_TO_BEGIN);
119 GenericTypeSerializer aSerializer(aStream);
120 aSerializer.writeFraction(aFraction);
122 aStream.Seek(STREAM_SEEK_TO_BEGIN);
124 Fraction aReadFraction(1, 2);
125 aSerializer.readFraction(aReadFraction);
126 CPPUNIT_ASSERT_EQUAL(false, aReadFraction.IsValid());
127 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aReadFraction.GetNumerator());
128 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aReadFraction.GetDenominator());
132 CPPUNIT_TEST_SUITE(GenericTypeSerializerTest);
133 CPPUNIT_TEST(testRoundtripPoint);
134 CPPUNIT_TEST(testRoundtripSize);
135 CPPUNIT_TEST(testRoundtripRectangle);
136 CPPUNIT_TEST(testRoundtripFraction);
137 CPPUNIT_TEST_SUITE_END();
140 CPPUNIT_TEST_SUITE_REGISTRATION(GenericTypeSerializerTest);
142 } // namespace tools
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */