static void test_parse_array_bad_nested_elems(void) { { const char *data = "[ \"foo\" [\"baz\"], \"bar\" ]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "[\"foo\"[\"baz\"],\"bar\"]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "[ \"foo\" {\"boing\": \"baz\"}, \"bar\" ]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "[\"foo\"{\"boing\":\"baz\"},\"bar\"]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } }
static void test_parse_object_garbage(void) { { const char *data = "{ \"first\": 1, garbage \"second\": 2 }"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "{ \"first\": 1 garbage \"second\": 2 }"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "{ \"first\": garbage, \"second\": 2 }"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "{ \"first\": garbage \"second\": 2 }"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } }
static void test_parse_array_garbage(void **state) { { const char *data = "[1, garbage]"; JsonElement *json = JsonParse(&data); assert_false(json); } { const char *data = "[1 garbage]"; JsonElement *json = JsonParse(&data); assert_false(json); } { const char *data = "[garbage]"; JsonElement *json = JsonParse(&data); assert_false(json); } { const char *data = "[garbage, 1]"; JsonElement *json = JsonParse(&data); assert_false(json); } }
static void test_parse_array_garbage(void) { { const char *data = "[1, garbage]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "[1 garbage]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "[garbage]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "[garbage, 1]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } }
static void test_parse_object_garbage(void **state) { { const char *data = "{ \"first\": 1, garbage \"second\": 2 }"; JsonElement *json = JsonParse(&data); assert_false(json); } { const char *data = "{ \"first\": 1 garbage \"second\": 2 }"; JsonElement *json = JsonParse(&data); assert_false(json); } { const char *data = "{ \"first\": garbage, \"second\": 2 }"; JsonElement *json = JsonParse(&data); assert_false(json); } { const char *data = "{ \"first\": garbage \"second\": 2 }"; JsonElement *json = JsonParse(&data); assert_false(json); } }
static void test_parse_array_nested_garbage(void **state) { { const char *data = "[1, [garbage]]"; JsonElement *json = JsonParse(&data); assert_false(json); } { const char *data = "[1, { garbage }]"; JsonElement *json = JsonParse(&data); assert_false(json); } }
static void test_parse_object_nested_garbage(void **state) { { const char *data = "{ \"first\": { garbage } }"; JsonElement *json = JsonParse(&data); assert_false(json); } { const char *data = "{ \"first\": [ garbage ] }"; JsonElement *json = JsonParse(&data); assert_false(json); } }
static void test_parse_empty_string(void) { const char *data = ""; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); data = "\"\""; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_string_equal("", JsonPrimitiveGetAsString(json)); JsonDestroy(json); }
static void test_parse_escaped_string(void) { { const char *data = "\"\\\\\""; const char *original = data; JsonElement *json = NULL; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_string_equal("\\", JsonPrimitiveGetAsString(json)); char *out = JsonToString(json); assert_string_equal(original, out); free(out); JsonDestroy(json); } { // included by paranoia from Redmine #5773 const char *data = "\"/\\\\//\\\\/\\\\\""; const char *original = data; JsonElement *json = NULL; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_string_equal("/\\//\\/\\", JsonPrimitiveGetAsString(json)); char *out = JsonToString(json); assert_string_equal(original, out); free(out); JsonDestroy(json); } { const char *data = "\"x\\tx\""; const char *original = data; JsonElement *json = NULL; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_string_equal("x\tx", JsonPrimitiveGetAsString(json)); char *out = JsonToString(json); assert_string_equal(original, out); free(out); JsonDestroy(json); } }
static void test_parse_bad_apple2(void **state) { const char *data = "]["; JsonElement *json = JsonParse(&data); assert_false(json); }
static void test_parse_array_diverse(void **state) { { const char *data = "[1, \"snookie\", 1.0, {}, [], true, false, null ]"; JsonElement *json = JsonParse(&data); assert_true(json); JsonElementDestroy(json); } { const char *data = "[1,\"snookie\",1.0,{},[],true,false,null]"; JsonElement *json = JsonParse(&data); assert_true(json); JsonElementDestroy(json); } }
static void test_parse_empty(void **state) { const char *data = ""; JsonElement *json = JsonParse(&data); assert_false(json); }
static void test_parse_object_diverse(void **state) { { const char *data = "{ \"a\": 1, \"b\": \"snookie\", \"c\": 1.0, \"d\": {}, \"e\": [], \"f\": true, \"g\": false, \"h\": null }"; JsonElement *json = JsonParse(&data); assert_true(json); JsonElementDestroy(json); } { const char *data = "{\"a\":1,\"b\":\"snookie\",\"c\":1.0,\"d\":{},\"e\":[],\"f\":true,\"g\":false,\"h\":null}"; JsonElement *json = JsonParse(&data); assert_true(json); JsonElementDestroy(json); } }
static void test_parse_object_double_colon(void) { { const char *data = "{ \"foo\":: \"bar\" }"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "{\"foo\"::\"bar\"}"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } }
static void test_parse_object_nested_garbage(void) { { const char *data = "{ \"first\": { garbage } }"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "{ \"first\": [ garbage ] }"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } }
static void test_parse_array_nested_garbage(void **state) { { const char *data = "[1, [garbage]]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "[1, { garbage }]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } }
static void test_parse_array_comma_after_brace(void) { { const char *data = "[ , \"foo\", \"bar\" ]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } { const char *data = "[,\"foo\",\"bar\"]"; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); } }
static void test_parse_bad_apple2(void) { const char *data = "]["; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); }
static void test_parse_empty_string(void) { const char *data = ""; JsonElement *json = NULL; assert_int_not_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_false(json); }
static void test_parse_array_diverse(void) { { const char *data = "[1, \"snookie\", 1.0, {}, [], true, false, null ]"; JsonElement *json = NULL; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_true(json); JsonDestroy(json); } { const char *data = "[1,\"snookie\",1.0,{},[],true,false,null]"; JsonElement *json = NULL; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_true(json); JsonDestroy(json); } }
static void test_parse_object_diverse(void) { { const char *data = "{ \"a\": 1, \"b\": \"snookie\", \"c\": 1.0, \"d\": {}, \"e\": [], \"f\": true, \"g\": false, \"h\": null }"; JsonElement *json = NULL; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_true(json); JsonDestroy(json); } { const char *data = "{\"a\":1,\"b\":\"snookie\",\"c\":1.0,\"d\":{},\"e\":[],\"f\":true,\"g\":false,\"h\":null}"; JsonElement *json = NULL; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_true(json); JsonDestroy(json); } }
static void test_parse_trim(void **state) { const char *data = " [] "; JsonElement *json = JsonParse(&data); assert_true(json); JsonElementDestroy(json); }
static void test_parse_array_extra_closing(void **state) { const char *data = " []]"; JsonElement *json = JsonParse(&data); assert_true(json); JsonElementDestroy(json); }
static void test_parse_array_extra_closing(void) { const char *data = " []]"; JsonElement *json = NULL; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_true(json); JsonDestroy(json); }
static void test_parse_tzz_evil_key(void) { const char *data = "{ \"third key! can? be$ anything&\": [ \"a\", \"b\", \"c\" ]}"; JsonElement *obj = NULL; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &obj)); assert_string_equal("b", JsonArrayGetAsString(JsonObjectGetAsArray(obj, "third key! can? be$ anything&"), 1)); JsonDestroy(obj); }
static void test_parse_array_simple(void **state) { const char *data = ARRAY_SIMPLE; JsonElement *arr = JsonParse(&data); assert_string_equal(JsonArrayGetAsString(arr, 1), "two"); assert_string_equal(JsonArrayGetAsString(arr, 0), "one"); JsonElementDestroy(arr); }
static void test_parse_trim(void **state) { const char *data = " [] "; JsonElement *json = NULL; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json)); assert_true(json); JsonElementDestroy(json); }
int CMp4DownloadClient::GetFileName(const char* url, CString& mainfilename) { if (url == NULL) return -1; bool bresult = false; if (!hotvrs_string_ptr_for_name) { hotvrs_string_ptr_for_name = new string[1]; } printf("hotvrs request...\n"); CMultiRequest hotvrs_client(Response_Whole_DataType); //使用手动重置为无信号状态,初始化时无信号状态 bresult = hotvrs_client.AddRequest(url, 0, HotVrsResponseForNameCallBackFunc, ProgressCB,NULL,this); if (!bresult) return -1; CURLcode resultcode = hotvrs_client.Perform(); if (resultcode > CURLE_OK) return -1; SHVideoInfo info_ptr; bresult = JsonParse(hotvrs_string_ptr_for_name[0].c_str(), hotvrs_string_ptr_for_name[0].size(), info_ptr); if (!bresult) return -1; switch (info_ptr.version) { case VER_ORIGINAL: mainfilename = info_ptr.name + L"[原话版]"; break; case VER_SUPER: mainfilename = info_ptr.name + L"[超清版]"; break; case VER_HIGH: mainfilename = info_ptr.name + L"[高清版]"; break; case VER_NORMAL: mainfilename = info_ptr.name + L"[普清版]"; break; default: mainfilename = info_ptr.name; break; } if (hotvrs_string_ptr_for_name) { delete []hotvrs_string_ptr_for_name; hotvrs_string_ptr_for_name=NULL; } return 0; }
static void test_parse_array_simple(void) { const char *data = ARRAY_SIMPLE; JsonElement *arr = NULL; assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &arr)); assert_string_equal(JsonArrayGetAsString(arr, 1), "two"); assert_string_equal(JsonArrayGetAsString(arr, 0), "one"); JsonDestroy(arr); }
static void test_parse_array_object(void **state) { const char *data = ARRAY_OBJECT; JsonElement *arr = JsonParse(&data); JsonElement *first = JsonArrayGetAsObject(arr, 0); assert_string_equal(JsonObjectGetAsString(first, "first"), "one"); JsonElementDestroy(arr); }