xref: /aoo41x/main/sal/qa/rtl/crc32/rtl_crc32.cxx (revision 79aad27f)
1*87d2adbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*87d2adbcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*87d2adbcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*87d2adbcSAndrew Rist  * distributed with this work for additional information
6*87d2adbcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*87d2adbcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*87d2adbcSAndrew Rist  * "License"); you may not use this file except in compliance
9*87d2adbcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*87d2adbcSAndrew Rist  *
11*87d2adbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*87d2adbcSAndrew Rist  *
13*87d2adbcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*87d2adbcSAndrew Rist  * software distributed under the License is distributed on an
15*87d2adbcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*87d2adbcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*87d2adbcSAndrew Rist  * specific language governing permissions and limitations
18*87d2adbcSAndrew Rist  * under the License.
19*87d2adbcSAndrew Rist  *
20*87d2adbcSAndrew Rist  *************************************************************/
21*87d2adbcSAndrew Rist 
22*87d2adbcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
26cdf0e10cSrcweir #include "precompiled_sal.hxx"
27cdf0e10cSrcweir // autogenerated file with codegen.pl
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <testshl/simpleheader.hxx>
30cdf0e10cSrcweir #include <rtl/crc.h>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace rtl_CRC32
33cdf0e10cSrcweir {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir class test : public CppUnit::TestFixture
36cdf0e10cSrcweir {
37cdf0e10cSrcweir public:
38cdf0e10cSrcweir     // initialise your test code values here.
setUp()39cdf0e10cSrcweir     void setUp()
40cdf0e10cSrcweir     {
41cdf0e10cSrcweir     }
42cdf0e10cSrcweir 
tearDown()43cdf0e10cSrcweir     void tearDown()
44cdf0e10cSrcweir     {
45cdf0e10cSrcweir     }
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     // insert your test code here.
rtl_crc32_001()49cdf0e10cSrcweir     void rtl_crc32_001()
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         // this is demonstration code
52cdf0e10cSrcweir         // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
53cdf0e10cSrcweir 
54cdf0e10cSrcweir         sal_uInt32 nCRC = 0;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir         char buf[] = {0};
57cdf0e10cSrcweir         int num = 0;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         nCRC = rtl_crc32(nCRC, buf, num);
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("empty crc buffer", nCRC == 0);
62cdf0e10cSrcweir     }
63cdf0e10cSrcweir 
rtl_crc32_002()64cdf0e10cSrcweir     void rtl_crc32_002()
65cdf0e10cSrcweir     {
66cdf0e10cSrcweir         sal_uInt32 nCRC = 0;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         char buf[] = {0,0};
69cdf0e10cSrcweir         int num = sizeof(buf);
70cdf0e10cSrcweir 
71cdf0e10cSrcweir         nCRC = rtl_crc32(nCRC, buf, num);
72cdf0e10cSrcweir 
73cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("buffer contain 2 empty bytes, crc is zero", nCRC != 0);
74cdf0e10cSrcweir     }
75cdf0e10cSrcweir 
rtl_crc32_002_1()76cdf0e10cSrcweir     void rtl_crc32_002_1()
77cdf0e10cSrcweir     {
78cdf0e10cSrcweir         sal_uInt32 nCRC = 0;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         char buf[] = {0,0,0};
81cdf0e10cSrcweir         int num = sizeof(buf);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         nCRC = rtl_crc32(nCRC, buf, num);
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("buffer contain 3 empty bytes, crc is zero", nCRC != 0);
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     /**
89cdf0e10cSrcweir      * crc32 check:
90cdf0e10cSrcweir      * Build checksum on two buffers with same size but different content,
91cdf0e10cSrcweir      * the result (crc32 checksum) must differ
92cdf0e10cSrcweir      */
93cdf0e10cSrcweir 
rtl_crc32_003()94cdf0e10cSrcweir     void rtl_crc32_003()
95cdf0e10cSrcweir     {
96cdf0e10cSrcweir         sal_uInt32 nCRC1 = 0;
97cdf0e10cSrcweir         char buf1[] = {2};
98cdf0e10cSrcweir         int num1 = sizeof(buf1);
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         nCRC1 = rtl_crc32(nCRC1, buf1, num1);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         sal_uInt32 nCRC2 = 0;
103cdf0e10cSrcweir         char buf2[] = {3};
104cdf0e10cSrcweir         int num2 = sizeof(buf2);
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         nCRC2 = rtl_crc32(nCRC2, buf2, num2);
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("checksum should differ for buf1 and buf2", nCRC1 != nCRC2);
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     /** check if the crc32 only use as much values, as given
112cdf0e10cSrcweir      *
113cdf0e10cSrcweir      */
rtl_crc32_003_1()114cdf0e10cSrcweir     void rtl_crc32_003_1()
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         sal_uInt32 nCRC1 = 0;
117cdf0e10cSrcweir         char buf1[] = {2,1};
118cdf0e10cSrcweir         int num1 = sizeof(buf1) - 1;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         nCRC1 = rtl_crc32(nCRC1, buf1, num1);
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         sal_uInt32 nCRC2 = 0;
123cdf0e10cSrcweir         char buf2[] = {2,2};
124cdf0e10cSrcweir         int num2 = sizeof(buf2) - 1;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         nCRC2 = rtl_crc32(nCRC2, buf2, num2);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("checksum leave it's bounds", nCRC1 == nCRC2);
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     /** check if the crc32 differ at same content in reverse order
132cdf0e10cSrcweir      *
133cdf0e10cSrcweir      */
rtl_crc32_003_2()134cdf0e10cSrcweir     void rtl_crc32_003_2()
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         sal_uInt32 nCRC1 = 0;
137cdf0e10cSrcweir         char buf1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
138cdf0e10cSrcweir         int num1 = sizeof(buf1);
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         nCRC1 = rtl_crc32(nCRC1, buf1, num1);
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         sal_uInt32 nCRC2 = 0;
143cdf0e10cSrcweir         char buf2[] = {20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
144cdf0e10cSrcweir         int num2 = sizeof(buf2);
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         nCRC2 = rtl_crc32(nCRC2, buf2, num2);
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("checksum should differ", nCRC1 != nCRC2);
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
154cdf0e10cSrcweir     // member functions of the current class,
155cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(test);
158cdf0e10cSrcweir     CPPUNIT_TEST(rtl_crc32_001);
159cdf0e10cSrcweir     CPPUNIT_TEST(rtl_crc32_002);
160cdf0e10cSrcweir     CPPUNIT_TEST(rtl_crc32_002_1);
161cdf0e10cSrcweir     CPPUNIT_TEST(rtl_crc32_003);
162cdf0e10cSrcweir     CPPUNIT_TEST(rtl_crc32_003_1);
163cdf0e10cSrcweir     CPPUNIT_TEST(rtl_crc32_003_2);
164cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
165cdf0e10cSrcweir }; // class test
166cdf0e10cSrcweir 
167cdf0e10cSrcweir // -----------------------------------------------------------------------------
168cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_CRC32::test, "rtl_crc32");
169cdf0e10cSrcweir } // namespace rtl_CRC32
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 
172cdf0e10cSrcweir // -----------------------------------------------------------------------------
173cdf0e10cSrcweir 
174cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions()
175cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand.
176cdf0e10cSrcweir NOADDITIONAL;
177cdf0e10cSrcweir 
178