Commit | Line | Data |
---|---|---|
866e5b51 FC |
1 | package org.eclipse.linuxtools.ctf.core.tests.types; |
2 | ||
3 | import static org.junit.Assert.assertEquals; | |
4 | import static org.junit.Assert.assertNotNull; | |
5 | import static org.junit.Assert.assertTrue; | |
6 | ||
7 | import java.util.HashMap; | |
8 | import java.util.List; | |
9 | ||
10 | import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; | |
11 | import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; | |
12 | import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; | |
13 | import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; | |
14 | import org.junit.After; | |
15 | import org.junit.Before; | |
16 | import org.junit.Test; | |
17 | ||
18 | /** | |
19 | * The class <code>StructDeclarationTest</code> contains tests for the class | |
20 | * <code>{@link StructDeclaration}</code>. | |
459ebacd | 21 | * |
866e5b51 FC |
22 | * @author ematkho |
23 | * @version $Revision: 1.0 $ | |
24 | */ | |
25 | public class StructDeclarationTest { | |
26 | ||
27 | private StructDeclaration fixture; | |
28 | ||
29 | /** | |
30 | * Launch the test. | |
459ebacd | 31 | * |
866e5b51 FC |
32 | * @param args |
33 | * the command line arguments | |
34 | */ | |
35 | public static void main(String[] args) { | |
36 | new org.junit.runner.JUnitCore().run(StructDeclarationTest.class); | |
37 | } | |
38 | ||
39 | /** | |
40 | * Perform pre-test initialization. | |
41 | */ | |
42 | @Before | |
43 | public void setUp() { | |
44 | fixture = new StructDeclaration(1L); | |
45 | } | |
46 | ||
47 | /** | |
48 | * Perform post-test clean-up. | |
49 | */ | |
50 | @After | |
51 | public void tearDown() { | |
52 | // Add additional tear down code here | |
53 | } | |
54 | ||
55 | /** | |
56 | * Run the StructDeclaration(long) constructor test. | |
57 | */ | |
58 | @Test | |
59 | public void testStructDeclaration() { | |
60 | assertNotNull(fixture); | |
459ebacd | 61 | assertEquals(1L, fixture.getMaxAlign()); |
866e5b51 FC |
62 | |
63 | String regex = "^\\[declaration\\] struct\\[[0-9a-f]{1,8}\\]$"; //$NON-NLS-1$ | |
64 | assertTrue(fixture.toString().matches(regex)); | |
65 | } | |
66 | ||
67 | /** | |
68 | * Run the void addField(String,Declaration) method test. | |
69 | */ | |
70 | @Test | |
71 | public void testAddField() { | |
72 | String name = ""; //$NON-NLS-1$ | |
73 | IDeclaration declaration = new StringDeclaration(); | |
74 | fixture.addField(name, declaration); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Run the StructDefinition createDefinition(DefinitionScope,String) method | |
79 | * test. | |
80 | */ | |
81 | @Test | |
82 | public void testCreateDefinition() { | |
83 | String fieldName = ""; //$NON-NLS-1$ | |
84 | StructDefinition result = fixture.createDefinition(null, fieldName); | |
85 | assertNotNull(result); | |
86 | } | |
87 | ||
88 | /** | |
89 | * Run the HashMap<String, Declaration> getFields() method test. | |
90 | */ | |
91 | @Test | |
92 | public void testGetFields() { | |
93 | HashMap<String, IDeclaration> result = fixture.getFields(); | |
94 | ||
95 | assertNotNull(result); | |
96 | assertEquals(0, result.size()); | |
97 | } | |
98 | ||
99 | /** | |
100 | * Run the List<String> getFieldsList() method test. | |
101 | */ | |
102 | @Test | |
103 | public void testGetFieldsList() { | |
104 | List<String> result = fixture.getFieldsList(); | |
105 | ||
106 | assertNotNull(result); | |
107 | assertEquals(0, result.size()); | |
108 | } | |
109 | ||
110 | /** | |
111 | * Run the long getMinAlign() method test. | |
112 | */ | |
113 | @Test | |
114 | public void testGetMinAlign() { | |
459ebacd | 115 | long result = fixture.getMaxAlign(); |
866e5b51 FC |
116 | assertEquals(1L, result); |
117 | } | |
118 | ||
119 | /** | |
120 | * Run the boolean hasField(String) method test. | |
121 | */ | |
122 | @Test | |
123 | public void testHasField() { | |
124 | String name = ""; //$NON-NLS-1$ | |
125 | boolean result = fixture.hasField(name); | |
126 | ||
127 | assertEquals(false, result); | |
128 | } | |
129 | ||
866e5b51 FC |
130 | /** |
131 | * Run the String toString() method test. | |
132 | */ | |
133 | @Test | |
134 | public void testToString() { | |
135 | String result = fixture.toString(); | |
136 | String trunc = result.substring(0, 21); | |
137 | ||
138 | assertEquals("[declaration] struct[", trunc); //$NON-NLS-1$ | |
139 | } | |
140 | } |