update dev300-m57
[ooovba.git] / sal / qa / rtl / crc32 / rtl_crc32.cxx
blob694a31b43e9fdb117840da8c466f5d0a697cfa51
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rtl_crc32.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sal.hxx"
34 // autogenerated file with codegen.pl
36 #include <cppunit/simpleheader.hxx>
37 #include <rtl/crc.h>
39 namespace rtl_CRC32
42 class test : public CppUnit::TestFixture
44 public:
45 // initialise your test code values here.
46 void setUp()
50 void tearDown()
55 // insert your test code here.
56 void rtl_crc32_001()
58 // this is demonstration code
59 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
61 sal_uInt32 nCRC = 0;
63 char buf[] = {0};
64 int num = 0;
66 nCRC = rtl_crc32(nCRC, buf, num);
68 CPPUNIT_ASSERT_MESSAGE("empty crc buffer", nCRC == 0);
71 void rtl_crc32_002()
73 sal_uInt32 nCRC = 0;
75 char buf[] = {0,0};
76 int num = sizeof(buf);
78 nCRC = rtl_crc32(nCRC, buf, num);
80 CPPUNIT_ASSERT_MESSAGE("buffer contain 2 empty bytes, crc is zero", nCRC != 0);
83 void rtl_crc32_002_1()
85 sal_uInt32 nCRC = 0;
87 char buf[] = {0,0,0};
88 int num = sizeof(buf);
90 nCRC = rtl_crc32(nCRC, buf, num);
92 CPPUNIT_ASSERT_MESSAGE("buffer contain 3 empty bytes, crc is zero", nCRC != 0);
95 /**
96 * crc32 check:
97 * Build checksum on two buffers with same size but different content,
98 * the result (crc32 checksum) must differ
101 void rtl_crc32_003()
103 sal_uInt32 nCRC1 = 0;
104 char buf1[] = {2};
105 int num1 = sizeof(buf1);
107 nCRC1 = rtl_crc32(nCRC1, buf1, num1);
109 sal_uInt32 nCRC2 = 0;
110 char buf2[] = {3};
111 int num2 = sizeof(buf2);
113 nCRC2 = rtl_crc32(nCRC2, buf2, num2);
115 CPPUNIT_ASSERT_MESSAGE("checksum should differ for buf1 and buf2", nCRC1 != nCRC2);
118 /** check if the crc32 only use as much values, as given
121 void rtl_crc32_003_1()
123 sal_uInt32 nCRC1 = 0;
124 char buf1[] = {2,1};
125 int num1 = sizeof(buf1) - 1;
127 nCRC1 = rtl_crc32(nCRC1, buf1, num1);
129 sal_uInt32 nCRC2 = 0;
130 char buf2[] = {2,2};
131 int num2 = sizeof(buf2) - 1;
133 nCRC2 = rtl_crc32(nCRC2, buf2, num2);
135 CPPUNIT_ASSERT_MESSAGE("checksum leave it's bounds", nCRC1 == nCRC2);
138 /** check if the crc32 differ at same content in reverse order
141 void rtl_crc32_003_2()
143 sal_uInt32 nCRC1 = 0;
144 char buf1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
145 int num1 = sizeof(buf1);
147 nCRC1 = rtl_crc32(nCRC1, buf1, num1);
149 sal_uInt32 nCRC2 = 0;
150 char buf2[] = {20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
151 int num2 = sizeof(buf2);
153 nCRC2 = rtl_crc32(nCRC2, buf2, num2);
155 CPPUNIT_ASSERT_MESSAGE("checksum should differ", nCRC1 != nCRC2);
160 // Change the following lines only, if you add, remove or rename
161 // member functions of the current class,
162 // because these macros are need by auto register mechanism.
164 CPPUNIT_TEST_SUITE(test);
165 CPPUNIT_TEST(rtl_crc32_001);
166 CPPUNIT_TEST(rtl_crc32_002);
167 CPPUNIT_TEST(rtl_crc32_002_1);
168 CPPUNIT_TEST(rtl_crc32_003);
169 CPPUNIT_TEST(rtl_crc32_003_1);
170 CPPUNIT_TEST(rtl_crc32_003_2);
171 CPPUNIT_TEST_SUITE_END();
172 }; // class test
174 // -----------------------------------------------------------------------------
175 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_CRC32::test, "rtl_crc32");
176 } // namespace rtl_CRC32
179 // -----------------------------------------------------------------------------
181 // this macro creates an empty function, which will called by the RegisterAllFunctions()
182 // to let the user the possibility to also register some functions by hand.
183 NOADDITIONAL;