LONGBOW_TEST_CASE(JSON, parcJSON_GetByPath) { TestData *data = longBowTestCase_GetClipBoardData(testCase); PARCJSON *json = data->json; char *s = parcJSON_ToString(json); printf("%s\n", s); parcMemory_Deallocate((void **) &s); const PARCJSONValue *value = parcJSON_GetByPath(json, "/string"); assertTrue(parcJSONValue_IsString(value), "Expected /string to be a string type."); value = parcJSON_GetByPath(json, "/null"); assertTrue(parcJSONValue_IsNull(value), "Expected /null to be a null type."); value = parcJSON_GetByPath(json, "/true"); assertTrue(parcJSONValue_IsBoolean(value), "Expected /true to be a boolean type."); value = parcJSON_GetByPath(json, "/integer"); assertTrue(parcJSONValue_IsNumber(value), "Expected /integer to be a number type."); value = parcJSON_GetByPath(json, "/float"); assertTrue(parcJSONValue_IsNumber(value), "Expected /float to be a number type."); value = parcJSON_GetByPath(json, "/array"); assertTrue(parcJSONValue_IsArray(value), "Expected /array to be an array type."); value = parcJSON_GetByPath(json, "/nonexistent"); assertNull(value, "Expected /nonexistent to be NULL"); value = parcJSON_GetByPath(json, "/array/1"); assertTrue(parcJSONValue_IsBoolean(value), "Expected /array/0 to be a boolean type."); value = parcJSON_GetByPath(json, "/array/5"); assertTrue(parcJSONValue_IsArray(value), "Expected /array/5 to be an array type."); assertNotNull(value, "Expected non-null pair"); }
LONGBOW_TEST_CASE(JSON, parcJSON_GetByPath_DeadEndPath) { TestData *data = longBowTestCase_GetClipBoardData(testCase); const PARCJSONValue *value = parcJSON_GetByPath(data->json, "/string/foo"); assertNull(value, "Expected null value return from parcJSON_GetByPath"); }
LONGBOW_TEST_CASE(JSON, parcJSON_GetByPath_BadArrayIndex) { TestData *data = longBowTestCase_GetClipBoardData(testCase); const PARCJSONValue *value = parcJSON_GetByPath(data->json, "/array/100"); assertNull(value, "Expected null value return from parcJSON_GetByPath"); }
LONGBOW_TEST_CASE(Global, athena_ProcessControl_CPI_REGISTER_PREFIX) { PARCURI *connectionURI; Athena *athena = athena_Create(100); CCNxName *name = ccnxName_CreateFromCString("ccnx:/foo/bar"); CCNxControl *control = ccnxControl_CreateAddRouteToSelfRequest(name); // CPI_REGISTER_PREFIX CCNxMetaMessage *registerPrefixCommand = ccnxMetaMessage_CreateFromControl(control); ccnxControl_Release(&control); control = ccnxControl_CreateRemoveRouteToSelfRequest(name); // CPI_UNREGISTER_PREFIX CCNxMetaMessage *unregisterPrefixCommand = ccnxMetaMessage_CreateFromControl(control); ccnxControl_Release(&control); ccnxName_Release(&name); connectionURI = parcURI_Parse("tcp://localhost:50100/listener/name=TCPListener"); const char *result = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); connectionURI = parcURI_Parse("tcp://localhost:50100/name=TCP_0"); result = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI); assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno)); parcURI_Release(&connectionURI); int linkId = athenaTransportLinkAdapter_LinkNameToId(athena->athenaTransportLinkAdapter, "TCP_0"); PARCBitVector *ingressVector = parcBitVector_Create(); parcBitVector_Set(ingressVector, linkId); // Call _Receive() once to prime the link. Messages are dropped until _Receive() is called once. PARCBitVector *linksRead = NULL; CCNxMetaMessage *msg = athenaTransportLinkAdapter_Receive(athena->athenaTransportLinkAdapter, &linksRead, -1); assertNull(msg, "Expected to NOT receive a message after the first call to _Receive()"); CCNxMetaMessage *cpiMessages[2]; cpiMessages[0] = registerPrefixCommand; // CPI_REGISTER_PREFIX cpiMessages[1] = unregisterPrefixCommand; // CPI_UNREGISTER_PREFIX for (int i = 0; i < 2; i++) { CCNxMetaMessage *cpiMessageToSend = cpiMessages[i]; athena_ProcessMessage(athena, cpiMessageToSend, ingressVector); ccnxMetaMessage_Release(&cpiMessageToSend); CCNxMetaMessage *ack = athenaTransportLinkAdapter_Receive(athena->athenaTransportLinkAdapter, &linksRead, -1); assertNotNull(ack, "Expected a CPI_ACK message back"); assertTrue(ccnxMetaMessage_IsControl(ack), "Expected a control message back"); parcBitVector_Release(&linksRead); PARCJSON *json = ccnxControl_GetJson(ack); const PARCJSONValue *cpiAckResult = parcJSON_GetByPath(json, "CPI_ACK/REQUEST/RESULT"); bool commandResult = parcJSONValue_GetBoolean(cpiAckResult); assertTrue(commandResult, "Expected the ACK to contain RESULT=true"); ccnxMetaMessage_Release(&ack); } parcBitVector_Release(&ingressVector); athena_Release(&athena); }
CCNxPortalAnchor * ccnxPortalAnchor_CreateFromJSON(const PARCJSON *json) { CCNxPortalAnchor *result = parcObject_CreateInstance(CCNxPortalAnchor); if (result != NULL) { result->prefix = ccnxName_CreateFromURI(parcBuffer_Overlay(parcJSONValue_GetString(parcJSON_GetByPath(json, "/namePrefix")), 0)); result->expireTime = parcJSONValue_GetInteger(parcJSON_GetByPath(json, "/expireTime")); ccnxPortalAnchor_OptionalAssertValid(result); } return result; }