1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 #include <cppunit/plugin/TestPlugIn.h>
30 class test
: public CppUnit::TestFixture
34 // insert your test code here.
37 // this is demonstration code
38 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
45 nCRC
= rtl_crc32(nCRC
, buf
, num
);
47 CPPUNIT_ASSERT_EQUAL_MESSAGE("empty crc buffer", static_cast<sal_uInt32
>(0), nCRC
);
55 int num
= sizeof(buf
);
57 nCRC
= rtl_crc32(nCRC
, buf
, num
);
59 CPPUNIT_ASSERT_MESSAGE("buffer contain 2 empty bytes, crc is zero", nCRC
!= 0);
62 void rtl_crc32_002_1()
67 int num
= sizeof(buf
);
69 nCRC
= rtl_crc32(nCRC
, buf
, num
);
71 CPPUNIT_ASSERT_MESSAGE("buffer contain 3 empty bytes, crc is zero", nCRC
!= 0);
76 * Build checksum on two buffers with same size but different content,
77 * the result (crc32 checksum) must differ
84 int num1
= sizeof(buf1
);
86 nCRC1
= rtl_crc32(nCRC1
, buf1
, num1
);
90 int num2
= sizeof(buf2
);
92 nCRC2
= rtl_crc32(nCRC2
, buf2
, num2
);
94 CPPUNIT_ASSERT_MESSAGE("checksum should differ for buf1 and buf2", nCRC1
!= nCRC2
);
97 /** check if the crc32 only use as much values, as given
100 void rtl_crc32_003_1()
102 sal_uInt32 nCRC1
= 0;
104 int num1
= sizeof(buf1
) - 1;
106 nCRC1
= rtl_crc32(nCRC1
, buf1
, num1
);
108 sal_uInt32 nCRC2
= 0;
110 int num2
= sizeof(buf2
) - 1;
112 nCRC2
= rtl_crc32(nCRC2
, buf2
, num2
);
114 CPPUNIT_ASSERT_EQUAL_MESSAGE("checksum leave it's bounds", nCRC2
, nCRC1
);
117 /** check if the crc32 differ at same content in reverse order
120 void rtl_crc32_003_2()
122 sal_uInt32 nCRC1
= 0;
123 char buf1
[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
124 int num1
= sizeof(buf1
);
126 nCRC1
= rtl_crc32(nCRC1
, buf1
, num1
);
128 sal_uInt32 nCRC2
= 0;
129 char buf2
[] = {20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
130 int num2
= sizeof(buf2
);
132 nCRC2
= rtl_crc32(nCRC2
, buf2
, num2
);
134 CPPUNIT_ASSERT_MESSAGE("checksum should differ", nCRC1
!= nCRC2
);
137 // Change the following lines only, if you add, remove or rename
138 // member functions of the current class,
139 // because these macros are need by auto register mechanism.
141 CPPUNIT_TEST_SUITE(test
);
142 CPPUNIT_TEST(rtl_crc32_001
);
143 CPPUNIT_TEST(rtl_crc32_002
);
144 CPPUNIT_TEST(rtl_crc32_002_1
);
145 CPPUNIT_TEST(rtl_crc32_003
);
146 CPPUNIT_TEST(rtl_crc32_003_1
);
147 CPPUNIT_TEST(rtl_crc32_003_2
);
148 CPPUNIT_TEST_SUITE_END();
151 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_CRC32::test
);
152 } // namespace rtl_CRC32
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */