ctkCoreTestingUtilities.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkCoreTestingUtilities_h
  15. #define __ctkCoreTestingUtilities_h
  16. // CTK includes
  17. #include <ctkCoreExport.h>
  18. // Qt includes
  19. #include <QString>
  20. #include <QStringList>
  21. #include <QVariant>
  22. /// This module provides functions to facilitate writing tests.
  23. ///
  24. /// Before using this module, first consider the QTestLib
  25. /// unit testing framework available in Qt.
  26. ///
  27. /// Example:
  28. ///
  29. /// \code{.cpp}
  30. /// int current = 40 + 2;
  31. /// int expected = 43;
  32. /// if (!CheckInt(__LINE__, "40 + 2", current, expected))
  33. /// {
  34. /// return false;
  35. /// }
  36. /// \endcode
  37. ///
  38. /// Usually these test methods are used by single-line convenience macros
  39. /// defined in ctkCoreTestingMacros.h.
  40. namespace ctkCoreTestingUtilities
  41. {
  42. CTK_CORE_EXPORT
  43. bool CheckInt(int line, const QString& description,
  44. int current, int expected);
  45. CTK_CORE_EXPORT
  46. bool CheckNotNull(int line, const QString& description,
  47. const void* pointer);
  48. CTK_CORE_EXPORT
  49. bool CheckNull(int line, const QString& description,
  50. const void* pointer);
  51. CTK_CORE_EXPORT
  52. bool CheckPointer(int line, const QString& description,
  53. void* current, void* expected, bool errorIfDifferent = true);
  54. CTK_CORE_EXPORT
  55. bool CheckString(int line, const QString& description,
  56. const char* current, const char* expected, bool errorIfDifferent = true );
  57. CTK_CORE_EXPORT
  58. bool CheckStringList(int line, const QString& description,
  59. const QStringList& current, const QStringList& expected);
  60. CTK_CORE_EXPORT
  61. bool CheckVariant(int line, const QString& description,
  62. const QVariant& current, const QVariant& expected);
  63. } // namespace ctkCoreTestingUtilities
  64. #include "ctkCoreTestingUtilities.tpp"
  65. #endif