src/core/test.h
author Craig Dowell <craigdo@ee.washington.edu>
Tue, 20 Oct 2009 10:05:57 -0700
changeset 5438 04cc3ffe0202
parent 5342 3c6109eec550
child 5441 b9b5be8b6e33
permissions -rw-r--r--
Make tests work with MinGW (make win32-system-wall-clock-ms work)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
     3
 * Copyright (c) 2009 University of Washington
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 */
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
5342
3c6109eec550 bug 675: kill old test framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5324
diff changeset
    19
#ifndef NS3_TEST_H
3c6109eec550 bug 675: kill old test framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5324
diff changeset
    20
#define NS3_TEST_H
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    22
#include <iostream>
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    23
#include <fstream>
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    24
#include <sstream>
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
#include <string>
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    26
#include <vector>
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    27
#include <list>
4773
904c1803d5dc test framework should probably work on all supported machines
Craig Dowell <craigdo@ee.washington.edu>
parents: 4772
diff changeset
    28
#include <limits>
4774
066f73df2229 fc11 is pretty picky about headers
Craig Dowell <craigdo@ee.washington.edu>
parents: 4773
diff changeset
    29
#include <stdint.h>
5438
04cc3ffe0202 Make tests work with MinGW (make win32-system-wall-clock-ms work)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5342
diff changeset
    30
04cc3ffe0202 Make tests work with MinGW (make win32-system-wall-clock-ms work)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5342
diff changeset
    31
#include "ns3/system-wall-clock-ms.h"
04cc3ffe0202 Make tests work with MinGW (make win32-system-wall-clock-ms work)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5342
diff changeset
    32
04cc3ffe0202 Make tests work with MinGW (make win32-system-wall-clock-ms work)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5342
diff changeset
    33
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    34
// 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    35
// Note on below macros:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    36
//
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    37
// When multiple statements are used in a macro, they should be bound together 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    38
// in a loop syntactically, so the macro can appear safely inside if clauses 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    39
// or other places that expect a single statement or a statement block.  The
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    40
// "strange" do while construct is a generally expected best practice for
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    41
// defining a robust macro.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    42
//
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    43
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    44
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    45
 * \brief Convenience macro to extract the source directory of the current 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    46
 * source file.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    47
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    48
 * \see TestCase::GetSourceDir
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    49
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    50
#define NS_TEST_SOURCEDIR \
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    51
  TestCase::GetSourceDir (__FILE__)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    52
5239
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5227
diff changeset
    53
#define NS_TEST_RETURN_IF_ERROR \
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5227
diff changeset
    54
  if (GetErrorStatus ()) \
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5227
diff changeset
    55
    {                    \
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5227
diff changeset
    56
      return true;       \
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5227
diff changeset
    57
    } 
2e753de86174 Remove and replace attribute unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5227
diff changeset
    58
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    59
// ===========================================================================
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    60
// Test for equality (generic version)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    61
// ===========================================================================
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    62
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    63
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    64
 * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    65
 */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    66
