diff options
author | Oliver Bolte <obo@openoffice.org> | 2006-10-13 10:43:53 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2006-10-13 10:43:53 +0000 |
commit | 9a98aa53f4eb66ed9abc2910efeb6d9413cd2d87 (patch) | |
tree | 75c663a06949fd9d5c50126bc1342952754603fd /package | |
parent | e45983feb241ae391475d19c6e2ce7ed3bd89ee3 (diff) |
INTEGRATION: CWS opofxmlstorage (1.1.2); FILE ADDED
2006/04/21 11:38:10 mav 1.1.2.1: #i64612# test OFOPXML storage
Diffstat (limited to 'package')
-rw-r--r-- | package/qa/ofopxmlstorages/StorageUnitTest.java | 166 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test01.java | 200 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test02.java | 164 | ||||
-rw-r--r-- | package/qa/ofopxmlstorages/Test03.java | 233 |
4 files changed, 763 insertions, 0 deletions
diff --git a/package/qa/ofopxmlstorages/StorageUnitTest.java b/package/qa/ofopxmlstorages/StorageUnitTest.java new file mode 100644 index 000000000000..a54328b2c2ac --- /dev/null +++ b/package/qa/ofopxmlstorages/StorageUnitTest.java @@ -0,0 +1,166 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: StorageUnitTest.java,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: obo $ $Date: 2006-10-13 11:43:15 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ +package complex.ofopxmlstorages; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.connection.XConnector; +import com.sun.star.connection.XConnection; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.uno.XNamingService; +import com.sun.star.uno.XComponentContext; + +import com.sun.star.container.*; +import com.sun.star.beans.*; +import com.sun.star.lang.*; + +import complexlib.ComplexTestCase; + +import complex.ofopxmlstorages.*; + +import util.utils; +import java.util.*; +import java.io.*; + +/* This unit test for storage objects is designed to + * test most important statements from storage service + * specification. + * + * Regression tests are added to extend the tested + * functionalities. + */ +public class StorageUnitTest extends ComplexTestCase +{ + private XMultiServiceFactory m_xMSF = null; + private XSingleServiceFactory m_xStorageFactory = null; + + public String[] getTestMethodNames() + { + return new String[] { + "ExecuteTest01", + "ExecuteTest02", + "ExecuteTest03", + "ExecuteTest04", + "ExecuteTest05", + "ExecuteTest06", + "ExecuteTest07", + "ExecuteTest08" + }; + } + + public String getTestObjectName() + { + return "StorageUnitTest"; + } + + public void before() + { + m_xMSF = (XMultiServiceFactory)param.getMSF(); + if ( m_xMSF == null ) + { + failed( "Can't create service factory!" ); + return; + } + + try { + Object oStorageFactory = m_xMSF.createInstance( "com.sun.star.embed.StorageFactory" ); + m_xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( XSingleServiceFactory.class, + oStorageFactory ); + } + catch( Exception e ) + { + failed( "Can't create storage factory!" ); + return; + } + + if ( m_xStorageFactory == null ) + { + failed( "Can't create service factory!" ); + return; + } + } + + public void ExecuteTest01() + { + StorageTest aTest = new Test01( m_xMSF, m_xStorageFactory, log ); + assure( "Test01 failed!", aTest.test() ); + } + + public void ExecuteTest02() + { + StorageTest aTest = new Test02( m_xMSF, m_xStorageFactory, log ); + assure( "Test02 failed!", aTest.test() ); + } + + public void ExecuteTest03() + { + StorageTest aTest = new Test03( m_xMSF, m_xStorageFactory, log ); + assure( "Test03 failed!", aTest.test() ); + } + + public void ExecuteTest04() + { + StorageTest aTest = new Test04( m_xMSF, m_xStorageFactory, log ); + assure( "Test04 failed!", aTest.test() ); + } + + public void ExecuteTest05() + { + StorageTest aTest = new Test05( m_xMSF, m_xStorageFactory, log ); + assure( "Test05 failed!", aTest.test() ); + } + + public void ExecuteTest06() + { + StorageTest aTest = new Test06( m_xMSF, m_xStorageFactory, log ); + assure( "Test06 failed!", aTest.test() ); + } + + public void ExecuteTest07() + { + StorageTest aTest = new Test07( m_xMSF, m_xStorageFactory, log ); + assure( "Test07 failed!", aTest.test() ); + } + + public void ExecuteTest08() + { + StorageTest aTest = new Test08( m_xMSF, m_xStorageFactory, log ); + assure( "Test08 failed!", aTest.test() ); + } +} + diff --git a/package/qa/ofopxmlstorages/Test01.java b/package/qa/ofopxmlstorages/Test01.java new file mode 100644 index 000000000000..0fe4c6a0aeec --- /dev/null +++ b/package/qa/ofopxmlstorages/Test01.java @@ -0,0 +1,200 @@ +package complex.ofopxmlstorages; + +import com.sun.star.uno.XInterface; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +import com.sun.star.embed.*; +import com.sun.star.beans.StringPair; + +import share.LogWriter; +import complex.ofopxmlstorages.TestHelper; +import complex.ofopxmlstorages.StorageTest; + +public class Test01 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test01( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test01: " ); + } + + public boolean test() + { + StringPair[][] aRelations1 = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue1" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetType", "Internal1" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value 1" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetType", "" ), new StringPair( "Type", "unknown1" ), new StringPair( "Target", "URL value1" ) } + }; + + StringPair[][] aRelations2 = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue2" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetType", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetType", "Internal2" ), new StringPair( "Type", "unknown2" ), new StringPair( "Target", "URL value 2" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetType", "Internal2" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetType", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) } + }; + + try + { + String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF ); + if ( sTempFileURL == null || sTempFileURL == "" ) + { + m_aTestHelper.Error( "No valid temporary file was created!" ); + return false; + } + + // create temporary storage based on arbitrary medium + // after such a storage is closed it is lost + XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory ); + if ( xTempStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + // open a new substorage + XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xTempSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + byte pBytes1[] = { 1, 1, 1, 1, 1 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, + "SubStream1", + "MediaType1", + true, + pBytes1, + aRelations1 ) ) + return false; + + byte pBytes2[] = { 2, 2, 2, 2, 2 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, + "SubStream2", + "MediaType2", + false, + pBytes2, + aRelations2 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, + true, + ElementModes.WRITE, + aRelations1 ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, + false, + ElementModes.WRITE, + aRelations1 ) ) + return false; + + // create temporary storage based on a previously created temporary file + XStorage xTempFileStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory, + sTempFileURL, + ElementModes.WRITE ); + if ( xTempFileStorage == null ) + { + m_aTestHelper.Error( "Can't create storage based on temporary file!" ); + return false; + } + + // copy xTempStorage to xTempFileStorage + // xTempFileStorage will be automatically commited + if ( !m_aTestHelper.copyStorage( xTempStorage, xTempFileStorage ) ) + return false; + + // dispose used storages to free resources + if ( !m_aTestHelper.disposeStorage( xTempStorage ) || !m_aTestHelper.disposeStorage( xTempFileStorage ) ) + return false; + + // ================================================ + // now check all the written and copied information + // ================================================ + + // the temporary file must not be locked any more after storage disposing + XStorage xResultStorage = m_aTestHelper.createStorageFromURL( m_xStorageFactory, + sTempFileURL, + ElementModes.WRITE ); + if ( xResultStorage == null ) + { + m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultStorage, + true, + ElementModes.WRITE, + aRelations1 ) ) + return false; + + // open existing substorage + XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage, + "SubStorage1", + ElementModes.READ ); + if ( xResultSubStorage == null ) + { + m_aTestHelper.Error( "Can't open existing substorage!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, + false, + ElementModes.READ, + aRelations1 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResultSubStorage, + "SubStream1", + "MediaType1", + pBytes1, + aRelations1 ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResultSubStorage, + "SubStream2", + "MediaType2", + pBytes2, + aRelations2 ) ) + return false; + + // dispose used storages to free resources + if ( !m_aTestHelper.disposeStorage( xResultStorage ) ) + return false; + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } + +} + diff --git a/package/qa/ofopxmlstorages/Test02.java b/package/qa/ofopxmlstorages/Test02.java new file mode 100644 index 000000000000..43930c92b96f --- /dev/null +++ b/package/qa/ofopxmlstorages/Test02.java @@ -0,0 +1,164 @@ +package complex.ofopxmlstorages; + +import com.sun.star.uno.XInterface; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.io.XStream; +import com.sun.star.io.XInputStream; + +import com.sun.star.embed.*; +import com.sun.star.beans.StringPair; + +import share.LogWriter; +import complex.ofopxmlstorages.TestHelper; +import complex.ofopxmlstorages.StorageTest; + +public class Test02 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test02( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test02: " ); + } + + public boolean test() + { + try + { + StringPair[][] aRelations = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetType", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetType", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetType", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetType", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) } + }; + + + XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF ); + if ( xTempFileStream == null ) + return false; + + // create storage based on the temporary stream + XStorage xTempStorage = m_aTestHelper.createStorageFromStream( m_xStorageFactory, + xTempFileStream, + ElementModes.WRITE ); + if ( xTempStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + // open a new substorage + XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xTempSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + byte pBytes1[] = { 1, 1, 1, 1, 1 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, + "SubStream1", + "MediaType1", + true, + pBytes1, + aRelations ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, + true, + ElementModes.WRITE, + aRelations ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, + false, + ElementModes.WRITE, + aRelations ) ) + return false; + + // commit substorage first + if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) + return false; + + // commit the root storage so the contents must be stored now + if ( !m_aTestHelper.commitStorage( xTempStorage ) ) + return false; + + // dispose used storage to free resources + if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) + return false; + + + // ================================================ + // now check all the written information + // ================================================ + + // close the output part of the temporary stream + // the output part must present since we already wrote to the stream + if ( !m_aTestHelper.closeOutput( xTempFileStream ) ) + return false; + + XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream ); + if ( xTempInStream == null ) + return false; + + + // open input stream + XStorage xResultStorage = m_aTestHelper.createStorageFromInputStream( m_xStorageFactory, xTempInStream ); + if ( xResultStorage == null ) + { + m_aTestHelper.Error( "Can't open storage based on input stream!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultStorage, true, ElementModes.READ, aRelations ) ) + return false; + + // open existing substorage + XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage, + "SubStorage1", + ElementModes.READ ); + if ( xResultSubStorage == null ) + { + m_aTestHelper.Error( "Can't open existing substorage!" ); + return false; + } + + if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, + false, + ElementModes.READ, + aRelations ) ) + return false; + + if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream1", "MediaType1", pBytes1, aRelations ) ) + return false; + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } + +} + diff --git a/package/qa/ofopxmlstorages/Test03.java b/package/qa/ofopxmlstorages/Test03.java new file mode 100644 index 000000000000..36aa06297031 --- /dev/null +++ b/package/qa/ofopxmlstorages/Test03.java @@ -0,0 +1,233 @@ +package complex.ofopxmlstorages; + +import com.sun.star.uno.XInterface; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; + +import com.sun.star.embed.*; +import com.sun.star.container.XNameAccess; +import com.sun.star.beans.StringPair; + +import share.LogWriter; +import complex.ofopxmlstorages.TestHelper; +import complex.ofopxmlstorages.StorageTest; + +public class Test03 implements StorageTest { + + XMultiServiceFactory m_xMSF; + XSingleServiceFactory m_xStorageFactory; + TestHelper m_aTestHelper; + + public Test03( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_xStorageFactory = xStorageFactory; + m_aTestHelper = new TestHelper( aLogWriter, "Test03: " ); + } + + public boolean test() + { + try + { + StringPair[][] aRelations = + { { new StringPair( "Id", "Num1" ) }, + { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) }, + { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, + { new StringPair( "Id", "Num2" ), new StringPair( "TargetType", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num3" ), new StringPair( "TargetType", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num4" ), new StringPair( "TargetType", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, + { new StringPair( "Id", "Num5" ), new StringPair( "TargetType", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) } + }; + + // create temporary storage based on arbitrary medium + // after such a storage is closed it is lost + XStorage xTempStorage = m_aTestHelper.createTempStorage( m_xMSF, m_xStorageFactory ); + if ( xTempStorage == null ) + { + m_aTestHelper.Error( "Can't create temporary storage representation!" ); + return false; + } + + // open a new substorage + XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, + "SubStorage1", + ElementModes.WRITE ); + if ( xTempSubStorage == null ) + { + m_aTestHelper.Error( "Can't create substorage!" ); + return false; + } + + byte pBytes1[] = { 1, 1, 1, 1, 1 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempStorage, + "SubStream1", + "MediaType1", + true, + pBytes1, + aRelations ) ) + return false; + + byte pBytes2[] = { 2, 2, 2, 2, 2 }; + + // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes + if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, + "SubStream2", + "MediaType2", + false, + pBytes2, + aRelations ) ) + return false; + + // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly + if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, + false, + ElementModes.WRITE, + aRelations ) ) + return false; + + if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) + return false; + + if ( !m_aTestHelper.disposeStorage( xTempSubStorage ) ) + return false; + + // ================================================ + // check storage hyerarchy tree + // ================================================ + + // check that isStorageElement() and isStreamElement reacts to nonexisting object correctly + try { + xTempStorage.isStorageElement( "does not exist" ); + m_aTestHelper.Error( "Nonexisting element doesn't detected by isStorageElement() call!" ); + return false; + } + catch( com.sun.star.container.NoSuchElementException ne ) + { + } + catch( Exception e ) + { + m_aTestHelper.Error( "Wrong exception is thrown by isStorageElement() call: " + e ); + return false; + } + + try { + xTempStorage.isStreamElement( "does not exist" ); + m_aTestHelper.Error( "Nonexisting element doesn't detected by isStreamElement() call!" ); + return false; + } + catch( com.sun.star.container.NoSuchElementException ne ) + { + } + catch( Exception e ) + { + m_aTestHelper.Error( "Wrong exception is thrown by isStreamElement() call: " + e ); + return false; + } + + XNameAccess xRootNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xTempStorage ); + if ( xRootNameAccess == null ) + { + m_aTestHelper.Error( "Root storage doesn't support XNameAccess!" ); + return false; + } + + try { + if ( !xTempStorage.isStorageElement( "SubStorage1" ) || xTempStorage.isStreamElement( "SubStorage1" ) ) + { + m_aTestHelper.Error( "Child 'SubStorage1' can not be detected as storage!" ); + return false; + } + + if ( xTempStorage.isStorageElement( "SubStream1" ) || !xTempStorage.isStreamElement( "SubStream1" ) ) + { + m_aTestHelper.Error( "Child 'SubStream1' can not be detected as stream!" ); + return false; + } + } + catch( Exception e ) + { + m_aTestHelper.Error( "Child's type can not be detected, exception: " + e ); + return false; + } + + + // check that root storage contents are represented correctly + String sRootCont[] = xRootNameAccess.getElementNames(); + + if ( sRootCont.length != 2 ) + { + m_aTestHelper.Error( "Root storage contains wrong amount of children!" ); + return false; + } + + if ( !( sRootCont[0].equals( "SubStorage1" ) && sRootCont[1].equals( "SubStream1" ) + || sRootCont[0].equals( "SubStream1" ) && sRootCont[1].equals( "SubStorage1" ) ) + || !( xRootNameAccess.hasByName( "SubStream1" ) && xRootNameAccess.hasByName( "SubStorage1" ) ) ) + { + m_aTestHelper.Error( "Root storage contains wrong list of children!" ); + return false; + } + + // get storage through XNameAccess + XStorage xResultSubStorage = getStorageFromNameAccess( xRootNameAccess, "SubStorage1" ); + if ( xResultSubStorage == null ) + return false; + + if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, + false, + ElementModes.READ, + aRelations ) ) + return false; + + XNameAccess xChildAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xResultSubStorage ); + if ( xChildAccess == null ) + { + m_aTestHelper.Error( "Child storage doesn't support XNameAccess!" ); + return false; + } + + if ( !xChildAccess.hasByName( "SubStream2" ) + || !xResultSubStorage.isStreamElement( "SubStream2" ) + || xResultSubStorage.isStorageElement( "SubStream2" ) ) + { + m_aTestHelper.Error( "'SubStream2' can not be detected as child stream element of 'SubStorage1'!" ); + return false; + } + + return true; + } + catch( Exception e ) + { + m_aTestHelper.Error( "Exception: " + e ); + return false; + } + } + + public XStorage getStorageFromNameAccess( XNameAccess xAccess, String sName ) + { + try + { + Object oStorage = xAccess.getByName( sName ); + XStorage xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oStorage ); + + if ( xResult != null ) + return xResult; + else + m_aTestHelper.Error( "Can't retrieve substorage '" + sName + "' through XNameAccess!" ); + } + catch( Exception e ) + { + m_aTestHelper.Error( "Can't retrieve substorage '" + sName + "' through XNameAccess, exception: " + e ); + } + + return null; + } + +} + |