diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-11-12 17:12:19 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-11-16 12:25:47 -0800 |
commit | 1caf89c32b80dc300b1fd349a2ece4557890c727 (patch) | |
tree | 21d66457063e8bcbf44b7604299dec7a6ac90f7f /test | |
parent | 36581f3d3015d525db92248004e9dc7477705694 (diff) | |
download | qtlocation-mapboxgl-1caf89c32b80dc300b1fd349a2ece4557890c727.tar.gz |
[core] Pass a value to response callback, not a reference
Diffstat (limited to 'test')
-rw-r--r-- | test/storage/cache_response.cpp | 4 | ||||
-rw-r--r-- | test/storage/cache_revalidate.cpp | 12 | ||||
-rw-r--r-- | test/storage/directory_reading.cpp | 3 | ||||
-rw-r--r-- | test/storage/file_reading.cpp | 9 | ||||
-rw-r--r-- | test/storage/http_cancel.cpp | 6 | ||||
-rw-r--r-- | test/storage/http_coalescing.cpp | 19 | ||||
-rw-r--r-- | test/storage/http_error.cpp | 6 | ||||
-rw-r--r-- | test/storage/http_header_parsing.cpp | 4 | ||||
-rw-r--r-- | test/storage/http_issue_1369.cpp | 4 | ||||
-rw-r--r-- | test/storage/http_load.cpp | 2 | ||||
-rw-r--r-- | test/storage/http_other_loop.cpp | 2 | ||||
-rw-r--r-- | test/storage/http_reading.cpp | 6 | ||||
-rw-r--r-- | test/storage/http_retry_network_status.cpp | 4 | ||||
-rw-r--r-- | test/storage/http_timeout.cpp | 2 |
14 files changed, 36 insertions, 47 deletions
diff --git a/test/storage/cache_response.cpp b/test/storage/cache_response.cpp index 306abc9f01..fb745d9ad4 100644 --- a/test/storage/cache_response.cpp +++ b/test/storage/cache_response.cpp @@ -21,7 +21,7 @@ TEST_F(Storage, CacheResponse) { Request* req1 = nullptr; Request* req2 = nullptr; - req1 = fs.request(resource, [&](const Response &res) { + req1 = fs.request(resource, [&](Response res) { fs.cancel(req1); EXPECT_EQ(nullptr, res.error); EXPECT_EQ(false, res.stale); @@ -34,7 +34,7 @@ TEST_F(Storage, CacheResponse) { // Now test that we get the same values as in the previous request. If we'd go to the server // again, we'd get different values. - req2 = fs.request(resource, [&](const Response &res2) { + req2 = fs.request(resource, [&](Response res2) { fs.cancel(req2); EXPECT_EQ(response.error, res2.error); EXPECT_EQ(response.stale, res2.stale); diff --git a/test/storage/cache_revalidate.cpp b/test/storage/cache_revalidate.cpp index c137b13da0..0dfe765e7f 100644 --- a/test/storage/cache_revalidate.cpp +++ b/test/storage/cache_revalidate.cpp @@ -18,7 +18,7 @@ TEST_F(Storage, CacheRevalidateSame) { const Resource revalidateSame { Resource::Unknown, "http://127.0.0.1:3000/revalidate-same" }; Request* req1 = nullptr; Request* req2 = nullptr; - req1 = fs.request(revalidateSame, [&](const Response &res) { + req1 = fs.request(revalidateSame, [&](Response res) { // This callback can get triggered multiple times. We only care about the first invocation. // It will get triggered again when refreshing the req2 (see below). static bool first = true; @@ -35,7 +35,7 @@ TEST_F(Storage, CacheRevalidateSame) { EXPECT_EQ(0, res.modified); EXPECT_EQ("snowfall", res.etag); - req2 = fs.request(revalidateSame, [&, res](const Response &res2) { + req2 = fs.request(revalidateSame, [&, res](Response res2) { if (res2.stale) { // Discard stale responses, if any. return; @@ -81,7 +81,7 @@ TEST_F(Storage, CacheRevalidateModified) { "http://127.0.0.1:3000/revalidate-modified" }; Request* req1 = nullptr; Request* req2 = nullptr; - req1 = fs.request(revalidateModified, [&](const Response& res) { + req1 = fs.request(revalidateModified, [&](Response res) { // This callback can get triggered multiple times. We only care about the first invocation. // It will get triggered again when refreshing the req2 (see below). static bool first = true; @@ -98,7 +98,7 @@ TEST_F(Storage, CacheRevalidateModified) { EXPECT_EQ(1420070400, res.modified); EXPECT_EQ("", res.etag); - req2 = fs.request(revalidateModified, [&, res](const Response &res2) { + req2 = fs.request(revalidateModified, [&, res](Response res2) { if (res2.stale) { // Discard stale responses, if any. return; @@ -142,7 +142,7 @@ TEST_F(Storage, CacheRevalidateEtag) { const Resource revalidateEtag { Resource::Unknown, "http://127.0.0.1:3000/revalidate-etag" }; Request* req1 = nullptr; Request* req2 = nullptr; - req1 = fs.request(revalidateEtag, [&](const Response &res) { + req1 = fs.request(revalidateEtag, [&](Response res) { // This callback can get triggered multiple times. We only care about the first invocation. // It will get triggered again when refreshing the req2 (see below). static bool first = true; @@ -159,7 +159,7 @@ TEST_F(Storage, CacheRevalidateEtag) { EXPECT_EQ(0, res.modified); EXPECT_EQ("response-1", res.etag); - req2 = fs.request(revalidateEtag, [&, res](const Response &res2) { + req2 = fs.request(revalidateEtag, [&, res](Response res2) { if (res2.stale) { // Discard stale responses, if any. return; diff --git a/test/storage/directory_reading.cpp b/test/storage/directory_reading.cpp index 1bd56a9a22..ae8c0b42c1 100644 --- a/test/storage/directory_reading.cpp +++ b/test/storage/directory_reading.cpp @@ -18,8 +18,7 @@ TEST_F(Storage, AssetReadDirectory) { util::RunLoop loop(uv_default_loop()); - Request* req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage" }, - [&](const Response &res) { + Request* req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage" }, [&](Response res) { fs.cancel(req); ASSERT_NE(nullptr, res.error); EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason); diff --git a/test/storage/file_reading.cpp b/test/storage/file_reading.cpp index 9e9d5b21a6..b9155c09c5 100644 --- a/test/storage/file_reading.cpp +++ b/test/storage/file_reading.cpp @@ -19,8 +19,7 @@ TEST_F(Storage, AssetEmptyFile) { util::RunLoop loop(uv_default_loop()); - Request* req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/empty" }, - [&](const Response &res) { + Request* req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/empty" }, [&](Response res) { fs.cancel(req); EXPECT_EQ(nullptr, res.error); EXPECT_EQ(false, res.stale); @@ -49,8 +48,7 @@ TEST_F(Storage, AssetNonEmptyFile) { util::RunLoop loop(uv_default_loop()); - Request* req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/nonempty" }, - [&](const Response &res) { + Request* req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/nonempty" }, [&](Response res) { fs.cancel(req); EXPECT_EQ(nullptr, res.error); EXPECT_EQ(false, res.stale); @@ -81,8 +79,7 @@ TEST_F(Storage, AssetNonExistentFile) { util::RunLoop loop(uv_default_loop()); - Request* req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/does_not_exist" }, - [&](const Response &res) { + Request* req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/does_not_exist" }, [&](Response res) { fs.cancel(req); ASSERT_NE(nullptr, res.error); EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason); diff --git a/test/storage/http_cancel.cpp b/test/storage/http_cancel.cpp index af378162ee..070c54b8b4 100644 --- a/test/storage/http_cancel.cpp +++ b/test/storage/http_cancel.cpp @@ -18,7 +18,7 @@ TEST_F(Storage, HTTPCancel) { auto req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, - [&](const Response &) { ADD_FAILURE() << "Callback should not be called"; }); + [&](Response) { ADD_FAILURE() << "Callback should not be called"; }); fs.cancel(req); HTTPCancel.finish(); @@ -36,10 +36,10 @@ TEST_F(Storage, HTTPCancelMultiple) { const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test" }; - auto req2 = fs.request(resource, [&](const Response &) { + auto req2 = fs.request(resource, [&](Response) { ADD_FAILURE() << "Callback should not be called"; }); - Request* req = fs.request(resource, [&](const Response &res) { + Request* req = fs.request(resource, [&](Response res) { fs.cancel(req); EXPECT_EQ(nullptr, res.error); EXPECT_EQ(false, res.stale); diff --git a/test/storage/http_coalescing.cpp b/test/storage/http_coalescing.cpp index 4255787285..58f30baebb 100644 --- a/test/storage/http_coalescing.cpp +++ b/test/storage/http_coalescing.cpp @@ -45,7 +45,7 @@ TEST_F(Storage, HTTPCoalescing) { Request* reqs[total]; for (int i = 0; i < total; i++) { - reqs[i] = fs.request(resource, [&complete, &fs, &reqs, i] (const Response &res) { + reqs[i] = fs.request(resource, [&complete, &fs, &reqs, i] (Response res) { fs.cancel(reqs[i]); complete(res); }); @@ -62,15 +62,10 @@ TEST_F(Storage, HTTPMultiple) { DefaultFileSource fs(nullptr); util::RunLoop loop(uv_default_loop()); - const Response *reference = nullptr; - const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test?expires=2147483647" }; Request* req1 = nullptr; Request* req2 = nullptr; - req1 = fs.request(resource, [&] (const Response &res) { - EXPECT_EQ(nullptr, reference); - reference = &res; - + req1 = fs.request(resource, [&] (Response res) { // Do not cancel the request right away. EXPECT_EQ(nullptr, res.error); ASSERT_TRUE(res.data.get()); @@ -80,9 +75,9 @@ TEST_F(Storage, HTTPMultiple) { EXPECT_EQ("", res.etag); // Start a second request for the same resource after the first one has been completed. - req2 = fs.request(resource, [&] (const Response &res2) { - // Make sure we get the same object ID as before. - EXPECT_EQ(reference, &res2); + req2 = fs.request(resource, [&, res] (Response res2) { + // Make sure we get the same data as before. + EXPECT_EQ(res.data.get(), res2.data.get()); // Now cancel both requests after both have been notified. fs.cancel(req1); @@ -118,7 +113,7 @@ TEST_F(Storage, HTTPStale) { const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test" }; Request* req1 = nullptr; Request* req2 = nullptr; - req1 = fs.request(resource, [&] (const Response &res) { + req1 = fs.request(resource, [&] (Response res) { // Do not cancel the request right away. EXPECT_EQ(nullptr, res.error); ASSERT_TRUE(res.data.get()); @@ -136,7 +131,7 @@ TEST_F(Storage, HTTPStale) { updates++; // Start a second request for the same resource after the first one has been completed. - req2 = fs.request(resource, [&] (const Response &res2) { + req2 = fs.request(resource, [&] (Response res2) { EXPECT_EQ(nullptr, res2.error); ASSERT_TRUE(res2.data.get()); EXPECT_EQ("Hello World!", *res2.data); diff --git a/test/storage/http_error.cpp b/test/storage/http_error.cpp index fd0a847a61..ce04e871eb 100644 --- a/test/storage/http_error.cpp +++ b/test/storage/http_error.cpp @@ -18,8 +18,7 @@ TEST_F(Storage, HTTPTemporaryError) { const auto start = uv_hrtime(); - Request* req1 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/temporary-error" }, - [&](const Response &res) { + Request* req1 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/temporary-error" }, [&](Response res) { static int counter = 0; switch (counter++) { case 0: { @@ -66,8 +65,7 @@ TEST_F(Storage, HTTPConnectionError) { const auto start = uv_hrtime(); - Request* req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3001/" }, - [&](const Response &res) { + Request* req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3001/" }, [&](Response res) { static int counter = 0; static int wait = 0; const auto duration = double(uv_hrtime() - start) / 1e9; diff --git a/test/storage/http_header_parsing.cpp b/test/storage/http_header_parsing.cpp index 415a232e92..8048addb52 100644 --- a/test/storage/http_header_parsing.cpp +++ b/test/storage/http_header_parsing.cpp @@ -18,7 +18,7 @@ TEST_F(Storage, HTTPExpiresParsing) { Request* req1 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test?modified=1420794326&expires=1420797926&etag=foo" }, - [&](const Response &res) { + [&](Response res) { fs.cancel(req1); EXPECT_EQ(nullptr, res.error); EXPECT_EQ(false, res.stale); @@ -46,7 +46,7 @@ TEST_F(Storage, HTTPCacheControlParsing) { SystemClock::now().time_since_epoch()).count(); Request* req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test?cachecontrol=max-age=120" }, - [&](const Response &res) { + [&](Response res) { fs.cancel(req2); EXPECT_EQ(nullptr, res.error); EXPECT_EQ(false, res.stale); diff --git a/test/storage/http_issue_1369.cpp b/test/storage/http_issue_1369.cpp index 3d7165d9be..5c05aead31 100644 --- a/test/storage/http_issue_1369.cpp +++ b/test/storage/http_issue_1369.cpp @@ -28,11 +28,11 @@ TEST_F(Storage, HTTPIssue1369) { const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test" }; - auto req = fs.request(resource, [&](const Response&) { + auto req = fs.request(resource, [&](Response) { ADD_FAILURE() << "Callback should not be called"; }); fs.cancel(req); - req = fs.request(resource, [&](const Response &res) { + req = fs.request(resource, [&](Response res) { fs.cancel(req); EXPECT_EQ(nullptr, res.error); EXPECT_EQ(false, res.stale); diff --git a/test/storage/http_load.cpp b/test/storage/http_load.cpp index be385afe99..fef1f06e7b 100644 --- a/test/storage/http_load.cpp +++ b/test/storage/http_load.cpp @@ -23,7 +23,7 @@ TEST_F(Storage, HTTPLoad) { const auto current = number++; reqs[i] = fs.request({ Resource::Unknown, std::string("http://127.0.0.1:3000/load/") + std::to_string(current) }, - [&, i, current](const Response &res) { + [&, i, current](Response res) { fs.cancel(reqs[i]); reqs[i] = nullptr; EXPECT_EQ(nullptr, res.error); diff --git a/test/storage/http_other_loop.cpp b/test/storage/http_other_loop.cpp index 3f50134de5..52475ae1a4 100644 --- a/test/storage/http_other_loop.cpp +++ b/test/storage/http_other_loop.cpp @@ -15,7 +15,7 @@ TEST_F(Storage, HTTPOtherLoop) { util::RunLoop loop(uv_default_loop()); Request* req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, - [&](const Response &res) { + [&](Response res) { fs.cancel(req); EXPECT_EQ(nullptr, res.error); EXPECT_EQ(false, res.stale); diff --git a/test/storage/http_reading.cpp b/test/storage/http_reading.cpp index b7ddc270d8..b72f060e63 100644 --- a/test/storage/http_reading.cpp +++ b/test/storage/http_reading.cpp @@ -19,7 +19,7 @@ TEST_F(Storage, HTTPTest) { const auto mainThread = uv_thread_self(); Request* req1 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, - [&](const Response &res) { + [&](Response res) { fs.cancel(req1); EXPECT_EQ(uv_thread_self(), mainThread); EXPECT_EQ(nullptr, res.error); @@ -47,7 +47,7 @@ TEST_F(Storage, HTTP404) { const auto mainThread = uv_thread_self(); Request* req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/doesnotexist" }, - [&](const Response &res) { + [&](Response res) { fs.cancel(req2); EXPECT_EQ(uv_thread_self(), mainThread); ASSERT_NE(nullptr, res.error); @@ -77,7 +77,7 @@ TEST_F(Storage, HTTP500) { const auto mainThread = uv_thread_self(); Request* req3 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/permanent-error" }, - [&](const Response &res) { + [&](Response res) { fs.cancel(req3); EXPECT_EQ(uv_thread_self(), mainThread); ASSERT_NE(nullptr, res.error); diff --git a/test/storage/http_retry_network_status.cpp b/test/storage/http_retry_network_status.cpp index 131186b5d7..66182f5be4 100644 --- a/test/storage/http_retry_network_status.cpp +++ b/test/storage/http_retry_network_status.cpp @@ -24,7 +24,7 @@ TEST_F(Storage, HTTPNetworkStatusChange) { const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/delayed" }; // This request takes 200 milliseconds to answer. - Request* req = fs.request(resource, [&](const Response& res) { + Request* req = fs.request(resource, [&](Response res) { fs.cancel(req); EXPECT_EQ(nullptr, res.error); EXPECT_EQ(false, res.stale); @@ -64,7 +64,7 @@ TEST_F(Storage, HTTPNetworkStatusChangePreempt) { const auto start = uv_hrtime(); const Resource resource{ Resource::Unknown, "http://127.0.0.1:3001/test" }; - Request* req = fs.request(resource, [&](const Response& res) { + Request* req = fs.request(resource, [&](Response res) { static int counter = 0; const auto duration = double(uv_hrtime() - start) / 1e9; if (counter == 0) { diff --git a/test/storage/http_timeout.cpp b/test/storage/http_timeout.cpp index 5855bdc4f2..d59ca3cb77 100644 --- a/test/storage/http_timeout.cpp +++ b/test/storage/http_timeout.cpp @@ -18,7 +18,7 @@ TEST_F(Storage, HTTPTimeout) { int counter = 0; const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test?cachecontrol=max-age=1" }; - Request* req = fs.request(resource, [&](const Response &res) { + Request* req = fs.request(resource, [&](Response res) { counter++; EXPECT_EQ(nullptr, res.error); EXPECT_EQ(false, res.stale); |