tmf.ui: remove duplication in TimeCompressionBar
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / types / StructDeclarationTest.java
CommitLineData
4bd7f2db
AM
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
f357bcd4 12package org.eclipse.tracecompass.ctf.core.tests.types;
866e5b51
FC
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
2db699c2 16import static org.junit.Assert.assertNull;
866e5b51
FC
17import static org.junit.Assert.assertTrue;
18
a4fa4e36 19import java.nio.ByteBuffer;
866e5b51 20
f357bcd4
AM
21import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
22import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
23import org.eclipse.tracecompass.ctf.core.event.types.StringDeclaration;
24import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
25import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
26import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
866e5b51
FC
27import org.junit.Before;
28import org.junit.Test;
29
30/**
31 * The class <code>StructDeclarationTest</code> contains tests for the class
32 * <code>{@link StructDeclaration}</code>.
459ebacd 33 *
866e5b51
FC
34 * @author ematkho
35 * @version $Revision: 1.0 $
36 */
37public class StructDeclarationTest {
38
39 private StructDeclaration fixture;
40
866e5b51
FC
41 /**
42 * Perform pre-test initialization.
43 */
44 @Before
45 public void setUp() {
46 fixture = new StructDeclaration(1L);
47 }
48
866e5b51
FC
49 /**
50 * Run the StructDeclaration(long) constructor test.
51 */
52 @Test
53 public void testStructDeclaration() {
54 assertNotNull(fixture);
459ebacd 55 assertEquals(1L, fixture.getMaxAlign());
866e5b51 56
4a9c1f07 57 String regex = "^\\[declaration\\] struct\\[[0-9a-f]{1,8}\\]$";
866e5b51
FC
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() {
4a9c1f07 66 String name = "";
866e5b51
FC
67 IDeclaration declaration = new StringDeclaration();
68 fixture.addField(name, declaration);
69 }
70
71 /**
72 * Run the StructDefinition createDefinition(DefinitionScope,String) method
73 * test.
a4fa4e36
MK
74 *
75 * @throws CTFReaderException
76 * out of bounds
866e5b51
FC
77 */
78 @Test
a4fa4e36 79 public void testCreateDefinition() throws CTFReaderException {
4a9c1f07 80 String fieldName = "";
aefc5c83
MK
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);
a4fa4e36 86 StructDefinition result = fixture.createDefinition(null, fieldName, bb);
866e5b51
FC
87 assertNotNull(result);
88 }
89
90 /**
2db699c2 91 * Run the Declaration getField(String) method test.
866e5b51
FC
92 */
93 @Test
2db699c2
AM
94 public void testGetField() {
95 IDeclaration result = fixture.getField("test");
866e5b51 96
2db699c2 97 assertNull(result);
866e5b51
FC
98 }
99
100 /**
101 * Run the List<String> getFieldsList() method test.
102 */
103 @Test
104 public void testGetFieldsList() {
a4fa4e36 105 Iterable<String> result = fixture.getFieldsList();
866e5b51
FC
106
107 assertNotNull(result);
a4fa4e36 108 assertEquals(false, result.iterator().hasNext());
866e5b51
FC
109 }
110
111 /**
112 * Run the long getMinAlign() method test.
113 */
114 @Test
115 public void testGetMinAlign() {
459ebacd 116 long result = fixture.getMaxAlign();
866e5b51
FC
117 assertEquals(1L, result);
118 }
119
120 /**
121 * Run the boolean hasField(String) method test.
122 */
123 @Test
124 public void testHasField() {
4a9c1f07 125 String name = "";
866e5b51
FC
126 boolean result = fixture.hasField(name);
127
128 assertEquals(false, result);
129 }
130
866e5b51
FC
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
4a9c1f07 139 assertEquals("[declaration] struct[", trunc);
866e5b51
FC
140 }
141}
This page took 0.073481 seconds and 5 git commands to generate.