1
0

unit.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* unit.c API unit tests driver
  2. *
  3. * Copyright (C) 2006-2017 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifndef CyaSSL_UNIT_H
  22. #define CyaSSL_UNIT_H
  23. #include <wolfssl/ssl.h>
  24. #include <wolfssl/test.h> /* thread and tcp stuff */
  25. #define Fail(description, result) do { \
  26. printf("\nERROR - %s line %d failed with:", __FILE__, __LINE__); \
  27. printf("\n expected: "); printf description; \
  28. printf("\n result: "); printf result; printf("\n\n"); \
  29. abort(); \
  30. } while(0)
  31. #define Assert(test, description, result) if (!(test)) Fail(description, result)
  32. #define AssertTrue(x) Assert( (x), ("%s is true", #x), (#x " => FALSE"))
  33. #define AssertFalse(x) Assert(!(x), ("%s is false", #x), (#x " => TRUE"))
  34. #define AssertNotNull(x) Assert( (x), ("%s is not null", #x), (#x " => NULL"))
  35. #define AssertNull(x) do { \
  36. void* _x = (void *) (x); \
  37. \
  38. Assert(!_x, ("%s is null", #x), (#x " => %p", _x)); \
  39. } while(0)
  40. #define AssertInt(x, y, op, er) do { \
  41. int _x = (int)x; \
  42. int _y = (int)y; \
  43. \
  44. Assert(_x op _y, ("%s " #op " %s", #x, #y), ("%d " #er " %d", _x, _y)); \
  45. } while(0)
  46. #define AssertIntEQ(x, y) AssertInt(x, y, ==, !=)
  47. #define AssertIntNE(x, y) AssertInt(x, y, !=, ==)
  48. #define AssertIntGT(x, y) AssertInt(x, y, >, <=)
  49. #define AssertIntLT(x, y) AssertInt(x, y, <, >=)
  50. #define AssertIntGE(x, y) AssertInt(x, y, >=, <)
  51. #define AssertIntLE(x, y) AssertInt(x, y, <=, >)
  52. #define AssertStr(x, y, op, er) do { \
  53. const char* _x = x; \
  54. const char* _y = y; \
  55. int _z = strcmp(_x, _y); \
  56. \
  57. Assert(_z op 0, ("%s " #op " %s", #x, #y), \
  58. ("\"%s\" " #er " \"%s\"", _x, _y));\
  59. } while(0)
  60. #define AssertStrEQ(x, y) AssertStr(x, y, ==, !=)
  61. #define AssertStrNE(x, y) AssertStr(x, y, !=, ==)
  62. #define AssertStrGT(x, y) AssertStr(x, y, >, <=)
  63. #define AssertStrLT(x, y) AssertStr(x, y, <, >=)
  64. #define AssertStrGE(x, y) AssertStr(x, y, >=, <)
  65. #define AssertStrLE(x, y) AssertStr(x, y, <=, >)
  66. void ApiTest(void);
  67. int SuiteTest(void);
  68. int HashTest(void);
  69. void SrpTest(void);
  70. #endif /* CyaSSL_UNIT_H */