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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
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
;
19 import java
.nio
.ByteBuffer
;
20 import java
.nio
.ByteOrder
;
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
;
37 * The class <code>ArrayDeclaration2Test</code> contains tests for the class
38 * <code>{@link ArrayDeclaration}</code>.
40 * @author Matthew Khouzam
41 * @version $Revision: 1.0 $
43 public class ArrayDeclaration2Test
{
45 private ArrayDeclaration fixture
;
48 * Perform pre-test initialization.
52 fixture
= new ArrayDeclaration(1, new StringDeclaration());
56 * Run the ArrayDeclaration(int,Declaration) constructor test.
59 public void testArrayDeclaration() {
61 IDeclaration elemType
= new StringDeclaration();
62 ArrayDeclaration result
= new ArrayDeclaration(length
, elemType
);
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());
72 * Run the ArrayDefinition createDefinition(DefinitionScope,String) method
75 * @throws CTFReaderException
76 * error in the bitbuffer
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
);
87 assertNotNull(result
);
93 * Run the Declaration getElementType() method test.
96 public void testGetElementType() {
97 IDeclaration result
= fixture
.getElementType();
98 assertNotNull(result
);
102 * Run the int getLength() method test.
105 public void testGetLength() {
106 int result
= fixture
.getLength();
107 assertEquals(1, result
);
111 * Run the boolean isString() method test.
114 public void testIsString_ownDefs() {
115 // it's an array of strings, not a string
116 assertFalse(fixture
.isString());
120 * Run the boolean isString() method 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
);
128 boolean result
= ad
.isString();
134 * Run the String toString() method test.
137 public void testToString() {
138 String result
= fixture
.toString();
139 String left
= "[declaration] array[";
140 String right
= result
.substring(0, left
.length());
142 assertEquals(left
, right
);