Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2c976465275c0a61ced5ef969cbbb2cb3edbe21e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*******************************************************************************
 * Copyright (c) 2009 Red Hat, Inc.
 * 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
 *
 * Contributors:
 *    Elliott Baron <ebaron@redhat.com> - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.internal.valgrind.massif.tests;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.File;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.linuxtools.internal.valgrind.massif.charting.ChartEditorInput;
import org.eclipse.linuxtools.internal.valgrind.massif.charting.ChartPNG;
import org.eclipse.linuxtools.internal.valgrind.massif.charting.HeapChart;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.PlatformUI;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class ChartExportTest extends AbstractMassifTest {
	private IPath pngPath;

	@Before
	public void prep() throws Exception {
		proj = createProjectAndBuild("alloctest"); //$NON-NLS-1$

		pngPath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
		assertNotNull(pngPath);
		pngPath = pngPath.append("alloctest").append("chart.png"); //$NON-NLS-1$ //$NON-NLS-2$
	}

	@Override
	@After
	public void tearDown() throws CoreException {
		File chartFile = pngPath.toFile();
		if (chartFile.exists()) {
			chartFile.delete();
		}

		deleteProject(proj);
		super.tearDown();
	}

	@Test
	public void testChartExportPNG() throws Exception {
		ILaunchConfiguration config = createConfiguration(proj.getProject());
		doLaunch(config, "testDefaults"); //$NON-NLS-1$

		IEditorInput input = PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage().getActiveEditor()
				.getEditorInput();
		assertTrue("input must be ChartEditorInput",
				input instanceof ChartEditorInput);
		HeapChart chart = ((ChartEditorInput) input).getChart();

		ChartPNG png = new ChartPNG(chart);
		png.renderPNG(pngPath);

		File chartFile = pngPath.toFile();
		assertTrue(chartFile.exists());
		assertTrue(chartFile.length() > 0);
	}

}

Back to the top