Hi Mikhail,

The attachment contains the unit-tests and the console outputs, the test was run upon clean SRC680_m217 and SRC680_m247 build, failed in the first and passed in the later. Could you review the tests please?
Thank you very much for the suggestions made. :-)

Best Regards,
Felix.


Mikhail Voitenko
Hi Felix,

First of all you will need to write an own InteractionHandler to write the unit tests. It will be close to the implementation you have done already, but this time in Java. The InteractionHandler should handle only com.sun.star.task.MasterPasswordRequest.

A good example is the default implementation in uui/source/iahndl.cxx, please just look for MasterPasswordRequest. The new implementation should set a 32 character string containing 0-9 and a-z symbols ( this is a digest, so it should contain hexadecimal digits ) to the continuation.

After the InteractionHandler implementation is ready it can be used to write the tests. Please see some schematic scenario examples below.

scenario1:
- use XPasswordContainer::add() to add a set of users and passwords for the same URL for runtime
- use XPasswordContainer::remove() to remove some of them
- use XPasswordContainer::find() to get the result and check it with the expected one
- use XPasswordContainer::remove() to remove the runtime passwords

scenario2:
- use XMasterPasswordHandling::allowPersistentStoring( true ) to allow the storing of the passwords - use XPasswordContainer::addPersistent() to add a set of users and passwords for the same URL persistently
- use XPasswordContainer::remove() to remove some of them
- use XPasswordContainer::find() to get the result and check it with the expected one
- use XPasswordContainer::getAllPersistent() to check the result
- use XPasswordContainer::removeAllPersistent() to remove all the persistent passwords
- use XPasswordContainer::remove() to remove the runtime passwords
- use XMasterPasswordHandling::allowPersistentStoring( false ) to disallow the storing of the passwords

scenario3:
- use XMasterPasswordHandling::allowPersistentStoring( true ) to allow the storing of the passwords - use XPasswordContainer::addPersistent() to add a set of users and passwords for the same URL persistently - use XPasswordContainer::add() to add the same set of users with different passwords for the same URL for runtime - use XPasswordContainer::find() to get the result for the URL and check that it contains persistent and runtime passwords ( will fail in the current master ) - use XPasswordContainer::removeAllPersistent() to remove all the persistent passwords
- use XPasswordContainer::remove() to remove the runtime passwords
- use XMasterPasswordHandling::allowPersistentStoring( false ) to disallow the storing of the passwords

This is only a short description so the questions are as always welcome.

Best Regards,
Mikhail.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

java -cp 
.;..\..\..\wntmsci10.pro\class;d:\OOEnv\J2SDK1~1.2_0\jre\lib\rt.jar;.;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\ridl.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\unoil.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\jurt.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\juh.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\jut.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\java_uno.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\OOoRunner.jar
 org.openoffice.Runner -TestBase java_complex  -o 
complex.passwordcontainer.PasswordContainerUnitTest PasswordContainerTest 
TestHelper Test01 Test02 Test03 MasterPasswdHandler
TestJob: -o complex.passwordcontainer.PasswordContainerUnitTest
Searching Class: complex.passwordcontainer.PasswordContainerUnitTest
Got test: [EMAIL PROTECTED]
LOG> Log started 25.01.2008 - 16:29:56
LOG> Starting ExecuteTest01
LOG> Finished ExecuteTest01
LOG> Starting ExecuteTest02
LOG> Finished ExecuteTest02
LOG> Starting ExecuteTest03
LOG> Finished ExecuteTest03
***** State for complex.passwordcontainer.PasswordContainerUnitTest ******
Whole unit: PASSED.OK
**************************************************************************
Job -o complex.passwordcontainer.PasswordContainerUnitTest done
java -cp 
.;..\..\..\wntmsci10.pro\class;d:\OOEnv\J2SDK1~1.2_0\jre\lib\rt.jar;.;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\ridl.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\unoil.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\jurt.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\juh.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\jut.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\java_uno.jar;f:\ooo_SRC680_m238\solver\680\wntmsci10.pro\bin\OOoRunner.jar
 org.openoffice.Runner -TestBase java_complex  -o 
