Fix for Linux tree item height bug.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / trace / TmfCheckpointIndexTest.java
CommitLineData
13cb5f43
FC
1/*******************************************************************************
2 * Copyright (c) 2009, 2010, 20112 Ericsson
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 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Adapted for TMF Trace Model 1.0
12 *******************************************************************************/
13
14package org.eclipse.linuxtools.tmf.core.tests.trace;
15
16import java.io.File;
13cb5f43
FC
17import java.io.IOException;
18import java.net.URISyntaxException;
19import java.net.URL;
20import java.util.Vector;
21
22import junit.framework.TestCase;
23
24import org.eclipse.core.runtime.FileLocator;
25import org.eclipse.core.runtime.Path;
26import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
b4f71e4a 27import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
13cb5f43
FC
28import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin;
29import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
30import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
31import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpointIndexer;
32import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
33import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
34
35/**
36 * <b><u>TmfTraceTest</u></b>
37 * <p>
38 * Test suite for the TmfTrace class.
39 */
40@SuppressWarnings("nls")
41public class TmfCheckpointIndexTest extends TestCase {
42
43 // ------------------------------------------------------------------------
44 // Variables
45 // ------------------------------------------------------------------------
46
47 private static final String DIRECTORY = "testfiles";
48 private static final String TEST_STREAM = "A-Test-10K";
49 private static final int BLOCK_SIZE = 500;
50 private static final int NB_EVENTS = 10000;
51 private static TestTrace fTrace = null;
52
53 // ------------------------------------------------------------------------
54 // Housekeeping
55 // ------------------------------------------------------------------------
56
57 public TmfCheckpointIndexTest(final String name) throws Exception {
58 super(name);
59 }
60
61 @Override
62 protected void setUp() throws Exception {
63 super.setUp();
64 fTrace = setupTrace(DIRECTORY + File.separator + TEST_STREAM);
65 }
66
67 @Override
68 protected void tearDown() throws Exception {
69 super.tearDown();
70 fTrace.dispose();
71 fTrace = null;
72 }
73
74 // ------------------------------------------------------------------------
75 // Helper classes
76 // ------------------------------------------------------------------------
77
78 private class TestIndexer extends TmfCheckpointIndexer<ITmfTrace<ITmfEvent>> {
79 @SuppressWarnings({ "unchecked", "rawtypes" })
80 public TestIndexer(TestTrace testTrace) {
81 super((ITmfTrace) testTrace);
82 }
83 public Vector<TmfCheckpoint> getCheckpoints() {
84 return fTraceIndex;
85 }
86 }
87
88 private class TestTrace extends TmfTraceStub {
b4f71e4a 89 public TestTrace(String path, int blockSize) throws TmfTraceException {
13cb5f43
FC
90 super(path, blockSize);
91 fIndexer = new TestIndexer(this);
92 }
93 public TestIndexer getIndexer() {
94 return (TestIndexer) fIndexer;
95 }
96 }
97
98 // ------------------------------------------------------------------------
99 // Helper functions
100 // ------------------------------------------------------------------------
101
102 private TestTrace setupTrace(final String path) {
103 if (fTrace == null) {
104 try {
105 final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(path), null);
106 final File test = new File(FileLocator.toFileURL(location).toURI());
107 fTrace = new TestTrace(test.toURI().getPath(), BLOCK_SIZE);
108 fTrace.indexTrace();
b4f71e4a
FC
109 } catch (final TmfTraceException e) {
110 e.printStackTrace();
13cb5f43
FC
111 } catch (final URISyntaxException e) {
112 e.printStackTrace();
113 } catch (final IOException e) {
114 e.printStackTrace();
115 }
116 }
117 return fTrace;
118 }
119
120 // ------------------------------------------------------------------------
121 // Verify checkpoints
122 // ------------------------------------------------------------------------
123
124 public void testTmfTraceIndexing() throws Exception {
125 assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize());
126 assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents());
127 assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
128 assertEquals("getRange-end", NB_EVENTS, fTrace.getTimeRange().getEndTime().getValue());
129 assertEquals("getStartTime", 1, fTrace.getStartTime().getValue());
130 assertEquals("getEndTime", NB_EVENTS, fTrace.getEndTime().getValue());
131
132 Vector<TmfCheckpoint> checkpoints = fTrace.getIndexer().getCheckpoints();
133 int pageSize = fTrace.getCacheSize();
134 assertTrue("Checkpoints exist", checkpoints != null);
135
136 // Validate that each checkpoint points to the right event
137 for (int i = 0; i < checkpoints.size(); i++) {
138 TmfCheckpoint checkpoint = checkpoints.get(i);
139 TmfContext context = new TmfContext(checkpoint.getLocation(), i * pageSize);
140 ITmfEvent event = fTrace.parseEvent(context);
141 assertTrue(context.getRank() == i * pageSize);
142 assertTrue((checkpoint.getTimestamp().compareTo(event.getTimestamp(), false) == 0));
143 }
144 }
145
146}
This page took 0.029156 seconds and 5 git commands to generate.