void parseRunPushLoop(ParseClient client) { while(1) { int socket = parseGetPushSocket(client); struct timeval tv; fd_set receive, send, error; tv.tv_sec = 10; tv.tv_usec= 0; FD_ZERO(&receive); FD_ZERO(&send); FD_ZERO(&error); FD_SET(socket, &error); FD_SET(socket, &receive); if(select(socket + 1, &receive, &send, &error, &tv) > 0) { if(FD_ISSET(socket, &error)) { parseLog(PARSE_LOG_WARN, "Push socket has problems.\n"); parseStopPushService(client); ParseClientInternal *clientInternal = getClient(client); // we need to notify about the problem because push will not be happening // any more if (clientInternal->pushCallback != NULL) { clientInternal->pushCallback(client, ECONNRESET, NULL); } } } parseProcessNextPushNotification(client); } }
int main(int argc, char *argv[]) { // CREATE UNIQUE IDENTIFIER FOR THE RUN run = time(NULL); char classPathOne[128] = {0}; char classPathTwo[128] = {0}; char classPathThree[128] = {0}; char objectId[11] = {0}; char path[256] = {0}; snprintf(classPathOne, sizeof(classPathOne), "/classes/TestObjectOne%ld", run); // TEST INITIALIZATION ParseClient client = parseInitializeWithServerURL(YOUR_APP_IP, YOUR_CLIENT_KEY, YOUR_SERVER_URL); logResults(client != NULL, 1, "parseInitialize call", "failed to start parse"); // TEST GENERATION OF INSTALLATION ID const char* id = parseGetInstallationId(client); logResults(id == NULL, 0, "parseGetInstallationId call", "remove .parse-embedded from home directory"); parseSendRequest(client, "GET", "/classes/testObjectFake/1111111", NULL, NULL); id = parseGetInstallationId(client); logResults(id != NULL, 1, "parseGetInstallationId call", "did not create the installation id properly"); logResults(verifyInstallationId(id), 0, "installation id generated correctly", "installation id is not correct"); // TEST CREATING AND FETCHING OBJECTS ON/FROM THE SERVER clearCachedResults(); parseSendRequest(client, "POST", classPathOne, "{\"test\":\"object1\", \"value\":1}", callback); logResults(cachedRunResult != NULL, 0, "create test object 1", "creating object failed"); memset(objectId, 0, sizeof(objectId)); logResults(simpleJsonProcessor(cachedRunResult, "objectId", objectId, sizeof(objectId)), 0, "object 1 created", "could not create an object"); clearCachedResults(); memset(path, 0, sizeof(path)); snprintf(path, sizeof(path), "%s/%s", classPathOne, objectId); parseSendRequest(client, "GET", classPathOne, NULL, callback); logResults(cachedRunResult != NULL, 0, "fetch test object 1", "fetching object failed"); clearCachedResults(); parseSendRequest(client, "POST", classPathOne, "{\"test\":\"object1\", \"value\":2}", callback); logResults(cachedRunResult != NULL, 0, "create test object 2", "creating object failed"); memset(objectId, 0, sizeof(objectId)); logResults(simpleJsonProcessor(cachedRunResult, "objectId", objectId, sizeof(objectId)), 0, "object 2 created", "could not create an object"); clearCachedResults(); memset(path, 0, sizeof(path)); snprintf(path, sizeof(path), "%s/%s", classPathOne, objectId); parseSendRequest(client, "GET", classPathOne, NULL, callback); logResults(cachedRunResult != NULL, 0, "fetch test object 2", "fetching object failed"); clearCachedResults(); parseSendRequest(client, "POST", classPathOne, "{\"test\":\"object1\", \"value\":3}", callback); logResults(cachedRunResult != NULL, 0, "create test object 3", "creating object failed"); char objectIdKeepAround[11] = {0}; logResults(simpleJsonProcessor(cachedRunResult, "objectId", objectIdKeepAround, sizeof(objectIdKeepAround)), 0, "object 3 created", "could not create an object"); clearCachedResults(); memset(path, 0, sizeof(path)); snprintf(path, sizeof(path), "%s/%s", classPathOne, objectIdKeepAround); parseSendRequest(client, "GET", classPathOne, NULL, callback); logResults(cachedRunResult != NULL, 0, "fetch test object 3", "fetching object failed"); clearCachedResults(); parseSendRequest(client, "POST", classPathOne, "{\"test\":\"object1\", \"value\":2}", callback); logResults(cachedRunResult != NULL, 0, "create test object 4", "creating object failed"); memset(objectId, 0, sizeof(objectId)); logResults(simpleJsonProcessor(cachedRunResult, "objectId", objectId, sizeof(objectId)), 0, "object 4 created", "could not create an object"); clearCachedResults(); memset(path, 0, sizeof(path)); snprintf(path, sizeof(path), "%s/%s", classPathOne, objectId); parseSendRequest(client, "GET", classPathOne, NULL, callback); logResults(cachedRunResult != NULL, 0, "fetch test object 4", "fetching object failed"); // TEST QUERIES clearCachedResults(); parseSendRequest(client, "GET", classPathOne, "where={\"value\":2}", callback); logResults(cachedRunResult != NULL, 0, "query objects", "querying objects failed"); const char* results = "{\"results\":[{\""; int cmp = !strncmp(cachedRunResult, results, strlen(results)); char* location1 = strstr(cachedRunResult, "objectId"); char* location2 = strstr(location1 + 1, "objectId"); char* location3 = strstr(location2 + 1, "objectId"); logResults(cmp && location1 && location2 && !location3, 0, "query value", "query results not valid"); // TEST OBJECT MODIFICATION clearCachedResults(); memset(path, 0, sizeof(path)); snprintf(path, sizeof(path), "%s/%s", classPathOne, objectIdKeepAround); parseSendRequest(client, "PUT", path, "{\"test\":\"object1\", \"value\":2}", callback); logResults(cachedRunResult != NULL, 0, "modify test object 3", "modifying object failed"); clearCachedResults(); parseSendRequest(client, "GET", classPathOne, "where={\"value\":2}", callback); logResults(cachedRunResult != NULL, 0, "query objects after modification", "querying objects failed"); results = "{\"results\":[{\""; cmp = !strncmp(cachedRunResult, results, strlen(results)); location1 = strstr(cachedRunResult, "objectId"); location2 = strstr(location1 + 1, "objectId"); location3 = strstr(location2 + 1, "objectId"); logResults(cmp && location1 && location2 && location3, 0, "query value after modifying an object", "query results not valid"); // TEST DELETING AN OBJECT clearCachedResults(); memset(path, 0, sizeof(path)); snprintf(path, sizeof(path), "%s/%s", classPathOne, objectIdKeepAround); parseSendRequest(client, "DELETE", path, NULL, callback); logResults(cachedRunResult != NULL, 0, "delete test object 3", "deleting object failed"); clearCachedResults(); parseSendRequest(client, "GET", classPathOne, "where={\"value\":2}", callback); logResults(cachedRunResult != NULL, 0, "query objects after delete", "querying objects failed"); results = "{\"results\":[{\""; cmp = !strncmp(cachedRunResult, results, strlen(results)); location1 = strstr(cachedRunResult, "objectId"); location2 = strstr(location1 + 1, "objectId"); location3 = strstr(location2 + 1, "objectId"); logResults(cmp && location1 && location2 && !location3, 0, "query value after deleting an object", "query results not valid"); // TEST PUSH parseSetPushCallback(client, pushCallback); parseStartPushService(client); int socket = parseGetPushSocket(client); int loopCount = 20; printf("[!!!!!!!] Run ./push.sh %s %ld\n", id, run); while(loopCount--) { struct timeval tv; fd_set receive, send, error; tv.tv_sec = 10; tv.tv_usec= 0; FD_ZERO(&receive); FD_ZERO(&send); FD_ZERO(&error); FD_SET(socket, &error); FD_SET(socket, &receive); select(socket + 1, &receive, &send, &error, &tv); parseProcessNextPushNotification(client); if (pushCounter == 10) loopCount = loopCount > 2 ? 2 : loopCount; } logResults(pushCounter == 10, 0, "receive push notifications", "did not receive the push notifications correctly"); logSummary(); return 0; }