xref: /aoo41x/main/sal/qa/rtl/crc32/rtl_crc32.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sal.hxx"
31 // autogenerated file with codegen.pl
32 
33 #include <testshl/simpleheader.hxx>
34 #include <rtl/crc.h>
35 
36 namespace rtl_CRC32
37 {
38 
39 class test : public CppUnit::TestFixture
40 {
41 public:
42     // initialise your test code values here.
43     void setUp()
44     {
45     }
46 
47     void tearDown()
48     {
49     }
50 
51 
52     // insert your test code here.
53     void rtl_crc32_001()
54     {
55         // this is demonstration code
56         // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
57 
58         sal_uInt32 nCRC = 0;
59 
60         char buf[] = {0};
61         int num = 0;
62 
63         nCRC = rtl_crc32(nCRC, buf, num);
64 
65         CPPUNIT_ASSERT_MESSAGE("empty crc buffer", nCRC == 0);
66     }
67 
68     void rtl_crc32_002()
69     {
70         sal_uInt32 nCRC = 0;
71 
72         char buf[] = {0,0};
73         int num = sizeof(buf);
74 
75         nCRC = rtl_crc32(nCRC, buf, num);
76 
77         CPPUNIT_ASSERT_MESSAGE("buffer contain 2 empty bytes, crc is zero", nCRC != 0);
78     }
79 
80     void rtl_crc32_002_1()
81     {
82         sal_uInt32 nCRC = 0;
83 
84         char buf[] = {0,0,0};
85         int num = sizeof(buf);
86 
87         nCRC = rtl_crc32(nCRC, buf, num);
88 
89         CPPUNIT_ASSERT_MESSAGE("buffer contain 3 empty bytes, crc is zero", nCRC != 0);
90     }
91 
92     /**
93      * crc32 check:
94      * Build checksum on two buffers with same size but different content,
95      * the result (crc32 checksum) must differ
96      */
97 
98     void rtl_crc32_003()
99     {
100         sal_uInt32 nCRC1 = 0;
101         char buf1[] = {2};
102         int num1 = sizeof(buf1);
103 
104         nCRC1 = rtl_crc32(nCRC1, buf1, num1);
105 
106         sal_uInt32 nCRC2 = 0;
107         char buf2[] = {3};
108         int num2 = sizeof(buf2);
109 
110         nCRC2 = rtl_crc32(nCRC2, buf2, num2);
111 
112         CPPUNIT_ASSERT_MESSAGE("checksum should differ for buf1 and buf2", nCRC1 != nCRC2);
113     }
114 
115     /** check if the crc32 only use as much values, as given
116      *
117      */
118     void rtl_crc32_003_1()
119     {
120         sal_uInt32 nCRC1 = 0;
121         char buf1[] = {2,1};
122         int num1 = sizeof(buf1) - 1;
123 
124         nCRC1 = rtl_crc32(nCRC1, buf1, num1);
125 
126         sal_uInt32 nCRC2 = 0;
127         char buf2[] = {2,2};
128         int num2 = sizeof(buf2) - 1;
129 
130         nCRC2 = rtl_crc32(nCRC2, buf2, num2);
131 
132         CPPUNIT_ASSERT_MESSAGE("checksum leave it's bounds", nCRC1 == nCRC2);
133     }
134 
135     /** check if the crc32 differ at same content in reverse order
136      *
137      */
138     void rtl_crc32_003_2()
139     {
140         sal_uInt32 nCRC1 = 0;
141         char buf1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
142         int num1 = sizeof(buf1);
143 
144         nCRC1 = rtl_crc32(nCRC1, buf1, num1);
145 
146         sal_uInt32 nCRC2 = 0;
147         char buf2[] = {20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
148         int num2 = sizeof(buf2);
149 
150         nCRC2 = rtl_crc32(nCRC2, buf2, num2);
151 
152         CPPUNIT_ASSERT_MESSAGE("checksum should differ", nCRC1 != nCRC2);
153     }
154 
155 
156 
157     // Change the following lines only, if you add, remove or rename
158     // member functions of the current class,
159     // because these macros are need by auto register mechanism.
160 
161     CPPUNIT_TEST_SUITE(test);
162     CPPUNIT_TEST(rtl_crc32_001);
163     CPPUNIT_TEST(rtl_crc32_002);
164     CPPUNIT_TEST(rtl_crc32_002_1);
165     CPPUNIT_TEST(rtl_crc32_003);
166     CPPUNIT_TEST(rtl_crc32_003_1);
167     CPPUNIT_TEST(rtl_crc32_003_2);
168     CPPUNIT_TEST_SUITE_END();
169 }; // class test
170 
171 // -----------------------------------------------------------------------------
172 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_CRC32::test, "rtl_crc32");
173 } // namespace rtl_CRC32
174 
175 
176 // -----------------------------------------------------------------------------
177 
178 // this macro creates an empty function, which will called by the RegisterAllFunctions()
179 // to let the user the possibility to also register some functions by hand.
180 NOADDITIONAL;
181 
182