1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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
10 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.event
;
15 import static org
.junit
.Assert
.assertEquals
;
17 import java
.util
.TimeZone
;
19 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
20 import org
.eclipse
.core
.runtime
.preferences
.InstanceScope
;
21 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.Activator
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimePreferencesConstants
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimePreferences
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestampFormat
;
25 import org
.junit
.Test
;
26 import org
.osgi
.service
.prefs
.BackingStoreException
;
29 * Test suite for the TmfTimestampFormat class.
31 public class TmfTimestampFormatTest
{
33 private static final String TEST_PATTERN
= "HH:mm:ss.SSS";
34 private static final TimeZone TEST_TIME_ZONE
= TimeZone
.getTimeZone(TimeZone
.getAvailableIDs(0)[0]);
36 private final TmfTimestampFormat tsf1
= new TmfTimestampFormat(TEST_PATTERN
);
37 private final TmfTimestampFormat tsf2
= new TmfTimestampFormat(TEST_PATTERN
, TEST_TIME_ZONE
);
40 * Test that the default value is loaded when using the default constructor
43 public void testDefaultConstructor() {
44 TmfTimestampFormat ts0
= new TmfTimestampFormat();
45 assertEquals("HH:mm:ss.SSS CCC NNN", ts0
.toPattern());
49 * Test that the value constructor properly assigns the value
52 public void testValueConstructor() {
53 assertEquals(TEST_PATTERN
, tsf1
.toPattern());
57 * Test that the value constructor using a time zone properly assigns the pattern and time zone
60 public void testValueTimeZoneConstructor() {
61 assertEquals(TEST_PATTERN
, tsf2
.toPattern());
62 assertEquals(TEST_TIME_ZONE
, tsf2
.getTimeZone());
66 * Make sure that the default formats in TmfTimestampFormat get updated when
67 * updateDefaultFormats is called.
70 public void testUpdateDefaultFormats() {
71 IEclipsePreferences node
= InstanceScope
.INSTANCE
.getNode(Activator
.PLUGIN_ID
);
73 String dateTimeTestValue
= ITmfTimePreferencesConstants
.TIME_HOUR_FMT
+ ":";
74 node
.put(ITmfTimePreferencesConstants
.DATIME
, dateTimeTestValue
);
76 String subSecTestValue
= ITmfTimePreferencesConstants
.SUBSEC_NANO_FMT
+ ":";
77 node
.put(ITmfTimePreferencesConstants
.SUBSEC
, subSecTestValue
);
80 } catch (BackingStoreException e
) {
82 TmfTimestampFormat
.updateDefaultFormats();
83 String expected
= dateTimeTestValue
+ "." + subSecTestValue
;
84 String expected2
= "TTT." + subSecTestValue
;
85 assertEquals(expected
, TmfTimestampFormat
.getDefaulTimeFormat().toPattern());
86 assertEquals(expected2
, TmfTimestampFormat
.getDefaulIntervalFormat().toPattern());
88 node
.put(ITmfTimePreferencesConstants
.DATIME
, ITmfTimePreferencesConstants
.TIME_HOUR_FMT
);
89 node
.put(ITmfTimePreferencesConstants
.SUBSEC
, ITmfTimePreferencesConstants
.SUBSEC_NANO_FMT
);
92 } catch (BackingStoreException e
) {
94 TmfTimestampFormat
.updateDefaultFormats();
98 * Test that getDefaulTimeFormat returns the appropriate value (from the default)
101 public void testGetDefaulTimeFormat() {
102 assertEquals(TmfTimestampFormat
.getDefaulTimeFormat().toPattern(), TmfTimePreferences
.getInstance().getTimePattern());
106 * Test that getDefaulIntervalFormat returns the appropriate value (from the default)
109 public void testGetDefaulIntervalFormat() {
110 assertEquals(TmfTimestampFormat
.getDefaulIntervalFormat().toPattern(), TmfTimePreferences
.getInstance().getIntervalPattern());