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