ultrajsontest.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "perftest.h"
  2. #if TEST_ULTRAJSON
  3. #include "ultrajson/ultrajsondec.c"
  4. #include "ultrajson/ultrajsonenc.c"
  5. class UltraJson : public PerfTest {
  6. };
  7. static char dummy = 0;
  8. static void Object_objectAddKey(JSOBJ obj, JSOBJ name, JSOBJ value) {}
  9. static void Object_arrayAddItem(JSOBJ obj, JSOBJ value) {}
  10. static JSOBJ Object_newString(wchar_t *start, wchar_t *end) { return &dummy; }
  11. static JSOBJ Object_newTrue(void) { return &dummy; }
  12. static JSOBJ Object_newFalse(void) { return &dummy; }
  13. static JSOBJ Object_newNull(void) { return &dummy; }
  14. static JSOBJ Object_newObject(void) { return &dummy; }
  15. static JSOBJ Object_newArray(void) { return &dummy; }
  16. static JSOBJ Object_newInteger(JSINT32 value) { return &dummy; }
  17. static JSOBJ Object_newLong(JSINT64 value) { return &dummy; }
  18. static JSOBJ Object_newDouble(double value) { return &dummy; }
  19. static void Object_releaseObject(JSOBJ obj) {}
  20. static JSONObjectDecoder decoder = {
  21. Object_newString,
  22. Object_objectAddKey,
  23. Object_arrayAddItem,
  24. Object_newTrue,
  25. Object_newFalse,
  26. Object_newNull,
  27. Object_newObject,
  28. Object_newArray,
  29. Object_newInteger,
  30. Object_newLong,
  31. Object_newDouble,
  32. Object_releaseObject,
  33. malloc,
  34. free,
  35. realloc
  36. };
  37. TEST_F(UltraJson, Decode) {
  38. for (int i = 0; i < kTrialCount; i++) {
  39. decoder.errorStr = NULL;
  40. decoder.errorOffset = NULL;
  41. void *ret = JSON_DecodeObject(&decoder, json_, length_);
  42. ASSERT_TRUE(ret != 0);
  43. }
  44. }
  45. TEST_F(UltraJson, Whitespace) {
  46. for (int i = 0; i < kTrialCount; i++) {
  47. decoder.errorStr = NULL;
  48. decoder.errorOffset = NULL;
  49. void *ret = JSON_DecodeObject(&decoder, whitespace_, whitespace_length_);
  50. ASSERT_TRUE(ret != 0);
  51. }
  52. }
  53. #endif // TEST_ULTRAJSON