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
.assertTrue
;
18 import java
.util
.List
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDeclaration
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDeclaration
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
25 import org
.junit
.Before
;
26 import org
.junit
.Test
;
29 * The class <code>StructDeclarationTest</code> contains tests for the class
30 * <code>{@link StructDeclaration}</code>.
33 * @version $Revision: 1.0 $
35 public class StructDeclarationTest
{
37 private StructDeclaration fixture
;
40 * Perform pre-test initialization.
44 fixture
= new StructDeclaration(1L);
48 * Run the StructDeclaration(long) constructor test.
51 public void testStructDeclaration() {
52 assertNotNull(fixture
);
53 assertEquals(1L, fixture
.getMaxAlign());
55 String regex
= "^\\[declaration\\] struct\\[[0-9a-f]{1,8}\\]$";
56 assertTrue(fixture
.toString().matches(regex
));
60 * Run the void addField(String,Declaration) method test.
63 public void testAddField() {
65 IDeclaration declaration
= new StringDeclaration();
66 fixture
.addField(name
, declaration
);
70 * Run the StructDefinition createDefinition(DefinitionScope,String) method
74 public void testCreateDefinition() {
75 String fieldName
= "";
76 StructDefinition result
= fixture
.createDefinition(null, fieldName
);
77 assertNotNull(result
);
81 * Run the HashMap<String, Declaration> getFields() method test.
84 public void testGetFields() {
85 Map
<String
, IDeclaration
> result
= fixture
.getFields();
87 assertNotNull(result
);
88 assertEquals(0, result
.size());
92 * Run the List<String> getFieldsList() method test.
95 public void testGetFieldsList() {
96 List
<String
> result
= fixture
.getFieldsList();
98 assertNotNull(result
);
99 assertEquals(0, result
.size());
103 * Run the long getMinAlign() method test.
106 public void testGetMinAlign() {
107 long result
= fixture
.getMaxAlign();
108 assertEquals(1L, result
);
112 * Run the boolean hasField(String) method test.
115 public void testHasField() {
117 boolean result
= fixture
.hasField(name
);
119 assertEquals(false, result
);
123 * Run the String toString() method test.
126 public void testToString() {
127 String result
= fixture
.toString();
128 String trunc
= result
.substring(0, 21);
130 assertEquals("[declaration] struct[", trunc
);