Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / configuration / backend / _XSchemaSupplier.java
blobaee858b6a6470dd8c8bcf903f418bd8bfb610f48
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 .
18 package ifc.configuration.backend;
20 import com.sun.star.configuration.backend.XSchema;
21 import com.sun.star.configuration.backend.XSchemaSupplier;
23 import lib.MultiMethodTest;
24 import util.XSchemaHandlerImpl;
26 public class _XSchemaSupplier extends MultiMethodTest {
27 public XSchemaSupplier oObj;
29 public void _getComponentSchema() {
30 boolean res = true;
31 XSchema aSchema = null;
33 try {
34 aSchema = oObj.getComponentSchema("org.openoffice.Office.Linguistic");
35 res &= (aSchema != null);
37 if (aSchema == null) {
38 log.println("\treturned Layer is NULL -- FAILED");
39 } else {
40 res &= checkSchema(aSchema);
42 } catch (com.sun.star.configuration.backend.BackendAccessException e) {
43 log.println("Unexpected Exception (" + e + ") -- FAILED");
44 res &= false;
45 } catch (com.sun.star.lang.IllegalArgumentException e) {
46 log.println("Unexpected Exception (" + e + ") -- FAILED");
47 res &= false;
49 tRes.tested("getComponentSchema()",res);
52 protected boolean checkSchema(XSchema aSchema) {
53 boolean res = false;
54 XSchemaHandlerImpl xSchemaHandlerImpl = new XSchemaHandlerImpl();
55 log.println("Checking for Exception in case of null argument");
57 try {
58 aSchema.readTemplates(null);
59 log.println("NoException thrown for null argument -- FAILED");
60 } catch (com.sun.star.lang.NullPointerException e) {
61 log.println("Expected Exception -- OK");
62 res = true;
63 } catch (com.sun.star.lang.WrappedTargetException e) {
64 log.println("Unexpected Exception (" + e + ") -- FAILED");
65 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
66 log.println("Unexpected Exception (" + e + ") -- FAILED");
69 log.println(
70 "checking readComponent with own XSchemaHandler implementation");
72 try {
73 aSchema.readComponent(xSchemaHandlerImpl);
75 String implCalled = xSchemaHandlerImpl.getCalls();
76 int sc = implCalled.indexOf("startComponent");
78 if (sc < 0) {
79 log.println("startComponent wasn't called -- FAILED");
80 res &= false;
81 } else {
82 log.println("startComponent was called -- OK");
83 res &= true;
86 int ec = implCalled.indexOf("endComponent");
88 if (ec < 0) {
89 log.println("endComponent wasn't called -- FAILED");
90 res &= false;
91 } else {
92 log.println("endComponent was called -- OK");
93 res &= true;
95 } catch (com.sun.star.lang.NullPointerException e) {
96 log.println("Unexpected Exception (" + e + ") -- FAILED");
97 res &= false;
98 } catch (com.sun.star.lang.WrappedTargetException e) {
99 log.println("Unexpected Exception (" + e + ") -- FAILED");
100 res &= false;
101 } catch (com.sun.star.configuration.backend.MalformedDataException e) {
102 log.println("Unexpected Exception (" + e + ") -- FAILED");
103 res &= false;
106 return res;