#define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line)                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    67
  do {                                                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    68
    if (!((actual) == (limit)))                                                                         \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    69
      {                                                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    70
        std::ostringstream msgStream;                                                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    71
        msgStream << msg;                                                                               \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    72
        std::ostringstream actualStream;                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    73
        actualStream << actual;                                                                         \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    74
        std::ostringstream limitStream;                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    75
        limitStream << limit;                                                                           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    76
        ReportTestFailure (std::string (#actual) + " (actual) == " + std::string (#limit) + " (limit)", \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    77
                       actualStream.str (), limitStream.str (), msgStream.str (), file, line);          \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    78
        if (!ContinueOnFailure ())                                                                      \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    79
          {                                                                                             \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    80
            return true;                                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    81
          }                                                                                             \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
    82
      }                                                                                                 \
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    83
  } while (false)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    84
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    85
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    86
 * \brief Test that an actual and expected (limit) value are equal and report
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    87
 * and abort if not.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    88
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    89
 * Check to see if the expected (limit) value is equal to the actual value found
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    90
 * in a test case.  If the two values are equal nothing happens, but if the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    91
 * comparison fails, an error is reported in a consistent way and the execution
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    92
 * of the current test case is aborted.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    93
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    94
 * The message is interpreted as a stream, for example:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    95
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    96
 * \code
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    97
 * NS_TEST_ASSERT_MSG_EQ (result, true, 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    98
 *      "cannot open file " << filename << " in test");
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
    99
 * \endcode
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   100
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   101
 * is legal.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   102
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   103
 * \param actual Expression for the actual value found during the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   104
 * \param limit Expression for the expected value of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   105
 * \param msg Message that is output if the test does not pass.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   106
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   107
 * \warning Do not use this macro if you are comparing floating point numbers
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   108
 * (float or double) as it is unlikely to do what you expect.  Use 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   109
 * NS_TEST_ASSERT_MSG_EQ_TOL instead.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   110
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   111
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   112
  NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   113
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   114
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   115
 * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   116
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   117
 * Required to avoid use of return statement which allows use in methods 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   118
 * (esp. callbacks) returning void.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   119
 */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   120
#define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line)                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   121
  do {                                                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   122
    if (!((actual) == (limit)))                                                                         \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   123
      {                                                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   124
        std::ostringstream msgStream;                                                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   125
        msgStream << msg;                                                                               \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   126
        std::ostringstream actualStream;                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   127
        actualStream << actual;                                                                         \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   128
        std::ostringstream limitStream;                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   129
        limitStream << limit;                                                                           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   130
        ReportTestFailure (std::string (#actual) + " (actual) == " + std::string (#limit) + " (limit)", \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   131
                       actualStream.str (), limitStream.str (), msgStream.str (), file, line);          \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   132
      }                                                                                                 \
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   133
  } while (false)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   134
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   135
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   136
 * \brief Test that an actual and expected (limit) value are equal and report
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   137
 * if not.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   138
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   139
 * Check to see if the expected (lmit) value is equal to the actual value found
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   140
 * in a test case.  If the two values are equal nothing happens, but if the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   141
 * comparison fails, an error is reported in a consistent way.  EXPECT* macros
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   142
 * do not return if an error is detected.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   143
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   144
 * The message is interpreted as a stream, for example:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   145
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   146
 * \code
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   147
 * NS_TEST_EXPECT_MSG_EQUAL (result, true, 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   148
 *      "cannot open file " << filename << " in test");
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   149
 * \endcode
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   150
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   151
 * is legal.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   152
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   153
 * \param actual Expression for the actual value found during the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   154
 * \param limit Expression for the expected value of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   155
 * \param msg Message that is output if the test does not pass.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   156
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   157
 * \warning Do not use this macro if you are comparing floating point numbers
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   158
 * (float or double) as it is unlikely to do what you expect.  Use 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   159
 * NS_TEST_EXPECT_MSG_EQ_TOL instead.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   160
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   161
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   162
  NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   163
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   164
// ===========================================================================
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   165
// Test for equality with a provided tolerance (use for floating point 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   166
// comparisons -- both float and double)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   167
// ===========================================================================
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   168
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   169
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   170
 * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   171
 */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   172
#define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line)                                       \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   173
  do {                                                                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   174
    if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol))                                                     \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   175
      {                                                                                                               \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   176
        std::ostringstream msgStream;                                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   177
        msgStream << msg;                                                                                             \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   178
        std::ostringstream actualStream;                                                                              \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   179
        actualStream << actual;                                                                                       \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   180
        std::ostringstream limitStream;                                                                               \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   181
        limitStream << limit << " +- " << tol;                                                                        \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   182
        std::ostringstream condStream;                                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   183
        condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol << " (tol) && " <<                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   184
                      #actual << " (actual) > " << #limit << " (limit) - " << #tol << " (tol)";                       \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   185
        ReportTestFailure (condStream.str (), actualStream.str (), limitStream.str (), msgStream.str (), file, line); \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   186
        if (!ContinueOnFailure ())                                                                                    \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   187
          {                                                                                                           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   188
            return true;                                                                                              \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   189
          }                                                                                                           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   190
      }                                                                                                               \
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   191
  } while (false)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   192
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   193
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   194
 * \brief Test that actual and expected (limit) values are equal to plus or minus
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   195
 * some tolerance and report and abort if not.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   196
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   197
 * Check to see if the expected (limit) value is equal to the actual value found
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   198
 * in a test case to some tolerance.  This is not the same thing as asking if
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   199
 * two floating point are equal to within some epsilon, but is useful for that
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   200
 * case.  This assertion is geared toward more of a measurement problem.  Consider
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   201
 * measuring a physical rod of some kind that you have ordered.  You need to 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   202
 * determine if it is "good."  You won't measure the rod to an arbitrary precision
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   203
 * of sixteen significant figures, you will measure the rod to determine if its 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   204
 * length is within the tolerances you provided.  For example, 12.00 inches plus
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   205
 * or minus .005 inch may be just fine.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   206
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   207
 * In ns-3, you might want to measure a signal to noise ratio and check to see
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   208
 * if the answer is what you expect.  If you naively measure (double)1128.93 and
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   209
 * compare this number with a constant 1128.93 you are almost certainly going to
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   210
 * have your test fail because of floating point rounding errors.  We provide a
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   211
 * floating point comparison function ns3::TestDoubleIsEqual() but you will 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   212
 * probably quickly find that is not what you want either.  It may turn out to
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   213
 * be the case that when you measured an snr that printed as 1128.93, what was 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   214
 * actually measured was something more like 1128.9287653857625442 for example.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   215
 * Given that the double epsilon is on the order of 0.0000000000000009, you would
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   216
 * need to provide sixteen significant figures of expected value for this kind of
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   217
 * test to pass even with a typical test for floating point "approximate equality."
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   218
 * That is clearly not required or desired.  You really want to be able to provide 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   219
 * 1128.93 along with a tolerance just like you provided 12 inches +- 0.005 inch 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   220
 * above.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   221
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   222
 * This assertion is designed for real measurements by taking into account
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   223
 * measurement tolerances.  By doing so it also automatically compensates for 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   224
 * floating point rounding errors.    If you really want to check floating point
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   225
 * equality down to the numeric_limits<double>::epsilon () range, consider using 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   226
 * ns3::TestDoubleIsEqual().
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   227
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   228
 * The message is interpreted as a stream, for example:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   229
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   230
 * \code
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   231
 * NS_TEST_ASSERT_MSG_EQ_TOL (snr, 1128.93, 0.005, "wrong snr (" << snr << ") in test");
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   232
 * \endcode
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   233
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   234
 * is legal.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   235
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   236
 * \param actual Expression for the actual value found during the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   237
 * \param limit Expression for the expected value of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   238
 * \param tol Tolerance of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   239
 * \param msg Message that is output if the test does not pass.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   240
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   241
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)                 \
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   242
  NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   243
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   244
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   245
 * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   246
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   247
 * Required to avoid use of return statement which allows use in methods 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   248
 * (esp. callbacks) returning void.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   249
 */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   250
