| 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 | |
| 6 | import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; |
| 7 | import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; |
| 8 | import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; |
| 9 | import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; |
| 10 | import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; |
| 11 | import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration; |
| 12 | import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition; |
| 13 | import org.eclipse.linuxtools.ctf.core.tests.TestParams; |
| 14 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
| 15 | import org.junit.After; |
| 16 | import org.junit.Before; |
| 17 | import org.junit.Test; |
| 18 | |
| 19 | /** |
| 20 | * The class <code>VariantDeclarationTest</code> contains tests for the class |
| 21 | * <code>{@link VariantDeclaration}</code>. |
| 22 | * |
| 23 | * @author ematkho |
| 24 | * @version $Revision: 1.0 $ |
| 25 | */ |
| 26 | public class VariantDeclarationTest { |
| 27 | |
| 28 | private VariantDeclaration fixture; |
| 29 | |
| 30 | /** |
| 31 | * Launch the test. |
| 32 | * |
| 33 | * @param args |
| 34 | * the command line arguments |
| 35 | */ |
| 36 | public static void main(String[] args) { |
| 37 | new org.junit.runner.JUnitCore().run(VariantDeclarationTest.class); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Perform pre-test initialization. |
| 42 | */ |
| 43 | @Before |
| 44 | public void setUp() { |
| 45 | fixture = new VariantDeclaration(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Perform post-test clean-up. |
| 50 | */ |
| 51 | @After |
| 52 | public void tearDown() { |
| 53 | // Add additional tear down code here |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Run the VariantDeclaration() constructor test. |
| 58 | */ |
| 59 | @Test |
| 60 | public void testVariantDeclaration() { |
| 61 | assertNotNull(fixture); |
| 62 | assertEquals(false, fixture.isTagged()); |
| 63 | String left = "[declaration] variant["; //$NON-NLS-1$ |
| 64 | assertEquals(left, fixture.toString().substring(0, left.length())); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Run the void addField(String,Declaration) method test. |
| 69 | */ |
| 70 | @Test |
| 71 | public void testAddField() { |
| 72 | fixture.setTag(""); //$NON-NLS-1$ |
| 73 | String tag = ""; //$NON-NLS-1$ |
| 74 | IDeclaration declaration = new StringDeclaration(); |
| 75 | fixture.addField(tag, declaration); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Run the VariantDefinition createDefinition(DefinitionScope,String) method |
| 80 | * test. |
| 81 | * |
| 82 | * @throws CTFReaderException Should not happen |
| 83 | */ |
| 84 | @Test |
| 85 | public void testCreateDefinition() throws CTFReaderException { |
| 86 | fixture.setTag(""); //$NON-NLS-1$ |
| 87 | IDefinitionScope definitionScope = createDefinitionScope(); |
| 88 | String fieldName = ""; //$NON-NLS-1$ |
| 89 | VariantDefinition result = fixture.createDefinition(definitionScope, |
| 90 | fieldName); |
| 91 | |
| 92 | assertNotNull(result); |
| 93 | } |
| 94 | |
| 95 | private static IDefinitionScope createDefinitionScope() throws CTFReaderException { |
| 96 | VariantDeclaration declaration = new VariantDeclaration(); |
| 97 | declaration.setTag(""); //$NON-NLS-1$ |
| 98 | VariantDeclaration variantDeclaration = new VariantDeclaration(); |
| 99 | variantDeclaration.setTag(""); //$NON-NLS-1$ |
| 100 | VariantDefinition variantDefinition = new VariantDefinition( |
| 101 | variantDeclaration, TestParams.createTrace(), ""); //$NON-NLS-1$ |
| 102 | IDefinitionScope definitionScope = new StructDefinition( |
| 103 | new StructDeclaration(1L), variantDefinition, ""); //$NON-NLS-1$ |
| 104 | String fieldName = ""; //$NON-NLS-1$ |
| 105 | |
| 106 | VariantDefinition result = new VariantDefinition(declaration, |
| 107 | definitionScope, fieldName); |
| 108 | return result; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Run the boolean hasField(String) method test. |
| 113 | */ |
| 114 | @Test |
| 115 | public void testHasField() { |
| 116 | fixture.setTag(""); //$NON-NLS-1$ |
| 117 | String tag = ""; //$NON-NLS-1$ |
| 118 | boolean result = fixture.hasField(tag); |
| 119 | |
| 120 | assertEquals(false, result); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Run the boolean isTagged() method test. |
| 125 | */ |
| 126 | @Test |
| 127 | public void testIsTagged() { |
| 128 | fixture.setTag(""); //$NON-NLS-1$ |
| 129 | boolean result = fixture.isTagged(); |
| 130 | |
| 131 | assertEquals(true, result); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Run the boolean isTagged() method test. |
| 136 | */ |
| 137 | @Test |
| 138 | public void testIsTagged_null() { |
| 139 | fixture.setTag((String) null); |
| 140 | boolean result = fixture.isTagged(); |
| 141 | |
| 142 | assertEquals(false, result); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Run the void setTag(String) method test. |
| 147 | */ |
| 148 | @Test |
| 149 | public void testSetTag() { |
| 150 | fixture.setTag(""); //$NON-NLS-1$ |
| 151 | String tag = ""; //$NON-NLS-1$ |
| 152 | fixture.setTag(tag); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Run the String toString() method test. |
| 157 | */ |
| 158 | @Test |
| 159 | public void testToString() { |
| 160 | fixture.setTag(""); //$NON-NLS-1$ |
| 161 | String result = fixture.toString(); |
| 162 | String left = "[declaration] variant["; //$NON-NLS-1$ |
| 163 | String right = result.substring(0, left.length()); |
| 164 | |
| 165 | assertEquals(left, right); |
| 166 | } |
| 167 | } |