Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XStringSubstitution.java
blob77d5fe5fbb43aeafc60de51ca6d5215c9ecaf77c
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 ifc.util;
21 import com.sun.star.util.XStringSubstitution;
22 import lib.MultiMethodTest;
24 public class _XStringSubstitution extends MultiMethodTest {
26 public XStringSubstitution oObj;
28 public void _getSubstituteVariableValue() {
29 boolean res = true;
30 try {
31 log.println("try to get the valid variable $(user) ...");
32 String toCheck = "$(user)";
33 String eString = oObj.getSubstituteVariableValue(toCheck);
34 res = eString.startsWith("file:///");
35 } catch (com.sun.star.container.NoSuchElementException e) {
36 log.println("$(user) does not exist");
37 tRes.tested("getSubstituteVariableValue()",false);
39 try {
40 log.println("try to get an invalid variable...");
41 String toCheck = "$(ThisVariableShouldNoExist)";
42 oObj.getSubstituteVariableValue(toCheck);
43 log.println("$(ThisVariableShouldNoExist) should not exist");
44 tRes.tested("getSubstituteVariableValue()",false);
46 } catch (com.sun.star.container.NoSuchElementException e) {
47 log.println("expected exception was thrown.");
48 res &= true;
51 tRes.tested("getSubstituteVariableValue()",res);
54 public void _substituteVariables() {
55 boolean res = true;
56 try {
57 log.println("try to get a valid variable...");
58 String toCheck = "$(user)";
59 String eString = oObj.substituteVariables(toCheck, false);
60 log.println(eString);
61 res = eString.startsWith("file:///");
62 } catch (com.sun.star.container.NoSuchElementException e) {
63 log.println("$(user) does not exist");
64 tRes.tested("substituteVariables()",false);
66 try {
67 log.println("try to get an invalid variable...");
68 String toCheck = "$(ThisVariableShouldNoExist)";
69 oObj.substituteVariables(toCheck,true);
70 log.println("$(ThisVariableShouldNoExist) should not exist");
71 tRes.tested("substituteVariables()",false);
73 } catch (com.sun.star.container.NoSuchElementException e) {
74 log.println("expected exception was thrown.");
75 res &= true;
78 tRes.tested("substituteVariables()",res);
81 public void _reSubstituteVariables() {
82 boolean res = true;
83 log.println("try to get a valid variable...");
84 String toCheck = "file:///";
85 String eString = oObj.reSubstituteVariables(toCheck);
86 log.println(eString);
87 res = eString.startsWith("file:///");
89 tRes.tested("reSubstituteVariables()",res);