org.eclipse.tracecompass.tmf.chart.core
Export-Package: org.eclipse.tracecompass.internal.tmf.chart.core.tests;x-internal:=true,
org.eclipse.tracecompass.tmf.chart.core.tests.chart,
+ org.eclipse.tracecompass.tmf.chart.core.tests.consumer,
+ org.eclipse.tracecompass.tmf.chart.core.tests.descriptor,
org.eclipse.tracecompass.tmf.chart.core.tests.resolver,
org.eclipse.tracecompass.tmf.chart.core.tests.stubs
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.descriptor;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.function.Function;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartDurationDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartNumericalDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.AbstractLongResolver;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject;
+import org.junit.Test;
+
+/**
+ * Test the {@link DataChartDurationDescriptor} class
+ *
+ * @author Geneviève Bastien
+ */
+public class DurationDescriptorTest {
+
+ private static final @NonNull String DESC_NAME = "test";
+
+ private final @NonNull INumericalResolver<StubObject, @NonNull Long> fResolver = new AbstractLongResolver<StubObject>() {
+
+ @Override
+ public @NonNull Function<StubObject, @Nullable Long> getMapper() {
+ return o -> o.getLong();
+ }
+ };
+
+ /**
+ * Test the {@link DataChartNumericalDescriptor#DataChartNumericalDescriptor(String, INumericalResolver)} constructor
+ */
+ @Test
+ public void testConstructor() {
+ DataChartNumericalDescriptor<StubObject, @NonNull Long> desc = new DataChartDurationDescriptor<>(DESC_NAME, fResolver);
+ assertEquals(DESC_NAME, desc.getName());
+ assertEquals("ns", desc.getUnit());
+ assertEquals(DESC_NAME + " (ns)", desc.getLabel());
+ }
+
+ /**
+ * Test the {@link DataChartNumericalDescriptor#DataChartNumericalDescriptor(String, INumericalResolver, String)} constructor
+ */
+ @Test
+ public void testConstructorWithUnit() {
+ String unit = "bla";
+ DataChartNumericalDescriptor<StubObject, @NonNull Long> desc = new DataChartDurationDescriptor<>(DESC_NAME, fResolver, unit);
+ assertEquals(DESC_NAME, desc.getName());
+ assertEquals(unit, desc.getUnit());
+ assertEquals(DESC_NAME + " (" + unit + ')', desc.getLabel());
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.descriptor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.function.Function;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartNumericalDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.AbstractLongResolver;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject;
+import org.junit.Test;
+
+/**
+ * Test the {@link DataChartNumericalDescriptor} class
+ *
+ * @author Geneviève Bastien
+ */
+public class NumericalDescriptorTest {
+
+ private static final @NonNull String DESC_NAME = "test";
+
+ private final @NonNull INumericalResolver<StubObject, @NonNull Long> fResolver = new AbstractLongResolver<StubObject>() {
+
+ @Override
+ public @NonNull Function<StubObject, @Nullable Long> getMapper() {
+ return o -> o.getLong();
+ }
+ };
+
+ /**
+ * Test the {@link DataChartNumericalDescriptor#DataChartNumericalDescriptor(String, INumericalResolver)} constructor
+ */
+ @Test
+ public void testConstructor() {
+ DataChartNumericalDescriptor<StubObject, @NonNull Long> desc = new DataChartNumericalDescriptor<>(DESC_NAME, fResolver);
+ assertEquals(DESC_NAME, desc.getName());
+ assertNull(desc.getUnit());
+ assertEquals(DESC_NAME, desc.getLabel());
+ }
+
+ /**
+ * Test the {@link DataChartNumericalDescriptor#DataChartNumericalDescriptor(String, INumericalResolver, String)} constructor
+ */
+ @Test
+ public void testConstructorWithUnit() {
+ String unit = "bla";
+ DataChartNumericalDescriptor<StubObject, @NonNull Long> desc = new DataChartNumericalDescriptor<>(DESC_NAME, fResolver, unit);
+ assertEquals(DESC_NAME, desc.getName());
+ assertEquals(unit, desc.getUnit());
+ assertEquals(DESC_NAME + " (" + unit + ')', desc.getLabel());
+ }
+
+}
import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver;
/**
- * Generic descriptor that describes a time range duration.
+ * Generic descriptor that describes a time range duration. Its default units
+ * are nanoseconds.
*
* @param <T>
* The type of the input it understands
* The resolver used for mapping durations
*/
public DataChartDurationDescriptor(String name, INumericalResolver<T, R> resolver) {
- super(name, resolver);
+ super(name, resolver, UNIT);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name
+ * The name of the descriptor
+ * @param resolver
+ * The resolver used for mapping numbers
+ * @param unit
+ * The unit of this descriptor, eg. s, ms, ns
+ */
+ public DataChartDurationDescriptor(String name, INumericalResolver<T, R> resolver, @Nullable String unit) {
+ super(name, resolver, unit);
}
// ------------------------------------------------------------------------
visitor.visit(this);
}
- @Override
- public @Nullable String getUnit() {
- return UNIT;
- }
-
}
private final String fName;
private final INumericalResolver<T, R> fResolver;
+ private final @Nullable String fUnit;
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
* The resolver used for mapping numbers
*/
public DataChartNumericalDescriptor(String name, INumericalResolver<T, R> resolver) {
+ this(name, resolver, null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name
+ * The name of the descriptor
+ * @param resolver
+ * The resolver used for mapping numbers
+ * @param unit
+ * The unit of this descriptor, eg. s, ms, ns
+ */
+ public DataChartNumericalDescriptor(String name, INumericalResolver<T, R> resolver, @Nullable String unit) {
fName = name;
fResolver = resolver;
+ fUnit = unit;
}
// ------------------------------------------------------------------------
@Override
public @Nullable String getUnit() {
- return null;
+ return fUnit;
}
@Override