ctkCoreTestingUtilities.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "ctkCoreTestingUtilities.h"
  2. namespace ctkCoreTestingUtilities
  3. {
  4. //----------------------------------------------------------------------------
  5. bool CheckInt(int line, const QString& description,
  6. int current, int expected)
  7. {
  8. return Check<int>(line, description, current, expected, "CheckInt");
  9. }
  10. //----------------------------------------------------------------------------
  11. bool CheckNotNull(int line, const QString& description,
  12. const void* pointer)
  13. {
  14. if(!pointer)
  15. {
  16. qWarning() << "\nLine " << line << " - " << description
  17. << " : CheckNotNull failed"
  18. << "\n\tpointer:" << pointer;
  19. return false;
  20. }
  21. return true;
  22. }
  23. //----------------------------------------------------------------------------
  24. bool CheckNull(int line, const QString& description, const void* pointer)
  25. {
  26. if(pointer)
  27. {
  28. qWarning() << "\nLine " << line << " - " << description
  29. << " : CheckNull failed"
  30. << "\n\tpointer:" << pointer;
  31. return false;
  32. }
  33. return true;
  34. }
  35. //----------------------------------------------------------------------------
  36. bool CheckPointer(int line, const QString& description,
  37. void* current, void* expected, bool errorIfDifferent /* = true */)
  38. {
  39. return Check<void*>(line, description, current, expected, "CheckPointer", errorIfDifferent);
  40. }
  41. //----------------------------------------------------------------------------
  42. bool CheckString(int line, const QString& description,
  43. const char* current, const char* expected, bool errorIfDifferent /* = true */)
  44. {
  45. QString testName = "CheckString";
  46. bool different = true;
  47. if (current == 0 || expected == 0)
  48. {
  49. different = !(current == 0 && expected == 0);
  50. }
  51. else if(strcmp(current, expected) == 0)
  52. {
  53. different = false;
  54. }
  55. if(different == errorIfDifferent)
  56. {
  57. qWarning() << "\nLine " << line << " - " << description
  58. << " : " << testName << " failed"
  59. << "\n\tcurrent :" << (current ? current : "<null>")
  60. << "\n\texpected:" << (expected ? expected : "<null>");
  61. return false;
  62. }
  63. return true;
  64. }
  65. //----------------------------------------------------------------------------
  66. bool CheckStringList(int line, const QString& description,
  67. const QStringList& current, const QStringList& expected)
  68. {
  69. return CheckList<QString>(line, description, current, expected, "CheckStringList");
  70. }
  71. //----------------------------------------------------------------------------
  72. bool CheckVariant(int line, const QString& description,
  73. const QVariant& current, const QVariant& expected)
  74. {
  75. return Check<QVariant>(line, description, current, expected, "CheckVariant");
  76. }
  77. } // namespace ctkCoreTestingUtilities