• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

TestBox.h

Go to the documentation of this file.
00001 #if ! defined(TS_TEST_BOX_HEADER)
00002 #define TS_TEST_BOX_HEADER
00003 
00004 /** @file
00005 
00006     Regression testing support class.
00007 
00008     @section license License
00009 
00010     Licensed to the Apache Software Foundation (ASF) under one
00011     or more contributor license agreements.  See the NOTICE file
00012     distributed with this work for additional information
00013     regarding copyright ownership.  The ASF licenses this file
00014     to you under the Apache License, Version 2.0 (the
00015     "License"); you may not use this file except in compliance
00016     with the License.  You may obtain a copy of the License at
00017 
00018     http://www.apache.org/licenses/LICENSE-2.0
00019 
00020     Unless required by applicable law or agreed to in writing, software
00021     distributed under the License is distributed on an "AS IS" BASIS,
00022     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00023     See the License for the specific language governing permissions and
00024     limitations under the License.
00025 */
00026 
00027 # include <ts/Regression.h>
00028 
00029 namespace {
00030   /** Class to make handling regression tests easier.
00031       This holds the important regression test values so they don't have to
00032       be passed repeated.
00033   */
00034   struct TestBox {
00035     typedef TestBox self; ///< Self reference type.
00036     RegressionTest* _test; ///< The test object.
00037     int* _status; ///< Current status pointer.
00038 
00039     /// Construct from @a test object and @a status pointer.
00040     TestBox(RegressionTest* test, int* status) : _test(test), _status(status) {}
00041 
00042     /// Construct from @a test object, @a status pointer and @a regression status.
00043     TestBox(RegressionTest* test, int* status, int rstatus) : _test(test), _status(status) {
00044       *this = rstatus;
00045     }
00046 
00047     /// Check the result and print a message on failure.
00048     bool check(bool result, char const* fmt, ...) TS_PRINTFLIKE(3, 4);
00049 
00050     /// Directly assign status.
00051     self& operator = (int status) { *_status = status; return *this; }
00052   };
00053 
00054   bool TestBox::check(bool result, char const* fmt, ...) {
00055     if (!result) {
00056       static size_t const N = 1<<16;
00057       char buffer[N]; // just stack, go big.
00058       va_list ap;
00059       va_start(ap, fmt);
00060       vsnprintf(buffer, N, fmt, ap);
00061       va_end(ap);
00062       rprintf(_test, "%s\n", buffer);
00063       *_status = REGRESSION_TEST_FAILED;
00064     }
00065     return result;
00066   }
00067 }
00068 #endif // TS_TEST_BOX_HEADER

Generated by  doxygen 1.7.1