complex.passwordcontainer.PasswordContainerUnitTest PasswordContainerTest 
TestHelper Test01 Test02 Test03 MasterPasswdHandler
TestJob: -o complex.passwordcontainer.PasswordContainerUnitTest
Searching Class: complex.passwordcontainer.PasswordContainerUnitTest
Got test: [EMAIL PROTECTED]
LOG> Log started 25.01.2008 - 16:48:36
LOG> Starting ExecuteTest01
LOG> Finished ExecuteTest01
LOG> Starting ExecuteTest02
LOG> Test02: Error: Exception: java.lang.NullPointerException
LOG> Test02 failed!
LOG> Finished ExecuteTest02
LOG> Starting ExecuteTest03
LOG> Test03: Error: Exception: java.lang.NullPointerException
LOG> Test03 failed!
LOG> Finished ExecuteTest03
***** State for complex.passwordcontainer.PasswordContainerUnitTest ******
ExecuteTest02 - Test02 failed!

ExecuteTest03 - Test03 failed!


Whole unit: PASSED.FAILED
**************************************************************************
Job -o complex.passwordcontainer.PasswordContainerUnitTest failed
'---* tg_merge.mk *---'
dmake:  Error executing 'D:\OOEnv\4NT400\4NT.EXE': No error
dmake:  Error code 255, while making 'run'
#*************************************************************************
#
#   OpenOffice.org - a multi-platform office productivity suite
#
#   $RCSfile: makefile.mk,v $
#
#   $Revision: 1.11 $
#
#   last change: $Author: obo $ $Date: 2006/10/13 11:46:54 $
#
#   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
#
#*************************************************************************

PRJ = ..$/..$/..
TARGET  = PasswordContainerUnitTest
PRJNAME = svtools
PACKAGE = complex$/passwordcontainer

# --- Settings -----------------------------------------------------
.INCLUDE: settings.mk


#----- compile .java files -----------------------------------------

JARFILES        = ridl.jar unoil.jar jurt.jar juh.jar jut.jar java_uno.jar 
OOoRunner.jar

JAVAFILES       =\
                                PasswordContainerUnitTest.java\
                                PasswordContainerTest.java\
                                TestHelper.java\
                                Test01.java\
                Test02.java\
                Test03.java\
                                MasterPasswdHandler.java

JAVACLASSFILES  = $(foreach,i,$(JAVAFILES) 
$(CLASSDIR)$/$(PACKAGE)$/$(i:b).class)

#----- make a jar from compiled files ------------------------------

MAXLINELENGTH = 100000

JARCLASSDIRS    = $(PACKAGE)
JARTARGET       = $(TARGET).jar
JARCOMPRESS     = TRUE

# --- Parameters for the test --------------------------------------

# start an office if the parameter is set for the makefile
.IF "$(OFFICE)" == ""
CT_APPEXECCOMMAND =
.ELSE
CT_APPEXECCOMMAND = -AppExecutionCommand "$(OFFICE)$/soffice 
-accept=socket,host=localhost,port=8100;urp;"
.ENDIF

# test base is java complex
CT_TESTBASE = -TestBase java_complex

# test looks something like the.full.package.TestName
CT_TEST     = -o $(PACKAGE:s\$/\.\).$(JAVAFILES:b)

# start the runner application
CT_APP      = org.openoffice.Runner

# --- Targets ------------------------------------------------------

.INCLUDE: target.mk

RUN: run

run:
    +java -cp $(CLASSPATH) $(CT_APP) $(CT_TESTBASE) $(CT_APPEXECCOMMAND) 
$(CT_TEST)


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author zxf
 */

package complex.passwordcontainer;

import com.sun.star.lib.uno.helper.WeakBase;
import com.sun.star.task.XInteractionContinuation;
import com.sun.star.ucb.XInteractionSupplyAuthentication;
import com.sun.star.task.XInteractionRequest;
import com.sun.star.task.XInteractionHandler;
import com.sun.star.task.MasterPasswordRequest;
import com.sun.star.uno.UnoRuntime;

