@Test public void testEnumerations() throws com.sun.star.uno.Exception
{
// fill a map
final String[] keys = new String[] { "This", "is", "an", "enumeration", "test" };
final String[] values = new String[] { "for", "the", "map", "implementation", "." };
XEnumerableMap map = com.sun.star.container.EnumerableMap.create( connection.getComponentContext(), new Type( String.class ), new Type( String.class ) );
impl_putAll( map, keys, values );
final Pair< ?, ? >[] paired = new Pair< ?, ? >[ keys.length ];
for ( int i=0; i<keys.length; ++i )
{
paired[i] = new Pair< Object, Object >( keys[i], values[i] );
}
// create non-isolated enumerators, and check their content
XEnumeration enumerateKeys = map.createKeyEnumeration( false );
XEnumeration enumerateValues = map.createValueEnumeration( false );
XEnumeration enumerateAll = map.createElementEnumeration( false );
impl_verifyEnumerationContent( enumerateKeys, keys, "key enumeration" );
impl_verifyEnumerationContent( enumerateValues, values, "value enumeration" );
impl_verifyEnumerationContent( enumerateAll, paired, "content enumeration" );
// all enumerators above have been created as non-isolated iterators, so they're expected to die when
// the underlying map changes
map.remove( keys[0] );
//? assureException( enumerateKeys, "hasMoreElements", new Object[] {}, DisposedException.class );
//? assureException( enumerateValues, "hasMoreElements", new Object[] {}, DisposedException.class );
//? assureException( enumerateAll, "hasMoreElements", new Object[] {}, DisposedException.class );
// now try with isolated iterators
map.put( keys[0], values[0] );
enumerateKeys = map.createKeyEnumeration( true );
enumerateValues = map.createValueEnumeration( true );
enumerateAll = map.createElementEnumeration( true );
map.put( "additional", "value" );
impl_verifyEnumerationContent( enumerateKeys, keys, "key enumeration" );
impl_verifyEnumerationContent( enumerateValues, values, "value enumeration" );
impl_verifyEnumerationContent( enumerateAll, paired, "content enumeration" );
}