tmf: Make CtfTmfEventField extend TmfEventField
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core.tests / src / org / eclipse / linuxtools / lttng2 / core / tests / control / model / impl / FieldInfoTest.java
CommitLineData
d4514365
BH
1/**********************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl;
13
14import junit.framework.TestCase;
15
16import org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo;
17import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.FieldInfo;
18
19/**
20 * The class <code>FieldInfoTest</code> contains test for the class <code>{@link FieldInfo}</code>.
21 */
22@SuppressWarnings({"nls", "javadoc"})
23public class FieldInfoTest extends TestCase {
24
25 // ------------------------------------------------------------------------
26 // Test data
27 // ------------------------------------------------------------------------
28 private IFieldInfo fFieldInfo1 = null;
29 private IFieldInfo fFieldInfo2 = null;
30
31 // ------------------------------------------------------------------------
32 // Housekeeping
33 // ------------------------------------------------------------------------
34 /**
35 * Perform pre-test initialization.
36 *
37 * @throws Exception if the initialization fails for some reason
38 *
39 */
40 @Override
41 public void setUp() throws Exception {
42 super.setUp();
43 ModelImplFactory factory = new ModelImplFactory();
44 fFieldInfo1 = factory.getFieldInfo1();
45 fFieldInfo2 = factory.getFieldInfo2();
46 }
47
48 /**
49 * Perform post-test clean-up.
50 *
51 * @throws Exception if the clean-up fails for some reason
52 *
53 */
54 @Override
55 public void tearDown() throws Exception {
56 }
57
58 // ------------------------------------------------------------------------
59 // Tests
60 // ------------------------------------------------------------------------
61
62 /**
63 * Run the BaseEventInfo() constructor test.
64 *
65 */
66 public void testFiledInfo() {
67 FieldInfo fixture = new FieldInfo("field");
68 assertNotNull(fixture);
69
70 assertEquals("field", fixture.getName());
71 assertNull(fixture.getFieldType());
72 }
73
74 /**
75 * Test Copy Constructor
76 */
77 public void testEventInfoCopy() {
78 FieldInfo info = new FieldInfo((FieldInfo)fFieldInfo1);
79
80 assertEquals(fFieldInfo1.getName(), info.getName());
81 assertEquals(fFieldInfo1.getFieldType(), info.getFieldType());
82 }
83
84 /**
85 * Test Copy Constructor
86 */
87 public void testEventCopy2() {
88 try {
89 FieldInfo info = null;
90 new FieldInfo(info);
91 fail("null copy");
92 }
93 catch (IllegalArgumentException e) {
94 // Success
95 }
96 }
97
98 /**
99 * Run the TraceEventType getEventType() method test.
100 *
101 * @throws Exception
102 *
103 */
104 public void testSetFieldType() {
105 FieldInfo info = new FieldInfo((FieldInfo)fFieldInfo1);
106
107 info.setFieldType("string");
108 assertEquals("string", info.getFieldType());
109 }
110
111 public void testToString() {
112 String result = fFieldInfo1.toString();
113
114 // add additional test code here
115 assertEquals("[FieldInfo([TraceInfo(Name=intfield)],type=int", result);
116 }
117
118 // ------------------------------------------------------------------------
119 // equals
120 // ------------------------------------------------------------------------
121
122 public void testEqualsReflexivity() {
123 assertTrue("equals", fFieldInfo1.equals(fFieldInfo1));
124 assertTrue("equals", fFieldInfo2.equals(fFieldInfo2));
125
126 assertTrue("equals", !fFieldInfo1.equals(fFieldInfo2));
127 assertTrue("equals", !fFieldInfo2.equals(fFieldInfo1));
128 }
129
130 public void testEqualsSymmetry() {
131 FieldInfo info1 = new FieldInfo((FieldInfo)fFieldInfo1);
132 FieldInfo info2 = new FieldInfo((FieldInfo)fFieldInfo2);
133
134 assertTrue("equals", info1.equals(fFieldInfo1));
135 assertTrue("equals", fFieldInfo1.equals(info1));
136
137 assertTrue("equals", info2.equals(fFieldInfo2));
138 assertTrue("equals", fFieldInfo2.equals(info2));
139 }
140
141 public void testEqualsTransivity() {
142 FieldInfo info1 = new FieldInfo((FieldInfo)fFieldInfo1);
143 FieldInfo info2 = new FieldInfo((FieldInfo)fFieldInfo1);
144 FieldInfo info3 = new FieldInfo((FieldInfo)fFieldInfo1);
145
146 assertTrue("equals", info1.equals(info2));
147 assertTrue("equals", info2.equals(info3));
148 assertTrue("equals", info1.equals(info3));
149 }
150
151 public void testEqualsNull() {
152 assertTrue("equals", !fFieldInfo1.equals(null));
153 assertTrue("equals", !fFieldInfo2.equals(null));
154 }
155
156 // ------------------------------------------------------------------------
157 // hashCode
158 // ------------------------------------------------------------------------
159
160 public void testHashCode() {
161 FieldInfo info1 = new FieldInfo((FieldInfo)fFieldInfo1);
162 FieldInfo info2 = new FieldInfo((FieldInfo)fFieldInfo2);
163
164 assertTrue("hashCode", fFieldInfo1.hashCode() == info1.hashCode());
165 assertTrue("hashCode", fFieldInfo2.hashCode() == info2.hashCode());
166
167 assertTrue("hashCode", fFieldInfo1.hashCode() != info2.hashCode());
168 assertTrue("hashCode", fFieldInfo2.hashCode() != info1.hashCode());
169 }
170}
This page took 0.032846 seconds and 5 git commands to generate.