This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: Tests for new javax.print.SimpleDoc class


Hi,

here are the tests for the newly committed SimpleDoc class.

Regards,
Wolfgang

2006-01-14 Wolfgang Baer <WBaer@gmx.de>

	* gnu/testlet/javax/print/SimpleDoc/: New directory.
	* gnu/testlet/javax/print/SimpleDoc/constructor.java,
	* gnu/testlet/javax/print/SimpleDoc/getAttributes.java,
	* gnu/testlet/javax/print/SimpleDoc/getReaderForText.java,
	* gnu/testlet/javax/print/SimpleDoc/getStreamForBytes.java: New tests.

//Tags: JDK1.4

//Copyright (C) 2006 Free Software Foundation, Inc.
//Written by Wolfgang Baer (WBaer@gmx.de)

//This file is part of Mauve.

//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.

//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING.  If not, write to
//the Free Software Foundation, 51 Franklin Street, Fifth Floor,
//Boston, MA, 02110-1301 USA.

package gnu.testlet.javax.print.SimpleDoc;

import java.io.CharArrayReader;

import javax.print.DocFlavor;
import javax.print.SimpleDoc;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

/**
 * Simple constructor tests.
 */
public class constructor implements Testlet
{
  public void test(TestHarness harness)
  {    
    try
      {
        // printdata matches flavor
        new SimpleDoc(new byte[100], DocFlavor.BYTE_ARRAY.GIF, null);
        harness.check(true);
      }
    catch (RuntimeException e)
      {
        e.printStackTrace();
        harness.check(false);
      }
    
    try
      {
        // check for sublcasses of reader
        new SimpleDoc(new CharArrayReader(new char[]{'A','b'}), 
          DocFlavor.READER.TEXT_PLAIN, null);
        harness.check(true);
      }
    catch (RuntimeException e)
      {
        e.printStackTrace();
        harness.check(false);
      }
    
    try
      {
        // printdata does not match flavor
        new SimpleDoc(new byte[100], DocFlavor.CHAR_ARRAY.TEXT_PLAIN, null);
        harness.check(false);
      }
    catch (IllegalArgumentException e)
      {
        harness.check(true);
      }

    try
      {
        new SimpleDoc(null, DocFlavor.CHAR_ARRAY.TEXT_PLAIN, null);
        harness.check(false);
      }
    catch (IllegalArgumentException e)
      {
        harness.check(true);
      }

    try
      {
        new SimpleDoc(new String("kk"), null, null);
        harness.check(false);
      }
    catch (IllegalArgumentException e)
      {
        harness.check(true);
      }
  }
}
//Tags: JDK1.4

//Copyright (C) 2006 Free Software Foundation, Inc.
//Written by Wolfgang Baer (WBaer@gmx.de)

//This file is part of Mauve.

//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.

//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING.  If not, write to
//the Free Software Foundation, 51 Franklin Street, Fifth Floor,
//Boston, MA, 02110-1301 USA.

package gnu.testlet.javax.print.SimpleDoc;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import javax.print.DocFlavor;
import javax.print.SimpleDoc;
import javax.print.attribute.DocAttributeSet;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.UnmodifiableSetException;
import javax.print.attribute.standard.Compression;
import javax.print.attribute.standard.OrientationRequested;
import javax.print.attribute.standard.Sides;

/**
 * Tests various aspects of the getAttributes method.
 */
public class getAttributes implements Testlet
{
  public void test(TestHarness harness)
  {
    HashDocAttributeSet set = new HashDocAttributeSet();
    set.add(Sides.DUPLEX);
    set.add(Compression.COMPRESS);
    set.add(OrientationRequested.LANDSCAPE);
    
    SimpleDoc doc = 
      new SimpleDoc(new byte[100], DocFlavor.BYTE_ARRAY.GIF, set);
    
    DocAttributeSet set1 = doc.getAttributes();
    DocAttributeSet set2 = doc.getAttributes();
    
    // everytime the same object needs to be returned.
    harness.check(set1 == set2);
    
    try
      {
        // it must be an unmodifiable view
        set1.remove(Compression.class);
        harness.check(false);
      }
    catch (UnmodifiableSetException e)
      {
        harness.check(true);
      }
  }

}
//Tags: JDK1.4

