android: Update app-specific/MIME type icons
[LibreOffice.git] / svl / qa / complex / passwordcontainer / Test03.java
blobfb49f4b99a0f81cb9aec2e0c175a95e2736ae9c0
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package complex.passwordcontainer;
21 import com.sun.star.lang.XMultiServiceFactory;
22 import com.sun.star.task.UrlRecord;
23 import com.sun.star.task.UserRecord;
24 import com.sun.star.task.XPasswordContainer;
25 import com.sun.star.task.XMasterPasswordHandling;
26 import com.sun.star.task.XInteractionHandler;
29 import com.sun.star.uno.UnoRuntime;
32 public class Test03 implements PasswordContainerTest {
33 private XMultiServiceFactory m_xMSF = null;
34 private TestHelper m_aTestHelper = null;
36 public Test03 ( XMultiServiceFactory xMSF )
38 m_xMSF = xMSF;
39 m_aTestHelper = new TestHelper ( "Test03: ");
42 public boolean test() {
43 final String sURL = "http://www.openoffice.org";
44 final String sUserPre = "OOoUser";
45 final String sPwdPre = "Password";
46 final int iPersistentUserNum = 10;
47 final int iRuntimeUserNum = 5;
49 UserRecord aInputUserList[] = new UserRecord[iPersistentUserNum+iRuntimeUserNum];
50 for(int i = 0; i < iPersistentUserNum; i++) {
51 String sTemp[] = {sPwdPre + "_1_" + i}; // currently one password for one user
52 aInputUserList[i] = new UserRecord(sUserPre + "_1_" + i, sTemp);
54 for(int i = 0; i < iRuntimeUserNum; i++) {
55 String sTemp[] = {sPwdPre + "_2_" + i};
56 aInputUserList[i+iPersistentUserNum] = new UserRecord(sUserPre + "_2_" + i, sTemp);
59 try {
60 Object oPasswordContainer = m_xMSF.createInstance("com.sun.star.task.PasswordContainer");
61 XPasswordContainer xContainer = UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer);
62 Object oHandler = m_xMSF.createInstance("com.sun.star.task.InteractionHandler");
63 XInteractionHandler xHandler = UnoRuntime.queryInterface(XInteractionHandler.class, oHandler);
64 MasterPasswdHandler aMHandler = new MasterPasswdHandler(xHandler);
65 XMasterPasswordHandling xMHandling = UnoRuntime.queryInterface(XMasterPasswordHandling.class, oPasswordContainer);
67 // allow the storing of the passwords
68 xMHandling.allowPersistentStoring(true);
70 // add a set of users and passwords for the same URL persistently
71 for(int i = 0; i < iPersistentUserNum; i++) {
72 xContainer.addPersistent(sURL, aInputUserList[i].UserName, aInputUserList[i].Passwords, aMHandler);
75 // add a set of users and passwords for the same URL for runtime
76 for(int i = 0; i < iRuntimeUserNum; i++) {
77 xContainer.add(sURL, aInputUserList[i+iPersistentUserNum].UserName, aInputUserList[i+iPersistentUserNum].Passwords, aMHandler);
80 // get the result for the URL and check that it contains persistent and runtime passwords
81 UrlRecord aRecord = xContainer.find(sURL, aMHandler);
82 if(!aRecord.Url.equals(sURL)) {
83 m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL);
84 return false;
86 if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList)) {
87 m_aTestHelper.Error("User list is not the expected");
88 return false;
91 // remove all the persistent passwords
92 xContainer.removeAllPersistent();
94 // remove the runtime passwords
95 aRecord = xContainer.find(sURL, aMHandler);
96 for(int i = 0; i < aRecord.UserList.length; i++) {
97 xContainer.remove(sURL, aRecord.UserList[i].UserName);
100 // disallow the storing of the passwords
101 xMHandling.allowPersistentStoring(false);
102 }catch(Exception e){
103 m_aTestHelper.Error("Exception: " + e);
104 return false;
106 return true;