e170e4423d90e8ece452ec33f8714ceaa651ab5b
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / StructDeclarationTest.java
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
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.linuxtools.ctf.core.tests.types;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertTrue;
17
18 import java.util.List;
19 import java.util.Map;
20
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;
27
28 /**
29 * The class <code>StructDeclarationTest</code> contains tests for the class
30 * <code>{@link StructDeclaration}</code>.
31 *
32 * @author ematkho
33 * @version $Revision: 1.0 $
34 */
35 public class StructDeclarationTest {
36
37 private StructDeclaration fixture;
38
39 /**
40 * Perform pre-test initialization.
41 */
42 @Before
43 public void setUp() {
44 fixture = new StructDeclaration(1L);
45 }
46
47 /**
48 * Run the StructDeclaration(long) constructor test.
49 */
50 @Test
51 public void testStructDeclaration() {
52 assertNotNull(fixture);
53 assertEquals(1L, fixture.getMaxAlign());
54
55 String regex = "^\\[declaration\\] struct\\[[0-9a-f]{1,8}\\]$";
56 assertTrue(fixture.toString().matches(regex));
57 }
58
59 /**
60 * Run the void addField(String,Declaration) method test.
61 */
62 @Test
63 public void testAddField() {
64 String name = "";
65 IDeclaration declaration = new StringDeclaration();
66 fixture.addField(name, declaration);
67 }
68
69 /**
70 * Run the StructDefinition createDefinition(DefinitionScope,String) method
71 * test.
72 */
73 @Test
74 public void testCreateDefinition() {
75 String fieldName = "";
76 StructDefinition result = fixture.createDefinition(null, fieldName);
77 assertNotNull(result);
78 }
79
80 /**
81 * Run the HashMap<String, Declaration> getFields() method test.
82 */
83 @Test
84 public void testGetFields() {
85 Map<String, IDeclaration> result = fixture.getFields();
86
87 assertNotNull(result);
88 assertEquals(0, result.size());
89 }
90
91 /**
92 * Run the List<String> getFieldsList() method test.
93 */
94 @Test
95 public void testGetFieldsList() {
96 List<String> result = fixture.getFieldsList();
97
98 assertNotNull(result);
99 assertEquals(0, result.size());
100 }
101
102 /**
103 * Run the long getMinAlign() method test.
104 */
105 @Test
106 public void testGetMinAlign() {
107 long result = fixture.getMaxAlign();
108 assertEquals(1L, result);
109 }
110
111 /**
112 * Run the boolean hasField(String) method test.
113 */
114 @Test
115 public void testHasField() {
116 String name = "";
117 boolean result = fixture.hasField(name);
118
119 assertEquals(false, result);
120 }
121
122 /**
123 * Run the String toString() method test.
124 */
125 @Test
126 public void testToString() {
127 String result = fixture.toString();
128 String trunc = result.substring(0, 21);
129
130 assertEquals("[declaration] struct[", trunc);
131 }
132 }
This page took 0.033702 seconds and 5 git commands to generate.