4a6e53df7e3dfc49e781dfb58a8afb1828a7f2ed
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / EnumDeclarationTest.java
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
12 package org.eclipse.linuxtools.ctf.core.tests.types;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertNull;
17 import static org.junit.Assert.assertTrue;
18
19 import java.nio.ByteBuffer;
20 import java.nio.ByteOrder;
21
22 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
23 import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
24 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
25 import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
26 import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
27 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
28 import org.eclipse.linuxtools.ctf.core.tests.io.Util;
29 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
30 import org.junit.Before;
31 import org.junit.Test;
32
33 /**
34 * The class <code>EnumDeclarationTest</code> contains tests for the class
35 * <code>{@link EnumDeclaration}</code>.
36 *
37 * @author ematkho
38 * @version $Revision: 1.0 $
39 */
40 public class EnumDeclarationTest {
41
42 private EnumDeclaration fixture;
43
44 /**
45 * Perform pre-test initialization.
46 */
47 @Before
48 public void setUp() {
49 fixture = new EnumDeclaration(IntegerDeclaration.createDeclaration(1, false, 1,
50 ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8));
51 }
52
53 /**
54 * Run the EnumDeclaration(IntegerDeclaration) constructor test.
55 */
56 @Test
57 public void testEnumDeclaration() {
58 IntegerDeclaration containerType = IntegerDeclaration.createDeclaration(1, false, 1,
59 ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8);
60
61 EnumDeclaration result = new EnumDeclaration(containerType);
62
63 assertNotNull(result);
64 String left = "[declaration] enum[";
65 assertEquals(left, result.toString().substring(0, left.length()));
66 }
67
68 /**
69 * Run the boolean add(long,long,String) method test.
70 */
71 @Test
72 public void testAdd() {
73 long low = 1L;
74 long high = 1L;
75 String label = "";
76
77 boolean result = fixture.add(low, high, label);
78
79 assertTrue(result);
80 }
81
82 /**
83 * Run the EnumDefinition createDefinition(DefinitionScope,String) method
84 * test.
85 *
86 * @throws CTFReaderException
87 * out of bounds error, won't happen
88 */
89 @Test
90 public void testCreateDefinition() throws CTFReaderException {
91 IDefinitionScope definitionScope = null;
92 String fieldName = "";
93 byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
94 BitBuffer bb = new BitBuffer(Util.testMemory(ByteBuffer.wrap(array)));
95
96 EnumDefinition result = fixture.createDefinition(definitionScope,
97 fieldName, bb);
98
99 assertNotNull(result);
100 }
101
102 /**
103 * Run the String query(long) method test.
104 */
105 @Test
106 public void testQuery() {
107 long value = 0;
108 String result = fixture.query(value);
109
110 assertNull(result);
111 }
112
113 /**
114 * Run the String toString() method test.
115 */
116 @Test
117 public void testToString() {
118 String result = fixture.toString();
119
120 String left = "[declaration] enum[";
121 assertEquals(left, result.substring(0, left.length()));
122 }
123 }
This page took 0.034952 seconds and 4 git commands to generate.