/************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org 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 Lesser General Public License version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ package complex.dbaccess; import complexlib.ComplexTestCase; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.beans.*; public class PropertyBag extends ComplexTestCase { private static final String VALUE = "Value"; private XPropertyContainer m_bag; private XPropertySet m_set; private XPropertyAccess m_access; private XMultiServiceFactory m_orb = null; public String[] getTestMethodNames() { return new String[] { "checkBasics", "checkSequenceAccess", "checkDynamicSet" }; } public String getTestObjectName() { return "PropertyBag"; } public void before() { m_orb = (XMultiServiceFactory)param.getMSF(); } public void checkBasics() { createEmptyBag(); log.println("testing the basics"); // check whether empty property names are rejected boolean caughtExpected = false; try { m_bag.addProperty( "", PropertyAttribute.BOUND, Integer.valueOf( 3 ) ); } catch(com.sun.star.lang.IllegalArgumentException e) { caughtExpected = true; } catch(com.sun.star.uno.Exception e) { } if ( !caughtExpected ) failed( "empty property names are not rejected by XPropertyContainer::addProperty" ); // check whether duplicate insertions are rejected caughtExpected = false; try { m_bag.addProperty( VALUE, PropertyAttribute.BOUND, "" ); m_bag.addProperty( VALUE, PropertyAttribute.BOUND, "" ); } catch(com.sun.star.beans.PropertyExistException e) { caughtExpected = true; } catch(com.sun.star.uno.Exception e) { } if ( !caughtExpected ) failed( "insertion of duplicate property names is not rejected" ); // try removing the property we just added - this should fail, as it does not have // the REMOVEABLE attribute caughtExpected = false; try { m_bag.removeProperty( VALUE); } catch(com.sun.star.beans.NotRemoveableException e) { caughtExpected = true; } catch(com.sun.star.uno.Exception e) { } if ( !caughtExpected ) failed( "removing non-removeable properties is expected to fail - but it didn't" ); // try removing a non-existent property caughtExpected = false; try { m_bag.removeProperty( "NonExistent" ); } catch(com.sun.star.beans.UnknownPropertyException e) { caughtExpected = true; } catch(com.sun.star.uno.Exception e) { } if ( !caughtExpected ) failed( "removing non-existent properties is expected to fail - but it didn't" ); // try writing and reading a value for the one property we have so far try { final String testValue = "someArbitraryValue"; m_set.setPropertyValue( VALUE , testValue); final String currentValue = (String)m_set.getPropertyValue( VALUE); if ( !currentValue.equals( testValue ) ) failed( "set property is not remembered" ); } catch(com.sun.star.uno.Exception e) { failed( "setting or getting a property value failed" ); } // try setting an illegal value for the property caughtExpected = false; try { m_set.setPropertyValue( VALUE, Integer.valueOf( 3 ) ); } catch(com.sun.star.lang.IllegalArgumentException e) { caughtExpected = true; } catch(com.sun.star.uno.Exception e) { } if ( !caughtExpected ) failed( "the bag does not respect the property type we declared for the property" ); } public void checkSequenceAccess() throws com.sun.star.uno.Exception { log.println( "checking PropertySetAccess via sequences" ); createStandardBag( false ); // --------------------------------- // XPropertyAccess.setPropertyValues final PropertyValue expectedValues[] = { new PropertyValue( "BoolValue", -1, Boolean.FALSE, PropertyState.DIRECT_VALUE ), new PropertyValue( "StringValue", -1, "some text", PropertyState.DIRECT_VALUE ), new PropertyValue( "IntegerValue", -1, Integer.valueOf( 3 ), PropertyState.DIRECT_VALUE ), new PropertyValue( "InterfaceValue", -1, m_bag, PropertyState.DIRECT_VALUE ) }; m_access.setPropertyValues( expectedValues ); for ( int i=0; i