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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.ctf
.core
.tests
.types
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
17 import java
.nio
.ByteBuffer
;
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
;
29 * The class <code>StringDefinitionTest</code> contains tests for the class
30 * <code>{@link StringDefinition}</code>.
33 * @version $Revision: 1.0 $
35 public class StringDefinitionTest
{
37 private StringDefinition fixture
;
38 private String testString
;
41 * Perform pre-test initialization.
43 * @throws CTFException
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");
54 BitBuffer bb
= new BitBuffer(byteBuffer
);
56 testString
= new String("testString");
57 byteBuffer
.put(testString
.getBytes());
59 fixture
= stringDec
.createDefinition(null, name
, bb
);
63 * Run the StringDefinition(StringDeclaration,DefinitionScope,String)
67 public void testStringDefinition() {
68 StringDeclaration declaration
= StringDeclaration
.getStringDeclaration(Encoding
.UTF8
);
69 IDefinitionScope definitionScope
= null;
70 String fieldName
= "";
72 StringDefinition result
= new StringDefinition(declaration
,
73 definitionScope
, fieldName
, "");
75 assertNotNull(result
);
79 * Run the StringDeclaration getDeclaration() method test.
82 public void testGetDeclaration() {
83 StringDeclaration result
= fixture
.getDeclaration();
84 assertNotNull(result
);
88 * Run the String getValue() method test.
91 public void testGetValue() {
92 String result
= fixture
.getValue();
93 assertNotNull(result
);
97 * Run the String setValue() method test.
100 public void testSetValue() {
102 String result
= fixture
.getValue();
103 assertNotNull(result
);
104 assertEquals("testString", result
);
108 * Run the String toString() method test.
111 public void testToString() {
112 String result
= fixture
.toString();
113 assertNotNull(result
);