-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathValueInterfaceWithEnumTest.java
More file actions
69 lines (52 loc) · 2.06 KB
/
ValueInterfaceWithEnumTest.java
File metadata and controls
69 lines (52 loc) · 2.06 KB
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
/*
* Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0
*/
package net.openhft.chronicle.values;
import net.openhft.chronicle.bytes.Byteable;
import net.openhft.chronicle.bytes.BytesStore;
import org.junit.jupiter.api.Test;
import static net.openhft.chronicle.values.ValueInterfaceWithEnumTest.SimpleValueInterface.SVIEnum.SIX;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author ges
* @since 3/2/16.
*/
public class ValueInterfaceWithEnumTest extends ValuesTestCommon {
/**
* This test will throw an {@link ArrayIndexOutOfBoundsException}. This seems to occur only with Enums having even number of
* values
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void testValueInterface() {
SimpleValueInterface nativeValue = Values.newNativeReference(SimpleValueInterface.class);
int modelSize = ValueModel.acquire(SimpleValueInterface.class).sizeInBytes();
((Byteable) nativeValue).bytesStore(BytesStore.wrap(new byte[modelSize]), 0, modelSize);
SimpleValueInterface heapValue = Values.newHeapInstance(SimpleValueInterface.class);
nativeValue.setId(1);
nativeValue.setTruth(true);
nativeValue.setSVIEnum(SIX);
heapValue.copyFrom(nativeValue);
assertEquals(1, heapValue.getId());
assertEquals(true, heapValue.getTruth());
assertEquals(SIX, heapValue.getSVIEnum());
heapValue.setId(2);
heapValue.setTruth(false);
heapValue.setSVIEnum(null);
nativeValue.copyFrom(heapValue);
assertEquals(2, nativeValue.getId());
assertEquals(false, nativeValue.getTruth());
assertEquals(null, nativeValue.getSVIEnum());
}
public interface SimpleValueInterface extends Copyable<SimpleValueInterface> {
int getId();
void setId(int id);
boolean getTruth();
void setTruth(boolean truth);
SVIEnum getSVIEnum();
void setSVIEnum(SVIEnum val);
enum SVIEnum {
ONE, TWO, THREE, FOUR, FIVE, SIX
}
}
}