tmf: add TmfTimestampFormat tests
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 9 Jan 2014 15:27:49 +0000 (10:27 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 14 Jan 2014 19:40:40 +0000 (14:40 -0500)
test 07, 007, 0.07, .007, 0.007, 0.00000007 ...
Basic regression tests for the parser

Change-Id: I458828d3ae8c74214b2281d95ac1bb51c44eb40f
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/20447
Tested-by: Hudson CI
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfTimestampFormatTest.java

index 7e1b82c23d000afeb537d13e8225d435c0509362..0b0f1bd87e92b07308d78612c5e07b399754daee 100644 (file)
@@ -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);
+    }
 }
This page took 0.032454 seconds and 5 git commands to generate.