Implement the new TMF Event Model
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / event / TmfEventTest.java
CommitLineData
d18dd09b
ASL
1/*******************************************************************************
2 * Copyright (c) 2009 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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
6c13869b 13package org.eclipse.linuxtools.tmf.core.tests.event;
d18dd09b 14
cbd4ad82
FC
15import junit.framework.TestCase;
16
4c564a2d 17import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
6c13869b 18import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
4c564a2d 19import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
6c13869b
FC
20import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
21import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
d18dd09b
ASL
22
23/**
24 * <b><u>TmfEventTest</u></b>
25 * <p>
cbd4ad82 26 * Test suite for the TmfEvent class.
d18dd09b 27 */
3b38ea61 28@SuppressWarnings("nls")
d18dd09b
ASL
29public class TmfEventTest extends TestCase {
30
cbd4ad82
FC
31 // ------------------------------------------------------------------------
32 // Variables
33 // ------------------------------------------------------------------------
34
cbbcc354 35 private final String fContext = TmfEventType.DEFAULT_CONTEXT_ID;
36 private final String fTypeId = "Some type";
37 private final String fLabel0 = "label1";
38 private final String fLabel1 = "label2";
39 private final String[] fLabels = new String[] { fLabel0, fLabel1 };
d18dd09b 40
4641c2f7
FC
41 private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, (byte) 2, 5);
42 private final TmfTimestamp fTimestamp2 = new TmfTimestamp(12350, (byte) 2, 5);
43 private final String fSource = "Source";
4c564a2d 44 private final TmfEventType fType = new TmfEventType(fContext, fTypeId, TmfEventField.makeRoot(fLabels));
4641c2f7 45 private final String fReference = "Some reference";
d18dd09b
ASL
46
47 private final TmfEvent fEvent1;
48 private final TmfEvent fEvent2;
49
4c564a2d
FC
50 private final TmfEventField fContent1;
51 private final TmfEventField fContent2;
d18dd09b 52
cbd4ad82 53 // ------------------------------------------------------------------------
d18dd09b 54 // Housekeeping
cbd4ad82 55 // ------------------------------------------------------------------------
d18dd09b 56
cbd4ad82
FC
57 /**
58 * @param name the test name
59 */
d18dd09b
ASL
60 public TmfEventTest(String name) {
61 super(name);
62
4c564a2d
FC
63 fContent1 = new TmfEventField(ITmfEventField.ROOT_ID, "Some content");
64 fEvent1 = new TmfEvent(null, fTimestamp1, fSource, fType, fContent1, fReference);
d18dd09b 65
4c564a2d
FC
66 fContent2 = new TmfEventField(ITmfEventField.ROOT_ID, "Some other content");
67 fEvent2 = new TmfEvent(null, fTimestamp2, fSource, fType, fContent2, fReference);
d18dd09b
ASL
68 }
69
70 @Override
71 protected void setUp() throws Exception {
72 super.setUp();
73 }
74
75 @Override
76 protected void tearDown() throws Exception {
77 super.tearDown();
78 }
79
cbd4ad82 80 // ------------------------------------------------------------------------
d18dd09b 81 // Constructors
cbd4ad82 82 // ------------------------------------------------------------------------
d18dd09b
ASL
83
84 public void testTmfEvent() {
cbbcc354 85 assertEquals("getTimestamp", fTimestamp1, fEvent1.getTimestamp());
86 assertEquals("getSource", fSource, fEvent1.getSource());
87 assertEquals("getType", fType, fEvent1.getType());
88 assertEquals("getContent", fContent1, fEvent1.getContent());
89 assertEquals("getReference", fReference, fEvent1.getReference());
d18dd09b
ASL
90 }
91
92 public void testTmfEvent2() {
cbbcc354 93 assertEquals("getTimestamp", fTimestamp2, fEvent2.getTimestamp());
94 assertEquals("getSource", fSource, fEvent2.getSource());
95 assertEquals("getType", fType, fEvent2.getType());
96 assertEquals("getContent", fContent2, fEvent2.getContent());
97 assertEquals("getReference", fReference, fEvent2.getReference());
d18dd09b
ASL
98 }
99
100 public void testTmfEventCopy() {
101 TmfEvent event = new TmfEvent(fEvent1);
cbbcc354 102 assertEquals("getTimestamp", fTimestamp1, event.getTimestamp());
103 assertEquals("getSource", fSource, event.getSource());
104 assertEquals("getType", fType, event.getType());
105 assertEquals("getContent", fContent1, event.getContent());
106 assertEquals("getReference", fReference, event.getReference());
d18dd09b
ASL
107 }
108
cbd4ad82
FC
109 public void testEventCopy2() throws Exception {
110 try {
111 new TmfEvent(null);
112 fail("null copy");
113 }
114 catch (IllegalArgumentException e) {
115 // Success
116 }
117 }
118
119 // ------------------------------------------------------------------------
120 // equals
121 // ------------------------------------------------------------------------
122
123 public void testEqualsReflexivity() throws Exception {
124 assertTrue("equals", fEvent1.equals(fEvent1));
125 assertTrue("equals", fEvent2.equals(fEvent2));
126
127 assertTrue("equals", !fEvent1.equals(fEvent2));
128 assertTrue("equals", !fEvent2.equals(fEvent1));
129 }
130
131 public void testEqualsSymmetry() throws Exception {
132 TmfEvent event1 = new TmfEvent(fEvent1);
133 TmfEvent event2 = new TmfEvent(fEvent2);
134
135 assertTrue("equals", event1.equals(fEvent1));
136 assertTrue("equals", fEvent1.equals(event1));
137
138 assertTrue("equals", event2.equals(fEvent2));
139 assertTrue("equals", fEvent2.equals(event2));
140 }
141
142 public void testEqualsTransivity() throws Exception {
143 TmfEvent event1 = new TmfEvent(fEvent1);
144 TmfEvent event2 = new TmfEvent(fEvent1);
145 TmfEvent event3 = new TmfEvent(fEvent1);
146
147 assertTrue("equals", event1.equals(event2));
148 assertTrue("equals", event2.equals(event3));
149 assertTrue("equals", event1.equals(event3));
150 }
151
cbd4ad82
FC
152 public void testEqualsNull() throws Exception {
153 assertTrue("equals", !fEvent1.equals(null));
154 assertTrue("equals", !fEvent2.equals(null));
155 }
156
157 // ------------------------------------------------------------------------
2fb2eb37
FC
158 // hashCode
159 // ------------------------------------------------------------------------
160
161 public void testHashCode() throws Exception {
162 TmfEvent event1 = new TmfEvent(fEvent1);
163 TmfEvent event2 = new TmfEvent(fEvent2);
164
165 assertTrue("hashCode", fEvent1.hashCode() == event1.hashCode());
166 assertTrue("hashCode", fEvent2.hashCode() == event2.hashCode());
167
168 assertTrue("hashCode", fEvent1.hashCode() != event2.hashCode());
169 assertTrue("hashCode", fEvent2.hashCode() != event1.hashCode());
170 }
171
ce970a71 172// // ------------------------------------------------------------------------
173// // toString
174// // ------------------------------------------------------------------------
175//
176// public void testToString() {
177// String expected1 = "[TmfEvent (" + fTimestamp1 + "," + fSource + "," + fType + "," + fContent1 + ")]";
178// assertEquals("toString", expected1, fEvent1.toString());
179//
180// String expected2 = "[TmfEvent(" + fTimestamp2 + "," + fSource + "," + fType + "," + fContent2 + ")]";
181// assertEquals("toString", expected2, fEvent2.toString());
182// }
cbd4ad82
FC
183
184 // ------------------------------------------------------------------------
185 // setContent
186 // ------------------------------------------------------------------------
187
188 public void testSetContent() {
189 TmfEvent event = new TmfEvent(fEvent1);
190 assertEquals("setContent", fContent1, event.getContent());
191
192 event.setContent(fContent2);
193 assertEquals("setContent", fContent2, event.getContent());
194
195 event.setContent(fContent1);
196 assertEquals("setContent", fContent1, event.getContent());
197 }
d18dd09b
ASL
198
199}
This page took 0.038266 seconds and 5 git commands to generate.