From 75d42a1670deaa2244ac774c0ff803d2690b13ba Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Tue, 21 Feb 2012 18:07:01 -0500 Subject: [PATCH] Improve test coverage for TmfEventField. --- .../core/tests/event/TmfEventFieldTest.java | 487 ++++++++++++------ .../core/tests/event/TmfEventTypeTest.java | 7 +- .../tests/event/TmfSimpleTimestampTest.java | 6 +- .../core/tests/event/TmfTimeRangeTest.java | 6 +- .../core/tests/event/TmfTimestampTest.java | 12 +- .../tmf/core/event/ITmfEventField.java | 4 +- .../tmf/core/event/TmfEventField.java | 31 +- 7 files changed, 364 insertions(+), 189 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java index 99ffc9ef7e..5562f9602c 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventFieldTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson + * Copyright (c) 2009, 2012 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,6 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Adjusted for new Event Model *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; @@ -25,163 +26,337 @@ import org.eclipse.linuxtools.tmf.core.event.TmfEventField; @SuppressWarnings("nls") public class TmfEventFieldTest extends TestCase { - // ------------------------------------------------------------------------ - // Variables - // ------------------------------------------------------------------------ - - private final String fFieldId = "Field"; - private final Object fValue1 = new String("Value"); - private final Object fValue2 = new Integer(10); + // ------------------------------------------------------------------------ + // Variables + // ------------------------------------------------------------------------ + + private final String fFieldName1 = "Field-1"; + private final String fFieldName2 = "Field-2"; + + private final Object fValue1 = new String("Value"); + private final Object fValue2 = new Integer(10); + + private TmfEventField fField1 = new TmfEventField(fFieldName1, fValue1); + private TmfEventField fField2 = new TmfEventField(fFieldName2, fValue2, null); + private TmfEventField fField3 = new TmfEventField(fFieldName1, fValue2, null); + + private final String fStructRootFieldName = "Root-S"; + private final String[] fStructFieldNames = new String[] { fFieldName1, fFieldName2 }; + private final TmfEventField fStructTerminalField1 = new TmfEventField(fFieldName1, null); + private final TmfEventField fStructTerminalField2 = new TmfEventField(fFieldName2, null); + private final TmfEventField fStructTerminalField3 = new TmfEventField(fFieldName1, null); + private final TmfEventField fStructRootField = new TmfEventField(fStructRootFieldName, + new ITmfEventField[] { fStructTerminalField1, fStructTerminalField2 }); + + private final String fRootFieldName = "Root"; + private final String[] fFieldNames = new String[] { fFieldName1, fFieldName2 }; + private final TmfEventField fRootField = new TmfEventField(fRootFieldName, + new ITmfEventField[] { fField1, fField2 }); + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + + /** + * @param name the test name + */ + public TmfEventFieldTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + public void testTerminalStructConstructor() { + assertSame("getName", fFieldName1, fStructTerminalField1.getName()); + assertNull("getValue", fStructTerminalField1.getValue()); + assertNull("getFields", fStructTerminalField1.getFields()); + assertNull("getField(name)", fStructTerminalField1.getField(fFieldName1)); + assertNull("getField(index)", fStructTerminalField1.getField(0)); + assertEquals("getFieldNames", 0, fStructTerminalField1.getFieldNames().length); + assertNull("getFieldName", fStructTerminalField1.getFieldName(-1)); + assertNull("getFieldName", fStructTerminalField1.getFieldName(0)); + } + + public void testNonTerminalStructConstructor() { + assertSame("getName", fStructRootFieldName, fStructRootField.getName()); + assertNull("getValue", fStructRootField.getValue()); + assertEquals("getFields", 2, fStructRootField.getFields().length); + assertSame("getField(name)", fStructTerminalField1, fStructRootField.getField(fFieldName1)); + assertSame("getField(name)", fStructTerminalField2, fStructRootField.getField(fFieldName2)); + assertSame("getField(index)", fStructTerminalField1, fStructRootField.getField(0)); + assertSame("getField(index)", fStructTerminalField2, fStructRootField.getField(1)); + + String[] names = fStructRootField.getFieldNames(); + assertEquals("getFieldNames length", 2, names.length); + for (int i = 0; i < names.length; i++) { + assertSame("getFieldNames", fStructFieldNames[i], names[i]); + assertSame("getFieldName", fFieldNames[i], fStructRootField.getFieldName(i)); + } + assertNull("getFieldName", fStructRootField.getFieldName(-1)); + assertNull("getFieldName", fStructRootField.getFieldName(names.length)); + } + + public void testTerminalConstructor() { + assertSame("getName", fFieldName1, fField1.getName()); + assertSame("getValue", fValue1, fField1.getValue()); + assertNull("getFields", fField1.getFields()); + assertNull("getField(name)", fField1.getField(fFieldName1)); + assertNull("getField(index)", fField1.getField(0)); + assertEquals("getFieldNames", 0, fField1.getFieldNames().length); + assertNull("getFieldName", fField1.getFieldName(0)); + + assertSame("getName", fFieldName2, fField2.getName()); + assertSame("getValue", fValue2, fField2.getValue()); + assertNull("getFields", fField2.getFields()); + assertNull("getField(name)", fField2.getField(fFieldName2)); + assertNull("getField(index)", fField2.getField(0)); + assertEquals("getFieldNames", 0, fField2.getFieldNames().length); + assertNull("getFieldName", fField2.getFieldName(0)); + } + + public void testNonTerminalConstructor() { + assertSame("getName", fRootFieldName, fRootField.getName()); + assertNull("getValue", fRootField.getValue()); + assertEquals("getFields", 2, fRootField.getFields().length); + assertSame("getField(name)", fField1, fRootField.getField(fFieldName1)); + assertSame("getField(name)", fField2, fRootField.getField(fFieldName2)); + assertSame("getField(index)", fField1, fRootField.getField(0)); + assertSame("getField(index)", fField2, fRootField.getField(1)); + + String[] names = fRootField.getFieldNames(); + assertEquals("getFieldNames length", 2, names.length); + for (int i = 0; i < names.length; i++) { + assertSame("getFieldNames", fFieldNames[i], names[i]); + assertSame("getFieldName", fFieldNames[i], fRootField.getFieldName(i)); + } + assertNull("getFieldName", fRootField.getFieldName(-1)); + assertNull("getFieldName", fRootField.getFieldName(names.length)); + } + + public void testConstructorBadArg() { + try { + new TmfEventField(null, fValue1, null); + fail("Invalid (null) field name"); + } catch (IllegalArgumentException e) { + } + } + + public void testTerminalCopyConstructor() { + TmfEventField copy = new TmfEventField(fField1); + assertSame("getName", fFieldName1, copy.getName()); + assertSame("getValue", fValue1, copy.getValue()); + assertNull("getFields", copy.getFields()); + assertNull("getField(name)", copy.getField(fFieldName1)); + assertNull("getField(index)", copy.getField(0)); + assertEquals("getFieldNames", 0, copy.getFieldNames().length); + assertNull("getFieldName", copy.getFieldName(0)); + } + + public void testNonTerminalCopyConstructor() { + assertSame("getName", fRootFieldName, fRootField.getName()); + assertNull("getValue", fRootField.getValue()); + assertEquals("getFields", 2, fRootField.getFields().length); + assertSame("getField(name)", fField1, fRootField.getField(fFieldName1)); + assertSame("getField(name)", fField2, fRootField.getField(fFieldName2)); + assertSame("getField(index)", fField1, fRootField.getField(0)); + assertSame("getField(index)", fField2, fRootField.getField(1)); + + String[] names = fRootField.getFieldNames(); + assertEquals("getFieldNames length", 2, names.length); + for (int i = 0; i < names.length; i++) { + assertSame("getFieldNames", fFieldNames[i], names[i]); + assertSame("getFieldName", fFieldNames[i], fRootField.getFieldName(i)); + } + assertNull("getFieldName", fRootField.getFieldName(names.length)); + } + + public void testCopyConstructorBadArg() { + try { + new TmfEventField(null); + fail("TmfEventField: null arguemnt"); + } catch (IllegalArgumentException e) { + } + } + + // ------------------------------------------------------------------------ + // Modifiers + // ------------------------------------------------------------------------ + + private class MyField extends TmfEventField { + + public MyField(String id, Object value) { + super(id, value); + } + + public MyField(TmfEventField field) { + super(field); + } + + @Override + public void setValue(Object value, ITmfEventField[] subfields) { + super.setValue(value, subfields); + } + } + + public void testSetValue() { + TmfEventField field = new TmfEventField(fFieldName1, fValue1, null); - private TmfEventField fField0; - private TmfEventField fField1; - private TmfEventField fField2; - private TmfEventField fField3; + MyField myField = new MyField(field); + assertSame("getValue", fValue1, myField.getValue()); + myField.setValue(fValue2, null); + assertSame("getValue", fValue2, myField.getValue()); + } // ------------------------------------------------------------------------ - // Housekeeping - // ------------------------------------------------------------------------ - - /** - * @param name the test name - */ - public TmfEventFieldTest(String name) { - super(name); - fField0 = new TmfEventField(fFieldId, fValue1, null); - fField1 = new TmfEventField(fFieldId, fValue1, null); - fField2 = new TmfEventField(fFieldId, fValue1, null); - fField3 = new TmfEventField(fFieldId, fValue2, null); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - public void testTmfEventField() { - assertSame("getId", fFieldId, fField0.getName()); - assertSame("getValue", fValue1, fField0.getValue()); - } - - public void testTmfEventFieldBadArg() { - try { - new TmfEventField(null, fValue1, null); - fail("null copy"); - } - catch (IllegalArgumentException e) { - // Success - } - } - - public void testTmfEventFieldCopy() { - TmfEventField original = new TmfEventField(fFieldId, fValue1, null); - TmfEventField field = new TmfEventField(original); - assertSame("getId", fFieldId, field.getName()); - assertSame("getValue", fValue1, field.getValue()); - } - - public void testTmfEventFieldCopy2() { - try { - new TmfEventField(null); - fail("null copy"); - } - catch (IllegalArgumentException e) { - // Success - } - } - - // ------------------------------------------------------------------------ - // Modifiers - // ------------------------------------------------------------------------ - - private class MyField extends TmfEventField { - public MyField(String id, Object value) { - super(id, value); - } - public MyField(TmfEventField field) { - super(field); - } - @Override - public void setValue(Object value, ITmfEventField[] subfields) { - super.setValue(value, subfields); - } - } - - public void testSetValue() { -// TmfEventField original = new TmfEventField(fContent, fFieldId, fValue1); - TmfEventField original = new TmfEventField(fFieldId, fValue1, null); - TmfEventField field = new TmfEventField(original); - - MyField myField = new MyField(field); - assertSame("getValue", fValue1, myField.getValue()); - - myField.setValue(fValue2, null); - assertSame("getValue", fValue2, myField.getValue()); - } - - // ------------------------------------------------------------------------ - // equals - // ------------------------------------------------------------------------ - - public void testEqualsReflexivity() throws Exception { - assertTrue("equals", fField0.equals(fField0)); - assertTrue("equals", fField3.equals(fField3)); - - assertTrue("equals", !fField0.equals(fField3)); - assertTrue("equals", !fField3.equals(fField0)); - } - - public void testEqualsSymmetry() throws Exception { - assertTrue("equals", fField0.equals(fField1)); - assertTrue("equals", fField1.equals(fField0)); - - assertTrue("equals", !fField0.equals(fField3)); - assertTrue("equals", !fField3.equals(fField0)); - } - - public void testEqualsTransivity() throws Exception { - assertTrue("equals", fField0.equals(fField1)); - assertTrue("equals", fField1.equals(fField2)); - assertTrue("equals", fField0.equals(fField2)); - } - - public void testEqualsNull() throws Exception { - assertTrue("equals", !fField0.equals(null)); - assertTrue("equals", !fField3.equals(null)); - } - - // ------------------------------------------------------------------------ - // hashCode - // ------------------------------------------------------------------------ - - public void testHashCode() throws Exception { - assertTrue("hashCode", fField0.hashCode() == fField1.hashCode()); - assertTrue("hashCode", fField0.hashCode() != fField3.hashCode()); - } - - // ------------------------------------------------------------------------ - // toString - // ------------------------------------------------------------------------ - - public void testToString() { - String expected1 = "TmfEventField [fFieldId=" + fFieldId + ", fValue=" + fValue1.toString() + "]"; -// TmfEventField field = new TmfEventField(fContent, fFieldId, fValue1); - TmfEventField field = new TmfEventField(fFieldId, fValue1, null); - assertEquals("toString", expected1, field.toString()); - - String expected2 = "TmfEventField [fFieldId=" + fFieldId + ", fValue=" + fValue2.toString() + "]"; -// field = new TmfEventField(fContent, fFieldId, fValue2); - field = new TmfEventField(fFieldId, fValue2, null); - assertEquals("toString", expected2, field.toString()); - } + // clone + // ------------------------------------------------------------------------ + + public void testClone() throws Exception { + ITmfEventField clone = fStructTerminalField1.clone(); + assertEquals("clone", fStructTerminalField1, clone); + + clone = fField1.clone(); + assertEquals("clone", fField1, clone); + + clone = fRootField.clone(); + assertEquals("clone", fRootField, clone); + + clone = fStructRootField.clone(); + assertEquals("clone", fStructRootField, clone); + } + + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ + + public void testHashCode() throws Exception { + TmfEventField copy = new TmfEventField(fField1); + assertTrue("hashCode", fField1.hashCode() == copy.hashCode()); + assertTrue("hashCode", fField1.hashCode() != fField2.hashCode()); + + copy = new TmfEventField(fStructTerminalField1); + assertTrue("hashCode", fStructTerminalField1.hashCode() == copy.hashCode()); + assertTrue("hashCode", fStructTerminalField1.hashCode() != fStructTerminalField2.hashCode()); + } + + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ + + public void testEqualsReflexivity() throws Exception { + assertTrue("equals", fField1.equals(fField1)); + assertTrue("equals", fField2.equals(fField2)); + + assertFalse("equals", fField1.equals(fField2)); + assertFalse("equals", fField2.equals(fField1)); + + assertTrue("equals", fStructTerminalField1.equals(fStructTerminalField1)); + assertTrue("equals", fStructTerminalField2.equals(fStructTerminalField2)); + + assertFalse("equals", fStructTerminalField1.equals(fStructTerminalField2)); + assertFalse("equals", fStructTerminalField2.equals(fStructTerminalField1)); + } + + public void testEqualsSymmetry() throws Exception { + TmfEventField copy0 = new TmfEventField(fField1); + assertTrue("equals", fField1.equals(copy0)); + assertTrue("equals", copy0.equals(fField1)); + + TmfEventField copy3 = new TmfEventField(fField2); + assertTrue("equals", fField2.equals(copy3)); + assertTrue("equals", copy3.equals(fField2)); + } + + public void testEqualsTransivity() throws Exception { + TmfEventField copy1 = new TmfEventField(fField1); + TmfEventField copy2 = new TmfEventField(copy1); + assertTrue("equals", fField1.equals(copy1)); + assertTrue("equals", copy1.equals(copy2)); + assertTrue("equals", fField1.equals(copy2)); + + copy1 = new TmfEventField(fField2); + copy2 = new TmfEventField(copy1); + assertTrue("equals", fField2.equals(copy1)); + assertTrue("equals", copy1.equals(copy2)); + assertTrue("equals", fField2.equals(copy2)); + } + + public void testEqualsNull() throws Exception { + assertFalse("equals", fField1.equals(null)); + assertFalse("equals", fField2.equals(null)); + } + + public void testEquals() throws Exception { + assertTrue("equals", fStructTerminalField1.equals(fStructTerminalField3)); + assertTrue("equals", fStructTerminalField3.equals(fStructTerminalField1)); + + assertFalse("equals", fStructTerminalField1.equals(fField3)); + assertFalse("equals", fField3.equals(fStructTerminalField1)); + } + + public void testNonEquals() throws Exception { + assertFalse("equals", fField1.equals(fField2)); + assertFalse("equals", fField2.equals(fField1)); + + assertFalse("equals", fField1.equals(fStructTerminalField1)); + } + + public void testEqualsNonType() throws Exception { + assertFalse("equals", fField1.equals(fValue1)); + } + + // ------------------------------------------------------------------------ + // toString + // ------------------------------------------------------------------------ + + public void testToString() { + String expected1 = "TmfEventField [fFieldId=" + fFieldName1 + ", fValue=" + fValue1.toString() + "]"; + TmfEventField field = new TmfEventField(fFieldName1, fValue1, null); + assertEquals("toString", expected1, field.toString()); + + String expected2 = "TmfEventField [fFieldId=" + fFieldName1 + ", fValue=" + fValue2.toString() + "]"; + field = new TmfEventField(fFieldName1, fValue2, null); + assertEquals("toString", expected2, field.toString()); + } + + // ------------------------------------------------------------------------ + // makeRoot + // ------------------------------------------------------------------------ + + public void testMakeRoot() { + ITmfEventField root = TmfEventField.makeRoot(fStructFieldNames); + String[] names = root.getFieldNames(); + assertEquals("getFieldNames length", 2, names.length); + for (int i = 0; i < names.length; i++) { + assertSame("getFieldNames", fStructFieldNames[i], names[i]); + assertSame("getFieldName", fStructFieldNames[i], root.getFieldName(i)); + assertNull("getValue", root.getField(i).getValue()); + } + assertNull("getFieldName", root.getFieldName(-1)); + assertNull("getFieldName", root.getFieldName(names.length)); + + root = TmfEventField.makeRoot(fFieldNames); + names = root.getFieldNames(); + assertEquals("getFieldNames length", 2, names.length); + for (int i = 0; i < names.length; i++) { + assertSame("getFieldNames", fFieldNames[i], names[i]); + assertSame("getFieldName", fFieldNames[i], root.getFieldName(i)); + assertNull("getValue", root.getField(i).getValue()); + } + assertNull("getFieldName", root.getFieldName(-1)); + assertNull("getFieldName", root.getFieldName(names.length)); + } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java index 4205a82e03..1dce224a3e 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson + * Copyright (c) 2009, 2012 Ericsson * * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 which @@ -8,6 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Francois Chouinard - Adjusted for new Event Model *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; @@ -21,7 +22,7 @@ import org.eclipse.linuxtools.tmf.core.event.TmfEventType; /** * TmfEventTypeTest *

- * JUnit test suite for the TmfEventType class. + * Test suite for the TmfEventType class. */ @SuppressWarnings("nls") public class TmfEventTypeTest extends TestCase { @@ -149,7 +150,7 @@ public class TmfEventTypeTest extends TestCase { public void testCopyConstructorCornerCases() { try { new TmfEventType(null); - fail("null argument"); + fail("TmfEventType: null argument"); } catch (IllegalArgumentException e) { } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java index c2caed2f91..937caffeb9 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfSimpleTimestampTest.java @@ -90,21 +90,21 @@ public class TmfSimpleTimestampTest extends TestCase { try { @SuppressWarnings("unused") ITmfTimestamp timestamp = new TmfSimpleTimestamp(null); - fail("null copy"); + fail("TmfSimpleTimestamp: null argument"); } catch (IllegalArgumentException e) { } try { @SuppressWarnings("unused") ITmfTimestamp ts = new TmfSimpleTimestamp(ts0a); - fail("bad scale"); + fail("TmfSimpleTimestamp: bad scale"); } catch (IllegalArgumentException e) { } try { @SuppressWarnings("unused") ITmfTimestamp ts = new TmfSimpleTimestamp(ts0b); - fail("bad precision"); + fail("TmfSimpleTimestamp: bad precision"); } catch (IllegalArgumentException e) { } } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java index 112b047c9f..3ee4a673ef 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimeRangeTest.java @@ -61,14 +61,14 @@ public class TmfTimeRangeTest extends TestCase { public void testBadConstructor() throws Exception { try { new TmfTimeRange(TmfTimestamp.BigBang, null); - fail("null copy"); + fail("TmfTimeRange: bad end time"); } catch (IllegalArgumentException e) { // Success } try { new TmfTimeRange(null, TmfTimestamp.BigCrunch); - fail("null copy"); + fail("TmfTimeRange: bad start time"); } catch (IllegalArgumentException e) { // Success } @@ -116,7 +116,7 @@ public class TmfTimeRangeTest extends TestCase { public void testCopyConstructor2() throws Exception { try { new TmfTimeRange(null); - fail("null copy"); + fail("TmfTimeRange: null argument"); } catch (IllegalArgumentException e) { // Success } diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java index 9232e6404e..1d4bd2c2f3 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampTest.java @@ -101,7 +101,7 @@ public class TmfTimestampTest extends TestCase { try { @SuppressWarnings("unused") ITmfTimestamp timestamp = new TmfTimestamp(null); - fail("null copy"); + fail("TmfTimestamp: null argument"); } catch (IllegalArgumentException e) { } } @@ -321,24 +321,24 @@ public class TmfTimestampTest extends TestCase { ts1.normalize(0, +MAX_SCALE_DIFF - 1); ts1.normalize(0, -MAX_SCALE_DIFF + 1); } catch (ArithmeticException e) { - fail(); + fail("normalize: scale error"); } // Test at limit try { ts1.normalize(0, +MAX_SCALE_DIFF); - fail(); + fail("normalize: scale error"); ts1.normalize(0, -MAX_SCALE_DIFF); - fail(); + fail("normalize: scale error"); } catch (ArithmeticException e) { } // Test over limit try { ts1.normalize(0, +MAX_SCALE_DIFF + 1); - fail(); + fail("normalize: scale error"); ts1.normalize(0, -MAX_SCALE_DIFF - 1); - fail(); + fail("normalize: scale error"); } catch (ArithmeticException e) { } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java index 36ea96763a..38211763f7 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEventField.java @@ -36,7 +36,7 @@ public interface ITmfEventField extends Cloneable { public Object getValue(); /** - * @return the list of subfield names (empty array if none) + * @return the list of subfield names (empty if none) */ public String[] getFieldNames(); @@ -46,7 +46,7 @@ public interface ITmfEventField extends Cloneable { public String getFieldName(int index); /** - * @return the list of subfields (empty array if none) + * @return the list of subfields (null if none) */ public ITmfEventField[] getFields(); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java index 7211ba451d..3571cc3b3e 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventField.java @@ -19,7 +19,9 @@ import java.util.Map; /** * TmfEventField *

- * A basic implementation of ITmfEventField. + * A basic implementation of ITmfEventField. Non-value fields are structural + * (i.e. used to represent the event structure including optional fields) while + * the valued fields are actual event fields. */ public class TmfEventField implements ITmfEventField { @@ -43,27 +45,26 @@ public class TmfEventField implements ITmfEventField { */ @SuppressWarnings("unused") private TmfEventField() { - throw new AssertionError(); } /** - * Constructor for a terminal field (i.e. no subfields) + * Constructor for a structural field * * @param name the event field id - * @param value the event field value + * @param subfields the list of subfields */ - public TmfEventField(String name, Object value) { - this(name, value, new ITmfEventField[0]); + public TmfEventField(String name, ITmfEventField[] fields) { + this(name, null, fields); } /** - * Constructor for a non-valued field (for structural purposes) + * Constructor for a terminal field (i.e. no subfields) * * @param name the event field id - * @param subfields the list of subfields + * @param value the event field value */ - public TmfEventField(String name, ITmfEventField[] fields) { - this(name, null, fields); + public TmfEventField(String name, Object value) { + this(name, value, null); } /** @@ -95,6 +96,7 @@ public class TmfEventField implements ITmfEventField { fValue = field.fValue; fFields = field.fFields; fFieldNames = field.fFieldNames; + populateStructs(); } // ------------------------------------------------------------------------ @@ -159,7 +161,7 @@ public class TmfEventField implements ITmfEventField { */ @Override public ITmfEventField getField(int index) { - if (index >= 0 && index < fFields.length) + if (fFields != null && index >= 0 && index < fFields.length) return fFields[index]; return null; } @@ -243,7 +245,7 @@ public class TmfEventField implements ITmfEventField { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((fName == null) ? 0 : fName.hashCode()); + result = prime * result + fName.hashCode(); result = prime * result + ((fValue == null) ? 0 : fValue.hashCode()); return result; } @@ -260,10 +262,7 @@ public class TmfEventField implements ITmfEventField { if (getClass() != obj.getClass()) return false; TmfEventField other = (TmfEventField) obj; - if (fName == null) { - if (other.fName != null) - return false; - } else if (!fName.equals(other.fName)) + if (!fName.equals(other.fName)) return false; if (fValue == null) { if (other.fValue != null) -- 2.34.1