use of org.eclipse.linuxtools.internal.cdt.libhover.devhelp.DevHelpToc in project linuxtools by eclipse.
the class CheckDevhelp method testHelpTopic.
@Test
public void testHelpTopic() throws IOException {
// We need to have a devhelp directory with contents to test.
// Copy over the needed devhelp/html contents in this test plug-in,
// test1.devhelp2 and index.html, to the workspace.
ClassLoader cl = getClass().getClassLoader();
Bundle bundle = null;
if (cl instanceof BundleReference) {
bundle = ((BundleReference) cl).getBundle();
}
IWorkspace ws = ResourcesPlugin.getWorkspace();
IPath wslocpath = ws.getRoot().getLocation();
// $NON-NLS-1$
IPath outfilepath = wslocpath.append("devhelp/html/test1");
File outfiledir = outfilepath.toFile();
assertTrue(outfiledir.mkdirs());
// $NON-NLS-1$
outfilepath = outfilepath.append("test1.devhelp2");
File outfile = outfilepath.toFile();
// $NON-NLS-1$
IPath outfilepath2 = wslocpath.append("devhelp/html/test1/index.html");
File outfile2 = outfilepath2.toFile();
outfile.createNewFile();
outfile2.createNewFile();
try (InputStream in = FileLocator.openStream(bundle, new Path("devhelp/html/test1/test1.devhelp2"), false)) {
// $NON-NLS-1$
Files.copy(in, Paths.get(outfile.toURI()), StandardCopyOption.REPLACE_EXISTING);
}
try (InputStream in2 = FileLocator.openStream(bundle, new Path("devhelp/html/test1/index.html"), false)) {
// $NON-NLS-1$
Files.copy(in2, Paths.get(outfile2.toURI()), StandardCopyOption.REPLACE_EXISTING);
}
// $NON-NLS-1$
IPath x = wslocpath.append("devhelp/html");
IPreferenceStore ps = DevHelpPlugin.getDefault().getPreferenceStore();
ps.setValue(PreferenceConstants.DEVHELP_DIRECTORY, x.toOSString());
DevHelpToc toc = new DevHelpToc();
ITopic[] topics = toc.getTopics();
// Verify we have the test1 topic
assertTrue(topics.length > 0);
ITopic topic = topics[0];
// $NON-NLS-1$
assertTrue(topic.getLabel().startsWith("test1"));
ITopic[] subtopics = topic.getSubtopics();
// Verify it has 4 or more sub-topics
assertTrue(subtopics.length > 3);
IUAElement[] elements = topic.getChildren();
assertTrue(elements.length > 3);
String href = topic.getHref();
// Verify the topic href is the index.html file and that the topic is
// enabled
assertEquals(href, // $NON-NLS-1$
"/org.eclipse.linuxtools.cdt.libhover.devhelp/test1/index.html");
assertTrue(topic.isEnabled(null));
}
Aggregations