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
.*;
16 import java
.nio
.ByteBuffer
;
17 import java
.nio
.ByteOrder
;
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
;
32 * The class <code>ArrayDeclarationTest</code> contains tests for the class
33 * <code>{@link ArrayDeclaration}</code>.
36 * @version $Revision: 1.0 $
38 public class ArrayDeclarationTest
{
40 private ArrayDeclaration fixture
;
43 * Perform pre-test initialization.
47 fixture
= new ArrayDeclaration(1, new StringDeclaration());
51 * Run the ArrayDeclaration(int,Declaration) constructor test.
54 public void testArrayDeclaration() {
56 IDeclaration elemType
= new StringDeclaration();
57 ArrayDeclaration result
= new ArrayDeclaration(length
, elemType
);
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());
67 * Run the ArrayDefinition createDefinition(DefinitionScope,String) method
70 * @throws CTFReaderException
71 * error in the bitbuffer
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
);
83 assertNotNull(result
);
87 * Run the Declaration getElementType() method test.
90 public void testGetElementType() {
91 IDeclaration result
= fixture
.getElementType();
92 assertNotNull(result
);
96 * Run the int getLength() method test.
99 public void testGetLength() {
100 int result
= fixture
.getLength();
101 assertEquals(1, result
);
105 * Run the boolean isString() method test.
108 public void testIsString_ownDefs() {
109 // it's an array of strings, not a string
110 assertFalse(fixture
.isString());
114 * Run the boolean isString() method 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
);
122 boolean result
= ad
.isString();
128 * Run the String toString() method test.
131 public void testToString() {
132 String result
= fixture
.toString();
133 String left
= "[declaration] array[";
134 String right
= result
.substring(0, left
.length());
136 assertEquals(left
, right
);