Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/LibreOffice/odk/examples/java/Storage/     Datei vom 5.10.2025 mit Größe 7 kB image not shown  

Quelle  Test06.java  Sprache: JAVA


/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XSingleServiceFactory;

import com.sun.star.uno.UnoRuntime;
import com.sun.star.embed.*;

public class Test06 implements StorageTest {

    XMultiServiceFactory m_xMSF;
    XSingleServiceFactory m_xStorageFactory;
    TestHelper m_aTestHelper;

    public Test06( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory )
    {
        m_xMSF = xMSF;
        m_xStorageFactory = xStorageFactory;
        m_aTestHelper = new TestHelper( "Test06: " );
    }

    public boolean test()
    {
        try
        {
            // create temporary storage based on arbitrary medium
            // after such a storage is closed it is lost
            Object oTempStorage = m_xStorageFactory.createInstance();
            XStorage xTempStorage = UnoRuntime.queryInterface( XStorage.class, oTempStorage );
            if ( xTempStorage == null )
            {
                m_aTestHelper.Error( "Can't create temporary storage representation!" );
                return false;
            }

            try
            {
                xTempStorage.copyToStorage( null );
                m_aTestHelper.Error( "The method must throw an exception because of illegal parameter!" );
                return false;
            }
            catch( com.sun.star.lang.IllegalArgumentException iae )
            {}
            catch( com.sun.star.uno.Exception ue )
            {}
            catch( Exception e )
            {
                m_aTestHelper.Error( "Unexpected exception because of illegal parameter : " + e );
                return false;
            }

            // open new substorages
            XStorage xTempSubStorage1 = m_aTestHelper.openSubStorage( xTempStorage,
                                                                    "SubStorage1",
                                                                    ElementModes.WRITE );
            XStorage xTempSubStorage2 = m_aTestHelper.openSubStorage( xTempStorage,
                                                                    "SubStorage2",
                                                                    ElementModes.WRITE );
            if ( xTempSubStorage1 == null || xTempSubStorage2 == null )
            {
                m_aTestHelper.Error( "Can't create substorage!" );
                return false;
            }

            // in case stream is open for reading it must exist
            try
            {
                xTempSubStorage1.openStreamElement( "NonExistingStream", ElementModes.READ );
                m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent stream for reading!" );
                return false;
            }
            catch( com.sun.star.uno.Exception ue )
            {}
            catch( Exception e )
            {
                m_aTestHelper.Error( "Unexpected exception in case of try to open nonexistent stream for reading : " + e );
                return false;
            }

            // in case a storage is open for reading it must exist
            try
            {
                xTempSubStorage1.openStreamElement( "NonExistingStorage", ElementModes.READ );
                m_aTestHelper.Error( "The method must throw an exception in case of try to open nonexistent storage for reading!" );
                return false;
            }
            catch( com.sun.star.uno.Exception ue )
            {}
            catch( Exception e )
            {
                m_aTestHelper.Error( "Unexpected exception in case of try to open nonexistent storage for reading : " + e );
                return false;
            }

            // in case of removing nonexistent element an exception must be thrown
            try
            {
                xTempSubStorage1.removeElement( "NonExistingElement" );
          

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-11-25) ¤

*Bot Zugriff