2
0

test_apu.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  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. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* Some simple functions to make the test apps easier to write and
  17. * a bit more consistent...
  18. * this is a >copy< of apr_test.h
  19. */
  20. /* Things to bear in mind when using these...
  21. *
  22. * If you include '\t' within the string passed in it won't be included
  23. * in the spacing, so use spaces instead :)
  24. *
  25. */
  26. #ifndef APU_TEST_INCLUDES
  27. #define APU_TEST_INCLUDES
  28. #include "apr_strings.h"
  29. #include "apr_time.h"
  30. #define TEST_EQ(str, func, value, good, bad) \
  31. printf("%-60s", str); \
  32. { \
  33. apr_status_t rv; \
  34. if ((rv = func) == value){ \
  35. char errmsg[200]; \
  36. printf("%s\n", bad); \
  37. fprintf(stderr, "Error was %d : %s\n", rv, \
  38. apr_strerror(rv, (char*)&errmsg, 200)); \
  39. exit(-1); \
  40. } \
  41. printf("%s\n", good); \
  42. }
  43. #define TEST_NEQ(str, func, value, good, bad) \
  44. printf("%-60s", str); \
  45. { \
  46. apr_status_t rv; \
  47. if ((rv = func) != value){ \
  48. char errmsg[200]; \
  49. printf("%s\n", bad); \
  50. fprintf(stderr, "Error was %d : %s\n", rv, \
  51. apr_strerror(rv, (char*)&errmsg, 200)); \
  52. exit(-1); \
  53. } \
  54. printf("%s\n", good); \
  55. }
  56. #define TEST_STATUS(str, func, testmacro, good, bad) \
  57. printf("%-60s", str); \
  58. { \
  59. apr_status_t rv = func; \
  60. if (!testmacro(rv)) { \
  61. char errmsg[200]; \
  62. printf("%s\n", bad); \
  63. fprintf(stderr, "Error was %d : %s\n", rv, \
  64. apr_strerror(rv, (char*)&errmsg, 200)); \
  65. exit(-1); \
  66. } \
  67. printf("%s\n", good); \
  68. }
  69. #define STD_TEST_NEQ(str, func) \
  70. TEST_NEQ(str, func, APR_SUCCESS, "OK", "Failed");
  71. #define PRINT_ERROR(rv) \
  72. { \
  73. char errmsg[200]; \
  74. fprintf(stderr, "Error was %d : %s\n", rv, \
  75. apr_strerror(rv, (char*)&errmsg, 200)); \
  76. exit(-1); \
  77. }
  78. #define MSG_AND_EXIT(msg) \
  79. printf("%s\n", msg); \
  80. exit (-1);
  81. #define TIME_FUNCTION(time, function) \
  82. { \
  83. apr_time_t tt = apr_time_now(); \
  84. function; \
  85. time = apr_time_now() - tt; \
  86. }
  87. #endif /* APU_TEST_INCLUDES */