This source file includes following definitions.
- value_
- value_
- Run
- TEST
- TEST
#include "mojo/public/cpp/utility/thread.h"
#include "mojo/public/cpp/system/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
namespace {
class SetIntThread : public Thread {
public:
SetIntThread(int* int_to_set, int value)
: int_to_set_(int_to_set),
value_(value) {
}
SetIntThread(const Options& options, int* int_to_set, int value)
: Thread(options),
int_to_set_(int_to_set),
value_(value) {
}
virtual ~SetIntThread() {
}
virtual void Run() MOJO_OVERRIDE {
*int_to_set_ = value_;
}
private:
int* const int_to_set_;
const int value_;
MOJO_DISALLOW_COPY_AND_ASSIGN(SetIntThread);
};
TEST(ThreadTest, CreateAndJoin) {
int value = 0;
{
SetIntThread thread(&value, 1234567);
}
EXPECT_EQ(0, value);
{
SetIntThread thread(&value, 12345678);
thread.Start();
thread.Join();
EXPECT_EQ(12345678, value);
}
{
Thread::Options options;
options.set_stack_size(1024 * 1024);
SetIntThread thread(options, &value, 12345678);
thread.Start();
thread.Join();
EXPECT_EQ(12345678, value);
}
}
#if !defined(NDEBUG)
TEST(ThreadTest, DebugAssertionFailures) {
EXPECT_DEATH({
int value = 0;
SetIntThread thread(&value, 1);
thread.Start();
thread.Start();
}, "");
EXPECT_DEATH({
int value = 0;
SetIntThread thread(&value, 2);
thread.Start();
}, "");
EXPECT_DEATH({
int value = 0;
SetIntThread thread(&value, 3);
thread.Start();
thread.Join();
thread.Join();
}, "");
EXPECT_DEATH({
int value = 0;
Thread::Options options;
options.set_stack_size(static_cast<size_t>(-1));
SetIntThread thread(options, &value, 4);
thread.Start();
thread.Join();
}, "");
}
#endif
}
}