bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / runner / complexlib / Assurance.java
blob9e7d269d6f1648de3f398cfde222c872e058b295
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 complexlib;
21 /**
22 * I have removed the assure(...) functions from ComplexTestCase due to the fact now I can
23 * use the functions every where and don't need to be a ComplexTestCase any longer.
25 public class Assurance
27 public static final boolean CONTINUE = true;
29 /** State of the current test method **/
30 protected boolean state = true;
32 /** The message if the test did fail **/
33 protected String message = null;
36 /**
37 * Assure that s is true.
38 * This function generates "Assure failed." as standard message.
39 * @param s The condition that should be true.
41 protected void assure(boolean s) {
42 assure("Assure failed.", s, false);
45 /**
46 * Assure that s is true.
47 * The given message will be only evaluated, if s is false.
48 * @param msg The message that is evaluated.
49 * @param s The condition that should be true.
51 protected void assure(String msg, boolean s) {
52 assure(msg, s, false);
55 /**
56 * Assure that two int values are equal
57 * @param message the message to print when the equality test fails
58 * @param expected specifies the expected int value
59 * @param actual specifies the actual int value
61 protected void assureEquals( String message, int expected, int actual ) {
62 assureEquals( message, Integer.valueOf( expected ), Integer.valueOf( actual ), false );
65 /**
66 * Assure that two string values are equal
67 * @param message the message to print when the equality test fails
68 * @param expected specifies the expected string value
69 * @param actual specifies the actual string value
71 protected void assureEquals( String message, String expected, String actual ) {
72 assureEquals( message, expected, actual, false );
75 /**
76 * assures the two given sequences are of equal length, and have equal content
78 public <T> void assureEquals( String i_message, T[] i_expected, T[] i_actual, boolean i_continue )
80 if ( i_expected.length != i_actual.length )
81 failed( i_message + ": expected element count: " + i_expected.length + ", actual element count: " + i_actual.length );
82 for ( int i=0; i<i_expected.length; ++i )
84 assureEquals( i_message + ": mismatch at element pos " + i, i_expected[i], i_actual[i], i_continue );
88 /**
89 * Mark the currently executed method as failed.
90 * with the given message.
91 * @param msg The message of the failure.
93 protected void failed(String msg) {
94 assure(msg, false, false);
97 /**
98 * Assure that s is true.
99 * The given message will be only evaluated, if s is false.
100 * Normally, assure() leaves the current test method, and the next one
101 * is executed. With the parameter 'cont' set to true, the current test
102 * method will continue.<br>
103 * The current method will of course marked as failed.
104 * @param msg The message that is evaluated.
105 * @param s The condition that should be true.
106 * @param cont Continue with test method, even if s is false.
108 protected void assure(String msg, boolean s, boolean cont) {
109 state &= s;
110 if (!s) {
111 message += msg + "\r\n";
112 if (!cont) {
113 throw new AssureException(msg);
118 private void assureEquals( String message, Object expected, Object actual, boolean cont ) {
119 assure( message + " (expected: " + expected.toString() + ", actual: " + actual.toString() + ")",
120 expected.equals( actual ), cont );
124 * Mark the currently executed method as failed.
125 * with the given message.
126 * The given message will be only evaluated, if s is false.
127 * With the parameter 'cont' set to true, the current test
128 * method will continue.<br>
129 * The current method will of course marked as failed.
130 * @param msg The message that is evaluated.
131 * @param cont Continue with test method, even if s is false.
133 protected void failed(String msg, boolean cont) {
134 assure(msg, false, cont);
137 public static class AssureException extends RuntimeException {
139 private AssureException(String msg) {
140 super(msg);