// Path: src/main/java/org/fit/cssbox/io/DefaultDOMSource.java
// public class DefaultDOMSource extends DOMSource
// {
//     static boolean neko_fixed = false;
// 
//     public DefaultDOMSource(DocumentSource src)
//     {
//         super(src);
//     }
// 
//     @Override
//     public Document parse() throws SAXException, IOException
//     {
//         //temporay NekoHTML fix until nekohtml gets fixed
//         if (!neko_fixed)
//         {
//             HTMLElements.Element li = HTMLElements.getElement(HTMLElements.LI);
//             HTMLElements.Element[] oldparents = li.parent;
//             li.parent = new HTMLElements.Element[oldparents.length + 1];
//             for (int i = 0; i < oldparents.length; i++)
//                 li.parent[i] = oldparents[i];
//             li.parent[oldparents.length] = HTMLElements.getElement(HTMLElements.MENU);
//             neko_fixed = true;
//         }
//         
//         DOMParser parser = new DOMParser(new HTMLConfiguration());
//         parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
//         if (charset != null)
//             parser.setProperty("http://cyberneko.org/html/properties/default-encoding", charset);
//         parser.parse(new org.xml.sax.InputSource(getDocumentSource().getInputStream()));
//         return parser.getDocument();
//     }
// 
// }
// 
// Path: src/main/java/org/fit/cssbox/io/DefaultDocumentSource.java
// public class DefaultDocumentSource extends DocumentSource
// {
//     /** The user-agent string used for HTTP connection */
//     private static String USER_AGENT = "Mozilla/5.0 (compatible; BoxBrowserTest/4.x; Linux) CSSBox/4.x (like Gecko)";
// 
//     private URLConnection con;
//     private InputStream is;
//     
//     /**
//      * Creates a network data source based on the target document URL.
//      * @param url the document URL
//      * @throws IOException
//      */
//     public DefaultDocumentSource(URL url) throws IOException
//     {
//         super(url);
//         con = createConnection(url);
//         is = null;
//     }
//     
//     /**
//      * Creates a data source based on the URL string. The data: urls are automatically
//      * recognized and  processed.
//      * @param urlstring The URL string
//      * @throws IOException
//      */
//     public DefaultDocumentSource(String urlstring) throws IOException
//     {
//         super(null, urlstring);
//         URL url = DataURLHandler.createURL(null, urlstring);
//         con = createConnection(url);
//         is = null;
//     }
//     
//     /**
//      * Creates a data source based on the URL string. The data: urls are automatically
//      * recognized and  processed.
//      * @param base The base URL to be used for the relative URLs in the urlstring
//      * @param urlstring The URL string
//      * @throws IOException
//      */
//     public DefaultDocumentSource(URL base, String urlstring) throws IOException
//     {
//         super(base, urlstring);
//         URL url = DataURLHandler.createURL(base, urlstring);
//         con = createConnection(url);
//         is = null;
//     }
//     
//     /**
//      * Creates and configures the URL connection.
//      * @param url the target URL
//      * @return the created connection instance
//      * @throws IOException
//      */
//     protected URLConnection createConnection(URL url) throws IOException
//     {
//         URLConnection con = url.openConnection();
//         con.setRequestProperty("User-Agent", USER_AGENT);
//         return con;
//     }
//     
//     @Override
//     public URL getURL()
//     {
//         return con.getURL();
//     }
//     
//     @Override
//     public InputStream getInputStream() throws IOException
//     {
//         if (is == null)
//             is = con.getInputStream();
//         return is;
//     }
//     
//     @Override
//     public String getContentType()
//     {
//         return con.getHeaderField("Content-Type");
//     }
// 
//     /**
//      * Obtains the current User-agent string used for new connections.
//      * @return the user-agent string.
//      */
//     public static String getUserAgent()
//     {
//         return USER_AGENT;
//     }
// 
//     /**
//      * Sets the user agent string that will be used for new connections.
//      * @param userAgent the user-agent string
//      */
//     public static void setUserAgent(String userAgent)
//     {
//         USER_AGENT = userAgent;
//     }
// 
//     @Override
//     public void close() throws IOException
//     {
//         if (is != null)
//             is.close();
//     }
//     
// 
// }


