diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /svl/qa/complex | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | svl/qa/complex/ConfigItems/CheckConfigItems.java | 156 | ||||
-rw-r--r-- | svl/qa/complex/passwordcontainer/MasterPasswdHandler.java | 73 | ||||
-rw-r--r-- | svl/qa/complex/passwordcontainer/PasswordContainerTest.java | 23 | ||||
-rw-r--r-- | svl/qa/complex/passwordcontainer/PasswordContainerUnitTest.java | 84 | ||||
-rw-r--r-- | svl/qa/complex/passwordcontainer/Test01.java | 98 | ||||
-rw-r--r-- | svl/qa/complex/passwordcontainer/Test02.java | 144 | ||||
-rw-r--r-- | svl/qa/complex/passwordcontainer/Test03.java | 108 | ||||
-rw-r--r-- | svl/qa/complex/passwordcontainer/TestHelper.java | 78 |
8 files changed, 764 insertions, 0 deletions
diff --git a/svl/qa/complex/ConfigItems/CheckConfigItems.java b/svl/qa/complex/ConfigItems/CheckConfigItems.java new file mode 100644 index 000000000..6503505f3 --- /dev/null +++ b/svl/qa/complex/ConfigItems/CheckConfigItems.java @@ -0,0 +1,156 @@ +/* + * 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 . + */ + +package complex.ConfigItems; + +import com.sun.star.beans.NamedValue; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.task.XJob; +import com.sun.star.uno.UnoRuntime; + + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; + + +/** @short todo document me + * @deprecated this tests seems no longer work as expected. + */ +@Deprecated +public class CheckConfigItems +{ + + // some const + + + // member + + /** points to the global uno service manager. */ + private XMultiServiceFactory m_xSmgr = null; + + /** implements real config item tests in C++. */ + private XJob m_xTest = null; + + + // test environment + + + /** @short Create the environment for following tests. + + * @descr Use either a component loader from desktop or + from frame + */ + @Before public void before() + throws java.lang.Exception + { + // get uno service manager from global test environment + m_xSmgr = getMSF(); + + // TODO register helper service + + // create module manager + m_xTest = UnoRuntime.queryInterface(XJob.class, m_xSmgr.createInstance("com.sun.star.comp.svl.ConfigItemTest")); + } + + + /** + * @short close the environment. + */ + @After public void after() + throws java.lang.Exception + { + // TODO deregister helper service + + m_xTest = null; + m_xSmgr = null; + } + + + @Test public void checkPicklist() + throws java.lang.Exception + { + impl_triggerTest("checkPicklist"); + } + + + @Test public void checkURLHistory() + throws java.lang.Exception + { + impl_triggerTest("checkURLHistory"); + } + + + @Test public void checkHelpBookmarks() + throws java.lang.Exception + { + impl_triggerTest("checkHelpBookmarks"); + } + + + @Test public void checkAccessibilityOptions() + throws java.lang.Exception + { + impl_triggerTest("checkAccessibilityOptions"); + } + + + @Test public void checkUserOptions() + throws java.lang.Exception + { + impl_triggerTest("checkUserOptions"); + } + + + /** @todo document me + */ + private void impl_triggerTest(String sTest) + throws java.lang.Exception + { + NamedValue[] lArgs = new NamedValue[1]; + lArgs[0] = new NamedValue(); + lArgs[0].Name = "Test"; + lArgs[0].Value = sTest; + m_xTest.execute(lArgs); + } + + + private XMultiServiceFactory getMSF() + { + return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + } + + // setup and close connections + @BeforeClass public static void setUpConnection() throws Exception { + System.out.println("setUpConnection()"); + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + System.out.println("tearDownConnection()"); + connection.tearDown(); + } + + private static final OfficeConnection connection = new OfficeConnection(); + +} diff --git a/svl/qa/complex/passwordcontainer/MasterPasswdHandler.java b/svl/qa/complex/passwordcontainer/MasterPasswdHandler.java new file mode 100644 index 000000000..9c9eec41c --- /dev/null +++ b/svl/qa/complex/passwordcontainer/MasterPasswdHandler.java @@ -0,0 +1,73 @@ +/* + * 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 . + */ + +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 { + private final 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 = 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 ); + } + } +} + + + + + + + diff --git a/svl/qa/complex/passwordcontainer/PasswordContainerTest.java b/svl/qa/complex/passwordcontainer/PasswordContainerTest.java new file mode 100644 index 000000000..b96a0986d --- /dev/null +++ b/svl/qa/complex/passwordcontainer/PasswordContainerTest.java @@ -0,0 +1,23 @@ +/* + * 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 . + */ + +package complex.passwordcontainer; + +interface PasswordContainerTest { + boolean test(); +} diff --git a/svl/qa/complex/passwordcontainer/PasswordContainerUnitTest.java b/svl/qa/complex/passwordcontainer/PasswordContainerUnitTest.java new file mode 100644 index 000000000..1de047a36 --- /dev/null +++ b/svl/qa/complex/passwordcontainer/PasswordContainerUnitTest.java @@ -0,0 +1,84 @@ +/* + * 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 . + */ + +package complex.passwordcontainer; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; + +public class PasswordContainerUnitTest { + private XMultiServiceFactory m_xMSF = null; + + @Before public void before() { + try { + m_xMSF = getMSF(); + } catch (Exception e) { + fail ("Cannot create service factory!"); + } + if (m_xMSF == null) { + fail ("Cannot create service factory!"); + } + } + + @After public void after() { + m_xMSF = null; + } + + @Test public void ExecuteTest01() + { + PasswordContainerTest aTest = new Test01(m_xMSF); + assertTrue("Test01 failed!", aTest.test()); + } + @Test public void ExecuteTest02() { + PasswordContainerTest aTest = new Test02(m_xMSF); + assertTrue("Test02 failed!", aTest.test()); + } + @Test public void ExecuteTest03() { + PasswordContainerTest aTest = new Test03(m_xMSF); + assertTrue("Test03 failed!", aTest.test()); + } + + private XMultiServiceFactory getMSF() + { + return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + } + + // setup and close connections + @BeforeClass public static void setUpConnection() throws Exception { + System.out.println("setUpConnection()"); + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + System.out.println("tearDownConnection()"); + connection.tearDown(); + } + + private static final OfficeConnection connection = new OfficeConnection(); + +} diff --git a/svl/qa/complex/passwordcontainer/Test01.java b/svl/qa/complex/passwordcontainer/Test01.java new file mode 100644 index 000000000..094259b1b --- /dev/null +++ b/svl/qa/complex/passwordcontainer/Test01.java @@ -0,0 +1,98 @@ +/* + * 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 . + */ + +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.uno.UnoRuntime; + + +public class Test01 implements PasswordContainerTest { + private XMultiServiceFactory m_xMSF = null; + private TestHelper m_aTestHelper = null; + + public Test01 ( XMultiServiceFactory xMSF ) + { + m_xMSF = xMSF; + m_aTestHelper = new TestHelper ( "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 = UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer); + Object oHandler = m_xMSF.createInstance( "com.sun.star.task.InteractionHandler" ); + XInteractionHandler xHandler = 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; + } +} diff --git a/svl/qa/complex/passwordcontainer/Test02.java b/svl/qa/complex/passwordcontainer/Test02.java new file mode 100644 index 000000000..caffd223c --- /dev/null +++ b/svl/qa/complex/passwordcontainer/Test02.java @@ -0,0 +1,144 @@ +/* + * 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 . + */ + +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; + + +public class Test02 implements PasswordContainerTest { + private XMultiServiceFactory m_xMSF = null; + private TestHelper m_aTestHelper = null; + + public Test02 ( XMultiServiceFactory xMSF ) + { + m_xMSF = xMSF; + m_aTestHelper = new TestHelper ( "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 = UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer); + Object oHandler = m_xMSF.createInstance("com.sun.star.task.InteractionHandler"); + XInteractionHandler xHandler = UnoRuntime.queryInterface(XInteractionHandler.class, oHandler); + MasterPasswdHandler aMHandler = new MasterPasswdHandler(xHandler); + XMasterPasswordHandling xMHandling = 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; + } +} + + + + + + + + + + + + + + + + + + + + + + + diff --git a/svl/qa/complex/passwordcontainer/Test03.java b/svl/qa/complex/passwordcontainer/Test03.java new file mode 100644 index 000000000..fb49f4b99 --- /dev/null +++ b/svl/qa/complex/passwordcontainer/Test03.java @@ -0,0 +1,108 @@ +/* + * 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 . + */ + +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; + + +public class Test03 implements PasswordContainerTest { + private XMultiServiceFactory m_xMSF = null; + private TestHelper m_aTestHelper = null; + + public Test03 ( XMultiServiceFactory xMSF ) + { + m_xMSF = xMSF; + m_aTestHelper = new TestHelper ( "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 = UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer); + Object oHandler = m_xMSF.createInstance("com.sun.star.task.InteractionHandler"); + XInteractionHandler xHandler = UnoRuntime.queryInterface(XInteractionHandler.class, oHandler); + MasterPasswdHandler aMHandler = new MasterPasswdHandler(xHandler); + XMasterPasswordHandling xMHandling = 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; + } +} diff --git a/svl/qa/complex/passwordcontainer/TestHelper.java b/svl/qa/complex/passwordcontainer/TestHelper.java new file mode 100644 index 000000000..b6f1f0842 --- /dev/null +++ b/svl/qa/complex/passwordcontainer/TestHelper.java @@ -0,0 +1,78 @@ +/* + * 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 . + */ + +package complex.passwordcontainer; + +import com.sun.star.task.UserRecord; + + +public class TestHelper { + private String m_sTestPrefix; + + public TestHelper( String sTestPrefix ) { + m_sTestPrefix = sTestPrefix; + } + + public void Error( String sError ) { + System.out.println( m_sTestPrefix + "Error: " + sError ); + } + + private void Message( String sMessage ) { + System.out.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; + } +} + + + + + + + + + + + |