LTTNG: Bug 436857: Keep process selection in CPU Usage tree viewer
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / 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
866e5b51
FC
12package org.eclipse.linuxtools.ctf.core.tests.types;
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16import static org.junit.Assert.assertTrue;
17
a4fa4e36 18import java.nio.ByteBuffer;
0594c61c 19import java.util.Map;
866e5b51 20
a4fa4e36 21import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
866e5b51
FC
22import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
23import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
24import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
25import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
a4fa4e36 26import org.eclipse.linuxtools.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 = "";
a4fa4e36
MK
81 BitBuffer bb = new BitBuffer(ByteBuffer.allocate(100));
82 StructDefinition result = fixture.createDefinition(null, fieldName, bb);
866e5b51
FC
83 assertNotNull(result);
84 }
85
86 /**
87 * Run the HashMap<String, Declaration> getFields() method test.
88 */
89 @Test
90 public void testGetFields() {
0594c61c 91 Map<String, IDeclaration> result = fixture.getFields();
866e5b51
FC
92
93 assertNotNull(result);
94 assertEquals(0, result.size());
95 }
96
97 /**
98 * Run the List<String> getFieldsList() method test.
99 */
100 @Test
101 public void testGetFieldsList() {
a4fa4e36 102 Iterable<String> result = fixture.getFieldsList();
866e5b51
FC
103
104 assertNotNull(result);
a4fa4e36 105 assertEquals(false, result.iterator().hasNext());
866e5b51
FC
106 }
107
108 /**
109 * Run the long getMinAlign() method test.
110 */
111 @Test
112 public void testGetMinAlign() {
459ebacd 113 long result = fixture.getMaxAlign();
866e5b51
FC
114 assertEquals(1L, result);
115 }
116
117 /**
118 * Run the boolean hasField(String) method test.
119 */
120 @Test
121 public void testHasField() {
4a9c1f07 122 String name = "";
866e5b51
FC
123 boolean result = fixture.hasField(name);
124
125 assertEquals(false, result);
126 }
127
866e5b51
FC
128 /**
129 * Run the String toString() method test.
130 */
131 @Test
132 public void testToString() {
133 String result = fixture.toString();
134 String trunc = result.substring(0, 21);
135
4a9c1f07 136 assertEquals("[declaration] struct[", trunc);
866e5b51
FC
137 }
138}
This page took 0.046182 seconds and 5 git commands to generate.