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