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
.HashMap
;
19 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
.After
;
26 import org
.junit
.Before
;
27 import org
.junit
.Test
;
30 * The class <code>StructDeclarationTest</code> contains tests for the class
31 * <code>{@link StructDeclaration}</code>.
34 * @version $Revision: 1.0 $
36 public class StructDeclarationTest
{
38 private StructDeclaration fixture
;
44 * the command line arguments
46 public static void main(String
[] args
) {
47 new org
.junit
.runner
.JUnitCore().run(StructDeclarationTest
.class);
51 * Perform pre-test initialization.
55 fixture
= new StructDeclaration(1L);
59 * Perform post-test clean-up.
62 public void tearDown() {
63 // Add additional tear down code here
67 * Run the StructDeclaration(long) constructor test.
70 public void testStructDeclaration() {
71 assertNotNull(fixture
);
72 assertEquals(1L, fixture
.getMaxAlign());
74 String regex
= "^\\[declaration\\] struct\\[[0-9a-f]{1,8}\\]$";
75 assertTrue(fixture
.toString().matches(regex
));
79 * Run the void addField(String,Declaration) method test.
82 public void testAddField() {
84 IDeclaration declaration
= new StringDeclaration();
85 fixture
.addField(name
, declaration
);
89 * Run the StructDefinition createDefinition(DefinitionScope,String) method
93 public void testCreateDefinition() {
94 String fieldName
= "";
95 StructDefinition result
= fixture
.createDefinition(null, fieldName
);
96 assertNotNull(result
);
100 * Run the HashMap<String, Declaration> getFields() method test.
103 public void testGetFields() {
104 HashMap
<String
, IDeclaration
> result
= fixture
.getFields();
106 assertNotNull(result
);
107 assertEquals(0, result
.size());
111 * Run the List<String> getFieldsList() method test.
114 public void testGetFieldsList() {
115 List
<String
> result
= fixture
.getFieldsList();
117 assertNotNull(result
);
118 assertEquals(0, result
.size());
122 * Run the long getMinAlign() method test.
125 public void testGetMinAlign() {
126 long result
= fixture
.getMaxAlign();
127 assertEquals(1L, result
);
131 * Run the boolean hasField(String) method test.
134 public void testHasField() {
136 boolean result
= fixture
.hasField(name
);
138 assertEquals(false, result
);
142 * Run the String toString() method test.
145 public void testToString() {
146 String result
= fixture
.toString();
147 String trunc
= result
.substring(0, 21);
149 assertEquals("[declaration] struct[", trunc
);