Commit | Line | Data |
---|---|---|
4bd7f2db AM |
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 | |
7 | * | |
8 | * Contributors: | |
9 | * Matthew Khouzam - Initial API and implementation | |
10 | *******************************************************************************/ | |
11 | ||
866e5b51 FC |
12 | package org.eclipse.linuxtools.ctf.core.tests.types; |
13 | ||
4f4b6212 | 14 | import static org.junit.Assert.assertEquals; |
866e5b51 FC |
15 | import static org.junit.Assert.assertNotNull; |
16 | ||
a4fa4e36 MK |
17 | import java.nio.ByteBuffer; |
18 | ||
486efb2e | 19 | import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; |
a4fa4e36 | 20 | import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; |
866e5b51 FC |
21 | import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; |
22 | import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition; | |
db8e8f7d | 23 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
866e5b51 FC |
24 | import org.junit.Before; |
25 | import org.junit.Test; | |
26 | ||
27 | /** | |
28 | * The class <code>StringDefinitionTest</code> contains tests for the class | |
29 | * <code>{@link StringDefinition}</code>. | |
024373d7 | 30 | * |
866e5b51 FC |
31 | * @author ematkho |
32 | * @version $Revision: 1.0 $ | |
33 | */ | |
34 | public class StringDefinitionTest { | |
35 | ||
36 | private StringDefinition fixture; | |
a4fa4e36 | 37 | private String testString; |
866e5b51 | 38 | |
866e5b51 FC |
39 | /** |
40 | * Perform pre-test initialization. | |
a4fa4e36 | 41 | * |
aefc5c83 MK |
42 | * @throws CTFReaderException |
43 | * won't happen | |
866e5b51 FC |
44 | */ |
45 | @Before | |
a4fa4e36 | 46 | public void setUp() throws CTFReaderException { |
4a9c1f07 | 47 | String name = "testString"; |
024373d7 | 48 | StringDeclaration stringDec = new StringDeclaration(); |
a4fa4e36 | 49 | ByteBuffer byteBuffer = ByteBuffer.allocate(100); |
aefc5c83 MK |
50 | if (byteBuffer == null) { |
51 | throw new IllegalStateException("Failed to allocate memory"); | |
52 | } | |
a4fa4e36 MK |
53 | BitBuffer bb = new BitBuffer(byteBuffer); |
54 | byteBuffer.mark(); | |
55 | testString = new String("testString"); | |
56 | byteBuffer.put(testString.getBytes()); | |
57 | byteBuffer.reset(); | |
58 | fixture = stringDec.createDefinition(null, name, bb); | |
866e5b51 FC |
59 | } |
60 | ||
866e5b51 FC |
61 | /** |
62 | * Run the StringDefinition(StringDeclaration,DefinitionScope,String) | |
63 | * constructor test. | |
64 | */ | |
65 | @Test | |
66 | public void testStringDefinition() { | |
67 | StringDeclaration declaration = new StringDeclaration(); | |
68 | IDefinitionScope definitionScope = null; | |
4a9c1f07 | 69 | String fieldName = ""; |
866e5b51 FC |
70 | |
71 | StringDefinition result = new StringDefinition(declaration, | |
a4fa4e36 | 72 | definitionScope, fieldName, ""); |
866e5b51 FC |
73 | |
74 | assertNotNull(result); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Run the StringDeclaration getDeclaration() method test. | |
79 | */ | |
80 | @Test | |
81 | public void testGetDeclaration() { | |
866e5b51 FC |
82 | StringDeclaration result = fixture.getDeclaration(); |
83 | assertNotNull(result); | |
84 | } | |
85 | ||
86 | /** | |
4f4b6212 | 87 | * Run the String getValue() method test. |
866e5b51 FC |
88 | */ |
89 | @Test | |
4f4b6212 EB |
90 | public void testGetValue() { |
91 | String result = fixture.getValue(); | |
866e5b51 FC |
92 | assertNotNull(result); |
93 | } | |
94 | ||
95 | /** | |
4f4b6212 | 96 | * Run the String setValue() method test. |
866e5b51 FC |
97 | */ |
98 | @Test | |
4f4b6212 | 99 | public void testSetValue() { |
a4fa4e36 | 100 | |
866e5b51 FC |
101 | String result = fixture.getValue(); |
102 | assertNotNull(result); | |
a4fa4e36 | 103 | assertEquals("testString", result); |
866e5b51 FC |
104 | } |
105 | ||
866e5b51 FC |
106 | /** |
107 | * Run the String toString() method test. | |
108 | */ | |
109 | @Test | |
110 | public void testToString() { | |
866e5b51 FC |
111 | String result = fixture.toString(); |
112 | assertNotNull(result); | |
113 | } | |
114 | } |