Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / testtools / com / sun / star / comp / bridge / CurrentContextChecker.java
blob6841f77b1fe9b3819566cbd93e691130c6c060c1
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 com.sun.star.comp.bridge;
21 import com.sun.star.uno.Any;
22 import com.sun.star.uno.Type;
23 import com.sun.star.uno.UnoRuntime;
24 import com.sun.star.uno.XCurrentContext;
25 import test.testtools.bridgetest.XCurrentContextChecker;
27 final class CurrentContextChecker implements XCurrentContextChecker {
30 public boolean perform(
31 XCurrentContextChecker other, int setSteps, int checkSteps)
33 if (setSteps == 0) {
34 XCurrentContext old = UnoRuntime.getCurrentContext();
35 UnoRuntime.setCurrentContext(
36 new XCurrentContext() {
37 public Object getValueByName(String Name) {
38 return Name.equals(KEY)
39 ? (Object) VALUE : (Object) Any.VOID;
41 });
42 try {
43 return performCheck(other, setSteps, checkSteps);
44 } finally {
45 UnoRuntime.setCurrentContext(old);
47 } else {
48 return performCheck(other, setSteps, checkSteps);
52 private boolean performCheck(
53 XCurrentContextChecker other, int setSteps, int checkSteps)
55 // assert other != null && checkSteps >= 0;
56 if (checkSteps == 0) {
57 XCurrentContext context = UnoRuntime.getCurrentContext();
58 if (context == null) {
59 return false;
61 Any a = Any.complete(context.getValueByName(KEY));
62 return
63 a.getType().equals(Type.STRING) && a.getObject().equals(VALUE);
64 } else {
65 return other.perform(
66 this, setSteps >= 0 ? setSteps - 1 : -1, checkSteps - 1);
70 private static final String KEY = "testtools.bridgetest.Key";
71 private static final String VALUE = "good";