LONGBOW_TEST_CASE(JSON, parcJSON_Equals) { PARCJSON *x = parcJSON_ParseString("{ \"string\" : \"xyzzy\" }"); PARCJSON *y = parcJSON_ParseString("{ \"string\" : \"xyzzy\" }"); PARCJSON *z = parcJSON_ParseString("{ \"string\" : \"xyzzy\" }"); PARCJSON *notEqual1 = parcJSON_ParseString("{ \"string\" : \"string\" }"); PARCJSON *notEqual2 = parcJSON_ParseString("{ \"string\" : \"xyzzy\", \"integer\" : 1 }"); parcObjectTesting_AssertEqualsFunction(parcJSON_Equals, x, y, z, notEqual1, notEqual2); parcJSON_Release(&x); parcJSON_Release(&y); parcJSON_Release(&z); parcJSON_Release(¬Equal1); parcJSON_Release(¬Equal2); }
LONGBOW_TEST_CASE(JSON, parcJSON_ParseString) { TestData *data = longBowTestCase_GetClipBoardData(testCase); PARCJSON *json = parcJSON_ParseString(data->expected); char *actual = parcJSON_ToString(json); assertTrue(strcmp(data->expected, actual) == 0, "Expected %s, actual %s", data->expected, actual); parcMemory_Deallocate((void **) &actual); parcJSON_Release(&json); }
static int _athenactl_ListFIB(PARCIdentity *identity, int argc, char **argv) { CCNxName *name = ccnxName_CreateFromURI(CCNxNameAthenaCommand_FIBList); CCNxInterest *interest = ccnxInterest_CreateSimple(name); ccnxName_Release(&name); const char *result = _athenactl_SendInterestControl(identity, interest); if (result) { PARCJSON *jsonContent = parcJSON_ParseString(result); if (jsonContent != NULL) { PARCJSONValue *resultValue = parcJSON_GetValueByName(jsonContent, JSON_KEY_RESULT); PARCJSONArray *fibEntryList = parcJSONValue_GetArray(resultValue); size_t fibEntryListLength = parcJSONArray_GetLength(fibEntryList); printf("Routes (%d):\n", (int) fibEntryListLength); if (fibEntryListLength == 0) { printf(" No Entries\n"); } for (size_t i = 0; i < fibEntryListLength; ++i) { PARCJSONValue *elementValue = parcJSONArray_GetValue(fibEntryList, i); PARCJSON *valueObj = parcJSONValue_GetJSON(elementValue); PARCJSONValue *value = parcJSON_GetValueByName(valueObj, JSON_KEY_NAME); char *prefixString = parcBuffer_ToString(parcJSONValue_GetString(value)); value = parcJSON_GetValueByName(valueObj, JSON_KEY_LINK); char *linkString = parcBuffer_ToString(parcJSONValue_GetString(value)); printf(" %s -> %s\n", prefixString, linkString); parcMemory_Deallocate(&prefixString); parcMemory_Deallocate(&linkString); } parcJSON_Release(&jsonContent); } else { printf("Returned value is not JSON: %s\n", result); } parcMemory_Deallocate(&result); } else { printf("NULL result recieved from route List request\n"); } ccnxMetaMessage_Release(&interest); return 0; }
LONGBOW_TEST_CASE(Global, cpiAddressList_FromJSON) { char json_str[] = "{\"ARRAY\":[{\"ADDRESSTYPE\":\"IFACE\",\"DATA\":\"AAAAAA==\"},{\"ADDRESSTYPE\":\"IFACE\",\"DATA\":\"AAAAAQ==\"}]}"; PARCJSON *json = parcJSON_ParseString(json_str); PARCJSONArray *jsonArray = parcJSONValue_GetArray(parcJSON_GetValueByIndex(json, 0)); CPIAddressList *test_list = cpiAddressList_CreateFromJson(jsonArray); CPIAddressList *truth_list = cpiAddressList_Create(); int loops = 2; for (int i = 0; i < loops; i++) { cpiAddressList_Append(truth_list, cpiAddress_CreateFromInterface(i)); } assertTrue(cpiAddressList_Equals(truth_list, test_list), "Lists did not match!"); cpiAddressList_Destroy(&truth_list); cpiAddressList_Destroy(&test_list); parcJSON_Release(&json); }
LONGBOW_TEST_CASE(JSON, parcJSON_AddObject) { PARCJSON *json = parcJSON_Create(); PARCJSON *expectedValue = parcJSON_ParseString("{ \"string\" : \"xyzzy\" }"); parcJSON_AddObject(json, "object", expectedValue); char *expectedName = "object"; const PARCJSONPair *pair = parcJSON_GetPairByName(json, expectedName); PARCBuffer *actualName = parcJSONPair_GetName(pair); PARCJSONValue *actualValue = parcJSONPair_GetValue(pair); assertTrue(strcmp(expectedName, parcBuffer_Overlay(actualName, 0)) == 0, "Expected name %s, actual %s", expectedName, (char *) parcBuffer_ToString(actualName)); assertTrue(parcJSON_Equals(expectedValue, parcJSONValue_GetJSON(actualValue)), "Expected value did not match the actual value."); parcJSON_Release(&expectedValue); parcJSON_Release(&json); }