import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.fit.cssbox.io.DefaultDOMSource;
import org.fit.cssbox.io.DefaultDocumentSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
     * @param testURL
     * @param threadCount the number of threads to be used for parallel testing
     */
    public TestBatch(URL testURL, int threadCount)
    {
        this.threadsUsed = threadCount;
        this.testURL = testURL;
        this.tests = new LinkedList<SourceEntry>();
        this.results = new LinkedHashMap<String, Float>();
        parseToc();
    }
    
    /**
     * Obtain the number of tests available.
     * @return
     */
    public int getTestCount()
    {
        return tests.size();
    }
    
    /**
     * Parses the HTML TOC and extracts the test names and tags. Fills the list of tests.
     */
    private void parseToc()
    {
        try
        {
            URL tocURL = new URL(testURL, "reftest-toc.htm");
            DefaultDocumentSource docSource = new DefaultDocumentSource(tocURL.toString());
// Path: src/main/java/org/fit/cssbox/io/DefaultDOMSource.java
// public class DefaultDOMSource extends DOMSource
// {
//     static boolean neko_fixed = false;
// 
//     public DefaultDOMSource(DocumentSource src)
//     {
//         super(src);
//     }
// 
//     @Override
//     public Document parse() throws SAXException, IOException
//     {
//         //temporay NekoHTML fix until nekohtml gets fixed
//         if (!neko_fixed)
//         {
//             HTMLElements.Element li = HTMLElements.getElement(HTMLElements.LI);
//             HTMLElements.Element[] oldparents = li.parent;
//             li.parent = new HTMLElements.Element[oldparents.length + 1];
//             for (int i = 0; i < oldparents.length; i++)
//                 li.parent[i] = oldparents[i];
//             li.parent[oldparents.length] = HTMLElements.getElement(HTMLElements.MENU);
//             neko_fixed = true;
//         }
//         
//         DOMParser parser = new DOMParser(new HTMLConfiguration());
//         parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
//         if (charset != null)
//             parser.setProperty("http://cyberneko.org/html/properties/default-encoding", charset);
//         parser.parse(new org.xml.sax.InputSource(getDocumentSource().getInputStream()));
//         return parser.getDocument();
//     }
// 
// }
// 
// Path: src/main/java/org/fit/cssbox/io/DefaultDocumentSource.java
// public class DefaultDocumentSource extends DocumentSource
// {
//     /** The user-agent string used for HTTP connection */
//     private static String USER_AGENT = "Mozilla/5.0 (compatible; BoxBrowserTest/4.x; Linux) CSSBox/4.x (like Gecko)";
// 
//     private URLConnection con;
//     private InputStream is;
//     
//     /**
//      * Creates a network data source based on the target document URL.
//      * @param url the document URL
//      * @throws IOException
//      */
//     public DefaultDocumentSource(URL url) throws IOException
//     {
//         super(url);
//         con = createConnection(url);
//         is = null;
//     }
//     
//     /**
//      * Creates a data source based on the URL string. The data: urls are automatically
//      * recognized and  processed.
//      * @param urlstring The URL string
//      * @throws IOException
//      */
//     public DefaultDocumentSource(String urlstring) throws IOException
//     {
//         super(null, urlstring);
//         URL url = DataURLHandler.createURL(null, urlstring);
//         con = createConnection(url);
//         is = null;
//     }
//     
//     /**
//      * Creates a data source based on the URL string. The data: urls are automatically
//      * recognized and  processed.
//      * @param base The base URL to be used for the relative URLs in the urlstring
//      * @param urlstring The URL string
//      * @throws IOException
//      */
//     public DefaultDocumentSource(URL base, String urlstring) throws IOException
//     {
//         super(base, urlstring);
//         URL url = DataURLHandler.createURL(base, urlstring);
//         con = createConnection(url);
//         is = null;
//     }
//     
//     /**
//      * Creates and configures the URL connection.
//      * @param url the target URL
//      * @return the created connection instance
//      * @throws IOException
//      */
//     protected URLConnection createConnection(URL url) throws IOException
//     {
//         URLConnection con = url.openConnection();
//         con.setRequestProperty("User-Agent", USER_AGENT);
//         return con;
//     }
//     
//     @Override
//     public URL getURL()
//     {
//         return con.getURL();
//     }
//     
//     @Override
//     public InputStream getInputStream() throws IOException
//     {
//         if (is == null)
//             is = con.getInputStream();
//         return is;
//     }
//     
//     @Override
//     public String getContentType()
//     {
//         return con.getHeaderField("Content-Type");
//     }
// 
//     /**
//      * Obtains the current User-agent string used for new connections.
//      * @return the user-agent string.
//      */
//     public static String getUserAgent()
//     {
//         return USER_AGENT;
//     }
// 
//     /**
//      * Sets the user agent string that will be used for new connections.
//      * @param userAgent the user-agent string
//      */
//     public static void setUserAgent(String userAgent)
//     {
//         USER_AGENT = userAgent;
//     }
// 
//     @Override
//     public void close() throws IOException
//     {
//         if (is != null)
//             is.close();
//     }
//     
// 
// }


// Path: src/main/java/org/fit/cssbox/testing/TestBatch.java
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.fit.cssbox.io.DefaultDOMSource;
import org.fit.cssbox.io.DefaultDocumentSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

     * @param testURL
     * @param threadCount the number of threads to be used for parallel testing
     */
    public TestBatch(URL testURL, int threadCount)
    {
        this.threadsUsed = threadCount;
        this.testURL = testURL;
        this.tests = new LinkedList<SourceEntry>();
        this.results = new LinkedHashMap<String, Float>();
        parseToc();
    }
    
    /**
     * Obtain the number of tests available.
     * @return
     */
    public int getTestCount()
    {
        return tests.size();
    }
    
    /**
     * Parses the HTML TOC and extracts the test names and tags. Fills the list of tests.
     */
    private void parseToc()
    {
        try
        {
            URL tocURL = new URL(testURL, "reftest-toc.htm");
            DefaultDocumentSource docSource = new DefaultDocumentSource(tocURL.toString());
            DefaultDOMSource parser = new DefaultDOMSource(docSource);