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