public class MasterPasswdHandler extends WeakBase 
        implements XInteractionHandler {
    XInteractionHandler m_xHandler;
    
    public MasterPasswdHandler( XInteractionHandler xHandler ) {
        m_xHandler = xHandler;
    }
    
    public void handle( XInteractionRequest xRequest ) {
        try {
            MasterPasswordRequest aMasterPasswordRequest;
            if( xRequest.getRequest() instanceof MasterPasswordRequest ) {
                aMasterPasswordRequest = (MasterPasswordRequest)xRequest.getRequest();
                if( aMasterPasswordRequest != null ) {
                    XInteractionContinuation xContinuations[] = xRequest.getContinuations();
                    XInteractionSupplyAuthentication xAuthentication = null;

                    for( int i = 0; i < xContinuations.length; ++i ) {
                        xAuthentication = (XInteractionSupplyAuthentication)UnoRuntime.queryInterface( XInteractionSupplyAuthentication.class, xContinuations[i]);
                        if( xAuthentication != null )
                            break;
                    }
                    if( xAuthentication.canSetPassword() )
                        xAuthentication.setPassword( "abcdefghijklmnopqrstuvwxyz123456" );
                    xAuthentication.select();
                }
            } else {
                m_xHandler.handle( xRequest );
            }
        } catch( Exception e ) {
            System.out.println( "MasterPasswordHandler Error: " + e );
        }
    }
}







/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: StorageUnitTest.java,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: obo $ $Date: 2006/10/13 11:45:51 $
 *
 *  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.passwordcontainer;

public interface PasswordContainerTest {
    boolean test();
}
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: StorageUnitTest.java,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: obo $ $Date: 2006/10/13 11:45:51 $
 *
 *  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.passwordcontainer;

import complexlib.ComplexTestCase;
import com.sun.star.lang.XMultiServiceFactory;

public class PasswordContainerUnitTest extends ComplexTestCase {
    private XMultiServiceFactory m_xMSF = null;
    
    public String[] getTestMethodNames() {
        return new String[] {
            "ExecuteTest01",
            "ExecuteTest02",
            "ExecuteTest03"};
    }
    public String getTestObjectName() {
        return "PasswordContainerUnitTest";
    }
    
    public void before() {
        try {
            m_xMSF = (XMultiServiceFactory) param.getMSF();
        } catch (Exception e) {
            failed ("Cannot create service factory!");
        }
        if (m_xMSF == null) {
            failed ("Cannot create service factory!");
        }
    }
    
    public void after() {
        m_xMSF = null;
    }
    
    public void ExecuteTest01() {
        PasswordContainerTest aTest = new Test01(m_xMSF, log);
        assure("Test01 failed!", aTest.test());
    }
    public void ExecuteTest02() {
        PasswordContainerTest aTest = new Test02(m_xMSF, log);
        assure("Test02 failed!", aTest.test());
    }
    public void ExecuteTest03() {
        PasswordContainerTest aTest = new Test03(m_xMSF, log);
        assure("Test03 failed!", aTest.test());
    }
}
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: StorageUnitTest.java,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: obo $ $Date: 2006/10/13 11:45:51 $
 *
 *  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.passwordcontainer;

import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.task.XInteractionHandler;
import com.sun.star.task.XPasswordContainer;
import com.sun.star.task.UrlRecord;
import com.sun.star.task.UserRecord;
import com.sun.star.task.XMasterPasswordHandling;

import com.sun.star.uno.UnoRuntime;

import share.LogWriter;

public class Test01 implements PasswordContainerTest {
    XMultiServiceFactory m_xMSF = null;
    XPasswordContainer m_xPasswordContainer = null;
    TestHelper m_aTestHelper = null;
    
    public Test01 ( XMultiServiceFactory xMSF, LogWriter aLogWriter )
    {
        m_xMSF = xMSF;
        m_aTestHelper = new TestHelper (aLogWriter, "Test01: ");
    }
    
