You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.8 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: unittest/simple_unittester.h
  3. *
  4. * Purpose: Simple, command-line unit-testing client.
  5. *
  6. * Created: 13th May 2004
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2004-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file unittest/simple_unittester.h
  40. *
  41. * \brief [C++ only] Definition of the stlsoft::unittest::simple_unittest_host
  42. * class, which is a simple command-line unit-testing host
  43. * (\ref group__library__unittest "Unit Test" Library).
  44. */
  45. #ifndef STLSOFT_INCL_UNITTEST_H_SIMPLE_UNITTESTER
  46. #define STLSOFT_INCL_UNITTEST_H_SIMPLE_UNITTESTER
  47. #ifndef _STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. # define STLSOFT_VER_UNITTEST_H_SIMPLE_UNITTESTER_MAJOR 1
  49. # define STLSOFT_VER_UNITTEST_H_SIMPLE_UNITTESTER_MINOR 3
  50. # define STLSOFT_VER_UNITTEST_H_SIMPLE_UNITTESTER_REVISION 4
  51. # define STLSOFT_VER_UNITTEST_H_SIMPLE_UNITTESTER_EDIT 20
  52. #endif /* !_STLSOFT_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Includes
  55. */
  56. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  57. # include <stlsoft/stlsoft.h>
  58. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  59. #ifdef STLSOFT_CF_std_NAMESPACE
  60. # include <vector>
  61. #else /* ? STLSOFT_CF_std_NAMESPACE */
  62. # if defined(STLSOFT_COMPILER_IS_WATCOM)
  63. # include <wcvector.h>
  64. # else /* ? compiler */
  65. # error No other non-std compiler is known
  66. # endif /* ? compiler */
  67. #endif /* STLSOFT_CF_std_NAMESPACE */
  68. #ifndef STLSOFT_UNITTEST
  69. # error This file cannot be used if STLSOFT_UNITTEST is not defined.
  70. #endif /* !STLSOFT_UNITTEST */
  71. /* /////////////////////////////////////////////////////////////////////////
  72. * Namespace
  73. */
  74. #ifndef STLSOFT_NO_NAMESPACE
  75. namespace stlsoft
  76. {
  77. namespace unittest
  78. {
  79. #endif /* STLSOFT_NO_NAMESPACE */
  80. /* /////////////////////////////////////////////////////////////////////////
  81. * Classes
  82. */
  83. class simple_unittest_host
  84. : public unittest_host
  85. {
  86. public:
  87. simple_unittest_host();
  88. virtual ~simple_unittest_host() stlsoft_throw_0();
  89. public:
  90. virtual ss_uint32_t register_unittest_fn(unittest_function pfn);
  91. virtual void deregister_unittest_fn(ss_uint32_t unittestId);
  92. public:
  93. static simple_unittest_host *get_host();
  94. bool test(bool bVerbose);
  95. private:
  96. static simple_unittest_host *make_host(void);
  97. private:
  98. ss_size_t size();
  99. private:
  100. #ifdef STLSOFT_CF_std_NAMESPACE
  101. typedef stlsoft_ns_qual_std(vector)<unittest_function> functions_t;
  102. #else /* ? STLSOFT_CF_std_NAMESPACE */
  103. # if defined(STLSOFT_COMPILER_IS_WATCOM)
  104. typedef WCValVector<unittest_function> functions_t;
  105. # else /* ? compiler */
  106. # error No other non-std compiler is known
  107. # endif /* ? compiler */
  108. #endif /* STLSOFT_CF_std_NAMESPACE */
  109. functions_t m_functions;
  110. };
  111. extern "C" unittest_host *get_unittest_host(void);
  112. /* ////////////////////////////////////////////////////////////////////// */
  113. #ifndef STLSOFT_NO_NAMESPACE
  114. } /* namespace unittest */
  115. } /* namespace stlsoft */
  116. #endif /* STLSOFT_NO_NAMESPACE */
  117. /* ////////////////////////////////////////////////////////////////////// */
  118. #endif /* !STLSOFT_INCL_UNITTEST_H_SIMPLE_UNITTESTER */
  119. /* ///////////////////////////// end of file //////////////////////////// */