diff options
author | Alex Zolotarev <alex@maps.me> | 2015-06-10 23:17:38 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:50:55 +0300 |
commit | 451d1b6420efef8a8d466171fc01367de9a5d96d (patch) | |
tree | 4e48062ad740b2468cc8644caca2847d33120a85 /3party/Alohalytics/tests/test_messages_queue.cc | |
parent | 83b7454b0c967d40734c377077e78ac86abebab0 (diff) |
[alohalytics] More review fixes.
Diffstat (limited to '3party/Alohalytics/tests/test_messages_queue.cc')
-rw-r--r-- | 3party/Alohalytics/tests/test_messages_queue.cc | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/3party/Alohalytics/tests/test_messages_queue.cc b/3party/Alohalytics/tests/test_messages_queue.cc index 9735486a63..44b26fdc98 100644 --- a/3party/Alohalytics/tests/test_messages_queue.cc +++ b/3party/Alohalytics/tests/test_messages_queue.cc @@ -205,7 +205,16 @@ using alohalytics::ProcessingResult; bool EndsWith(const std::string & str, const std::string & suffix) { const std::string::size_type str_size = str.size(), suffix_size = suffix.size(); - return str_size >= suffix_size && str.find_last_of(suffix) == str_size - suffix_size; + return str_size >= suffix_size && std::equal(suffix.begin(), suffix.end(), str.end() - suffix_size); +} + +void Test_EndsWith() { + TEST_EQUAL(true, EndsWith("", "")); + TEST_EQUAL(true, EndsWith("Hello, World!", " World!")); + TEST_EQUAL(true, EndsWith("Hello", "Hello")); + TEST_EQUAL(false, EndsWith("Hello, World!", " World! ")); + TEST_EQUAL(false, EndsWith("Hell", "Hello")); + TEST_EQUAL(false, EndsWith("ello", "Hello")); } // Removes all MessagesQueue's files in the directory. @@ -390,9 +399,9 @@ void Test_MessagesQueue_CreateArchiveOnSizeLimitHit() { } size += generated_size; }; - static const std::ofstream::pos_type limit = q.kMaxFileSizeInBytes / 2 + 100; - std::thread worker([&generator]() { generator(kTestWorkerMessage, limit); }); - generator(kTestMessage, limit); + static const std::ofstream::pos_type number_of_bytes_to_generate = q.kMaxFileSizeInBytes / 2 + 100; + std::thread worker([&generator]() { generator(kTestWorkerMessage, number_of_bytes_to_generate); }); + generator(kTestMessage, number_of_bytes_to_generate); worker.join(); std::vector<std::ofstream::pos_type> file_sizes; @@ -405,11 +414,7 @@ void Test_MessagesQueue_CreateArchiveOnSizeLimitHit() { TEST_EQUAL(ProcessingResult::EProcessedSuccessfully, finish_task.get()); TEST_EQUAL(size_t(2), file_sizes.size()); TEST_EQUAL(size, file_sizes[0] + file_sizes[1]); - if (file_sizes[0] < q.kMaxFileSizeInBytes) { - TEST_EQUAL(true, file_sizes[1] > q.kMaxFileSizeInBytes); - } else { - TEST_EQUAL(true, file_sizes[0] > q.kMaxFileSizeInBytes); - } + TEST_EQUAL(true, (file_sizes[0] > q.kMaxFileSizeInBytes) != (file_sizes[1] > q.kMaxFileSizeInBytes)); } void Test_MessagesQueue_HighLoadAndIntegrity() { @@ -422,7 +427,7 @@ void Test_MessagesQueue_HighLoadAndIntegrity() { MessagesQueue q; const int kMaxThreads = 300; std::mt19937 gen(std::mt19937::default_seed); - std::uniform_int_distribution<> dis(1, std::numeric_limits<char>::max()); + std::uniform_int_distribution<> dis('A', 'Z'); auto const generator = [&q](char c) { q.PushMessage(std::string(static_cast<size_t>(c), c)); }; std::vector<std::thread> threads; size_t total_size = 0; @@ -462,6 +467,7 @@ void Test_MessagesQueue_HighLoadAndIntegrity() { } int main(int, char * []) { + // TODO(AlexZ): Split unit tests into two separate files. Test_ScopedRemoveFile(); Test_GetDirectoryFromFilePath(); Test_CreateTemporaryFile(); @@ -470,6 +476,7 @@ int main(int, char * []) { Test_ForEachFileInDir(); Test_GetFileSize(); + Test_EndsWith(); Test_MessagesQueue_InMemory_Empty(); Test_MessagesQueue_InMemory_SuccessfulProcessing(); Test_MessagesQueue_InMemory_FailedProcessing(); |