cid#1607171 Data race condition
[LibreOffice.git] / sal / qa / rtl / crc32 / rtl_crc32.cxx
blob34b900f8555b90b632a3e4e87b3e27ff64146d57
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>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
24 #include <rtl/crc.h>
26 namespace rtl_CRC32
29 class test : public CppUnit::TestFixture
31 public:
33 // insert your test code here.
34 void rtl_crc32_001()
36 // this is demonstration code
37 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
39 sal_uInt32 nCRC = 0;
41 char buf[] = {0};
42 int num = 0;
44 nCRC = rtl_crc32(nCRC, buf, num);
46 CPPUNIT_ASSERT_EQUAL_MESSAGE("empty crc buffer", static_cast<sal_uInt32>(0), nCRC);
49 void rtl_crc32_002()
51 sal_uInt32 nCRC = 0;
53 char buf[] = {0,0};
54 int num = sizeof(buf);
56 nCRC = rtl_crc32(nCRC, buf, num);
58 CPPUNIT_ASSERT_MESSAGE("buffer contain 2 empty bytes, crc is zero", nCRC != 0);
61 void rtl_crc32_002_1()
63 sal_uInt32 nCRC = 0;
65 char buf[] = {0,0,0};
66 int num = sizeof(buf);
68 nCRC = rtl_crc32(nCRC, buf, num);
70 CPPUNIT_ASSERT_MESSAGE("buffer contain 3 empty bytes, crc is zero", nCRC != 0);
73 /**
74 * crc32 check:
75 * Build checksum on two buffers with same size but different content,
76 * the result (crc32 checksum) must differ
79 void rtl_crc32_003()
81 sal_uInt32 nCRC1 = 0;
82 char buf1[] = {2};
83 int num1 = sizeof(buf1);
85 nCRC1 = rtl_crc32(nCRC1, buf1, num1);
87 sal_uInt32 nCRC2 = 0;
88 char buf2[] = {3};
89 int num2 = sizeof(buf2);
91 nCRC2 = rtl_crc32(nCRC2, buf2, num2);
93 CPPUNIT_ASSERT_MESSAGE("checksum should differ for buf1 and buf2", nCRC1 != nCRC2);
96 /** check if the crc32 only use as much values, as given
99 void rtl_crc32_003_1()
101 sal_uInt32 nCRC1 = 0;
102 char buf1[] = {2,1};
103 int num1 = sizeof(buf1) - 1;
105 nCRC1 = rtl_crc32(nCRC1, buf1, num1);
107 sal_uInt32 nCRC2 = 0;
108 char buf2[] = {2,2};
109 int num2 = sizeof(buf2) - 1;
111 nCRC2 = rtl_crc32(nCRC2, buf2, num2);
113 CPPUNIT_ASSERT_EQUAL_MESSAGE("checksum leave it's bounds", nCRC2, nCRC1);
116 /** check if the crc32 differ at same content in reverse order
119 void rtl_crc32_003_2()
121 sal_uInt32 nCRC1 = 0;
122 char buf1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
123 int num1 = sizeof(buf1);
125 nCRC1 = rtl_crc32(nCRC1, buf1, num1);
127 sal_uInt32 nCRC2 = 0;
128 char buf2[] = {20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
129 int num2 = sizeof(buf2);
131 nCRC2 = rtl_crc32(nCRC2, buf2, num2);
133 CPPUNIT_ASSERT_MESSAGE("checksum should differ", nCRC1 != nCRC2);
136 // Change the following lines only, if you add, remove or rename
137 // member functions of the current class,
138 // because these macros are need by auto register mechanism.
140 CPPUNIT_TEST_SUITE(test);
141 CPPUNIT_TEST(rtl_crc32_001);
142 CPPUNIT_TEST(rtl_crc32_002);
143 CPPUNIT_TEST(rtl_crc32_002_1);
144 CPPUNIT_TEST(rtl_crc32_003);
145 CPPUNIT_TEST(rtl_crc32_003_1);
146 CPPUNIT_TEST(rtl_crc32_003_2);
147 CPPUNIT_TEST_SUITE_END();
148 }; // class test
150 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_CRC32::test);
151 } // namespace rtl_CRC32
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */