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: New tests for javax.print.attribute.EnumSyntax


Hi,

I'm checking in some new tests for javax.print.attribute.EnumSyntax.
The tests in serialize fail currently. The patch implementing the
needed readResolve method is pending on classpath.

2005-11-12 Wolfgang Baer <WBaer@gmx.de>

	* gnu/testlet/javax/print/attribute/EnumSyntax/serialize.java: New test
	* gnu/testlet/javax/print/attribute/EnumSyntax/equals.java: New test.
	* gnu/testlet/javax/print/attribute/EnumSyntax/WrongEnumSyntax.java,
	* gnu/testlet/javax/print/attribute/EnumSyntax/CorrectEnumSyntax.java:
	New helper classes for serialization and equal tests.

Regards,
Wolfgang
//Tags: not-a-test

//Copyright (C) 2005 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, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA.  */


package gnu.testlet.javax.print.attribute.EnumSyntax;

import javax.print.attribute.EnumSyntax;

/**
 * Helper class testing EnumSyntax implementation which
 * is correctly subclassed according to specification.
 */
public class CorrectEnumSyntax extends EnumSyntax
{
  public static final CorrectEnumSyntax TEST1 = new CorrectEnumSyntax(3);
  public static final CorrectEnumSyntax TEST2 = new CorrectEnumSyntax(4);
  public static final CorrectEnumSyntax TEST3 = new CorrectEnumSyntax(5);

  protected CorrectEnumSyntax(int value)
  {
    super(value);
  }

  protected int getOffset()
  {
    return 3;
  }

  private static final String[] stringTable = { "test1", "test2", "test3"};

  protected String[] getStringTable()
  {
    return stringTable;
  }

  private static final CorrectEnumSyntax[] enumValueTable = 
                                        { TEST1, TEST2, TEST3};

  protected EnumSyntax[] getEnumValueTable()
  {
    return enumValueTable;
  }
}
//Tags: not-a-test

//Copyright (C) 2005 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, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA.  */


package gnu.testlet.javax.print.attribute.EnumSyntax;

import javax.print.attribute.EnumSyntax;

/**
 * Helper class testing EnumSyntax implementation.
 */
public class WrongEnumSyntax extends EnumSyntax
{
  public static final WrongEnumSyntax TEST = new WrongEnumSyntax(100);

  protected WrongEnumSyntax(int value)
  {
    super(value);
  }
}
//Tags: JDK1.4
//Uses: WrongEnumSyntax CorrectEnumSyntax

//Copyright (C) 2005 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, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA.  */


package gnu.testlet.javax.print.attribute.EnumSyntax;

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

/**
 * Tests that two instances behave correctly for equal, hashcode, 
 * identity test and toString methods.
 */
public class equals implements Testlet
{

  public void test(TestHarness harness)
  {
    // Also its not a correctly subclass of EnumSyntax
    // it is used here to test some fallback mechanisms.
    WrongEnumSyntax test = WrongEnumSyntax.TEST;
    WrongEnumSyntax test2 = WrongEnumSyntax.TEST;

    harness.check(test.hashCode() == 100, "hashcode()");
    harness.check(test.equals(test2), "equals()");
    harness.check(test == test2, "identity");
    harness.check(test.toString(), "100", "toString");
    
    CorrectEnumSyntax test3 = CorrectEnumSyntax.TEST3;
    CorrectEnumSyntax test4 = CorrectEnumSyntax.TEST3;

    harness.check(test3.hashCode() == 5, "hashcode()");
    harness.check(test3.equals(test4), "equals()");
    harness.check(test3 == test4, "identity");
    harness.check(test3.toString(), "test3", "toString");
  }
  
}
//Tags: JDK1.4
//Uses: WrongEnumSyntax CorrectEnumSyntax

//Copyright (C) 2005 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, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA.  */


package gnu.testlet.javax.print.attribute.EnumSyntax;

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

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

/**
 * Tests serialization with EnumSyntax subclasses correctly
 * subclassed and one which is used to show correct exeption
 * handling of failures in readResolve user code.
 */
public class serialize implements Testlet
{

  public void test(TestHarness harness)
  {
    testSerializeErrors(harness);
    testSerializeNoErrors(harness);
  }
  
  /** Tests for exceptions in readResolve are thrown */
  private void testSerializeErrors(TestHarness harness)
  {
    WrongEnumSyntax test = WrongEnumSyntax.TEST;
    try
      {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(test);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(
            buffer.toByteArray()));
        in.readObject();
        in.close();

        harness.check(false, "serialize error");
      }
    catch (Exception e)
      {        
        harness.check(true, "serialize error");
      }
  }
  
  /** Tests correct serialization */
  private void testSerializeNoErrors(TestHarness harness)
  {
    CorrectEnumSyntax inObj = CorrectEnumSyntax.TEST2;
    CorrectEnumSyntax outObj = null;
    try
      {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(inObj);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(
            buffer.toByteArray()));
        outObj = (CorrectEnumSyntax) in.readObject();
        in.close();

        harness.check(true, "serialize no error");
        
        // test for identical object
        harness.check(inObj == outObj, "identity test");
        harness.check(inObj.equals(outObj), "equality test");
        harness.check(inObj.hashCode() == outObj.hashCode(), "hashcode test");
      }
    catch (Exception e)
      {        
        harness.check(false, "serialize no error");
      }
  }
}

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