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
.assertNotNull
;
16 import static org
.junit
.Assert
.assertNull
;
17 import static org
.junit
.Assert
.assertTrue
;
19 import java
.nio
.ByteBuffer
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDeclaration
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDeclaration
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
26 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
27 import org
.junit
.Before
;
28 import org
.junit
.Test
;
31 * The class <code>StructDeclarationTest</code> contains tests for the class
32 * <code>{@link StructDeclaration}</code>.
35 * @version $Revision: 1.0 $
37 public class StructDeclarationTest
{
39 private StructDeclaration fixture
;
42 * Perform pre-test initialization.
46 fixture
= new StructDeclaration(1L);
50 * Run the StructDeclaration(long) constructor test.
53 public void testStructDeclaration() {
54 assertNotNull(fixture
);
55 assertEquals(1L, fixture
.getMaxAlign());
57 String regex
= "^\\[declaration\\] struct\\[[0-9a-f]{1,8}\\]$";
58 assertTrue(fixture
.toString().matches(regex
));
62 * Run the void addField(String,Declaration) method test.
65 public void testAddField() {
67 IDeclaration declaration
= new StringDeclaration();
68 fixture
.addField(name
, declaration
);
72 * Run the StructDefinition createDefinition(DefinitionScope,String) method
75 * @throws CTFReaderException
79 public void testCreateDefinition() throws CTFReaderException
{
80 String fieldName
= "";
81 ByteBuffer allocate
= ByteBuffer
.allocate(100);
82 if( allocate
== null){
83 throw new IllegalStateException("Failed to allocate memory");
85 BitBuffer bb
= new BitBuffer(allocate
);
86 StructDefinition result
= fixture
.createDefinition(null, fieldName
, bb
);
87 assertNotNull(result
);
91 * Run the Declaration getField(String) method test.
94 public void testGetField() {
95 IDeclaration result
= fixture
.getField("test");
101 * Run the List<String> getFieldsList() method test.
104 public void testGetFieldsList() {
105 Iterable
<String
> result
= fixture
.getFieldsList();
107 assertNotNull(result
);
108 assertEquals(false, result
.iterator().hasNext());
112 * Run the long getMinAlign() method test.
115 public void testGetMinAlign() {
116 long result
= fixture
.getMaxAlign();
117 assertEquals(1L, result
);
121 * Run the boolean hasField(String) method test.
124 public void testHasField() {
126 boolean result
= fixture
.hasField(name
);
128 assertEquals(false, result
);
132 * Run the String toString() method test.
135 public void testToString() {
136 String result
= fixture
.toString();
137 String trunc
= result
.substring(0, 21);
139 assertEquals("[declaration] struct[", trunc
);