btf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / ArrayDeclaration2Test.java
CommitLineData
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
12package org.eclipse.linuxtools.ctf.core.tests.types;
13
7b4f13e6
MK
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertFalse;
16import static org.junit.Assert.assertNotNull;
17import static org.junit.Assert.assertTrue;
9639bf3a 18
a4fa4e36 19import java.nio.ByteBuffer;
9639bf3a 20import java.nio.ByteOrder;
866e5b51 21
a4fa4e36
MK
22import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
23import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
7b4f13e6 24import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition;
9377d173 25import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration;
9639bf3a 26import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
866e5b51 27import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
9639bf3a 28import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
866e5b51 29import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
aefc5c83 30import org.eclipse.linuxtools.ctf.core.tests.io.Util;
a4fa4e36 31import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
7b4f13e6 32import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration;
866e5b51
FC
33import org.junit.Before;
34import org.junit.Test;
35
36/**
7b4f13e6 37 * The class <code>ArrayDeclaration2Test</code> contains tests for the class
866e5b51 38 * <code>{@link ArrayDeclaration}</code>.
4bd7f2db 39 *
7b4f13e6 40 * @author Matthew Khouzam
866e5b51
FC
41 * @version $Revision: 1.0 $
42 */
7b4f13e6 43public class ArrayDeclaration2Test {
866e5b51
FC
44
45 private ArrayDeclaration fixture;
46
866e5b51
FC
47 /**
48 * Perform pre-test initialization.
49 */
50 @Before
51 public void setUp() {
52 fixture = new ArrayDeclaration(1, new StringDeclaration());
53 }
54
866e5b51
FC
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);
4a9c1f07 65 String left = "[declaration] array[";
866e5b51
FC
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.
a4fa4e36
MK
74 *
75 * @throws CTFReaderException
76 * error in the bitbuffer
866e5b51
FC
77 */
78 @Test
a4fa4e36 79 public void testCreateDefinition() throws CTFReaderException {
4a9c1f07 80 String fieldName = "";
866e5b51 81 IDefinitionScope definitionScope = null;
7b4f13e6 82 AbstractArrayDefinition result;
a4fa4e36 83 byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
aefc5c83 84 BitBuffer bb = new BitBuffer(Util.testMemory(ByteBuffer.wrap(array)));
a4fa4e36 85 result = fixture.createDefinition(definitionScope, fieldName, bb);
866e5b51
FC
86
87 assertNotNull(result);
88 }
89
aefc5c83
MK
90
91
866e5b51
FC
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
9639bf3a
MK
110 /**
111 * Run the boolean isString() method test.
112 */
113 @Test
114 public void testIsString_ownDefs() {
a4fa4e36 115 // it's an array of strings, not a string
9639bf3a
MK
116 assertFalse(fixture.isString());
117 }
118
119 /**
120 * Run the boolean isString() method test.
121 */
122 @Test
123 public void testIsString_complex() {
a4fa4e36
MK
124 final IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 16,
125 ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
9377d173 126 CompoundDeclaration ad = new ArrayDeclaration(0, id);
9639bf3a
MK
127
128 boolean result = ad.isString();
129
130 assertTrue(result);
131 }
132
866e5b51
FC
133 /**
134 * Run the String toString() method test.
135 */
136 @Test
137 public void testToString() {
138 String result = fixture.toString();
4a9c1f07 139 String left = "[declaration] array[";
866e5b51
FC
140 String right = result.substring(0, left.length());
141
142 assertEquals(left, right);
143 }
144}
This page took 0.058045 seconds and 5 git commands to generate.