ctf: Make events immutable
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / ArrayDeclarationTest.java
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
12 package org.eclipse.linuxtools.ctf.core.tests.types;
13
14 import static org.junit.Assert.*;
15
16 import java.nio.ByteBuffer;
17 import java.nio.ByteOrder;
18
19 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
20 import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
21 import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
22 import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
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;
26 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
27 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 /**
32 * The class <code>ArrayDeclarationTest</code> contains tests for the class
33 * <code>{@link ArrayDeclaration}</code>.
34 *
35 * @author ematkho
36 * @version $Revision: 1.0 $
37 */
38 public class ArrayDeclarationTest {
39
40 private ArrayDeclaration fixture;
41
42 /**
43 * Perform pre-test initialization.
44 */
45 @Before
46 public void setUp() {
47 fixture = new ArrayDeclaration(1, new StringDeclaration());
48 }
49
50 /**
51 * Run the ArrayDeclaration(int,Declaration) constructor test.
52 */
53 @Test
54 public void testArrayDeclaration() {
55 int length = 1;
56 IDeclaration elemType = new StringDeclaration();
57 ArrayDeclaration result = new ArrayDeclaration(length, elemType);
58
59 assertNotNull(result);
60 String left = "[declaration] array[";
61 String right = result.toString().substring(0, left.length());
62 assertEquals(left, right);
63 assertEquals(1, result.getLength());
64 }
65
66 /**
67 * Run the ArrayDefinition createDefinition(DefinitionScope,String) method
68 * test.
69 *
70 * @throws CTFReaderException
71 * error in the bitbuffer
72 */
73 @Test
74 public void testCreateDefinition() throws CTFReaderException {
75 String fieldName = "";
76 IDefinitionScope definitionScope = null;
77 ArrayDefinition result;
78 byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
79 ByteBuffer byb = ByteBuffer.wrap(array);
80 BitBuffer bb = new BitBuffer(byb);
81 result = fixture.createDefinition(definitionScope, fieldName, bb);
82
83 assertNotNull(result);
84 }
85
86 /**
87 * Run the Declaration getElementType() method test.
88 */
89 @Test
90 public void testGetElementType() {
91 IDeclaration result = fixture.getElementType();
92 assertNotNull(result);
93 }
94
95 /**
96 * Run the int getLength() method test.
97 */
98 @Test
99 public void testGetLength() {
100 int result = fixture.getLength();
101 assertEquals(1, result);
102 }
103
104 /**
105 * Run the boolean isString() method test.
106 */
107 @Test
108 public void testIsString_ownDefs() {
109 // it's an array of strings, not a string
110 assertFalse(fixture.isString());
111 }
112
113 /**
114 * Run the boolean isString() method test.
115 */
116 @Test
117 public void testIsString_complex() {
118 final IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 16,
119 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
120 ArrayDeclaration ad = new ArrayDeclaration(0, id);
121
122 boolean result = ad.isString();
123
124 assertTrue(result);
125 }
126
127 /**
128 * Run the String toString() method test.
129 */
130 @Test
131 public void testToString() {
132 String result = fixture.toString();
133 String left = "[declaration] array[";
134 String right = result.substring(0, left.length());
135
136 assertEquals(left, right);
137 }
138 }
This page took 0.032553 seconds and 5 git commands to generate.