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
.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
;
29 * The class <code>StringDeclarationTest</code> contains tests for the class
30 * <code>{@link StringDeclaration}</code>.
33 * @version $Revision: 1.0 $
35 public class StringDeclarationTest
{
37 private StringDeclaration fixture
;
40 * Perform pre-test initialization.
44 fixture
= new StringDeclaration(Encoding
.ASCII
);
48 * Run the StringDeclaration() constructor test.
51 public void testStringDeclaration() {
52 StringDeclaration result
= new StringDeclaration();
54 assertNotNull(result
);
55 String string
= "[declaration] string[";
56 assertEquals(string
, result
.toString().substring(0, string
.length()));
60 * Run the StringDeclaration(Encoding) constructor test.
63 public void testStringDeclaration_2() {
64 Encoding encoding
= Encoding
.ASCII
;
65 StringDeclaration result
= new StringDeclaration(encoding
);
67 assertNotNull(result
);
68 String string
= "[declaration] string[";
69 assertEquals(string
, result
.toString().substring(0, string
.length()));
73 * Run the StringDefinition createDefinition(DefinitionScope,String) method
76 * @throws CTFReaderException
77 * out of buffer exception
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");
87 BitBuffer bb
= new BitBuffer(allocate
);
88 StringDefinition result
= fixture
.createDefinition(definitionScope
,
91 assertNotNull(result
);
95 * Run the Encoding getEncoding() method test.
98 public void testGetEncoding() {
99 Encoding result
= fixture
.getEncoding();
101 assertNotNull(result
);
102 assertEquals("ASCII", result
.name());
103 assertEquals("ASCII", result
.toString());
104 assertEquals(1, result
.ordinal());
108 * Run the String toString() method test.
111 public void testToString() {
112 String result
= fixture
.toString();
113 String left
= "[declaration] string[";
114 String right
= result
.substring(0, left
.length());
116 assertEquals(left
, right
);