Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/Thread.cpp

Issue 29367003: Issue #4711 - Rewrite legacy thread facilities
Patch Set: Created Dec. 7, 2016, 4:44 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/Thread.h ('K') | « test/Prefs.cpp ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/Thread.cpp
===================================================================
deleted file mode 100644
--- a/test/Thread.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * This file is part of Adblock Plus <https://adblockplus.org/>,
- * Copyright (C) 2006-2016 Eyeo GmbH
- *
- * Adblock Plus is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as
- * published by the Free Software Foundation.
- *
- * Adblock Plus is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <gtest/gtest.h>
-#include <queue>
-#include <vector>
-
-#include "../src/Thread.h"
-
-namespace
-{
- class Mock : public AdblockPlus::Thread
- {
- public:
- int timesCalled;
- AdblockPlus::Mutex mutex;
-
- Mock() : timesCalled(0)
- {
- }
-
- void Run()
- {
- AdblockPlus::Sleep(5);
- AdblockPlus::Lock lock(mutex);
- timesCalled++;
- }
- };
-
- class LockingMock : public AdblockPlus::Thread
- {
- public:
- bool working;
-
- LockingMock(std::vector<std::string>& log, AdblockPlus::Mutex& logMutex)
- : log(log), logMutex(logMutex)
- {
- }
-
- void Run()
- {
- AdblockPlus::Lock lock(logMutex);
- log.push_back("started");
- AdblockPlus::Sleep(5);
- log.push_back("ended");
- }
-
- private:
- const std::string name;
- std::vector<std::string>& log;
- AdblockPlus::Mutex& logMutex;
- };
-}
-
-TEST(ThreadTest, Run)
-{
- Mock mock;
- ASSERT_EQ(0, mock.timesCalled);
- mock.Start();
- mock.mutex.Lock();
- ASSERT_EQ(0, mock.timesCalled);
- mock.mutex.Unlock();
- mock.Join();
- ASSERT_EQ(1, mock.timesCalled);
-}
-
-TEST(ThreadTest, Mutex)
-{
- std::vector<std::string> log;
- AdblockPlus::Mutex logMutex;
- LockingMock mock1(log, logMutex);
- LockingMock mock2(log, logMutex);
- mock1.Start();
- mock2.Start();
- mock1.Join();
- mock2.Join();
- ASSERT_EQ("started", log[0]);
- ASSERT_EQ("ended", log[1]);
- ASSERT_EQ("started", log[2]);
- ASSERT_EQ("ended", log[3]);
-}
« src/Thread.h ('K') | « test/Prefs.cpp ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld