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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.fastsearch;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import com.yahoo.prelude.fastsearch.DocsumField;
import com.yahoo.prelude.fastsearch.FastHit;
/**
* Tests DocsumField class functionality
*
* @author Bjørn Borud
*/
public class DocsumFieldTestCase extends junit.framework.TestCase {
public DocsumFieldTestCase(String name) {
super(name);
}
public void testConstructors() {
DocsumField.create("test", "string");
DocsumField.create("test", "integer");
DocsumField.create("test", "byte");
DocsumField.create("test", "int64");
}
public void testByte() {
FastHit hit = new FastHit();
DocsumField c = DocsumField.create("test", "byte");
byte[] byteData = { 10, 20, 30, 40};
ByteBuffer buffer = ByteBuffer.wrap(byteData);
buffer.order(ByteOrder.LITTLE_ENDIAN);
c.decode(buffer, hit);
assertEquals(1, buffer.position());
assertEquals("10", hit.getField("test").toString());
c.decode(buffer, hit);
assertEquals(2, buffer.position());
assertEquals("20", hit.getField("test").toString());
c.decode(buffer, hit);
assertEquals(3, buffer.position());
assertEquals("30", hit.getField("test").toString());
}
public void testLongString() {
FastHit hit = new FastHit();
DocsumField c = DocsumField.create("test", "longstring");
byte[] byteData = {
4, 0, 0, 0, 'c', 'a', 'f', 'e', 4, 0, 0, 0, 'B', 'A',
'B', 'E'};
ByteBuffer buffer = ByteBuffer.wrap(byteData);
buffer.order(ByteOrder.LITTLE_ENDIAN);
c.decode(buffer, hit);
assertEquals(8, buffer.position());
assertEquals("cafe", hit.getField("test"));
c.decode(buffer, hit);
assertEquals(16, buffer.position());
assertEquals("BABE", hit.getField("test"));
}
}
|