ctf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / StringDeclarationTest.java
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
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
17 import java.nio.ByteBuffer;
18
19 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
20 import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
21 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
22 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
23 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
24 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 /**
29 * The class <code>StringDeclarationTest</code> contains tests for the class
30 * <code>{@link StringDeclaration}</code>.
31 *
32 * @author ematkho
33 * @version $Revision: 1.0 $
34 */
35 public class StringDeclarationTest {
36
37 private StringDeclaration fixture;
38
39 /**
40 * Perform pre-test initialization.
41 */
42 @Before
43 public void setUp() {
44 fixture = new StringDeclaration(Encoding.ASCII);
45 }
46
47 /**
48 * Run the StringDeclaration() constructor test.
49 */
50 @Test
51 public void testStringDeclaration() {
52 StringDeclaration result = new StringDeclaration();
53
54 assertNotNull(result);
55 String string = "[declaration] string[";
56 assertEquals(string, result.toString().substring(0, string.length()));
57 }
58
59 /**
60 * Run the StringDeclaration(Encoding) constructor test.
61 */
62 @Test
63 public void testStringDeclaration_2() {
64 Encoding encoding = Encoding.ASCII;
65 StringDeclaration result = new StringDeclaration(encoding);
66
67 assertNotNull(result);
68 String string = "[declaration] string[";
69 assertEquals(string, result.toString().substring(0, string.length()));
70 }
71
72 /**
73 * Run the StringDefinition createDefinition(DefinitionScope,String) method
74 * test.
75 *
76 * @throws CTFReaderException
77 * out of buffer exception
78 */
79 @Test
80 public void testCreateDefinition() throws CTFReaderException {
81 IDefinitionScope definitionScope = null;
82 String fieldName = "id";
83 ByteBuffer allocate = ByteBuffer.allocate(100);
84 if (allocate == null) {
85 throw new IllegalStateException("Failed to allocate memory");
86 }
87 BitBuffer bb = new BitBuffer(allocate);
88 StringDefinition result = fixture.createDefinition(definitionScope,
89 fieldName, bb);
90
91 assertNotNull(result);
92 }
93
94 /**
95 * Run the Encoding getEncoding() method test.
96 */
97 @Test
98 public void testGetEncoding() {
99 Encoding result = fixture.getEncoding();
100
101 assertNotNull(result);
102 assertEquals("ASCII", result.name());
103 assertEquals("ASCII", result.toString());
104 assertEquals(1, result.ordinal());
105 }
106
107 /**
108 * Run the String toString() method test.
109 */
110 @Test
111 public void testToString() {
112 String result = fixture.toString();
113 String left = "[declaration] string[";
114 String right = result.substring(0, left.length());
115
116 assertEquals(left, right);
117 }
118 }
This page took 0.033138 seconds and 5 git commands to generate.