package org.jdom.tests;

import junit.framework.Test;
import junit.framework.TestSuite;
import junit.ui.LoadingTestRunner;

import org.jdom.DocType;
import org.jdom.IllegalNameException;

import java.util.Hashtable;

public class DocTypeTest extends junit.framework.TestCase {
   

  public DocTypeTest(String name) {
    super(name); 
  }

  private DocType rootOnly;
  private DocType xhtml;
  private DocType system;

  protected void setUp() {
    rootOnly = new DocType("rootOnly");
    xhtml = new DocType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN",
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
    system = new DocType("person", "http://metalab.unc.edu/xml/dtds/person.dtd");
  }

  public void testClone() {
    
    assertEquals(rootOnly, rootOnly.clone());
    assertEquals(system, system.clone());
    assertEquals(xhtml, xhtml.clone());
    
  }
  
  public void testEquals() {
    
    assert(!rootOnly.equals(xhtml));
    assert(!system.equals(xhtml));
    assert(!system.equals(rootOnly));
    
  }
  
  public void testGet() {

  }
  
  public void testConstructor() {
    
    try {
      new DocType("bad name");
      fail("Expected IllegalNameException");
    }
    catch (IllegalNameException ex) { // expected result
    }  
    
    try {
      new DocType("", "some data");
      fail("Expected IllegalNameException");
    }
    catch (IllegalNameException ex) { // expected result
    }  
    
    try {
      new DocType("879879", "some data");
      fail("Expected IllegalNameException");
    }
    catch (IllegalNameException ex) { // expected result
    }  
    
    try {
      new DocType("8yut", "some data");
      fail("Expected IllegalNameException");
    }
    catch (IllegalNameException ex) { // expected result
    }  
    
    try {
      new DocType("bad name", "some data", "uri");
      fail("Expected IllegalNameException");
    }
    catch (IllegalNameException ex) { // expected result
    }  
    
  }
  

  public void testToString() {
    
    assertNotNull(rootOnly.toString());   
    assertNotNull(xhtml.toString());   
    assertNotNull(system.toString());   
    assert(rootOnly.toString().length() > 0);   
    assert(xhtml.toString().length() > 0);   
    assert(system.toString().length() > 0);   
    
  }
  
  public void testGetSerializedForm() {
    
    assertNotNull(rootOnly.getSerializedForm());   
    assertNotNull(xhtml.getSerializedForm());   
    assertNotNull(system.getSerializedForm());   
    assert(rootOnly.getSerializedForm().length() > 0);   
    assert(xhtml.getSerializedForm().length() > 0);   
    assert(system.getSerializedForm().length() > 0);   
    assert(rootOnly.getSerializedForm().startsWith("<!DOCTYPE"));   
    assert(xhtml.getSerializedForm().startsWith("<!DOCTYPE"));   
    assert(system.getSerializedForm().startsWith("<!DOCTYPE"));          
    assert(rootOnly.getSerializedForm().endsWith(">"));   
    assert(xhtml.getSerializedForm().endsWith(">"));   
    assert(system.getSerializedForm().endsWith(">"));   
        
  }
  
  public void testHashCode() {
    
  }
  
  public static Test suite() { 
    return new TestSuite(DocTypeTest.class); 
  }

  public static void main (String[] args) {
    String[] tests = {"org.jdom.tests.DocTypeTest"};
    LoadingTestRunner.main(tests);
  }

}