#define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line)                                       \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   251
  do {                                                                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   252
    if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol))                                                     \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   253
      {                                                                                                               \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   254
        std::ostringstream msgStream;                                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   255
        msgStream << msg;                                                                                             \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   256
        std::ostringstream actualStream;                                                                              \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   257
        actualStream << actual;                                                                                       \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   258
        std::ostringstream limitStream;                                                                               \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   259
        limitStream << limit << " +- " << tol;                                                                        \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   260
        std::ostringstream condStream;                                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   261
        condStream << #actual << " (actual) < " << #limit << " (limit) + " << #tol << " (tol) && " <<                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   262
                      #actual << " (actual) > " << #limit << " (limit) - " << #tol << " (tol)";                       \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   263
        ReportTestFailure (condStream.str (), actualStream.str (), limitStream.str (), msgStream.str (), file, line); \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   264
      }                                                                                                               \
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   265
  } while (false)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   266
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   267
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   268
 * \brief Test that actual and expected (limit) values are equal to plus or minus
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   269
 * some tolerance and report if not.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   270
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   271
 * Check to see if the expected (limit) value is equal to the actual value found
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   272
 * in a test case to some tolerance.  This is not the same thing as asking if
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   273
 * two floating point are equal to within some epsilon, but is useful for that
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   274
 * case.  This assertion is geared toward more of a measurement problem.  Consider
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   275
 * measuring a physical rod of some kind that you have ordered.  You need to 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   276
 * determine if it is "good."  You won't measure the rod to an arbitrary precision
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   277
 * of sixteen significant figures, you will measure the rod to determine if its 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   278
 * length is within the tolerances you provided.  For example, 12.00 inches plus
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   279
 * or minus .005 inch may be just fine.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   280
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   281
 * In ns-3, you might want to measure a signal to noise ratio and check to see
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   282
 * if the answer is what you expect.  If you naively measure (double)1128.93 and
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   283
 * compare this number with a constant 1128.93 you are almost certainly going to
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   284
 * have your test fail because of floating point rounding errors.  We provide a
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   285
 * floating point comparison function ns3::TestDoubleIsEqual() but you will 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   286
 * probably quickly find that is not what you want either.  It may turn out to
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   287
 * be the case that when you measured an snr that printed as 1128.93, what was 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   288
 * actually measured was something more like 1128.9287653857625442 for example.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   289
 * Given that the double epsilon is on the order of 0.0000000000000009, you would
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   290
 * need to provide sixteen significant figures of expected value for this kind of
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   291
 * test to pass even with a typical test for floating point "approximate equality."
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   292
 * That is clearly not required or desired.  You really want to be able to provide 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   293
 * 1128.93 along with a tolerance just like you provided 12 inches +- 0.005 inch 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   294
 * above.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   295
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   296
 * This assertion is designed for real measurements by taking into account
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   297
 * measurement tolerances.  By doing so it also automatically compensates for 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   298
 * floating point rounding errors.    If you really want to check floating point
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   299
 * equality down to the numeric_limits<double>::epsilon () range, consider using 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   300
 * ns3::TestDoubleIsEqual().
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   301
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   302
 * The message is interpreted as a stream, for example:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   303
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   304
 * \code
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   305
 * NS_TEST_EXPECT_MSG_EQ_TOL (snr, 1128.93, 0.005, "wrong snr (" << snr << ") in test");
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   306
 * \endcode
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   307
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   308
 * is legal.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   309
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   310
 * \param actual Expression for the actual value found during the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   311
 * \param limit Expression for the expected value of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   312
 * \param tol Tolerance of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   313
 * \param msg Message that is output if the test does not pass.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   314
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   315
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   316
  NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   317
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   318
// ===========================================================================
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   319
// Test for inequality
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   320
// ===========================================================================
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   321
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   322
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   323
 * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   324
 */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   325