    public boolean test() {
        final String sURL = "http://www.openoffice.org";;
        final String sUserPre = "OOoUser";
        final String sPwdPre = "Password";
        final int iUserNum1 = 10;   
        final int iUserNum2 = 5;
        
        UserRecord aInputUserList1[] = new UserRecord[iUserNum1];
        for(int i = 0; i < iUserNum1; i++) {
            String sTemp[] = {sPwdPre + "_1_" + i};     // currently one password for one user 
            aInputUserList1[i] = new UserRecord(sUserPre + "_1_" + i, sTemp);
        }
        UserRecord aInputUserList2[] = new UserRecord[iUserNum2];
        for(int i = 0; i < iUserNum2; i++) {
            String sTemp[] = {sPwdPre + "_2_" + i};
            aInputUserList2[i] = new UserRecord(sUserPre + "_2_" + i, sTemp);
        }
        try {
            Object oPasswordContainer = m_xMSF.createInstance( "com.sun.star.task.PasswordContainer" );
            XPasswordContainer xContainer = (XPasswordContainer)UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer);
            Object oHandler = m_xMSF.createInstance( "com.sun.star.task.InteractionHandler" );
            XInteractionHandler xHandler = (XInteractionHandler)UnoRuntime.queryInterface(XInteractionHandler.class, oHandler);
            MasterPasswdHandler aMHandler = new MasterPasswdHandler( xHandler );
            
            // add a set of users and passwords for the same URL for runtime 
            for(int i = 0; i < iUserNum1; i++) {
                xContainer.add(sURL, aInputUserList1[i].UserName, aInputUserList1[i].Passwords, aMHandler);
            }
            for (int i = 0; i < iUserNum2; i++) {
                xContainer.add(sURL, aInputUserList2[i].UserName, aInputUserList2[i].Passwords, aMHandler);
            }

            // remove some of the passwords 
            for (int i = 0; i < iUserNum1; i++) {
                xContainer.remove(sURL, aInputUserList1[i].UserName);
            }
            
            // get the result and check it with the expected one 
            UrlRecord aRecord = xContainer.find(sURL, aMHandler);
            if(!aRecord.Url.equals(sURL)) {
                m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL);
                return false;
            }
            if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList2)) {
                m_aTestHelper.Error("User list is not the expected");
                return false;
            }
            
            // remove the runtime passwords
            aRecord = xContainer.find(sURL, aMHandler);
            for(int i = 0; i < aRecord.UserList.length; i++) {
                xContainer.remove(sURL, aRecord.UserList[i].UserName);
            }
        } catch(Exception e) {
            m_aTestHelper.Error("Exception: " + e);
            return false;
        }
        return true;
    }
}
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: StorageUnitTest.java,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: obo $ $Date: 2006/10/13 11:45:51 $
 *
 *  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.passwordcontainer;

import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.task.XPasswordContainer;
import com.sun.star.task.XMasterPasswordHandling;
import com.sun.star.task.XInteractionHandler;
import com.sun.star.task.UrlRecord;
import com.sun.star.task.UserRecord;

import com.sun.star.uno.UnoRuntime;

import share.LogWriter;

public class Test02 implements PasswordContainerTest {
    XMultiServiceFactory m_xMSF = null;
    XPasswordContainer m_xPasswordContainer = null;
    TestHelper m_aTestHelper = null;
    
    public Test02 ( XMultiServiceFactory xMSF, LogWriter aLogWriter )
    {
        m_xMSF = xMSF;
        m_aTestHelper = new TestHelper (aLogWriter, "Test02: ");
    }
    
