android: Update app-specific/MIME type icons
[LibreOffice.git] / svl / qa / complex / passwordcontainer / Test02.java
blobcaffd223ce5ae5cd2e66fe267a84c31b700941ba
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.XPasswordContainer;
23 import com.sun.star.task.XMasterPasswordHandling;
24 import com.sun.star.task.XInteractionHandler;
25 import com.sun.star.task.UrlRecord;
26 import com.sun.star.task.UserRecord;
28 import com.sun.star.uno.UnoRuntime;
31 public class Test02 implements PasswordContainerTest {
32 private XMultiServiceFactory m_xMSF = null;
33 private TestHelper m_aTestHelper = null;
35 public Test02 ( XMultiServiceFactory xMSF )
37 m_xMSF = xMSF;
38 m_aTestHelper = new TestHelper ( "Test02: ");
41 public boolean test() {
42 final String sURL = "http://www.openoffice.org";
43 final String sUserPre = "OOoUser";
44 final String sPwdPre = "Password";
45 final int iUserNum1 = 10;
46 final int iUserNum2 = 5;
48 UserRecord aInputUserList1[] = new UserRecord[iUserNum1];
49 for(int i = 0; i < iUserNum1; i++) {
50 String sTemp[] = {sPwdPre + "_1_" + i}; // currently one password for one user
51 aInputUserList1[i] = new UserRecord(sUserPre + "_1_" + i, sTemp);
53 UserRecord aInputUserList2[] = new UserRecord[iUserNum2];
54 for(int i = 0; i < iUserNum2; i++) {
55 String sTemp[] = {sPwdPre + "_2_" + i};
56 aInputUserList2[i] = 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 < iUserNum1; ++i) {
72 xContainer.addPersistent(sURL, aInputUserList1[i].UserName, aInputUserList1[i].Passwords, aMHandler);
74 for(int i = 0; i < iUserNum2; ++i) {
75 xContainer.addPersistent(sURL, aInputUserList2[i].UserName, aInputUserList2[i].Passwords, aMHandler);
78 // remove some of the passwords
79 for(int i = 0; i < iUserNum1; ++i) {
80 xContainer.remove(sURL, aInputUserList1[i].UserName);
83 // get the result with find() and check it with the expected one
84 UrlRecord aRecord = xContainer.find(sURL, aMHandler);
85 if(!aRecord.Url.equals(sURL)) {
86 m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL);
87 return false;
89 if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList2)) {
90 m_aTestHelper.Error("User list is not the expected");
91 return false;
94 // get the result with getAllPersistent() and check
95 UrlRecord aRecords[] = xContainer.getAllPersistent(aMHandler);
96 if(!aRecords[0].Url.equals(sURL)) {
97 m_aTestHelper.Error("URL mismatch");
98 return false;
100 if(!m_aTestHelper.sameLists(aRecords[0].UserList, aInputUserList2)) {
101 m_aTestHelper.Error("User list is not the expected");
102 return false;
105 // remove all the persistent passwords
106 xContainer.removeAllPersistent();
108 // remove the runtime passwords
109 for(int i = 0; i < aRecords[0].UserList.length; ++i) {
110 xContainer.remove(sURL, aRecords[0].UserList[i].UserName);
113 // disallow the storing of the passwords
114 xMHandling.allowPersistentStoring(false);
115 } catch(Exception e) {
116 m_aTestHelper.Error("Exception: " + e);
117 return false;
119 return true;