Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6fcac6c902897ea2bd03afdcddc4691509f17cea (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*******************************************************************************
 * Copyright (c) 2008, 2015 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.ua.tests.help.performance;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.help.ITopic;
import org.eclipse.help.internal.toc.TocAssembler;
import org.eclipse.help.internal.toc.TocContribution;
import org.eclipse.help.internal.toc.TocFile;
import org.eclipse.help.internal.toc.TocFileParser;
import org.eclipse.test.performance.Dimension;
import org.eclipse.test.performance.PerformanceTestCase;
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
import org.xml.sax.SAXException;

public class TocAssemblePerformanceTest extends PerformanceTestCase {
	
	/*
	 * Returns an instance of this Test.
	 */
	public static Test suite() {
		return new TestSuite(TocAssemblePerformanceTest.class);
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
	}
	
	private TocContribution parse(TocFileParser parser, String tocFile)
			throws IOException, SAXException, ParserConfigurationException {
		return parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), tocFile, true, "en", null, null));
	}
	
	public void assembleToc() throws Exception {
		TocFileParser parser = new TocFileParser();
		List<TocContribution> contributions = new ArrayList<TocContribution>();
		contributions.add(parse(parser, "data/help/performance/org.eclipse.jdt.doc.isv/jdttoc.xml"));
		contributions.add(parse(parser, "data/help/performance/org.eclipse.jdt.doc.isv/topics_Guide.xml"));
		contributions.add(parse(parser, "data/help/performance/org.eclipse.jdt.doc.isv/topics_Porting.xml"));
		contributions.add(parse(parser, "data/help/performance/org.eclipse.jdt.doc.isv/topics_Questions.xml"));
		contributions.add(parse(parser, "data/help/performance/org.eclipse.jdt.doc.isv/topics_Reference.xml"));
		contributions.add(parse(parser, "data/help/performance/org.eclipse.jdt.doc.isv/topics_Samples.xml"));
		contributions.add(parse(parser, "data/help/performance/org.eclipse.jdt.doc.isv/topics_Samples.xml"));
		TocAssembler assembler = new TocAssembler();	
		contributions = assembler.assemble(contributions);
		assertEquals(1, contributions.size());
		TocContribution toc = contributions.get(0);
		assertEquals(101, countTopics(toc.getToc().getTopics()));
	}

	
	private int countTopics(ITopic[] topics) {
		int result = topics.length;
		for (ITopic topic : topics) {
			result = result + countTopics(topic.getSubtopics());
		}
		return result;
	}

	public void testTocAssemble() throws Exception {
		tagAsSummary("Assemble TOC", Dimension.ELAPSED_PROCESS);
		
		// run the tests
		for (int i=0; i < 100; ++i) {
			boolean warmup = i < 2;
			if (!warmup) {
			    startMeasuring();
			}
			for (int j = 0; j < 20; j++) {
			    assembleToc();
			}
			if (!warmup) {
			    stopMeasuring();
		    }
		}
		
		commitMeasurements();
		assertPerformance();
	}
	
	
}

Back to the top