/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/**
* {@link Context} Test
*/
public class ContextTest {
/**
* The value returned by {@link RuntimeEnvironment#isQuickContextScan()}
* before the test is run. Will be used to restore the flag after each
* test case.
*/
private boolean savedQuickContextScanFlag;
@SuppressWarnings("javadoc")
public void setUp() {
// Save initial value of the quick context scan flag.
}
@SuppressWarnings("javadoc")
public void tearDown() {
// Restore the initial value of the quick context scan flag.
}
/**
* Tests for the isEmpty() method.
* @throws ParseException
*/
@SuppressWarnings("static-method")
@Test
// Definition search should be used
assertFalse(c.isEmpty());
// Symbol search should be used
assertFalse(c.isEmpty());
// Full search should be used
assertFalse(c.isEmpty());
// History search should not be used
assertTrue(c.isEmpty());
// Path search should not be used
assertTrue(c.isEmpty());
// Combined search should be fine
assertFalse(c.isEmpty());
}
/**
* Tests for the getContext() method.
* @throws ParseException
*/
@SuppressWarnings("static-method")
@Test
testGetContext(true, true); // limited scan, output to list
testGetContext(false, true); // unlimited scan, output to list
testGetContext(true, false); // limited scan, output to writer
testGetContext(false, false); // unlimited scan, output to writer
}
/**
* Helper method for testing various paths through the getContext() method.
*
* @param limit true if limited, quick context scan should be used
* @param hitList true if output should be written to a list instead of
* a writer
*/
throws ParseException
{
// Search freetext for the term "def"
if (hitList) {
}
? "abc <b>def</b> ghi"
: "<a class=\"rsh\" href=\"#1\"><span class=\"l\">1</span> "
+ "abc <b>def</b> ghi</a><br/>";
// Search with definitions
if (hitList) {
}
? "abc <b>def</b> ghi"
: "<a class=\"rsh\" href=\"#1\"><span class=\"l\">1</span> "
+ "abc <b>def</b> ghi</a> <span class=\"rshd\"> type</span> <br/>";
// Search with no input (will search definitions)
if (hitList) {
}
? "text"
: "<a class=\"rsh\" href=\"#1\"><span class=\"l\">1</span> "
+ "text</a> <span class=\"rshd\">type</span><br/>";
// Search with no results
if (hitList) {
} else {
}
// History search (should not show source context)
if (hitList) {
} else {
}
}
/**
* Test that we don't get an {@code ArrayIndexOutOfBoundsException} when
* a long (>100 characters) line which contains a match is not
* terminated with a newline character before the buffer boundary.
* Bug #383.
* @throws ParseException
*/
@SuppressWarnings("static-method")
@Test
}
/**
* Test that we get the [all...] link if a very long line crosses the
* buffer boundary. Bug 383.
* @throws ParseException
*/
@SuppressWarnings("static-method")
@Test
// Create input which consists of one single line longer than
// Context.MAXFILEREAD.
}
}
/**
* Test that a line with more than 100 characters after the first match
* is truncated, and that … is appended to show that the line is
* truncated. Bug 383.
* @throws ParseException
*/
@SuppressWarnings("static-method")
@Test
}
}
/**
* Test that valid HTML is generated for a match that spans multiple
* lines. It used to nest the tags incorrectly. Bug #15632.
* @throws Exception
*/
@SuppressWarnings("static-method")
@Test
// XML boilerplate
// Search for a multi-token phrase that spans multiple lines in the
// input file. The generated HTML fragment is inserted inside a root
// element so that the StringWriter contains a valid XML document.
assertTrue("No match found",
// Close the XML document body
// Check that valid XML was generated. This call used to fail with
// SAXParseException: [Fatal Error] :3:55: The element type "b" must
// be terminated by the matching end-tag "</b>".
}
/**
* Parse the XML document contained in a string.
*
* @param document string with the contents of an XML document
* @return a DOM representation of the document
* @throws Exception if the document cannot be parsed
*/
return DocumentBuilderFactory.newInstance().
}
/**
* Verify that the matching lines are shown in their original form and
* not lower-cased (bug #16848).
* @throws Exception
*/
@SuppressWarnings("static-method")
@Test
assertEquals("<a class=\"rsh\" href=\"#0\"><span class=\"l\">0</span> "
}
/**
* The results from mixed-case symbol search should contain tags.
* @throws Exception
*/
@SuppressWarnings("static-method")
@Test
// Freetext search should match regardless of case
// Defs search should only match if case matches
// Refs search should only match if case matches
// Path search shouldn't match anything in source
// Refs should only match if case matches, but freetext will match
// regardless of case
// Refs should only match if case matches, hist shouldn't match
// anything in source
}
/**
* Helper method which does the work for {@link #bug17582()}.
*
* @param builder builder for the query we want to test
* @param lines the expected line numbers in the hit list
* @param tags the expected tags in the hit list
*/
@SuppressWarnings("boxing")
throws Exception
{
}
}
}