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 org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
18 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDefinitionScope
;
19 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDeclaration
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDefinition
;
21 import org
.junit
.After
;
22 import org
.junit
.Before
;
23 import org
.junit
.Test
;
26 * The class <code>StringDeclarationTest</code> contains tests for the class
27 * <code>{@link StringDeclaration}</code>.
30 * @version $Revision: 1.0 $
32 public class StringDeclarationTest
{
34 private StringDeclaration fixture
;
40 * the command line arguments
42 public static void main(String
[] args
) {
43 new org
.junit
.runner
.JUnitCore().run(StringDeclarationTest
.class);
47 * Perform pre-test initialization.
51 fixture
= new StringDeclaration(Encoding
.ASCII
);
55 * Perform post-test clean-up.
58 public void tearDown() {
59 // Add additional tear down code here
63 * Run the StringDeclaration() constructor test.
66 public void testStringDeclaration() {
67 StringDeclaration result
= new StringDeclaration();
69 assertNotNull(result
);
70 String string
= "[declaration] string["; //$NON-NLS-1$
71 assertEquals(string
, result
.toString().substring(0, string
.length()));
75 * Run the StringDeclaration(Encoding) constructor test.
78 public void testStringDeclaration_2() {
79 Encoding encoding
= Encoding
.ASCII
;
80 StringDeclaration result
= new StringDeclaration(encoding
);
82 assertNotNull(result
);
83 String string
= "[declaration] string["; //$NON-NLS-1$
84 assertEquals(string
, result
.toString().substring(0, string
.length()));
88 * Run the StringDefinition createDefinition(DefinitionScope,String) method
92 public void testCreateDefinition() {
93 IDefinitionScope definitionScope
= null;
94 String fieldName
= "id"; //$NON-NLS-1$
95 StringDefinition result
= fixture
.createDefinition(definitionScope
,
98 assertNotNull(result
);
102 * Run the Encoding getEncoding() method test.
105 public void testGetEncoding() {
106 Encoding result
= fixture
.getEncoding();
108 assertNotNull(result
);
109 assertEquals("ASCII", result
.name()); //$NON-NLS-1$
110 assertEquals("ASCII", result
.toString()); //$NON-NLS-1$
111 assertEquals(1, result
.ordinal());
115 * Run the void setEncoding(Encoding) method test.
118 public void testSetEncoding() {
119 Encoding encoding
= Encoding
.ASCII
;
120 fixture
.setEncoding(encoding
);
124 * Run the String toString() method test.
127 public void testToString() {
128 String result
= fixture
.toString();
129 String left
= "[declaration] string["; //$NON-NLS-1$
130 String right
= result
.substring(0, left
.length());
132 assertEquals(left
, right
);