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