00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2009 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef TESTUTILITIES_H 00011 #define TESTUTILITIES_H 00012 00013 #include <iostream> 00014 #include <string> 00015 00016 /** 00017 * Evaluates an expression and reports errors to an output stream. 00018 * 00019 * @param expression 00020 * The conditional source code expression to check. It must evaluate 00021 * to \c true or \c false. 00022 * @param output 00023 * The output stream in which to report an error. An error is logged 00024 * only if the given expression evaluates to \c false. 00025 * 00026 * @see isseas() 00027 */ 00028 #define testAssert(expression, output) \ 00029 ((expression) ? true : TestUtilities::assertionLogger(output, #expression, __FILE__, __LINE__)) 00030 00031 /** 00032 * Evaluates an expression and updates a success flag. 00033 * 00034 * This macro first evaluates a success flag that must be named \em success. 00035 * If the success flag evaluates to \c false, then this macro does nothing. If 00036 * the success flag evaluates to \c true, the given expression is evaluated 00037 * using the testAssert() macro and the success flag is updated to include the 00038 * evaluation result. 00039 * 00040 * isseas = <b>i</b>f (<b>s</b>uccess) <b>s</b>uccess and-<b>e</b>quals <b>a</b>ssert to <b>s</b>tream 00041 * 00042 * @param expression 00043 * The conditional source code expression to check. It must evaluate 00044 * to \c true or \c false. 00045 * @param output 00046 * The output stream in which to report an error. An error is logged 00047 * only if the given expression evaluates to \c false. 00048 * 00049 * @see testAssert() 00050 */ 00051 #define isseas(expression, output) \ 00052 success = success && testAssert(expression, output) 00053 00054 /** 00055 * Convenience functions for testing plug-ins and other code. 00056 * 00057 * This namespace contains functions that can be used by Testable plug-ins or 00058 * other code to implement test code to test plug-in functionality. 00059 * 00060 * The following related macros may also be helpful when writing test code: 00061 * - isseas() 00062 * - testAssert() 00063 */ 00064 namespace TestUtilities 00065 { 00066 /** 00067 * Returns a directory path that can be used to import data for testing. 00068 * 00069 * @return Returns the directory path specified in the import path 00070 * configuration setting. 00071 * 00072 * @see ConfigurationSettings::getSettingImportPath() 00073 */ 00074 std::string getTestDataPath(); 00075 00076 /** 00077 * Reports errors to an output stream. 00078 * 00079 * @warning The assertion logger is used in conjunction with the testAssert() 00080 * macro to report errors to an output stream, and should not be 00081 * called directly. 00082 * 00083 * @param output 00084 * The output stream in which to report the error. 00085 * @param expression 00086 * The conditional source code expression causing the error. 00087 * @param file 00088 * The source file in which the error occurred. 00089 * @param line 00090 * The line in the source file where the error occurred. 00091 * 00092 * @return Always returns false. 00093 */ 00094 bool assertionLogger(std::ostream& output, const std::string& expression, const std::string& file, int line); 00095 } 00096 00097 #endif