<commit_before>package za.co.twyst.tbxml.test;

import java.io.InputStreamReader;
import java.io.Reader;

import android.content.Context;
import android.test.AndroidTestCase;

import za.co.twyst.tbxml.dummy.R;
import za.co.twyst.tbxml.TBXML;

public class TestAPI extends AndroidTestCase
       { // CONSTANTS
	
	     @SuppressWarnings("unused")
		 private static final String TAG         = "TBXML";
	     private static final String DESCRIPTION = "Takes the vague slightly right-slanting break about 3m left of the large chimney filled with chockstones.";
	     
	     // TEST VARIABLES
	     
	     private TBXML tbxml;
	     
	     // SETUP/TEARDOWN

	     protected void setUp() throws Exception 
	               { tbxml = new TBXML();
	               }

	     protected void tearDown() throws Exception 
	               { tbxml.release();
	               }
	
	     // UNIT TESTS
	
	     public void testParse() throws Exception
	            { String xml = read(R.raw.routesx);
	              
	              tbxml.parse(xml);
	              
	              long root        = tbxml.rootXMLElement();         assertTrue("Invalid 'root' element",        root        != 0);
	              long section     = tbxml.firstChild (root);        assertTrue("Invalid 'section' element",     section     != 0);
                  long route       = tbxml.firstChild (section);     assertTrue("Invalid 'route' element",       route       != 0);
                  long description = tbxml.firstChild (route);       assertTrue("Invalid 'description' element", description != 0);
                  long firstAscent = tbxml.nextSibling(description); assertTrue("Invalid 'first ascent' element",firstAscent != 0);
	            }
	     
         public void testChildElementNamed() throws Exception
                { String xml = read(R.raw.routesx);
                  
                  tbxml.parse(xml);
                  
                  long root        = tbxml.rootXMLElement();         assertTrue("Invalid 'root' element",        root        != 0);
                  long section     = tbxml.firstChild (root);        assertTrue("Invalid 'section' element",     section     != 0);
                  long route       = tbxml.firstChild (section);     assertTrue("Invalid 'route' element",       route       != 0);
                  long description = tbxml.firstChild (route);       assertTrue("Invalid 'description' element", description != 0);
                  long firstAscent = tbxml.nextSibling(description); assertTrue("Invalid 'first ascent' element",firstAscent != 0);
                  
                  assertEquals("Invalid 'section' element",    section,     tbxml.childElementNamed("section",     root));
                  assertEquals("Invalid 'route' element",      route,       tbxml.childElementNamed("route",       section));
                  assertEquals("Invalid 'description' element", description,tbxml.childElementNamed("description", route));
                  assertEquals("Invalid 'first-ascent' element",firstAscent,tbxml.childElementNamed("first-ascent",route));<commit_msg>Validating TBXML against XPath<commit_after>package za.co.twyst.tbxml.test;

import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Node;
import org.xml.sax.InputSource;

import android.content.Context;
import android.test.AndroidTestCase;

import za.co.twyst.tbxml.dummy.R;
import za.co.twyst.tbxml.TBXML;

public class TestAPI extends AndroidTestCase
       { // CONSTANTS
	
	     @SuppressWarnings("unused")
		 private static final String TAG         = "TBXML";
	     private static final String DESCRIPTION = "Takes the vague slightly right-slanting break about 3m left of the large chimney filled with chockstones.";
	     
	     // TEST VARIABLES
	     
	     private TBXML tbxml;
	     private XPath xpath;

	     // SETUP/TEARDOWN

	     protected void setUp() throws Exception 
	               { tbxml = new TBXML();
	                 xpath = XPathFactory.newInstance().newXPath();
	               }

	     protected void tearDown() throws Exception 
	               { tbxml.release();
	               }
	
	     // UNIT TESTS
	
	     public void testParse() throws Exception
	            { String      xml = read(R.raw.routesx);
	              InputSource source  = new InputSource(new StringReader(xml));

	              tbxml.parse(xml);
	              
	              Node xpathRoot = (Node) xpath.evaluate("/routes",source,XPathConstants.NODE);
	              long tbxmlRoot = tbxml.rootXMLElement();         
	              
	              assertTrue("Invalid 'root' element",tbxmlRoot != 0);
	              
	              long tbxmlSection = tbxml.firstChild (tbxmlRoot);        
	              
	              assertTrue("Invalid 'section' element",tbxmlSection != 0);
	              
                  long tbxmlRoute = tbxml.firstChild (tbxmlSection);     
                  
                  assertTrue("Invalid 'route' element",tbxmlRoute != 0);
                  
                  long tbxmlDescription = tbxml.firstChild (tbxmlRoute);       
                  
                  assertTrue("Invalid 'description' element", tbxmlDescription != 0);
                  
                  long tbxmlFirstAscent = tbxml.nextSibling(tbxmlDescription); 
                  
                  assertTrue("Invalid 'first ascent' element",tbxmlFirstAscent != 0);
	            }
	     
         public void testChildElementNamed() throws Exception
                { String xml = read(R.raw.routesx);
                  
                  tbxml.parse(xml);
                  
                  long root        = tbxml.rootXMLElement();         assertTrue("Invalid 'root' element",        root        != 0);
                  long section     = tbxml.firstChild (root);        assertTrue("Invalid 'section' element",     section     != 0);
                  long route       = tbxml.firstChild (section);     assertTrue("Invalid 'route' element",       route       != 0);
                  long description = tbxml.firstChild (route);       assertTrue("Invalid 'description' element", description != 0);
                  long firstAscent = tbxml.nextSibling(description); assertTrue("Invalid 'first ascent' element",firstAscent != 0);
                  
                  assertEquals("Invalid 'section' element",    section,     tbxml.childElementNamed("section",     root));
                  assertEquals("Invalid 'route' element",      route,       tbxml.childElementNamed("route",       section));
                  assertEquals("Invalid 'description' element", description,tbxml.childElementNamed("description", route));
                  assertEquals("Invalid 'first-ascent' element",firstAscent,tbxml.childElementNamed("first-ascent",route));
{'fraction_non_alphanumeric': 0.09758565852248084, 'fraction_numerical': 0.0033251409570623103, 'mean_word_length': 1.8657829328914664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 71}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4146858', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1666, 'n_words': 413}