btf: Move plugins to the Trace Compass namespace
[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.assertNull;
17 import static org.junit.Assert.assertTrue;
18
19 import java.nio.ByteBuffer;
20
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;
29
30 /**
31 * The class <code>StructDeclarationTest</code> contains tests for the class
32 * <code>{@link StructDeclaration}</code>.
33 *
34 * @author ematkho
35 * @version $Revision: 1.0 $
36 */
37 public class StructDeclarationTest {
38
39 private StructDeclaration fixture;
40
41 /**
42 * Perform pre-test initialization.
43 */
44 @Before
45 public void setUp() {
46 fixture = new StructDeclaration(1L);
47 }
48
49 /**
50 * Run the StructDeclaration(long) constructor test.
51 */
52 @Test
53 public void testStructDeclaration() {
54 assertNotNull(fixture);
55 assertEquals(1L, fixture.getMaxAlign());
56
57 String regex = "^\\[declaration\\] struct\\[[0-9a-f]{1,8}\\]$";
58 assertTrue(fixture.toString().matches(regex));
59 }
60
61 /**
62 * Run the void addField(String,Declaration) method test.
63 */
64 @Test
65 public void testAddField() {
66 String name = "";
67 IDeclaration declaration = new StringDeclaration();
68 fixture.addField(name, declaration);
69 }
70
71 /**
72 * Run the StructDefinition createDefinition(DefinitionScope,String) method
73 * test.
74 *
75 * @throws CTFReaderException
76 * out of bounds
77 */
78 @Test
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");
84 }
85 BitBuffer bb = new BitBuffer(allocate);
86 StructDefinition result = fixture.createDefinition(null, fieldName, bb);
87 assertNotNull(result);
88 }
89
90 /**
91 * Run the Declaration getField(String) method test.
92 */
93 @Test
94 public void testGetField() {
95 IDeclaration result = fixture.getField("test");
96
97 assertNull(result);
98 }
99
100 /**
101 * Run the List<String> getFieldsList() method test.
102 */
103 @Test
104 public void testGetFieldsList() {
105 Iterable<String> result = fixture.getFieldsList();
106
107 assertNotNull(result);
108 assertEquals(false, result.iterator().hasNext());
109 }
110
111 /**
112 * Run the long getMinAlign() method test.
113 */
114 @Test
115 public void testGetMinAlign() {
116 long result = fixture.getMaxAlign();
117 assertEquals(1L, result);
118 }
119
120 /**
121 * Run the boolean hasField(String) method test.
122 */
123 @Test
124 public void testHasField() {
125 String name = "";
126 boolean result = fixture.hasField(name);
127
128 assertEquals(false, result);
129 }
130
131 /**
132 * Run the String toString() method test.
133 */
134 @Test
135 public void testToString() {
136 String result = fixture.toString();
137 String trunc = result.substring(0, 21);
138
139 assertEquals("[declaration] struct[", trunc);
140 }
141 }
This page took 0.036135 seconds and 5 git commands to generate.