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 / StringDefinitionTest.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.StringDeclaration;
22 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
23 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
24 import org.junit.Before;
25 import org.junit.Test;
26
27 /**
28 * The class <code>StringDefinitionTest</code> contains tests for the class
29 * <code>{@link StringDefinition}</code>.
30 *
31 * @author ematkho
32 * @version $Revision: 1.0 $
33 */
34 public class StringDefinitionTest {
35
36 private StringDefinition fixture;
37 private String testString;
38
39 /**
40 * Perform pre-test initialization.
41 *
42 * @throws CTFReaderException
43 * won't happen
44 */
45 @Before
46 public void setUp() throws CTFReaderException {
47 String name = "testString";
48 StringDeclaration stringDec = new StringDeclaration();
49 ByteBuffer byteBuffer = ByteBuffer.allocate(100);
50 if (byteBuffer == null) {
51 throw new IllegalStateException("Failed to allocate memory");
52 }
53 BitBuffer bb = new BitBuffer(byteBuffer);
54 byteBuffer.mark();
55 testString = new String("testString");
56 byteBuffer.put(testString.getBytes());
57 byteBuffer.reset();
58 fixture = stringDec.createDefinition(null, name, bb);
59 }
60
61 /**
62 * Run the StringDefinition(StringDeclaration,DefinitionScope,String)
63 * constructor test.
64 */
65 @Test
66 public void testStringDefinition() {
67 StringDeclaration declaration = new StringDeclaration();
68 IDefinitionScope definitionScope = null;
69 String fieldName = "";
70
71 StringDefinition result = new StringDefinition(declaration,
72 definitionScope, fieldName, "");
73
74 assertNotNull(result);
75 }
76
77 /**
78 * Run the StringDeclaration getDeclaration() method test.
79 */
80 @Test
81 public void testGetDeclaration() {
82 StringDeclaration result = fixture.getDeclaration();
83 assertNotNull(result);
84 }
85
86 /**
87 * Run the String getValue() method test.
88 */
89 @Test
90 public void testGetValue() {
91 String result = fixture.getValue();
92 assertNotNull(result);
93 }
94
95 /**
96 * Run the String setValue() method test.
97 */
98 @Test
99 public void testSetValue() {
100
101 String result = fixture.getValue();
102 assertNotNull(result);
103 assertEquals("testString", result);
104 }
105
106 /**
107 * Run the String toString() method test.
108 */
109 @Test
110 public void testToString() {
111 String result = fixture.toString();
112 assertNotNull(result);
113 }
114 }
This page took 0.056573 seconds and 5 git commands to generate.