Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <sal/types.h>
30 : : #include <cppunit/TestFixture.h>
31 : : #include <cppunit/extensions/HelperMacros.h>
32 : : #include <cppunit/plugin/TestPlugIn.h>
33 : :
34 : : #include <rtl/crc.h>
35 : :
36 : : namespace rtl_CRC32
37 : : {
38 : :
39 [ - + ]: 90 : class test : public CppUnit::TestFixture
40 : : {
41 : : public:
42 : : // initialise your test code values here.
43 : 30 : void setUp()
44 : : {
45 : 30 : }
46 : :
47 : 30 : void tearDown()
48 : : {
49 : 30 : }
50 : :
51 : :
52 : : // insert your test code here.
53 : 5 : void rtl_crc32_001()
54 : : {
55 : : // this is demonstration code
56 : : // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
57 : :
58 : 5 : sal_uInt32 nCRC = 0;
59 : :
60 : 5 : char buf[] = {0};
61 : 5 : int num = 0;
62 : :
63 : 5 : nCRC = rtl_crc32(nCRC, buf, num);
64 : :
65 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("empty crc buffer", nCRC == 0);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
66 : 5 : }
67 : :
68 : 5 : void rtl_crc32_002()
69 : : {
70 : 5 : sal_uInt32 nCRC = 0;
71 : :
72 : 5 : char buf[] = {0,0};
73 : 5 : int num = sizeof(buf);
74 : :
75 : 5 : nCRC = rtl_crc32(nCRC, buf, num);
76 : :
77 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("buffer contain 2 empty bytes, crc is zero", nCRC != 0);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
78 : 5 : }
79 : :
80 : 5 : void rtl_crc32_002_1()
81 : : {
82 : 5 : sal_uInt32 nCRC = 0;
83 : :
84 : 5 : char buf[] = {0,0,0};
85 : 5 : int num = sizeof(buf);
86 : :
87 : 5 : nCRC = rtl_crc32(nCRC, buf, num);
88 : :
89 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("buffer contain 3 empty bytes, crc is zero", nCRC != 0);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
90 : 5 : }
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 : 5 : void rtl_crc32_003()
99 : : {
100 : 5 : sal_uInt32 nCRC1 = 0;
101 : 5 : char buf1[] = {2};
102 : 5 : int num1 = sizeof(buf1);
103 : :
104 : 5 : nCRC1 = rtl_crc32(nCRC1, buf1, num1);
105 : :
106 : 5 : sal_uInt32 nCRC2 = 0;
107 : 5 : char buf2[] = {3};
108 : 5 : int num2 = sizeof(buf2);
109 : :
110 : 5 : nCRC2 = rtl_crc32(nCRC2, buf2, num2);
111 : :
112 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("checksum should differ for buf1 and buf2", nCRC1 != nCRC2);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
113 : 5 : }
114 : :
115 : : /** check if the crc32 only use as much values, as given
116 : : *
117 : : */
118 : 5 : void rtl_crc32_003_1()
119 : : {
120 : 5 : sal_uInt32 nCRC1 = 0;
121 : 5 : char buf1[] = {2,1};
122 : 5 : int num1 = sizeof(buf1) - 1;
123 : :
124 : 5 : nCRC1 = rtl_crc32(nCRC1, buf1, num1);
125 : :
126 : 5 : sal_uInt32 nCRC2 = 0;
127 : 5 : char buf2[] = {2,2};
128 : 5 : int num2 = sizeof(buf2) - 1;
129 : :
130 : 5 : nCRC2 = rtl_crc32(nCRC2, buf2, num2);
131 : :
132 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("checksum leave it's bounds", nCRC1 == nCRC2);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
133 : 5 : }
134 : :
135 : : /** check if the crc32 differ at same content in reverse order
136 : : *
137 : : */
138 : 5 : void rtl_crc32_003_2()
139 : : {
140 : 5 : sal_uInt32 nCRC1 = 0;
141 : 5 : char buf1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
142 : 5 : int num1 = sizeof(buf1);
143 : :
144 : 5 : nCRC1 = rtl_crc32(nCRC1, buf1, num1);
145 : :
146 : 5 : sal_uInt32 nCRC2 = 0;
147 : 5 : char buf2[] = {20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
148 : 5 : int num2 = sizeof(buf2);
149 : :
150 : 5 : nCRC2 = rtl_crc32(nCRC2, buf2, num2);
151 : :
152 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("checksum should differ", nCRC1 != nCRC2);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
153 : 5 : }
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 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE(test);
[ + - ][ + - ]
[ # # ]
162 [ + - ][ + - ]: 5 : CPPUNIT_TEST(rtl_crc32_001);
[ + - ][ + - ]
[ + - ][ + - ]
163 [ + - ][ + - ]: 5 : CPPUNIT_TEST(rtl_crc32_002);
[ + - ][ + - ]
[ + - ][ + - ]
164 [ + - ][ + - ]: 5 : CPPUNIT_TEST(rtl_crc32_002_1);
[ + - ][ + - ]
[ + - ][ + - ]
165 [ + - ][ + - ]: 5 : CPPUNIT_TEST(rtl_crc32_003);
[ + - ][ + - ]
[ + - ][ + - ]
166 [ + - ][ + - ]: 5 : CPPUNIT_TEST(rtl_crc32_003_1);
[ + - ][ + - ]
[ + - ][ + - ]
167 [ + - ][ + - ]: 5 : CPPUNIT_TEST(rtl_crc32_003_2);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
168 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
169 : : }; // class test
170 : :
171 : : // -----------------------------------------------------------------------------
172 : 5 : CPPUNIT_TEST_SUITE_REGISTRATION(rtl_CRC32::test);
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 [ + - ][ + - ]: 20 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
181 : :
182 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|