From: Matthew Khouzam Date: Thu, 9 Jan 2014 15:27:49 +0000 (-0500) Subject: tmf: add TmfTimestampFormat tests X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=bc69e637aa1ada041e0fe963edcc002986f7cd67;p=deliverable%2Ftracecompass.git tmf: add TmfTimestampFormat tests test 07, 007, 0.07, .007, 0.007, 0.00000007 ... Basic regression tests for the parser Change-Id: I458828d3ae8c74214b2281d95ac1bb51c44eb40f Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/20447 Tested-by: Hudson CI --- diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampFormatTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampFormatTest.java index 7e1b82c23d..0b0f1bd87e 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampFormatTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampFormatTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Ericsson + * Copyright (c) 2013 - 2014 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,12 +8,14 @@ * * Contributors: * Marc-Andre Laperle - Initial API and implementation + * Matthew Khouzam - Added timestamp string tests *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.tests.event; import static org.junit.Assert.assertEquals; +import java.text.ParseException; import java.util.TimeZone; import org.eclipse.core.runtime.preferences.IEclipsePreferences; @@ -31,10 +33,16 @@ import org.osgi.service.prefs.BackingStoreException; public class TmfTimestampFormatTest { private static final String TEST_PATTERN = "HH:mm:ss.SSS"; + private static final String TEST_PATTERN_2 = "TTT.SSSCCCNNN"; + private static final String TEST_PATTERN_3 = "TTT.SSS"; + private static final String TEST_PATTERN_4 = "TTT.SSS CCC NNN"; private static final TimeZone TEST_TIME_ZONE = TimeZone.getTimeZone(TimeZone.getAvailableIDs(0)[0]); - private final TmfTimestampFormat tsf1 = new TmfTimestampFormat(TEST_PATTERN); - private final TmfTimestampFormat tsf2 = new TmfTimestampFormat(TEST_PATTERN, TEST_TIME_ZONE); + private static final TmfTimestampFormat tsf1 = new TmfTimestampFormat(TEST_PATTERN); + private static final TmfTimestampFormat tsf2 = new TmfTimestampFormat(TEST_PATTERN, TEST_TIME_ZONE); + private static final TmfTimestampFormat tsf3 = new TmfTimestampFormat(TEST_PATTERN_2); + private static final TmfTimestampFormat tsf4 = new TmfTimestampFormat(TEST_PATTERN_3); + private static final TmfTimestampFormat tsf5 = new TmfTimestampFormat(TEST_PATTERN_4); /** * Test that the default value is loaded when using the default constructor @@ -54,7 +62,8 @@ public class TmfTimestampFormatTest { } /** - * Test that the value constructor using a time zone properly assigns the pattern and time zone + * Test that the value constructor using a time zone properly assigns the + * pattern and time zone */ @Test public void testValueTimeZoneConstructor() { @@ -95,7 +104,8 @@ public class TmfTimestampFormatTest { } /** - * Test that getDefaulTimeFormat returns the appropriate value (from the default) + * Test that getDefaulTimeFormat returns the appropriate value (from the + * default) */ @Test public void testGetDefaulTimeFormat() { @@ -103,10 +113,155 @@ public class TmfTimestampFormatTest { } /** - * Test that getDefaulIntervalFormat returns the appropriate value (from the default) + * Test that getDefaulIntervalFormat returns the appropriate value (from the + * default) */ @Test public void testGetDefaulIntervalFormat() { assertEquals(TmfTimestampFormat.getDefaulIntervalFormat().toPattern(), TmfTimePreferences.getInstance().getIntervalPattern()); } + + /** + * Test the time value 007, should return 7 seconds + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testParseStringTime() throws ParseException { + long result = tsf3.parseValue("07"); + assertEquals(7000000000L, result); + } + + /** + * Test the time value 007, should return 7 seconds + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testParseStringCompleteTime() throws ParseException { + long result = tsf3.parseValue("07.00"); + assertEquals(7000000000L, result); + } + + /** + * Test the time value 007, should return 7 seconds + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testParseStringCompleteMilliTime() throws ParseException { + long result = tsf3.parseValue("0.07"); + assertEquals(70000000L, result); + } + + /** + * Test the time value 007, should return 7 miliseconds + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testParseStringDecimalTime() throws ParseException { + long result = tsf3.parseValue(".007"); + assertEquals(7000000L, result); + } + + /** + * Test the time value 007, should return 7 miliseconds + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testParseStringCompleteDecimalTime() throws ParseException { + long result = tsf3.parseValue("0.007"); + assertEquals(7000000L, result); + } + + /** + * Tests the time value of 70 ns + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testParseStringNanoTime() throws ParseException { + long result = tsf3.parseValue("0.00000007"); + assertEquals(70L, result); + } + + /** + * Tests the time value of 70 ns + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testCustomParseStringNanoTime() throws ParseException { + long result = tsf3.parseValue("0.00000007"); + assertEquals(70L, result); + } + + /** + * Tests the time value of 70 ns + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testCustomParseStringNanoSeparatorTime() throws ParseException { + long result = tsf5.parseValue("0.000 000 07"); + assertEquals(70L, result); + } + + /** + * Tests the time value of 70 ns + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testCustomParseStringNanoSeparatorTime2() throws ParseException { + long result = tsf5.parseValue("0.00000007"); + assertEquals(70L, result); + } + + /** + * Tests the time value of 123 ms + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testCustomParseStringMiliOK() throws ParseException { + long result = tsf4.parseValue("0.123"); + assertEquals(123000000L, result); + } + + /** + * Tests the time value of 123.456 ms + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testCustomParseStringMiliLong() throws ParseException { + long result = tsf4.parseValue("0.12345"); + assertEquals(123000000L, result); + } + + /** + * Tests the time value of 123 ms as .123, no zero + * + * @throws ParseException + * should not happen, if it does, the test is a failure + */ + @Test + public void testCustomParseStringMiliNoZero() throws ParseException { + long result = tsf4.parseValue(".123"); + assertEquals(123000000L, result); + } }