    public boolean test() {
        final String sURL = "http://www.openoffice.org";;
        final String sUserPre = "OOoUser";
        final String sPwdPre = "Password";
        final int iUserNum1 = 10;   
        final int iUserNum2 = 5;
                
        UserRecord aInputUserList1[] = new UserRecord[iUserNum1];
        for(int i = 0; i < iUserNum1; i++) {
            String sTemp[] = {sPwdPre + "_1_" + i};     // currently one password for one user 
            aInputUserList1[i] = new UserRecord(sUserPre + "_1_" + i, sTemp);
        }
        UserRecord aInputUserList2[] = new UserRecord[iUserNum2];
        for(int i = 0; i < iUserNum2; i++) {
            String sTemp[] = {sPwdPre + "_2_" + i};
            aInputUserList2[i] = new UserRecord(sUserPre + "_2_" + i, sTemp);
        }
        
        try {
            Object oPasswordContainer = m_xMSF.createInstance("com.sun.star.task.PasswordContainer");
            XPasswordContainer xContainer = (XPasswordContainer)UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer);
            Object oHandler = m_xMSF.createInstance("com.sun.star.task.InteractionHandler");
            XInteractionHandler xHandler = (XInteractionHandler)UnoRuntime.queryInterface(XInteractionHandler.class, oHandler);
            MasterPasswdHandler aMHandler = new MasterPasswdHandler(xHandler);
            XMasterPasswordHandling xMHandling = (XMasterPasswordHandling)UnoRuntime.queryInterface(XMasterPasswordHandling.class, oPasswordContainer);
            
            // allow the storing of the passwords 
            xMHandling.allowPersistentStoring(true);
            
            // add a set of users and passwords for the same URL persistently 
            for(int i = 0; i < iUserNum1; ++i) {
                xContainer.addPersistent(sURL, aInputUserList1[i].UserName, aInputUserList1[i].Passwords, aMHandler);
            }
            for(int i = 0; i < iUserNum2; ++i) {
                xContainer.addPersistent(sURL, aInputUserList2[i].UserName, aInputUserList2[i].Passwords, aMHandler);
            }
            
            // remove some of the passwords
            for(int i = 0; i < iUserNum1; ++i) {
                xContainer.remove(sURL, aInputUserList1[i].UserName);
            }
            
            // get the result with find() and check it with the expected one
            UrlRecord aRecord = xContainer.find(sURL, aMHandler);
            if(!aRecord.Url.equals(sURL)) {
                m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL);
                return false;
            }
            if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList2)) {
                m_aTestHelper.Error("User list is not the expected");
                return false;
            }
            
            // get the result with getAllPersistent() and check
            UrlRecord aRecords[] = xContainer.getAllPersistent(aMHandler);
            if(!aRecords[0].Url.equals(sURL)) {
                m_aTestHelper.Error("URL mismatch");
                return false;
            }
            if(!m_aTestHelper.sameLists(aRecords[0].UserList, aInputUserList2)) {
                m_aTestHelper.Error("User list is not the expected");
                return false;
            }
            
            // remove all the persistent passwords 
            xContainer.removeAllPersistent();
            
            // remove the runtime passwords 
            for(int i = 0; i < aRecords[0].UserList.length; ++i) {
                xContainer.remove(sURL, aRecords[0].UserList[i].UserName);
            }
            
            // disallow the storing of the passwords 
            xMHandling.allowPersistentStoring(false);
        } catch(Exception e) {
            m_aTestHelper.Error("Exception: " + e);
            return false;
        }
        return true;
    }
}























/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: StorageUnitTest.java,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: obo $ $Date: 2006/10/13 11:45:51 $
 *
 *  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.passwordcontainer;

import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.task.UrlRecord;
import com.sun.star.task.UserRecord;
import com.sun.star.task.XPasswordContainer;
import com.sun.star.task.XMasterPasswordHandling;
import com.sun.star.task.XInteractionHandler;


import com.sun.star.uno.UnoRuntime;
import share.LogWriter;

public class Test03 implements PasswordContainerTest {
    XMultiServiceFactory m_xMSF = null;
    XPasswordContainer m_xPasswordContainer = null;
    TestHelper m_aTestHelper = null;
    
    public Test03 ( XMultiServiceFactory xMSF, LogWriter aLogWriter )
    {
        m_xMSF = xMSF;
        m_aTestHelper = new TestHelper (aLogWriter, "Test03: ");
    }
    
