Commit | Line | Data |
---|---|---|
c1cd9635 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 Ericsson |
c1cd9635 MAL |
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 | * Marc-Andre Laperle - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.tests.event; |
c1cd9635 MAL |
14 | |
15 | import static org.junit.Assert.assertEquals; | |
c1cd9635 MAL |
16 | |
17 | import java.util.Map; | |
18 | import java.util.TimeZone; | |
19 | ||
20 | import org.eclipse.core.runtime.preferences.DefaultScope; | |
21 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; | |
22 | import org.eclipse.core.runtime.preferences.InstanceScope; | |
2bdf0193 AM |
23 | import org.eclipse.tracecompass.internal.tmf.core.Activator; |
24 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimePreferencesConstants; | |
25 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimePreferences; | |
c1cd9635 MAL |
26 | import org.junit.Test; |
27 | import org.osgi.service.prefs.BackingStoreException; | |
28 | ||
29 | /** | |
30 | * Test suite for the TmfTimePreferences class. | |
31 | */ | |
32 | public class TmfTimePreferencesTest { | |
33 | ||
030f8f1f PT |
34 | private static final String TIME_PATTERN = "HH:mm:ss.SSS SSS SSS"; |
35 | private static final String INTERVAL_PATTERN = "TTT.SSS SSS SSS"; | |
c1cd9635 MAL |
36 | |
37 | /** | |
38 | * Test that the preferences get initialized to the default | |
39 | */ | |
40 | @Test | |
41 | public void testInit() { | |
42 | assertEquals(DefaultScope.INSTANCE.getNode(Activator.PLUGIN_ID).get(ITmfTimePreferencesConstants.DATIME, null), ITmfTimePreferencesConstants.TIME_HOUR_FMT); | |
43 | } | |
44 | ||
c1cd9635 MAL |
45 | /** |
46 | * Test that getTimePattern returns the appropriate time pattern (from the default) | |
47 | */ | |
48 | @Test | |
49 | public void testGetTimePattern() { | |
7c34a4ea | 50 | assertEquals(TIME_PATTERN, TmfTimePreferences.getTimePattern()); |
c1cd9635 MAL |
51 | } |
52 | ||
53 | /** | |
54 | * Test that getIntervalPattern returns the appropriate interval pattern (from the default) | |
55 | */ | |
56 | @Test | |
57 | public void testGetIntervalPattern() { | |
7c34a4ea | 58 | assertEquals(INTERVAL_PATTERN, TmfTimePreferences.getIntervalPattern()); |
c1cd9635 MAL |
59 | } |
60 | ||
61 | /** | |
62 | * Test that getTimeZone returns the appropriate time zone (from the default) | |
63 | */ | |
64 | @Test | |
65 | public void testGetTimeZone() { | |
7c34a4ea | 66 | assertEquals(TimeZone.getDefault(), TmfTimePreferences.getTimeZone()); |
c1cd9635 MAL |
67 | } |
68 | ||
69 | /** | |
70 | * Test that getPreferenceMap returns the appropriate map even after preferences get modified | |
71 | * and make sure it doesn't affect the defaults | |
72 | */ | |
73 | @Test | |
74 | public void testGetPreferenceMap() { | |
7c34a4ea | 75 | Map<String, String> defaultPreferenceMap = TmfTimePreferences.getDefaultPreferenceMap(); |
c1cd9635 MAL |
76 | assertEquals(ITmfTimePreferencesConstants.TIME_HOUR_FMT, defaultPreferenceMap.get(ITmfTimePreferencesConstants.DATIME)); |
77 | ||
78 | // Modify the preferences | |
79 | String testValue = ITmfTimePreferencesConstants.TIME_HOUR_FMT + "foo"; | |
80 | IEclipsePreferences node = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); | |
81 | node.put(ITmfTimePreferencesConstants.DATIME, testValue); | |
82 | try { | |
83 | node.flush(); | |
84 | } catch (BackingStoreException e) { | |
85 | } | |
86 | // Make sure the modification is in the map | |
7c34a4ea | 87 | Map<String, String> preferenceMap = TmfTimePreferences.getPreferenceMap(); |
c1cd9635 MAL |
88 | assertEquals(testValue, preferenceMap.get(ITmfTimePreferencesConstants.DATIME)); |
89 | ||
90 | // Make sure the default is still the same | |
7c34a4ea | 91 | defaultPreferenceMap = TmfTimePreferences.getDefaultPreferenceMap(); |
c1cd9635 MAL |
92 | assertEquals(ITmfTimePreferencesConstants.TIME_HOUR_FMT, defaultPreferenceMap.get(ITmfTimePreferencesConstants.DATIME)); |
93 | } | |
94 | ||
95 | /** | |
96 | * Test that computeTimePattern computes the appropriate time pattern from a preference map (from the default) | |
97 | */ | |
98 | @Test | |
99 | public void testComputeTimePattern() { | |
7c34a4ea | 100 | assertEquals(TIME_PATTERN, TmfTimePreferences.computeTimePattern(TmfTimePreferences.getPreferenceMap())); |
c1cd9635 MAL |
101 | } |
102 | ||
103 | } |