/*
 *-----------------------------------------------------------------------
 *
 * run_json_test_suite --
 *
 *      Given a path to a directory containing JSON tests, import each
 *      test into a BSON blob and call the provided callback for
 *      evaluation.
 *
 *      It is expected that the callback will assert on failure, so if
 *      callback returns quietly the test is considered to have passed.
 *
 *-----------------------------------------------------------------------
 */
void
install_json_test_suite(TestSuite *suite, const char *dir_path, test_hook callback)
{
   char test_paths[MAX_NUM_TESTS][MAX_TEST_NAME_LENGTH];
   int num_tests;
   int i;
   bson_t *test;
   char *skip_json;
   char *ext;

   num_tests = collect_tests_from_dir(&test_paths[0],
                                      dir_path,
                                      0, MAX_NUM_TESTS);

   for (i = 0; i < num_tests; i++) {
      test = get_bson_from_json_file(test_paths[i]);

      if (test) {
         skip_json = strstr(test_paths[i], "/json") + strlen("/json");
         assert(skip_json);
         ext = strstr (skip_json, ".json");
         assert(ext);
         ext[0] = '\0';

         TestSuite_AddWC(suite, skip_json, (void (*)(void *))callback, (void (*)(void*))bson_destroy, test);
      } else {
         fprintf(stderr, "NO DATA\n");
      }
   }
}
Example #2
0
void
test_add_spec_test (TestSuite *suite, const char *filename, test_hook callback)
{
   bson_t *test;
   char *skip_json;

   test = get_bson_from_json_file ((char *)filename);
   skip_json = strstr (filename, "json")+4;
   skip_json = bson_strndup (skip_json, strlen (skip_json)-5);

   TestSuite_AddWC (suite, skip_json, (void (*)(void *))callback, (void (*)(void*))bson_destroy, test);
   bson_free (skip_json);
}