    public boolean test() {
        final String sURL = "http://www.openoffice.org";;
        final String sUserPre = "OOoUser";
        final String sPwdPre = "Password";
        final int iPersistentUserNum = 10;   
        final int iRuntimeUserNum = 5;
        
        UserRecord aInputUserList[] = new UserRecord[iPersistentUserNum+iRuntimeUserNum];
        for(int i = 0; i < iPersistentUserNum; i++) {
            String sTemp[] = {sPwdPre + "_1_" + i};     // currently one password for one user 
            aInputUserList[i] = new UserRecord(sUserPre + "_1_" + i, sTemp);
        }
        for(int i = 0; i < iRuntimeUserNum; i++) {
            String sTemp[] = {sPwdPre + "_2_" + i};
            aInputUserList[i+iPersistentUserNum] = new UserRecord(sUserPre + "_2_" + i, sTemp);
        }
        
        try {
            Object oPasswordContainer = m_xMSF.createInstance("com.sun.star.task.PasswordContainer");
            XPasswordContainer xContainer = (XPasswordContainer)UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer);
            Object oHandler = m_xMSF.createInstance("com.sun.star.task.InteractionHandler");
            XInteractionHandler xHandler = (XInteractionHandler)UnoRuntime.queryInterface(XInteractionHandler.class, oHandler);
            MasterPasswdHandler aMHandler = new MasterPasswdHandler(xHandler);
            XMasterPasswordHandling xMHandling = (XMasterPasswordHandling)UnoRuntime.queryInterface(XMasterPasswordHandling.class, oPasswordContainer);
            
            // allow the storing of the passwords 
            xMHandling.allowPersistentStoring(true);
            
            // add a set of users and passwords for the same URL persistently 
            for(int i = 0; i < iPersistentUserNum; i++) {
                xContainer.addPersistent(sURL, aInputUserList[i].UserName, aInputUserList[i].Passwords, aMHandler);
            }
            
            // add a set of users and passwords for the same URL for runtime 
            for(int i = 0; i < iRuntimeUserNum; i++) {
                xContainer.add(sURL, aInputUserList[i+iPersistentUserNum].UserName, aInputUserList[i+iPersistentUserNum].Passwords, aMHandler);
            }
            
            // get the result for the URL and check that it contains persistent and runtime passwords
            UrlRecord aRecord = xContainer.find(sURL, aMHandler);
            if(!aRecord.Url.equals(sURL)) {
                m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL);
                return false;
            }
            if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList)) {
                m_aTestHelper.Error("User list is not the expected");
                return false;
            }
            
            // remove all the persistent passwords 
            xContainer.removeAllPersistent();
            
             // remove the runtime passwords 
            aRecord = xContainer.find(sURL, aMHandler);
            for(int i = 0; i < aRecord.UserList.length; i++) {
                xContainer.remove(sURL, aRecord.UserList[i].UserName);
            }
            
            // disallow the storing of the passwords 
            xMHandling.allowPersistentStoring(false);
        }catch(Exception e){
            m_aTestHelper.Error("Exception: " + e);
            return false;
        }
        return true;
    }
}
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: StorageUnitTest.java,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: obo $ $Date: 2006/10/13 11:45:51 $
 *
 *  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.passwordcontainer;

import com.sun.star.task.UserRecord;

import share.LogWriter;

public class TestHelper {
    LogWriter m_aLogWriter;
    String m_sTestPrefix;
    
    public TestHelper( LogWriter aLogWriter, String sTestPrefix ) {
        m_aLogWriter = aLogWriter;
        m_sTestPrefix = sTestPrefix;
    }
    
    public void Error( String sError ) {
        m_aLogWriter.println( m_sTestPrefix + "Error: " + sError );
    }
    
    public void Message( String sMessage ) {
        m_aLogWriter.println( m_sTestPrefix + sMessage );
    }
    
    public boolean sameLists(UserRecord aUserList1[], UserRecord aUserList2[]) {
        // only works when every name is unique within the list containing it
        
        if(aUserList1.length != aUserList2.length) {
            Message("User list lengths: " + aUserList1.length + " <--> " + aUserList2.length + " respectively ");
            return false;
        }
        
        for(int i = 0; i < aUserList1.length; i++) {
            int j;
            for(j = 0; j < aUserList2.length; j++) {
                if(!aUserList1[i].UserName.equals(aUserList2[j].UserName)) 
                    continue;
                if(aUserList1[i].Passwords[0].equals(aUserList2[j].Passwords[0])) {
                    break;
                }
            }
            if(j == aUserList2.length) {
                for(int k = 0; k < aUserList1.length; k++) {
                    Message(aUserList1[k].UserName + " <--> " + aUserList2[i].UserName);
                }
                return false;
            }
        }
        return true;
    }
}











---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to