This is the mail archive of the
mauve-patches@sourceware.org
mailing list for the Mauve project.
FYI: New tests for javax.print.attribute.EnumSyntax
- From: Wolfgang Baer <WBaer at gmx dot de>
- To: mauve-patches at sources dot redhat dot com
- Date: Sun, 13 Nov 2005 20:11:48 +0100
- Subject: FYI: New tests for javax.print.attribute.EnumSyntax
Hi,
I'm checking in some new tests for javax.print.attribute.HashAttributeSet.java
Some tests related to null handling and hashcode fail currently - fixes
are on my disk and pending checkin into GNU classpath.
2005-11-13 Wolfgang Baer <WBaer@gmx.de>
* gnu/testlet/javax/print/attribute/HashAttributeSet/emptySet.java,
* gnu/testlet/javax/print/attribute/HashAttributeSet/nullTests.java,
* gnu/testlet/javax/print/attribute/HashAttributeSet/populatedSet.java,
New tests.
* gnu/testlet/javax/print/attribute/HashAttributeSet/
SimpleAttribute.java,
* gnu/testlet/javax/print/attribute/HashAttributeSet/
AnotherSimpleAttribute.java,
New helper classes for emptySet and populatedSet 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.HashAttributeSet;
import javax.print.attribute.Attribute;
/**
* Another simple attribute implementation.
*/
public class AnotherSimpleAttribute implements Attribute
{
private int value;
public AnotherSimpleAttribute(int value) {
this.value = value;
}
public Class getCategory()
{
return this.getClass();
}
public String getName()
{
return "AnotherSimpleAttribute";
}
public boolean equals(Object obj)
{
if (obj instanceof AnotherSimpleAttribute)
{
AnotherSimpleAttribute att = (AnotherSimpleAttribute) obj;
if (att.value == this.value)
return true;
}
return false;
}
public int hashCode()
{
return this.value;
}
}
//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.HashAttributeSet;
import javax.print.attribute.Attribute;
/**
* A simple attribute implementation.
*/
public class SimpleAttribute implements Attribute
{
private int value;
public SimpleAttribute(int value) {
this.value = value;
}
public Class getCategory()
{
return this.getClass();
}
public String getName()
{
return "SimpleAttribute";
}
public boolean equals(Object obj)
{
if (obj instanceof SimpleAttribute)
{
SimpleAttribute att = (SimpleAttribute) obj;
if (att.value == this.value)
return true;
}
return false;
}
public int hashCode()
{
return this.value;
}
}
//Tags: JDK1.4
//Uses: SimpleAttribute
//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.HashAttributeSet;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import javax.print.attribute.HashAttributeSet;
/**
* Test methods behaviour for an empty set.
*/
public class emptySet implements Testlet
{
public void test(TestHarness harness)
{
HashAttributeSet testSet = new HashAttributeSet();
HashAttributeSet testSet2 = new HashAttributeSet();
harness.check(testSet.equals(testSet2), true, "equals");
harness.check(testSet.hashCode(), 0, "hashcode");
harness.check(testSet.toArray().length, 0, "toArray");
harness.check(testSet.isEmpty(), true, "isEmpty 1");
testSet.add(new SimpleAttribute(1));
testSet.remove(new SimpleAttribute(1).getCategory());
harness.check(testSet.isEmpty(), true, "isEmpty 2");
}
}
//Tags: JDK1.4
//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.HashAttributeSet;
import javax.print.attribute.Attribute;
import javax.print.attribute.AttributeSet;
import javax.print.attribute.HashAttributeSet;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
/**
* Tests behaviour for various methods if parameters are null.
*/
public class nullTests implements Testlet
{
public void test(TestHarness harness)
{
harness.checkPoint("constructor tests");
try
{
new HashAttributeSet((Attribute) null);
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
try
{
new HashAttributeSet((AttributeSet) null);
harness.check(true);
}
catch (NullPointerException e)
{
harness.check(false);
}
try
{
new HashAttributeSet((Attribute[]) null);
harness.check(true);
}
catch (NullPointerException e)
{
harness.check(false);
}
try
{
new HashAttributeSet(new Attribute[] { null });
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
harness.checkPoint("method tests");
HashAttributeSet testSet = new HashAttributeSet();
try
{
testSet.get(null);
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
try
{
testSet.add(null);
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
try
{
testSet.addAll(null);
harness.check(false);
}
catch (NullPointerException e)
{
harness.check(true);
}
harness.check(testSet.remove((Attribute) null), false);
harness.check(testSet.remove((Class) null), false);
harness.check(testSet.containsKey(null), false);
harness.check(testSet.containsValue(null), false);
}
}
//Tags: JDK1.4
//Uses: SimpleAttribute AnotherSimpleAttribute
//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.HashAttributeSet;
import javax.print.attribute.HashAttributeSet;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
/**
* Tests various methods for populated sets.
*/
public class populatedSet implements Testlet
{
public void test(TestHarness harness)
{
SimpleAttribute att1 = new SimpleAttribute(1);
HashAttributeSet testSet = new HashAttributeSet( att1 );
// test basic functionality
harness.check(testSet.containsValue(att1), true, "containsValue");
harness.check(testSet.containsKey(att1.getCategory()),
true, "containsKey");
harness.check(testSet.remove(att1), true, "remove");
harness.check(testSet.isEmpty(), true, "isEmpty");
harness.check(testSet.add(att1), true, "add");
harness.check(testSet.add(att1), false, "re-add");
// test category replacement
SimpleAttribute att2 = new SimpleAttribute(3);
SimpleAttribute[] array =
new SimpleAttribute[] { new SimpleAttribute(2), att2 };
testSet = new HashAttributeSet( array );
harness.check(testSet.size(), 1, "size");
harness.check(testSet.hashCode(), 3, "hashcode");
harness.check(testSet.containsValue(att2), true, "containsValue");
AnotherSimpleAttribute att3 = new AnotherSimpleAttribute(4);
harness.check(testSet.add(att3), true, "add");
harness.check(testSet.size(), 2, "size");
harness.check(testSet.hashCode(), 7, "hashcode");
// build equal set for euqals test
HashAttributeSet testSet2 = new HashAttributeSet();
testSet2.add(att2);
testSet2.add(att3);
harness.check(testSet.equals(testSet2), true, "equals");
harness.check(testSet2.addAll(testSet), false, "addAll");
testSet2.clear();
harness.check(testSet2.isEmpty(), true, "isEmpty");
// test hashcode
testSet = new HashAttributeSet();
testSet.add( new SimpleAttribute(1));
testSet.add( new AnotherSimpleAttribute(2));
testSet2 = new HashAttributeSet();
testSet2.add( new SimpleAttribute(2));
testSet2.add( new AnotherSimpleAttribute(1));
harness.check(testSet.hashCode() == testSet2.hashCode(), "equal hashcode");
harness.check(testSet.equals(testSet2), false, "no equality");
}
}