1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*******************************************************************************
* Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Marc R. Hoffmann - initial API and implementation
*
*******************************************************************************/
package org.jacoco.core.internal.data;
import static org.junit.Assert.assertEquals;
import java.io.UnsupportedEncodingException;
import org.jacoco.core.data.ExecutionDataWriter;
import org.junit.Test;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
/**
* Unit tests for {@link CRC64}.
*/
public class CRC64Test {
@Test
public void except_java_9_checksums_should_be_different_for_different_bytecode_versions() {
assertEquals(0x589E9080A572741EL,
CRC64.classId(createClass(Opcodes.V10)));
// should remove workaround for Java 9
// during change of exec file version
assertEquals(0x1007, ExecutionDataWriter.FORMAT_VERSION);
assertEquals(0xB5284860A572741CL,
CRC64.classId(createClass(Opcodes.V9)));
assertEquals(0xB5284860A572741CL,
CRC64.classId(createClass(Opcodes.V1_8)));
assertEquals(0x45284D30A572741AL,
CRC64.classId(createClass(Opcodes.V1_7)));
}
private static byte[] createClass(final int version) {
final ClassWriter cw = new ClassWriter(0);
cw.visit(version, 0, "Foo", null, "java/lang/Object", null);
cw.visitEnd();
cw.toByteArray();
return cw.toByteArray();
}
@Test
public void test0() {
final long sum = CRC64.classId(new byte[0]);
assertEquals(0L, sum);
}
/**
* Example taken from http://swissknife.sourceforge.net/docs/CRC64.html
*
* @throws UnsupportedEncodingException
*/
@Test
public void test1() throws UnsupportedEncodingException {
final long sum = CRC64.classId("IHATEMATH".getBytes("ASCII"));
assertEquals(0xE3DCADD69B01ADD1L, sum);
}
/**
* Example generated with http://fsumfe.sourceforge.net/
*
* @throws UnsupportedEncodingException
*/
@Test
public void test2() {
final long sum = CRC64.classId(
new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff });
assertEquals(0x5300000000000000L, sum);
}
/**
* Example generated with http://fsumfe.sourceforge.net/
*
* @throws UnsupportedEncodingException
*/
@Test
public void test3() throws UnsupportedEncodingException {
final long sum = CRC64
.classId("JACOCO_JACOCO_JACOCO_JACOCO".getBytes("ASCII"));
assertEquals(0xD8016B38AAD48308L, sum);
}
}
|