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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.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
.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
;
28 * The class <code>StringDefinitionTest</code> contains tests for the class
29 * <code>{@link StringDefinition}</code>.
32 * @version $Revision: 1.0 $
34 public class StringDefinitionTest
{
36 private StringDefinition fixture
;
37 private String testString
;
40 * Perform pre-test initialization.
42 * @throws CTFReaderException
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");
53 BitBuffer bb
= new BitBuffer(byteBuffer
);
55 testString
= new String("testString");
56 byteBuffer
.put(testString
.getBytes());
58 fixture
= stringDec
.createDefinition(null, name
, bb
);
62 * Run the StringDefinition(StringDeclaration,DefinitionScope,String)
66 public void testStringDefinition() {
67 StringDeclaration declaration
= new StringDeclaration();
68 IDefinitionScope definitionScope
= null;
69 String fieldName
= "";
71 StringDefinition result
= new StringDefinition(declaration
,
72 definitionScope
, fieldName
, "");
74 assertNotNull(result
);
78 * Run the StringDeclaration getDeclaration() method test.
81 public void testGetDeclaration() {
82 StringDeclaration result
= fixture
.getDeclaration();
83 assertNotNull(result
);
87 * Run the String getValue() method test.
90 public void testGetValue() {
91 String result
= fixture
.getValue();
92 assertNotNull(result
);
96 * Run the String setValue() method test.
99 public void testSetValue() {
101 String result
= fixture
.getValue();
102 assertNotNull(result
);
103 assertEquals("testString", result
);
107 * Run the String toString() method test.
110 public void testToString() {
111 String result
= fixture
.toString();
112 assertNotNull(result
);