//Copyright (C) 2006 Free Software Foundation, Inc.
//Written by Wolfgang Baer (WBaer@gmx.de)

//This file is part of Mauve.

//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.

//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING.  If not, write to
//the Free Software Foundation, 51 Franklin Street, Fifth Floor,
//Boston, MA, 02110-1301 USA.

package gnu.testlet.javax.print.SimpleDoc;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.io.CharArrayReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;

import javax.print.DocFlavor;
import javax.print.SimpleDoc;

/**
 * Checks getReaderForText
 */
public class getReaderForText implements Testlet
{
  public void test(TestHarness harness)
  {      
    SimpleDoc doc = new SimpleDoc(
      new String("Text to print"), DocFlavor.STRING.TEXT_PLAIN, null);
    
    try
      {
        Reader reader1 = doc.getReaderForText();
        Reader reader2 = doc.getReaderForText();
        harness.check(reader1 == reader2);
        harness.check(reader1 instanceof StringReader);
      }
    catch (IOException e)
      {
        harness.check(false);
      }    
    
    SimpleDoc doc1 = new SimpleDoc(
      new char[]{'A','b'}, DocFlavor.CHAR_ARRAY.TEXT_PLAIN, null);
                                
    try
      {
        Reader reader2 = doc1.getReaderForText();
        Reader reader3 = doc1.getReaderForText();
        harness.check(reader2 == reader3);
        harness.check(reader2 instanceof CharArrayReader);
      }
    catch (IOException e)
      {
        harness.check(false);
      }
    
    SimpleDoc doc2 = new SimpleDoc(
      new CharArrayReader(new char[]{'A','b'}), DocFlavor.READER.TEXT_PLAIN, null);
                                                             
    try
      {
        Reader reader4 = doc2.getReaderForText();
        Reader reader5 = doc2.getReaderForText();
        harness.check(reader4 == reader5);
        harness.check(reader4 == doc2.getPrintData());
      }
    catch (IOException e)
      {
        harness.check(false);
      }   
    
    SimpleDoc doc3 = new SimpleDoc(
      new byte[]{'A','b'}, DocFlavor.BYTE_ARRAY.AUTOSENSE, null);
                                                                                          
    try
      {
        Reader reader6 = doc3.getReaderForText();
        harness.check(reader6 == null);
      }
    catch (IOException e)
      {
        harness.check(false);
      }   
  }

}
//Tags: JDK1.4

//Copyright (C) 2006 Free Software Foundation, Inc.
//Written by Wolfgang Baer (WBaer@gmx.de)

//This file is part of Mauve.

//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.

//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING.  If not, write to
//the Free Software Foundation, 51 Franklin Street, Fifth Floor,
//Boston, MA, 02110-1301 USA.


package gnu.testlet.javax.print.SimpleDoc;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.print.DocFlavor;
import javax.print.SimpleDoc;

/**
 * Checks getStreamForBytes
 */
public class getStreamForBytes implements Testlet
{
  public void test(TestHarness harness)
  {
    SimpleDoc doc = new SimpleDoc(new byte[]{'2','3'},
        DocFlavor.BYTE_ARRAY.GIF, null);

    try
      {
        InputStream stream1 = doc.getStreamForBytes();
        InputStream stream2 = doc.getStreamForBytes();
        harness.check(stream1 == stream2);
        harness.check(stream1 instanceof ByteArrayInputStream);
      }
    catch (IOException e)
      {
        harness.check(false);
      }

    SimpleDoc doc1 = new SimpleDoc(
        new ByteArrayInputStream(new byte[] { 'A', 'b' }),
        DocFlavor.INPUT_STREAM.GIF, null);

    try
      {
        InputStream stream3 = doc1.getStreamForBytes();
        InputStream stream4 = doc1.getStreamForBytes();
        harness.check(stream3 == stream4);
        harness.check(stream3 == doc1.getPrintData());
      }
    catch (IOException e)
      {
        harness.check(false);
      }
  }
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]