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 | ||
6 | import org.eclipse.linuxtools.ctf.core.event.types.Encoding; | |
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.StringDefinition; | |
10 | import org.junit.After; | |
11 | import org.junit.Before; | |
12 | import org.junit.Test; | |
13 | ||
14 | /** | |
15 | * The class <code>StringDeclarationTest</code> contains tests for the class | |
16 | * <code>{@link StringDeclaration}</code>. | |
17 | * | |
18 | * @author ematkho | |
19 | * @version $Revision: 1.0 $ | |
20 | */ | |
21 | public class StringDeclarationTest { | |
22 | ||
23 | private StringDeclaration fixture; | |
24 | ||
25 | /** | |
26 | * Launch the test. | |
27 | * | |
28 | * @param args | |
29 | * the command line arguments | |
30 | */ | |
31 | public static void main(String[] args) { | |
32 | new org.junit.runner.JUnitCore().run(StringDeclarationTest.class); | |
33 | } | |
34 | ||
35 | /** | |
36 | * Perform pre-test initialization. | |
37 | */ | |
38 | @Before | |
39 | public void setUp() { | |
40 | fixture = new StringDeclaration(Encoding.ASCII); | |
41 | } | |
42 | ||
43 | /** | |
44 | * Perform post-test clean-up. | |
45 | */ | |
46 | @After | |
47 | public void tearDown() { | |
48 | // Add additional tear down code here | |
49 | } | |
50 | ||
51 | /** | |
52 | * Run the StringDeclaration() constructor test. | |
53 | */ | |
54 | @Test | |
55 | public void testStringDeclaration() { | |
56 | StringDeclaration result = new StringDeclaration(); | |
57 | ||
58 | assertNotNull(result); | |
59 | String string = "[declaration] string["; //$NON-NLS-1$ | |
60 | assertEquals(string, result.toString().substring(0, string.length())); | |
61 | } | |
62 | ||
63 | /** | |
64 | * Run the StringDeclaration(Encoding) constructor test. | |
65 | */ | |
66 | @Test | |
67 | public void testStringDeclaration_2() { | |
68 | Encoding encoding = Encoding.ASCII; | |
69 | StringDeclaration result = new StringDeclaration(encoding); | |
70 | ||
71 | assertNotNull(result); | |
72 | String string = "[declaration] string["; //$NON-NLS-1$ | |
73 | assertEquals(string, result.toString().substring(0, string.length())); | |
74 | } | |
75 | ||
76 | /** | |
77 | * Run the StringDefinition createDefinition(DefinitionScope,String) method | |
78 | * test. | |
79 | */ | |
80 | @Test | |
81 | public void testCreateDefinition() { | |
82 | IDefinitionScope definitionScope = null; | |
83 | String fieldName = "id"; //$NON-NLS-1$ | |
84 | StringDefinition result = fixture.createDefinition(definitionScope, | |
85 | fieldName); | |
86 | ||
87 | assertNotNull(result); | |
88 | } | |
89 | ||
90 | /** | |
91 | * Run the Encoding getEncoding() method test. | |
92 | */ | |
93 | @Test | |
94 | public void testGetEncoding() { | |
95 | Encoding result = fixture.getEncoding(); | |
96 | ||
97 | assertNotNull(result); | |
98 | assertEquals("ASCII", result.name()); //$NON-NLS-1$ | |
99 | assertEquals("ASCII", result.toString()); //$NON-NLS-1$ | |
100 | assertEquals(1, result.ordinal()); | |
101 | } | |
102 | ||
103 | /** | |
104 | * Run the void setEncoding(Encoding) method test. | |
105 | */ | |
106 | @Test | |
107 | public void testSetEncoding() { | |
108 | Encoding encoding = Encoding.ASCII; | |
109 | fixture.setEncoding(encoding); | |
110 | } | |
111 | ||
112 | /** | |
113 | * Run the String toString() method test. | |
114 | */ | |
115 | @Test | |
116 | public void testToString() { | |
117 | String result = fixture.toString(); | |
118 | String left = "[declaration] string["; //$NON-NLS-1$ | |
119 | String right = result.substring(0, left.length()); | |
120 | ||
121 | assertEquals(left, right); | |
122 | } | |
123 | } |