Commit | Line | Data |
---|---|---|
4bd7f2db AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 Ericsson | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Matthew Khouzam - Initial API and implementation | |
10 | *******************************************************************************/ | |
11 | ||
866e5b51 FC |
12 | package org.eclipse.linuxtools.ctf.core.tests.types; |
13 | ||
14 | import static org.junit.Assert.assertEquals; | |
15 | import static org.junit.Assert.assertNotNull; | |
16 | ||
a4fa4e36 | 17 | import java.nio.ByteBuffer; |
866e5b51 FC |
18 | import java.nio.ByteOrder; |
19 | ||
a4fa4e36 MK |
20 | import org.eclipse.jdt.annotation.NonNull; |
21 | import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; | |
22 | import org.eclipse.linuxtools.ctf.core.event.types.Definition; | |
866e5b51 FC |
23 | import org.eclipse.linuxtools.ctf.core.event.types.Encoding; |
24 | import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; | |
25 | import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; | |
a4fa4e36 | 26 | import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; |
866e5b51 FC |
27 | import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration; |
28 | import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition; | |
29 | import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; | |
30 | import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; | |
31 | import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; | |
a4fa4e36 | 32 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
866e5b51 FC |
33 | import org.junit.Before; |
34 | import org.junit.Test; | |
35 | ||
a4fa4e36 MK |
36 | import com.google.common.collect.ImmutableList; |
37 | ||
866e5b51 FC |
38 | /** |
39 | * The class <code>SequenceDeclarationTest</code> contains tests for the class | |
40 | * <code>{@link SequenceDeclaration}</code>. | |
284fdee8 | 41 | * |
866e5b51 FC |
42 | * @author ematkho |
43 | * @version $Revision: 1.0 $ | |
44 | */ | |
be6df2d8 | 45 | @SuppressWarnings("javadoc") |
866e5b51 FC |
46 | public class SequenceDeclarationTest { |
47 | ||
a4fa4e36 | 48 | @NonNull private static final String FIELD_NAME = "LengthName"; |
866e5b51 | 49 | |
a4fa4e36 MK |
50 | private SequenceDeclaration fixture; |
51 | @NonNull private BitBuffer input = new BitBuffer(); | |
866e5b51 FC |
52 | |
53 | @Before | |
54 | public void setUp() { | |
a4fa4e36 MK |
55 | fixture = new SequenceDeclaration(FIELD_NAME, new StringDeclaration()); |
56 | byte array[] = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' }; | |
57 | ByteBuffer byb = ByteBuffer.wrap(array); | |
58 | input = new BitBuffer(byb); | |
866e5b51 FC |
59 | } |
60 | ||
866e5b51 FC |
61 | /** |
62 | * Run the SequenceDeclaration(String,Declaration) constructor test. | |
63 | */ | |
64 | @Test | |
65 | public void testSequenceDeclaration() { | |
4a9c1f07 | 66 | String lengthName = ""; |
866e5b51 FC |
67 | IDeclaration elemType = new StringDeclaration(); |
68 | ||
4a9c1f07 | 69 | SequenceDeclaration result = new SequenceDeclaration(lengthName, elemType); |
866e5b51 | 70 | assertNotNull(result); |
4a9c1f07 | 71 | String string = "[declaration] sequence["; |
866e5b51 FC |
72 | assertEquals(string, result.toString().substring(0, string.length())); |
73 | } | |
74 | ||
75 | /** | |
76 | * Run the SequenceDefinition createDefinition(DefinitionScope,String) | |
77 | * method test. | |
a4fa4e36 MK |
78 | * |
79 | * @throws CTFReaderException | |
80 | * an error in the bitbuffer | |
866e5b51 FC |
81 | */ |
82 | @Test | |
a4fa4e36 MK |
83 | public void testCreateDefinition() throws CTFReaderException { |
84 | long seqLen = 2; | |
85 | IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8, | |
86 | ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 32); | |
866e5b51 | 87 | StructDeclaration structDec = new StructDeclaration(0); |
a4fa4e36 MK |
88 | structDec.addField(FIELD_NAME, id); |
89 | StructDefinition structDef = new StructDefinition( | |
90 | structDec, | |
91 | null, | |
92 | "x", | |
93 | ImmutableList.of(FIELD_NAME), | |
94 | new Definition[] { | |
95 | new IntegerDefinition( | |
96 | id, | |
97 | null, | |
98 | FIELD_NAME, | |
99 | seqLen) | |
100 | }); | |
101 | SequenceDefinition result = fixture.createDefinition(structDef, FIELD_NAME, input); | |
866e5b51 FC |
102 | assertNotNull(result); |
103 | } | |
104 | ||
105 | /** | |
106 | * Run the Declaration getElementType() method test. | |
107 | */ | |
108 | @Test | |
109 | public void testGetElementType() { | |
110 | IDeclaration result = fixture.getElementType(); | |
111 | assertNotNull(result); | |
112 | } | |
113 | ||
114 | /** | |
115 | * Run the String toString() method test. | |
116 | */ | |
117 | @Test | |
118 | public void testToString() { | |
119 | String result = fixture.toString(); | |
4a9c1f07 | 120 | String left = "[declaration] sequence["; |
866e5b51 FC |
121 | assertEquals(left, result.substring(0, left.length())); |
122 | } | |
123 | } |