Commit | Line | Data |
---|---|---|
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 |
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 | ||
866e5b51 | 18 | import java.util.List; |
0594c61c | 19 | import java.util.Map; |
866e5b51 FC |
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; | |
866e5b51 FC |
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>. | |
459ebacd | 31 | * |
866e5b51 FC |
32 | * @author ematkho |
33 | * @version $Revision: 1.0 $ | |
34 | */ | |
35 | public class StructDeclarationTest { | |
36 | ||
37 | private StructDeclaration fixture; | |
38 | ||
866e5b51 FC |
39 | /** |
40 | * Perform pre-test initialization. | |
41 | */ | |
42 | @Before | |
43 | public void setUp() { | |
44 | fixture = new StructDeclaration(1L); | |
45 | } | |
46 | ||
866e5b51 FC |
47 | /** |
48 | * Run the StructDeclaration(long) constructor test. | |
49 | */ | |
50 | @Test | |
51 | public void testStructDeclaration() { | |
52 | assertNotNull(fixture); | |
459ebacd | 53 | assertEquals(1L, fixture.getMaxAlign()); |
866e5b51 | 54 | |
4a9c1f07 | 55 | String regex = "^\\[declaration\\] struct\\[[0-9a-f]{1,8}\\]$"; |
866e5b51 FC |
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() { | |
4a9c1f07 | 64 | String name = ""; |
866e5b51 FC |
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() { | |
4a9c1f07 | 75 | String fieldName = ""; |
866e5b51 FC |
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() { | |
0594c61c | 85 | Map<String, IDeclaration> result = fixture.getFields(); |
866e5b51 FC |
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() { | |
459ebacd | 107 | long result = fixture.getMaxAlign(); |
866e5b51 FC |
108 | assertEquals(1L, result); |
109 | } | |
110 | ||
111 | /** | |
112 | * Run the boolean hasField(String) method test. | |
113 | */ | |
114 | @Test | |
115 | public void testHasField() { | |
4a9c1f07 | 116 | String name = ""; |
866e5b51 FC |
117 | boolean result = fixture.hasField(name); |
118 | ||
119 | assertEquals(false, result); | |
120 | } | |
121 | ||
866e5b51 FC |
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 | ||
4a9c1f07 | 130 | assertEquals("[declaration] struct[", trunc); |
866e5b51 FC |
131 | } |
132 | } |