JSON_FAIL.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "JSON_FAIL.h"
  2. #include "../../Source/JSONDebug.h"
  3. #if defined JSON_DEBUG
  4. #ifndef JSON_STDERROR
  5. static json_string last;
  6. #ifdef JSON_LIBRARY
  7. static void callback(const json_char * p){ last = p; }
  8. #else
  9. static void callback(const json_string & p){ last = p; }
  10. #endif
  11. #endif
  12. #endif
  13. const json_string fail_constf = JSON_TEXT("fail"); //should pass the same pointer all the way through, no copies
  14. const json_string null_constf = JSON_TEXT("");
  15. #if defined JSON_DEBUG || defined JSON_SAFE
  16. json_error_callback_t origCallbackf = NULL;
  17. #endif
  18. void testJSONDebug_JSON_FAIL::setUp(const std::string & methodName){
  19. BaseTest::setUp(methodName);
  20. #if defined JSON_DEBUG
  21. #ifndef JSON_STDERROR
  22. origCallbackf = JSONDebug::register_callback(callback); //check that the callback was called
  23. last = null_constf;
  24. #endif
  25. #endif
  26. }
  27. void testJSONDebug_JSON_FAIL::tearDown(void){
  28. BaseTest::tearDown();
  29. #if defined JSON_DEBUG
  30. #ifndef JSON_STDERROR
  31. JSONDebug::register_callback(origCallbackf); //check that the callback was called
  32. #endif
  33. #endif
  34. }
  35. /**
  36. * Make sure fails do call the callback
  37. */
  38. void testJSONDebug_JSON_FAIL::testFail(void){
  39. #if defined JSON_DEBUG
  40. #ifndef JSON_STDERROR
  41. JSON_FAIL(fail_constf);
  42. assertEquals(last, fail_constf); //make sure the callback was actually called
  43. #endif
  44. #endif
  45. }