test_loadb.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
  3. *
  4. * Jansson is free software; you can redistribute it and/or modify
  5. * it under the terms of the MIT license. See LICENSE for details.
  6. */
  7. #include <jansson.h>
  8. #include <string.h>
  9. #include "util.h"
  10. static void run_tests()
  11. {
  12. json_t *json;
  13. json_error_t error;
  14. const char str[] = "[\"A\", {\"B\": \"C\"}, 1, 2, 3]garbage";
  15. size_t len = strlen(str) - strlen("garbage");
  16. json = json_loadb(str, len, 0, &error);
  17. if(!json) {
  18. fail("json_loadb failed on a valid JSON buffer");
  19. }
  20. json_decref(json);
  21. json = json_loadb(str, len - 1, 0, &error);
  22. if (json) {
  23. json_decref(json);
  24. fail("json_loadb should have failed on an incomplete buffer, but it didn't");
  25. }
  26. if(error.line != 1) {
  27. fail("json_loadb returned an invalid line number on fail");
  28. }
  29. if(strcmp(error.text, "']' expected near end of file") != 0) {
  30. fail("json_loadb returned an invalid error message for an unclosed top-level array");
  31. }
  32. }