#define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line)                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   326
  do {                                                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   327
    if (!((actual) != (limit)))                                                                         \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   328
      {                                                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   329
        std::ostringstream msgStream;                                                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   330
        msgStream << msg;                                                                               \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   331
        std::ostringstream actualStream;                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   332
        actualStream << actual;                                                                         \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   333
        std::ostringstream limitStream;                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   334
        limitStream << limit;                                                                           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   335
        ReportTestFailure (std::string (#actual) + " (actual) != " + std::string (#limit) + " (limit)", \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   336
                       actualStream.str (), limitStream.str (), msgStream.str (), file, line);          \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   337
        if (!ContinueOnFailure ())                                                                      \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   338
          {                                                                                             \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   339
            return true;                                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   340
          }                                                                                             \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   341
      }                                                                                                 \
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   342
  } while (false)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   343
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   344
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   345
 * \brief Test that an actual and expected (limit) value are equal and report
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   346
 * and abort if not.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   347
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   348
 * Check to see if the expected (limit) value is not equal to the actual value
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   349
 * found in a test case.  If the two values are equal nothing happens, but if 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   350
 * the comparison fails, an error is reported in a consistent way and the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   351
 * execution of the current test case is aborted.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   352
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   353
 * The message is interpreted as a stream, for example:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   354
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   355
 * \code
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   356
 * NS_TEST_ASSERT_MSG_NE (result, false, 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   357
 *      "cannot open file " << filename << " in test");
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   358
 * \endcode
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   359
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   360
 * is legal.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   361
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   362
 * \param actual Expression for the actual value found during the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   363
 * \param limit Expression for the expected value of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   364
 * \param msg Message that is output if the test does not pass.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   365
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   366
 * \warning Do not use this macro if you are comparing floating point numbers
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   367
 * (float or double).  Use NS_TEST_ASSERT_MSG_FLNE instead.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   368
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   369
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   370
  NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   371
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   372
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   373
 * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   374
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   375
 * Required to avoid use of return statement which allows use in methods 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   376
 * (callbacks) returning void.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   377
 */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   378
#define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line)                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   379
  do {                                                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   380
    if (!((actual) != (limit)))                                                                         \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   381
      {                                                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   382
        std::ostringstream msgStream;                                                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   383
        msgStream << msg;                                                                               \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   384
        std::ostringstream actualStream;                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   385
        actualStream << actual;                                                                         \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   386
        std::ostringstream limitStream;                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   387
        limitStream << limit;                                                                           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   388
        ReportTestFailure (std::string (#actual) + " (actual) != " + std::string (#limit) + " (limit)", \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   389
                       actualStream.str (), limitStream.str (), msgStream.str (), file, line);          \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   390
      }                                                                                                 \
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   391
  } while (false)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   392
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   393
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   394
 * \brief Test that an actual and expected (limit) value are equal and report
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   395
 * if not.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   396
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   397
 * Check to see if the expected (limit) value is equal to the actual value 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   398
 * found in a test case.  If the two values are equal nothing happens, but if 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   399
 * the comparison fails, an error is reported in a consistent way.  EXPECT* 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   400
 * macros do not return if an error is detected.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   401
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   402
 * The message is interpreted as a stream, for example:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   403
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   404
 * \code
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   405
 * NS_TEST_EXPECT_MSG_EQUAL (result, true, 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   406
 *      "cannot open file " << filename << " in test");
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   407
 * \endcode
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   408
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   409
 * is legal.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   410
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   411
 * \param actual Expression for the actual value found during the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   412
 * \param limit Expression for the expected value of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   413
 * \param msg Message that is output if the test does not pass.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   414
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   415
 * \warning Do not use this macro if you are comparing floating point numbers
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   416
 * (float or double).  Use NS_TEST_EXPECT_MSG_FLNE instead.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   417
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   418
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   419
  NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   420
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   421
// ===========================================================================
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   422
// Test for less than relation
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   423
// ===========================================================================
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   424
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   425
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   426
 * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   427
 */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   428
#define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line)                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   429
  do {                                                                                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   430
    if (!((actual) < (limit)))                                                                           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   431
      {                                                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   432
        std::ostringstream msgStream;                                                                    \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   433
        msgStream << msg;                                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   434
        std::ostringstream actualStream;                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   435
        actualStream << actual;                                                                          \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   436
        std::ostringstream limitStream;                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   437
        limitStream << limit;                                                                            \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   438
        ReportTestFailure (std::string (#actual) + " (actual) < " + std::string (#limit) + " (limit)",   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   439
                       actualStream.str (), limitStream.str (), msgStream.str (), file, line);           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   440
        if (!ContinueOnFailure ())                                                                       \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   441
          {                                                                                              \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   442
            return true;                                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   443
          }                                                                                              \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   444
      }                                                                                                  \
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   445
  } while (false)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   446
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   447
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   448
 * \brief Test that an actual value is less than a limit and report and abort
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   449
 * if not.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   450
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   451
 * Check to see if the actual value found in a test case is less than the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   452
 * limit value.  If the actual value is lesser nothing happens, but if the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   453
 * check fails, an error is reported in a consistent way and the execution
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   454
 * of the current test case is aborted.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   455
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   456
 * The message is interpreted as a stream.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   457
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   458
 * \param actual Expression for the actual value found during the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   459
 * \param limit Expression for the limit value of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   460
 * \param msg Message that is output if the test does not pass.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   461
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   462
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   463
  NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   464
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   465
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   466
 * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   467
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   468
 * Required to avoid use of return statement which allows use in methods 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   469
 * (callbacks) returning void.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   470
 */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   471
#define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line)                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   472
  do {                                                                                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   473
    if (!((actual) < (limit)))                                                                           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   474
      {                                                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   475
        std::ostringstream msgStream;                                                                    \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   476
        msgStream << msg;                                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   477
        std::ostringstream actualStream;                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   478
        actualStream << actual;                                                                          \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   479
        std::ostringstream limitStream;                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   480
        limitStream << limit;                                                                            \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   481
        ReportTestFailure (std::string (#actual) + " (actual) < " + std::string (#limit) + " (limit)",   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   482
                       actualStream.str (), limitStream.str (), msgStream.str (), file, line);           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   483
      }                                                                                                  \
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   484
  } while (false)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   485
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   486
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   487
 * \brief Test that an actual value is less than a limit and report if not.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   488
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   489
 * Check to see if the actual value found in a test case is less than the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   490
 * limit value.  If the actual value is lesser nothing happens, but if the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   491
 * check fails, an error is reported in a consistent way.  EXPECT* macros do 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   492
 * not return if an error is detected.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   493
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   494
 * The message is interpreted as a stream.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   495
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   496
 * \param actual Expression for the actual value found during the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   497
 * \param limit Expression for the limit value of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   498
 * \param msg Message that is output if the test does not pass.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   499
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   500
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   501
  NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   502
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   503
// ===========================================================================
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   504
// Test for greater than relation
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   505
// ===========================================================================
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   506
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   507
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   508
 * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   509
 */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   510
#define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line)                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   511
  do {                                                                                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   512
    if (!((actual) > (limit)))                                                                           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   513
      {                                                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   514
        std::ostringstream msgStream;                                                                    \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   515
        msgStream << msg;                                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   516
        std::ostringstream actualStream;                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   517
        actualStream << actual;                                                                          \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   518
        std::ostringstream limitStream;                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   519
        limitStream << limit;                                                                            \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   520
        ReportTestFailure (std::string (#actual) + " (actual) > " + std::string (#limit) + " (limit)",   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   521
                       actualStream.str (), limitStream.str (), msgStream.str (), file, line);           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   522
        if (!ContinueOnFailure ())                                                                       \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   523
          {                                                                                              \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   524
            return true;                                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   525
          }                                                                                              \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   526
      }                                                                                                  \
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   527
  } while (false)
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   528
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   529
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   530
 * \brief Test that an actual value is greater than a limit and report and abort
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   531
 * if not.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   532
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   533
 * Check to see if the actaul value found in a test case is greater than the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   534
 * limit value.  If the actual value is greater nothing happens, but if the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   535
 * check fails, an error is reported in a consistent way and the execution
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   536
 * of the current test case is aborted.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   537
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   538
 * The message is interpreted as a stream.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   539
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   540
 * \param actual Expression for the actual value found during the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   541
 * \param limit Expression for the limit value of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   542
 * \param msg Message that is output if the test does not pass.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   543
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   544
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   545
  NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   546
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   547
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   548
 * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   549
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   550
 * Required to avoid use of return statement which allows use in methods 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   551
 * (callbacks) returning void.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   552
 */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   553
#define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line)                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   554
  do {                                                                                                   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   555
    if (!((actual) > (limit)))                                                                           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   556
      {                                                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   557
        std::ostringstream msgStream;                                                                    \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   558
        msgStream << msg;                                                                                \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   559
        std::ostringstream actualStream;                                                                 \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   560
        actualStream << actual;                                                                          \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   561
        std::ostringstream limitStream;                                                                  \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   562
        limitStream << limit;                                                                            \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   563
        ReporTesttFailure (std::string (#actual) + " (actual) > " + std::string (#limit) + " (limit)",   \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   564
                       actualStream.str (), limitStream.str (), msgStream.str (), file, line);           \
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   565
      }                                                                                                  \
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   566
  } while (false)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   567
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   568
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   569
 * \brief Test that an actual value is greater than a limit and report if not.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   570
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   571
 * Check to see if the actual value found in a test case is greater than the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   572
 * limit value.  If the actual value is greater nothing happens, but if the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   573
 * check fails, an error is reported in a consistent way.  EXPECT* macros do 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   574
 * not return if an error is detected.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   575
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   576
 * The message is interpreted as a stream.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   577
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   578
 * \param actual Expression for the actual value found during the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   579
 * \param limit Expression for the limit value of the test.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   580
 * \param msg Message that is output if the test does not pass.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   581
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   582
#define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   583
  NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   584
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   585
namespace ns3 {
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   586
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   587
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   588
 * \brief Compare two double precision floating point numbers and declare them
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   589
 * equal if they are within some epsilon of each other.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   590
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   591
 * Approximate comparison of floating point numbers near equality is trickier
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   592
 * than one may expect and is well-discussed in the literature.  Basic 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   593
 * strategies revolve around a suggestion by Knuth to compare the floating 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   594
 * point numbers as binary integers, supplying a maximum difference between
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   595
 * them .  This max difference is specified in Units in the Last Place (ulps)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   596
 * or a floating point epsilon.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   597
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   598
 * This routine is based on the GNU Scientific Library function gsl_fcmp.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   599
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   600
 * \param a The first of double precision floating point numbers to compare
5225
9c612cb88d6b Doxygenize.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 5185
diff changeset
   601
 * \param b The second of double precision floating point numbers to compare
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   602
 * \param epsilon The second of double precision floating point numberss to compare
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   603
 * \returns Returns true if the doubles are equal to a precision defined by epsilon
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   604
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   605
  bool TestDoubleIsEqual (const double a, const double b, const double epsilon = std::numeric_limits<double>::epsilon ());
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   606
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   607
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   608
 * \brief A single test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   609
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   610
class TestCase
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   611
{
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   612
public:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   613
  TestCase (std::string name);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   614
  virtual ~TestCase ();
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   615
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   616
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   617
   * \brief Run this test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   618
   * \returns Boolean sense of "an error has occurred."
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   619
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   620
  bool Run (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   621
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   622
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   623
   * \brief Set the verbosity of this test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   624
   * \param verbose Whether or not to print "stuff."
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   625
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   626
  void SetVerbose (bool verbose);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   627
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   628
  /**
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   629
   * \brief Tell the test case whether or not to continue testing if an error is
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   630
   * detected.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   631
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   632
   * Typically, test cases depend on some number of individual tests.  Often, 
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   633
   * these tests build on functionality that has been previously verified.  In 
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   634
   * this case, subsequent test failures may simply be alternate manifestations
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   635
   * of previously detected errors.  Some developers may only be interested in 
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   636
   * seeing the first failure.  Other developers may want to see all the 
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   637
   * information they can get, and want to see all failures.  This is a matter
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   638
   * of individual preference, so we allow this behavior to be configured.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   639
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   640
   * \param continueOnFailure If true, run tests after a failure has been 
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   641
   *                          detected, otherwise stop on the first error.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   642
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   643
  void SetContinueOnFailure (bool continueOnFailure);
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   644
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   645
  /**
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   646
   * \brief Set the name of this test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   647
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   648
  void SetName (std::string name);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   649
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   650
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   651
   * \brief Get the name of this test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   652
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   653
   std::string GetName (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   654
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   655
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   656
   * \brief Set the base directory of the ns-3 distribution.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   657
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   658
  void SetBaseDir (std::string dir);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   659
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   660
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   661
   * \brief Get the base directory of the ns-3 distribution.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   662
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   663
  std::string GetBaseDir (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   664
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   665
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   666
 * \brief Get the source directory of the current source file.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   667
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   668
 * One of the basic models of the test environment is that dedicated test- 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   669
 * and response vectors live in the same directory as the source file.  So it 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   670
 * is a common operation to figure out what directory a given source file lives
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   671
 * in.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   672
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   673
 * __FILE__ provides almost all of what we need, but in the gnu toolchain it 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   674
 * comes out as something like "../src/core/pcap-file-test-suite.cc".
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   675
 * 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   676
 * We really don't want to have any dependency on the directory out of which a
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   677
 * test is run, so we ask that any test-runner give us the base directory of the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   678
 * distribution, which is set via TestCase::SetBaseDir().  That string will look 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   679
 * something like "/home/user/repos/ns-3-allinone/ns-3-dev".
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   680
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   681
 * This function stitches the two pieces together and removes the file name to 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   682
 * return something like "/home/user/repos/ns-3-allinone/ns-3-dev/src/core/".
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   683
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   684
 * \param file The current source file name relative to the base directory.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   685
 * \returns The current source directory.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   686
 *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   687
 * \warning Always call this function as GetSourceDir (__FILE__) or use the 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   688
 * convenience macro NS_TEST_SOURCEDIR.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   689
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   690
  std::string GetSourceDir (std::string file);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   691
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   692
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   693
   * \brief Set the stream to which status and result messages will be written.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   694
   *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   695
   * We really don't want to have to pass an ofstream around to every function
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   696
   * and we especially don't want to have to make our clients plumb an ofstream
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   697
   * around so we need to save it.  Since file streams are not designed to be
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   698
   * copied or assigned (what does it mean to have duplicate streams to a file) 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   699
   * we have to stash a pointer to the stream.
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   700
   *
5227
ecb08c1fc273 Fix some doxygen warnings revealed by WARN_NO_PARAMDOC=YES in doc/doxygen.conf.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 5225
diff changeset
   701
   * \param ofs output file stream
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   702
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   703
  void SetStream (std::ofstream *ofs);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   704
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   705
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   706
   * \brief Get the stream to which status and result messages will be written.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   707
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   708
  std::ofstream *GetStream (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   709
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   710
  /**
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   711
   * \brief Manually update the error status of this test case.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   712
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   713
   * This does a logical OR of the error argument with the current error status.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   714
   * If the argument is false, it does nothing.  If the argument is true, it 
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   715
   * sets the error status to "an error has occurred."
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   716
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   717
   * \param error The status to use to update the test case error status
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   718
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   719
  void UpdateErrorStatus (bool error);
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   720
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   721
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   722
   * \brief Manually set the error status of this test case.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   723
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   724
   * This sets the current error status to the argument provided.  Can be used
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   725
   * to reset any previous errors if the argument is false.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   726
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   727
   * \param error The status to use to set the test case error status
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   728
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   729
  void SetErrorStatus (bool error);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   730
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   731
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   732
   * \brief Get the error status of this test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   733
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   734
  bool GetErrorStatus (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   735
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   736
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   737
   * \brief Should test cases continue running in the presence of errors?
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   738
   * \returns True if the test case should continue, false otherwise.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   739
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   740
  bool ContinueOnFailure (void);
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   741
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   742
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   743
   * \brief Issue a test report than the test suite has started running.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   744
   */
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   745
  void ReportStart (void);
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   746
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   747
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   748
   * \brief Issue a test report than the test case has declared success.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   749
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   750
  void ReportCaseSuccess (void);
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   751
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   752
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   753
   * \brief Issue a test report than the test case has declared failure.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   754
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   755
  void ReportCaseFailure (void);
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   756
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   757
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   758
   * \brief Issue a test report than the test case has found an error and
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   759
   * report the details.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   760
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   761
  void ReportTestFailure (std::string cond, std::string actual, std::string limit, std::string message, 
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   762
    std::string file, int32_t line);
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   763
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   764
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   765
   * \brief Issue a test report than the test case has completed its run.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   766
   */
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   767
  void ReportEnd (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   768
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   769
protected:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   770
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   771
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   772
   * \brief Implementation of reporting method for the start of the test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   773
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   774
  virtual void DoReportStart (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   775
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   776
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   777
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   778
   * \brief Implementation of reporting method for success of the test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   779
   */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   780
  virtual void DoReportCaseSuccess (void);
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   781
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   782
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   783
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   784
   * \brief Implementation of reporting method for failure of the test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   785
   */
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   786
  virtual void DoReportCaseFailure (void);
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   787
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   788
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   789
   * \internal
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   790
   * \brief Implementation of reporting method for failure of the test case.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   791
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   792
  virtual void DoReportTestFailure (std::string cond, std::string actual, std::string limit, std::string message, 
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   793
    std::string file, int32_t line);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   794
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   795
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   796
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   797
   * \brief Implementation of reporting method for the end of the test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   798
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   799
  virtual void DoReportEnd (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   800
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   801
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   802
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   803
   * \param verbose Turn on any output the test case may provide
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   804
   * \brief Implementation to do any local setup required for this test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   805
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   806
  virtual void DoSetup (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   807
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   808
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   809
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   810
   * \brief Implementation to actually run this test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   811
   * \param verbose Turn on any output the test case may provide
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   812
   * \returns Boolean sense of "an error has occurred."
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   813
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   814
  virtual bool DoRun (void) = 0;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   815
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   816
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   817
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   818
   * \param verbose Turn on any output the test case may provide
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   819
   * \brief Implementation to do any local setup required for this test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   820
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   821
  virtual void DoTeardown (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   822
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   823
private:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   824
  TestCase (TestCase& tc);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   825
  TestCase& operator= (TestCase& tc);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   826
5438
04cc3ffe0202 Make tests work with MinGW (make win32-system-wall-clock-ms work)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5342
diff changeset
   827
  SystemWallClockMs m_clock;
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   828
  std::string m_name;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   829
  bool m_verbose;
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   830
  bool m_continueOnFailure;
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   831
  bool m_detailsReported;
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   832
  std::string m_basedir;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   833
  std::ofstream *m_ofs;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   834
  bool m_error;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   835
};
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   836
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   837
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   838
 * \brief A suite of tests to run.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   839
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   840
class TestSuite
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   841
{
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   842
public:
5225
9c612cb88d6b Doxygenize.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 5185
diff changeset
   843
  /**
9c612cb88d6b Doxygenize.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 5185
diff changeset
   844
   * \enum TestType
9c612cb88d6b Doxygenize.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 5185
diff changeset
   845
   * \brief Type of test.
9c612cb88d6b Doxygenize.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 5185
diff changeset
   846
   */
4773
904c1803d5dc test framework should probably work on all supported machines
Craig Dowell <craigdo@ee.washington.edu>
parents: 4772
diff changeset
   847
  enum TestType {
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   848
    BVT = 1,    /**< This test suite implements a Build Verification Test */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   849
    UNIT,       /**< This test suite implements a Unit Test */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   850
    SYSTEM,     /**< This test suite implements a System Test */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   851
    EXAMPLE,    /**< This test suite implements an Example Test */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   852
    PERFORMANCE /**< This test suite implements a Performance Test */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   853
  };
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   854
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   855
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   856
   * \brief Constuct a new test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   857
   *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   858
   * \param name The name of the test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   859
   * \param type The TestType of the test suite (defaults to UNIT test).
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   860
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   861
  TestSuite (std::string name, TestType type = UNIT);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   862
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   863
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   864
   * \brief Destroy a test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   865
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   866
  virtual ~TestSuite ();
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   867
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   868
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   869
   * \brief Run this test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   870
   *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   871
   * \returns Boolean sense of "an error has occurred."
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   872
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   873
  bool Run (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   874
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   875
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   876
   * \brief Add an individual test case to this test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   877
   *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   878
   * \param testCase Pointer to the test case object to be added.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   879
   * \returns Integer assigned as identifer of the provided test case.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   880
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   881
  uint32_t AddTestCase (TestCase *testCase);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   882
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   883
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   884
   * \brief Get the number of test cases that have been added to this test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   885
   *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   886
   * \returns Number of test cases in the suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   887
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   888
  uint32_t GetNTestCases (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   889
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   890
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   891
   * \brief Get the test case at index i.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   892
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   893
  TestCase *GetTestCase (uint32_t i);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   894
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   895
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   896
   * \brief get the kind of test this test suite implements
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   897
   *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   898
   * \returns the TestType of the suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   899
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   900
  TestType GetTestType (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   901
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   902
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   903
   * \brief Set the verbosity of this test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   904
   * \param verbose Whether or not to print "stuff."
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   905
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   906
  void SetVerbose (bool verbose);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   907
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   908
  /**
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   909
   * \brief Tell the test suite and its test cases whether or not to continue
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   910
   * testing if an error is detected.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   911
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   912
   * Typically, test suites depend on some number of test cases, which in turn
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   913
   * depend on some number of individual tests.  Often, these tests build on 
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   914
   * functionality that has been previously verified.  In this case, subsequent
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   915
   * test failures may simply be alternate manifestations of previously detected
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   916
   * errors.  Some developers may only be interested in seeing the first failure.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   917
   * Other developers may want to see all the information they can get, and want
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   918
   * to see all failures.  This is a matter of individual preference, so we allow
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   919
   * this behavior to be configured.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   920
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   921
   * \param continueOnFailure If true, continue running test cases after a 
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   922
   *                          failure has been detected, otherwise stop on the 
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   923
   *                          first error.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   924
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   925
  void SetContinueOnFailure (bool continueOnFailure);
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   926
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   927
  /**
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   928
   * \brief Set the name of this test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   929
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   930
  void SetName (std::string name);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   931
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   932
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   933
   * \brief Get the name of this test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   934
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   935
   std::string GetName (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   936
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   937
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   938
   * \brief Set the base directory of the ns-3 distribution.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   939
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   940
  void SetBaseDir (std::string basedir);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   941
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   942
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   943
   * \brief Get the base directory of the ns-3 distribution.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   944
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   945
  std::string GetBaseDir (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   946
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   947
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   948
   * \brief Set the stream to which status and result messages will be written.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   949
   *
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   950
   * We really don't want to have to pass an ofstream around to every function
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   951
   * and we especially don't want to have to make our clients plumb an ofstream
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   952
   * around so we need to save it.  Since file streams are not designed to be
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   953
   * copied or assigned (what does it mean to have duplicate streams to a file) 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   954
   * we have to stash a pointer to the stream.
5227
ecb08c1fc273 Fix some doxygen warnings revealed by WARN_NO_PARAMDOC=YES in doc/doxygen.conf.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 5225
diff changeset
   955
   * \param ofs output file stream
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   956
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   957
  void SetStream (std::ofstream *ofs);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   958
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   959
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   960
   * \brief Manually update the error status of this test suite.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   961
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   962
   * This does a logical OR of the error argument with the current error status.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   963
   * If the argument is false, it does nothing.  If the argument is true, it 
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   964
   * sets the error status to "an error has occurred."
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   965
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   966
   * \param error The status to use to update the test suite error status
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   967
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   968
  void UpdateErrorStatus (bool error);
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   969
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   970
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   971
   * \brief Manually set the error status of this test suite.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   972
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   973
   * This sets the current error status to the argument provided.  Can be used
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   974
   * to reset any previous errors if the argument is false.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   975
   *
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   976
   * \param error The status to use to set the test suite error status
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   977
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   978
  void SetErrorStatus (bool error);
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   979
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   980
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   981
   * \brief Get the error status of this test suite.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   982
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   983
  bool GetErrorStatus (void);
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   984
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   985
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   986
   * \brief Should test suite continue running cases in the presence of errors?
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   987
   * \returns True if the test suite should continue, false otherwise.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   988
   */
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   989
  bool ContinueOnFailure (void);
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   990
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   991
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   992
   * \brief Issue a test report than the test suite has started running.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   993
   */
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   994
  void ReportStart (void);
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   995
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   996
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   997
   * \brief Issue a test report than the test suite has declared success.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
   998
   */
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
   999
  void ReportSuccess (void);
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
  1000
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
  1001
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
  1002
   * \brief Issue a test report than the test suite has found an error.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
  1003
   */
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1004
  void ReportFailure (void);
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
  1005
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
  1006
  /**
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
  1007
   * \brief Issue a test report than the test suite has completed its run.
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
  1008
   */
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1009
  void ReportEnd (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1010
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1011
protected:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1012
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1013
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1014
   * \brief Implementation of reporting method for the start of the test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1015
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1016
  virtual void DoReportStart (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1017
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1018
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1019
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1020
   * \brief Implementation of reporting method for success of the test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1021
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1022
  virtual void DoReportSuccess (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1023
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1024
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1025
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1026
   * \brief Implementation of reporting method for failure of the test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1027
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1028
  virtual void DoReportFailure (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1029
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1030
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1031
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1032
   * \brief Implementation of reporting method for the end of the test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1033
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1034
  virtual void DoReportEnd (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1035
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1036
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1037
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1038
   * \param verbose Turn on any output the test case may provide
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1039
   * \brief Implementation to do any local setup required for this test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1040
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1041
  virtual void DoSetup (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1042
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1043
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1044
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1045
   * \brief Implementation to actually run this test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1046
   * \param verbose Turn on any output the test case may provide
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1047
   * \returns Boolean sense of "an error has occurred."
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1048
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1049
  virtual bool DoRun (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1050
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1051
  /**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1052
   * \internal
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1053
   * \param verbose Turn on any output the test case may provide
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1054
   * \brief Implementation to do any local setup required for this test suite.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1055
   */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1056
  virtual void DoTeardown (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1057
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1058
private:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1059
  TestSuite (TestSuite& ts);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1060
  TestSuite& operator= (TestSuite& ts);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1061
5438
04cc3ffe0202 Make tests work with MinGW (make win32-system-wall-clock-ms work)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5342
diff changeset
  1062
  SystemWallClockMs m_clock;
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1063
  std::string m_name;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1064
  bool m_verbose;
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
  1065
  bool m_continueOnFailure;
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1066
  std::string m_basedir;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1067
  std::ofstream *m_ofs;
5324
0ba73cdd2a43 Refalgamize test framework to allow multiple test failures
Craig Dowell <craigdo@ee.washington.edu>
parents: 5239
diff changeset
  1068
  bool m_error;
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1069
  TestType m_type;
5438
04cc3ffe0202 Make tests work with MinGW (make win32-system-wall-clock-ms work)
Craig Dowell <craigdo@ee.washington.edu>
parents: 5342
diff changeset
  1070
  
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1071
  typedef std::vector<TestCase *> TestCaseVector_t;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1072
  TestCaseVector_t m_tests;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1073
};
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1074
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1075
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1076
 * \brief A runner to execute tests.
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1077
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1078
class TestRunner
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1079
{
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1080
public:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1081
  static uint32_t AddTestSuite (TestSuite *testSuite);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1082
  static uint32_t GetNTestSuites (void);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1083
  static TestSuite *GetTestSuite (uint32_t n);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1084
};
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1085
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1086
/**
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1087
 * \brief A simple way to store test vectors (for stimulus or from responses)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1088
 */
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1089
template <typename T>
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1090
class TestVectors
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1091
{
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1092
public:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1093
  TestVectors ();
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1094
  virtual ~TestVectors ();
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1095
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1096
  void Reserve (uint32_t reserve);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1097
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1098
  uint32_t Add (T vector);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1099
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1100
  uint32_t GetN (void) const;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1101
  T Get (uint32_t i) const;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1102
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1103
private:
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1104
  TestVectors (const TestVectors& tv);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1105
  TestVectors& operator= (const TestVectors& tv);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1106
  bool operator== (const TestVectors& tv) const;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1107
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1108
  typedef std::vector<T> TestVector_t;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1109
  TestVector_t m_vectors;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1110
};
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1111
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1112
template <typename T>
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1113
TestVectors<T>::TestVectors ()
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1114
  : m_vectors ()
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1115
{
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1116
}
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1117
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1118
template <typename T>
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1119
void
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1120
TestVectors<T>::Reserve (uint32_t reserve)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1121
{
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1122
  m_vectors.reserve (reserve);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1123
}
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1124
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1125
template <typename T>
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1126
TestVectors<T>::~TestVectors ()
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1127
{
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1128
}
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1129
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1130
template <typename T>
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1131
uint32_t
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1132
TestVectors<T>::Add (T vector)
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1133
{
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1134
  uint32_t index = m_vectors.size ();
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1135
  m_vectors.push_back (vector);
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1136
  return index;
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1137
}
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1138
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1139
template <typename T>
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1140
uint32_t 
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1141
TestVectors<T>::GetN (void) const
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1142
{
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1143
  return m_vectors.size ();
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1144
}
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1145
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1146
template <typename T>
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1147
T
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1148
TestVectors<T>::Get (uint32_t i) const
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1149
{
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1150
  NS_ABORT_MSG_UNLESS (m_vectors.size () > i, "TestVectors::Get(): Bad index");
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1151
  return m_vectors[i];
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1152
}
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4678
diff changeset
  1153
5342
3c6109eec550 bug 675: kill old test framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5324
diff changeset
  1154
} // namespace ns3 
9
2c31ae7c94db import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
  1155
5342
3c6109eec550 bug 675: kill old test framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5324
diff changeset
  1156
#endif /* NS3_TEST_H */