TEST(LockManager, ConflictingConversion) { LockManager lockMgr; const ResourceId resId(RESOURCE_COLLECTION, std::string("TestDB.collection")); MMAPV1LockerImpl locker1; MMAPV1LockerImpl locker2; LockRequestCombo request1(&locker1); LockRequestCombo request2(&locker2); // The S requests are granted right away ASSERT(LOCK_OK == lockMgr.lock(resId, &request1, MODE_S)); ASSERT(request1.numNotifies == 0); ASSERT(LOCK_OK == lockMgr.lock(resId, &request2, MODE_S)); ASSERT(request2.numNotifies == 0); // Convert first request to conflicting ASSERT(LOCK_WAITING == lockMgr.convert(resId, &request1, MODE_X)); ASSERT(request1.numNotifies == 0); // Free the second lock and make sure the first is granted lockMgr.unlock(&request2); ASSERT(request1.mode == MODE_X); ASSERT(request1.numNotifies == 1); ASSERT(request2.numNotifies == 0); // Frees the first reference, mode remains X lockMgr.unlock(&request1); ASSERT(request1.mode == MODE_X); ASSERT(request1.recursiveCount == 1); lockMgr.unlock(&request1); }
// Copy constructor with all the parameter and copy constructor for constructor with request and mimetype as parameter. void tst_QMediaResource::copyConstructor() { // Initialise all the parameters. const QUrl url(QString::fromLatin1("http://test.com/test.mp4")); const QString mimeType(QLatin1String("video/mp4")); const QString amrCodec(QLatin1String("amr")); const QString h264Codec(QLatin1String("h264")); const qint64 dataSize(23600); int audioBitRate = 1, sampleRate = 2, channelCount = 3, videoBitRate = 4; QSize resolution(QSize(640, 480)); QString language("eng"); // Create the instance with url and mimetype. QMediaResource original(url, mimeType); // Set all the parameters. original.setAudioCodec(amrCodec); original.setLanguage(QString("eng")); original.setVideoCodec(h264Codec); original.setDataSize(dataSize); original.setAudioBitRate(audioBitRate); original.setSampleRate(sampleRate); original.setChannelCount(channelCount); original.setVideoBitRate(videoBitRate); original.setResolution(resolution); // Copy the instance to new object. QMediaResource copy(original); // Verify all the parameters of the copied object. QCOMPARE(copy.url(), url); QCOMPARE(copy.mimeType(), mimeType); QCOMPARE(copy.audioCodec(), amrCodec); QCOMPARE(copy.language(), language ); QCOMPARE(copy.videoCodec(), h264Codec); QCOMPARE(copy.dataSize(), dataSize); QCOMPARE(copy.audioBitRate(), audioBitRate); QCOMPARE(copy.sampleRate(), sampleRate); QCOMPARE(copy.channelCount(), channelCount); QCOMPARE(copy.videoBitRate(), videoBitRate); QCOMPARE(copy.resolution(), resolution); // Compare both the objects are equal. QCOMPARE(original == copy, true); QCOMPARE(original != copy, false); // Initialise the request parameter. QNetworkRequest request1(QUrl(QString::fromLatin1("http://test.com/test.mp4"))); // Constructor with rerquest and mimetype. QMediaResource original1(request1, mimeType); // Copy the object and verify if both are eqaul or not. QMediaResource copy1(original1); QCOMPARE(copy1.url(), url); QCOMPARE(copy1.mimeType(), mimeType); QCOMPARE(copy1.request(), request1); QCOMPARE(original1 == copy1, true); }
void UT_CNATTraversalPendingRequest::TestL() { TUint32 requestId1 = 1; TNATTraversalPendingRequest request1(requestId1,this,*this); EUNIT_ASSERT(requestId1 == request1.RequestId()); request1.CompleteRequest(); EUNIT_ASSERT(iLastRequestId == request1.RequestId()); iLastRequestId = 0; TNATTraversalPendingRequest::TimerExpired(&request1); EUNIT_ASSERT(iLastRequestId == request1.RequestId()); EUNIT_ASSERT(iRequestCompletedCalled); TUint32 requestId2 = 2; TNATTraversalPendingRequest request2(requestId2,NULL,*this); // observer NULL iLastRequestId = 0; request2.CompleteRequest(); EUNIT_ASSERT(0 == iLastRequestId); // compare EUNIT_ASSERT(-1 == TNATTraversalPendingRequest::RequestOrder(request1,request2)); EUNIT_ASSERT(1 == TNATTraversalPendingRequest::RequestOrder(request2,request1)); EUNIT_ASSERT(0 == TNATTraversalPendingRequest::RequestOrder(request1,request1)); }
TEST(LockManager, CancelWaitingConversionStrongModes) { LockManager lockMgr; const ResourceId resId(RESOURCE_COLLECTION, std::string("TestDB.collection")); MMAPV1LockerImpl locker1; MMAPV1LockerImpl locker2; LockRequestCombo request1(&locker1); LockRequestCombo request2(&locker2); // First request granted right away ASSERT(LOCK_OK == lockMgr.lock(resId, &request1, MODE_S)); ASSERT(request1.numNotifies == 0); // Second request is granted right away ASSERT(LOCK_OK == lockMgr.lock(resId, &request2, MODE_S)); ASSERT(request2.numNotifies == 0); // Convert second request to conflicting ASSERT(LOCK_WAITING == lockMgr.convert(resId, &request2, MODE_X)); ASSERT(request2.mode == MODE_S); ASSERT(request2.convertMode == MODE_X); ASSERT(request2.numNotifies == 0); // Cancel the conflicting upgrade lockMgr.unlock(&request2); ASSERT(request2.mode == MODE_S); ASSERT(request2.convertMode == MODE_NONE); ASSERT(request2.numNotifies == 0); // Free the remaining locks so the LockManager destructor does not complain lockMgr.unlock(&request1); lockMgr.unlock(&request2); }
TEST_F(ResourceFetcherTest, RevalidateWhileFinishingLoading) { KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.png"); ResourceResponse response; response.setURL(url); response.setHTTPStatusCode(200); response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); response.setHTTPHeaderField(HTTPNames::ETag, "1234567890"); URLTestHelpers::registerMockedURLLoadWithCustomResponse( url, testImageFilename, WebString::fromUTF8(""), WrappedResourceResponse(response)); ResourceFetcher* fetcher1 = ResourceFetcher::create(ResourceFetcherTestMockFetchContext::create()); ResourceRequest request1(url); request1.setHTTPHeaderField(HTTPNames::Cache_Control, "no-cache"); FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo()); Resource* resource1 = ImageResource::fetch(fetchRequest1, fetcher1); Persistent<RequestSameResourceOnComplete> client = new RequestSameResourceOnComplete(resource1); resource1->addClient(client); Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); EXPECT_TRUE(client->notifyFinishedCalled()); resource1->removeClient(client); memoryCache()->remove(resource1); }
TEST(LockManager, CompatibleFirstImmediateGrant) { LockManager lockMgr; const ResourceId resId(RESOURCE_GLOBAL, 0); MMAPV1LockerImpl locker1; LockRequestCombo request1(&locker1); MMAPV1LockerImpl locker2; LockRequestCombo request2(&locker2); request2.compatibleFirst = true; MMAPV1LockerImpl locker3; LockRequestCombo request3(&locker3); // Lock all in IS mode ASSERT(LOCK_OK == lockMgr.lock(resId, &request1, MODE_IS)); ASSERT(LOCK_OK == lockMgr.lock(resId, &request2, MODE_IS)); ASSERT(LOCK_OK == lockMgr.lock(resId, &request3, MODE_IS)); // Now an exclusive mode comes, which would block MMAPV1LockerImpl lockerX; LockRequestCombo requestX(&lockerX); ASSERT(LOCK_WAITING == lockMgr.lock(resId, &requestX, MODE_X)); // If an S comes, it should be granted, because of request2 { MMAPV1LockerImpl lockerS; LockRequestCombo requestS(&lockerS); ASSERT(LOCK_OK == lockMgr.lock(resId, &requestS, MODE_S)); ASSERT(lockMgr.unlock(&requestS)); } // If request1 goes away, the policy should still be compatible-first, because of request2 ASSERT(lockMgr.unlock(&request1)); // If S comes again, it should be granted, because of request2 still there { MMAPV1LockerImpl lockerS; LockRequestCombo requestS(&lockerS); ASSERT(LOCK_OK == lockMgr.lock(resId, &requestS, MODE_S)); ASSERT(lockMgr.unlock(&requestS)); } // With request2 gone the policy should go back to FIFO, even though request3 is active ASSERT(lockMgr.unlock(&request2)); { MMAPV1LockerImpl lockerS; LockRequestCombo requestS(&lockerS); ASSERT(LOCK_WAITING == lockMgr.lock(resId, &requestS, MODE_S)); ASSERT(lockMgr.unlock(&requestS)); } // Unlock request3 to keep the lock mgr not assert for leaked locks ASSERT(lockMgr.unlock(&request3)); ASSERT(lockMgr.unlock(&requestX)); }
TEST_F(ResourceFetcherTest, RevalidateDeferedResourceFromTwoInitiators) { KURL url(ParsedURLString, "http://127.0.0.1:8000/font.woff"); ResourceResponse response; response.setURL(url); response.setHTTPStatusCode(200); response.setHTTPHeaderField(HTTPNames::ETag, "1234567890"); Platform::current()->getURLLoaderMockFactory()->registerURL( url, WrappedResourceResponse(response), ""); ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchContext::create(); ResourceFetcher* fetcher = ResourceFetcher::create(context); // Fetch to cache a resource. ResourceRequest request1(url); FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo()); Resource* resource1 = FontResource::fetch(fetchRequest1, fetcher); ASSERT_TRUE(resource1); fetcher->startLoad(resource1); Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); EXPECT_TRUE(resource1->isLoaded()); EXPECT_FALSE(resource1->errorOccurred()); // Set the context as it is on reloads. context->setLoadComplete(true); context->setCachePolicy(CachePolicyRevalidate); // Revalidate the resource. ResourceRequest request2(url); FetchRequest fetchRequest2 = FetchRequest(request2, FetchInitiatorInfo()); Resource* resource2 = FontResource::fetch(fetchRequest2, fetcher); ASSERT_TRUE(resource2); EXPECT_EQ(resource1, resource2); EXPECT_TRUE(resource2->isCacheValidator()); EXPECT_TRUE(resource2->stillNeedsLoad()); // Fetch the same resource again before actual load operation starts. ResourceRequest request3(url); FetchRequest fetchRequest3 = FetchRequest(request3, FetchInitiatorInfo()); Resource* resource3 = FontResource::fetch(fetchRequest3, fetcher); ASSERT_TRUE(resource3); EXPECT_EQ(resource2, resource3); EXPECT_TRUE(resource3->isCacheValidator()); EXPECT_TRUE(resource3->stillNeedsLoad()); // startLoad() can be called from any initiator. Here, call it from the // latter. fetcher->startLoad(resource3); Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); EXPECT_TRUE(resource3->isLoaded()); EXPECT_FALSE(resource3->errorOccurred()); EXPECT_TRUE(resource2->isLoaded()); EXPECT_FALSE(resource2->errorOccurred()); memoryCache()->remove(resource1); }
TEST(RequestTests, Constructors) { gallocy::http::Request request1(GET_REQUEST, gallocy::common::Peer()); ASSERT_EQ(request1.method, "GET"); #if 0 gallocy::http::Request request2 = request1; ASSERT_EQ(request2.method, "GET"); gallocy::http::Request request3(request1); ASSERT_EQ(request3.method, "GET"); #endif }
TEST_F(CachingCorrectnessTest, PostToSameURLTwice) { ResourceRequest request1(KURL(ParsedURLString, kResourceURL)); request1.setHTTPMethod(HTTPNames::POST); ResourcePtr<Resource> resource1 = new Resource(ResourceRequest(request1.url()), Resource::Raw); resource1->setLoading(true); memoryCache()->add(resource1.get()); ResourceRequest request2(KURL(ParsedURLString, kResourceURL)); request2.setHTTPMethod(HTTPNames::POST); FetchRequest fetch2(request2, FetchInitiatorInfo()); ResourcePtr<Resource> resource2 = RawResource::fetchSynchronously(fetch2, fetcher()); EXPECT_EQ(resource2, memoryCache()->resourceForURL(request2.url())); EXPECT_NE(resource1, resource2); }
TEST(LockManager, ConvertUpgrade) { LockManager lockMgr; const ResourceId resId(RESOURCE_COLLECTION, std::string("TestDB.collection")); MMAPV1LockerImpl locker1; LockRequestCombo request1(&locker1); ASSERT(LOCK_OK == lockMgr.lock(resId, &request1, MODE_S)); MMAPV1LockerImpl locker2; LockRequestCombo request2(&locker2); ASSERT(LOCK_OK == lockMgr.lock(resId, &request2, MODE_S)); // Upgrade the S lock to X ASSERT(LOCK_WAITING == lockMgr.convert(resId, &request1, MODE_X)); ASSERT(!lockMgr.unlock(&request1)); ASSERT(lockMgr.unlock(&request1)); ASSERT(lockMgr.unlock(&request2)); }
TEST(LockManager, CompatibleFirstGrantAlreadyQueued) { LockManager lockMgr; const ResourceId resId(RESOURCE_GLOBAL, 0); // This tests the following behavior: // Lock held in X, queue: S IX IS, where S is compatibleFirst. // Once X unlocks both the S and IS requests should proceed. MMAPV1LockerImpl locker1; LockRequestCombo request1(&locker1); MMAPV1LockerImpl locker2; LockRequestCombo request2(&locker2); request2.compatibleFirst = true; MMAPV1LockerImpl locker3; LockRequestCombo request3(&locker3); MMAPV1LockerImpl locker4; LockRequestCombo request4(&locker4); // Hold the lock in X and establish the S IX IS queue. ASSERT(LOCK_OK == lockMgr.lock(resId, &request1, MODE_X)); ASSERT(LOCK_WAITING == lockMgr.lock(resId, &request2, MODE_S)); ASSERT(LOCK_WAITING == lockMgr.lock(resId, &request3, MODE_IX)); ASSERT(LOCK_WAITING == lockMgr.lock(resId, &request4, MODE_IS)); // Now unlock, so all readers should be able to proceed, while the IX remains queued. ASSERT(lockMgr.unlock(&request1)); ASSERT(request2.lastResult == LOCK_OK); ASSERT(request3.lastResult == LOCK_INVALID); ASSERT(request4.lastResult == LOCK_OK); // Now unlock the S lock, and the IX succeeds as well. ASSERT(lockMgr.unlock(&request2)); ASSERT(request3.lastResult == LOCK_OK); // Unlock remaining ASSERT(lockMgr.unlock(&request4)); ASSERT(lockMgr.unlock(&request3)); }
TEST(LockManager, Downgrade) { LockManager lockMgr; const ResourceId resId(RESOURCE_COLLECTION, std::string("TestDB.collection")); MMAPV1LockerImpl locker1; LockRequestCombo request1(&locker1); ASSERT(LOCK_OK == lockMgr.lock(resId, &request1, MODE_X)); MMAPV1LockerImpl locker2; LockRequestCombo request2(&locker2); ASSERT(LOCK_WAITING == lockMgr.lock(resId, &request2, MODE_S)); // Downgrade the X request to S lockMgr.downgrade(&request1, MODE_S); ASSERT(request2.numNotifies == 1); ASSERT(request2.lastResult == LOCK_OK); ASSERT(request2.recursiveCount == 1); ASSERT(lockMgr.unlock(&request1)); ASSERT(lockMgr.unlock(&request2)); }
TEST(LockManager, Conflict) { LockManager lockMgr; const ResourceId resId(RESOURCE_COLLECTION, std::string("TestDB.collection")); MMAPV1LockerImpl locker1; MMAPV1LockerImpl locker2; LockRequestCombo request1(&locker1); LockRequestCombo request2(&locker2); // First request granted right away ASSERT(LOCK_OK == lockMgr.lock(resId, &request1, MODE_S)); ASSERT(request1.recursiveCount == 1); ASSERT(request1.numNotifies == 0); // Second request must block ASSERT(LOCK_WAITING == lockMgr.lock(resId, &request2, MODE_X)); ASSERT(request2.mode == MODE_X); ASSERT(request2.recursiveCount == 1); ASSERT(request2.numNotifies == 0); // Release first request lockMgr.unlock(&request1); ASSERT(request1.recursiveCount == 0); ASSERT(request1.numNotifies == 0); ASSERT(request2.mode == MODE_X); ASSERT(request2.recursiveCount == 1); ASSERT(request2.numNotifies == 1); ASSERT(request2.lastResult == LOCK_OK); // Release second acquire lockMgr.unlock(&request2); ASSERT(request2.recursiveCount == 0); ASSERT(request1.numNotifies == 0); ASSERT(request2.numNotifies == 1); }
bool JouleDevice::getUnitFreeSpace(QString &memory, QString &err) { emit updateStatus(tr("Get Unit Free Space...")); if (JOULE_DEBUG) printf("Get Unit Free Space\n"); JoulePacket request1(GET_FREE_SPACE); if (!request1.write(dev, err)) return false; JoulePacket response1 = JoulePacket(GET_FREE_SPACE); if (response1.read(dev, err)) { if (response1.payload.length()>3) { int empty = qByteArray2Int(response1.payload.left(2)); int total = qByteArray2Int(response1.payload.right(2)); int percentage = 100 * empty / total; memory = QString("%1/%2 (%3%)").arg(empty).arg(total).arg(percentage); return true; } } return false; }
static int coap_receive(void) { coap_error_code = NO_ERROR; PRINTF("handle_incoming_data(): received uip_datalen=%u \n", (uint16_t)uip_datalen()); if (uip_newdata()) { PRINTF("receiving UDP datagram from: "); PRINT6ADDR(&UIP_IP_BUF->srcipaddr); PRINTF(":%u\n Length: %u\n Data: ", uip_ntohs(UIP_UDP_BUF->srcport), uip_datalen() ); PRINTBITS(uip_appdata, uip_datalen()); PRINTF("\n"); coap_error_code = coap_parse_message(message, uip_appdata, uip_datalen()); if (coap_error_code==NO_ERROR) { /*TODO duplicates suppression, if required by application */ PRINTF(" Parsed: v %u, t %u, tkl %u, c %u, mid %u\n", message->version, message->type, message->token_len, message->code, message->mid); PRINTF(" URL: %.*s\n", message->uri_path_len, message->uri_path); PRINTF(" Payload: %.*s\n", message->payload_len, message->payload); /* Handle requests. */ if (message->code >= COAP_GET && message->code <= COAP_DELETE) { #if COAP_CEU int ret; TCEU_Transaction t = { message->mid, &UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, request1, NULL, NULL, NULL, 0, {} }; tceu__int___void_ ps = { &ret, &t }; ceu_go_event(CEU_IN_COAP_REQUEST, &ps); if (! ret) { coap_error_code = SERVICE_UNAVAILABLE_5_03; coap_error_message = "NoFreeTraBuffer"; } #else /* Use transaction buffer for response to confirmable request. */ if ( (transaction = coap_new_transaction(message->mid, &UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport)) ) { request1(transaction,NULL); } else { coap_error_code = SERVICE_UNAVAILABLE_5_03; coap_error_message = "NoFreeTraBuffer"; } /* if (transaction buffer) */ #endif } else { /* Responses */ if (message->type==COAP_TYPE_CON && message->code==0) { PRINTF("Received Ping\n"); coap_error_code = PING_RESPONSE; } else if (message->type==COAP_TYPE_ACK) { /* Transactions are closed through lookup below */ PRINTF("Received ACK\n"); } else if (message->type==COAP_TYPE_RST) { PRINTF("Received RST\n"); /* Cancel possible subscriptions. */ #ifdef COAP_OBSERVER coap_remove_observer_by_mid(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, message->mid); #endif } #if COAP_CEU ceu_go_event(CEU_IN_COAP_RESPONSE, message); #else if ( (transaction = coap_get_transaction_by_mid(message->mid)) ) { /* Free transaction memory before callback, as it may create a new transaction. */ restful_response_handler callback = transaction->callback; void *callback_data = transaction->callback_data; coap_clear_transaction(transaction); /* Check if someone registered for the response */ if (callback) { callback(callback_data, message); } } /* if (ACKed transaction) */ transaction = NULL; #endif } /* Request or Response */ } /* if (parsed correctly) */ if (coap_error_code==NO_ERROR) { #if ! COAP_CEU if (transaction) coap_send_transaction(transaction); #endif } else if (coap_error_code==MANUAL_RESPONSE) /* TODO! */ { PRINTF("Clearing transaction for manual response"); #if ! COAP_CEU coap_clear_transaction(transaction); #endif } else { coap_message_type_t reply_type = COAP_TYPE_ACK; PRINTF("ERROR %u: %s\n", coap_error_code, coap_error_message); #if ! COAP_CEU coap_clear_transaction(transaction); #endif /* Set to sendable error code. */ if (coap_error_code >= 192) { coap_error_code = INTERNAL_SERVER_ERROR_5_00; } if (coap_error_code == PING_RESPONSE) { coap_error_code = 0; reply_type = COAP_TYPE_RST; } /* Reuse input buffer for error message. */ coap_init_message(message, reply_type, coap_error_code, message->mid); coap_set_payload(message, coap_error_message, strlen(coap_error_message)); coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, uip_appdata, coap_serialize_message(message, uip_appdata)); } } /* if (new data) */ return coap_error_code; }