testtool.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "xmlrpc_config.h"
  4. #include "xmlrpc-c/util.h"
  5. #include "xmlrpc-c/util_int.h"
  6. #include "testtool.h"
  7. /* Defines global variable, 'total_tests', 'total_failures' */
  8. /* This is a good place to set a breakpoint. */
  9. void
  10. test_failure(const char * const file,
  11. unsigned int const line,
  12. const char * const label,
  13. const char * const statement) {
  14. ++total_failures;
  15. printf("\n%s:%u: test failure: %s (%s)\n", file, line, label, statement);
  16. /* We abort rather than exit so one can tell from a dump or debug session
  17. who called us.
  18. */
  19. abort();
  20. }
  21. void
  22. test_fault(xmlrpc_env * const envP,
  23. int const expectedCode,
  24. const char * const fileName,
  25. unsigned int const lineNumber) {
  26. ++total_tests;
  27. if (!envP->fault_occurred)
  28. test_failure(fileName, lineNumber, "no fault occurred", "");
  29. else if (envP->fault_code != expectedCode)
  30. test_failure(fileName, lineNumber, "wrong fault occurred",
  31. envP->fault_string);
  32. else
  33. printf(".");
  34. xmlrpc_env_clean(envP);
  35. xmlrpc_env_init(envP);
  36. }
  37. void
  38. test_null_string(const char * const string,
  39. const char * const fileName,
  40. unsigned int const lineNumber) {
  41. ++total_tests;
  42. if (string != NULL)
  43. test_failure(fileName, lineNumber, "string not null", string);
  44. else
  45. printf(".");
  46. }