2014-09-04 08:44:03 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-10-01 08:34:25 +00:00
|
|
|
#ifndef V8_UNITTESTS_TEST_UTILS_H_
|
|
|
|
#define V8_UNITTESTS_TEST_UTILS_H_
|
2014-09-04 08:44:03 +00:00
|
|
|
|
|
|
|
#include "include/v8.h"
|
|
|
|
#include "src/base/macros.h"
|
2014-10-06 12:27:24 +00:00
|
|
|
#include "src/base/utils/random-number-generator.h"
|
2016-09-20 16:07:25 +00:00
|
|
|
#include "src/zone/accounting-allocator.h"
|
|
|
|
#include "src/zone/zone.h"
|
2014-09-04 08:44:03 +00:00
|
|
|
#include "testing/gtest-support.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
2015-04-29 09:54:34 +00:00
|
|
|
class ArrayBufferAllocator;
|
|
|
|
|
2014-10-07 07:36:21 +00:00
|
|
|
|
2015-01-26 11:21:14 +00:00
|
|
|
class TestWithIsolate : public virtual ::testing::Test {
|
2014-09-04 08:44:03 +00:00
|
|
|
public:
|
|
|
|
TestWithIsolate();
|
|
|
|
virtual ~TestWithIsolate();
|
|
|
|
|
|
|
|
Isolate* isolate() const { return isolate_; }
|
|
|
|
|
2017-02-10 16:01:38 +00:00
|
|
|
v8::internal::Isolate* i_isolate() const {
|
|
|
|
return reinterpret_cast<v8::internal::Isolate*>(isolate());
|
|
|
|
}
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
static void SetUpTestCase();
|
|
|
|
static void TearDownTestCase();
|
|
|
|
|
|
|
|
private:
|
2016-06-29 07:39:45 +00:00
|
|
|
static v8::ArrayBuffer::Allocator* array_buffer_allocator_;
|
2014-09-04 08:44:03 +00:00
|
|
|
static Isolate* isolate_;
|
|
|
|
Isolate::Scope isolate_scope_;
|
|
|
|
HandleScope handle_scope_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestWithIsolate);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class TestWithContext : public virtual TestWithIsolate {
|
|
|
|
public:
|
|
|
|
TestWithContext();
|
|
|
|
virtual ~TestWithContext();
|
|
|
|
|
|
|
|
const Local<Context>& context() const { return context_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Local<Context> context_;
|
|
|
|
Context::Scope context_scope_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestWithContext);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-06 12:27:24 +00:00
|
|
|
namespace base {
|
|
|
|
|
|
|
|
class TestWithRandomNumberGenerator : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
TestWithRandomNumberGenerator();
|
|
|
|
virtual ~TestWithRandomNumberGenerator();
|
|
|
|
|
|
|
|
RandomNumberGenerator* rng() { return &rng_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
RandomNumberGenerator rng_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestWithRandomNumberGenerator);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace base
|
|
|
|
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
// Forward declarations.
|
|
|
|
class Factory;
|
|
|
|
|
|
|
|
|
|
|
|
class TestWithIsolate : public virtual ::v8::TestWithIsolate {
|
|
|
|
public:
|
|
|
|
TestWithIsolate() {}
|
|
|
|
virtual ~TestWithIsolate();
|
|
|
|
|
|
|
|
Factory* factory() const;
|
|
|
|
Isolate* isolate() const {
|
|
|
|
return reinterpret_cast<Isolate*>(::v8::TestWithIsolate::isolate());
|
|
|
|
}
|
2014-12-02 04:48:57 +00:00
|
|
|
base::RandomNumberGenerator* random_number_generator() const;
|
2014-09-04 08:44:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestWithIsolate);
|
|
|
|
};
|
|
|
|
|
2015-01-23 16:29:50 +00:00
|
|
|
class TestWithZone : public virtual ::testing::Test {
|
2014-09-04 08:44:03 +00:00
|
|
|
public:
|
2016-10-17 12:12:30 +00:00
|
|
|
TestWithZone() : zone_(&allocator_, ZONE_NAME) {}
|
2014-09-04 08:44:03 +00:00
|
|
|
virtual ~TestWithZone();
|
|
|
|
|
|
|
|
Zone* zone() { return &zone_; }
|
|
|
|
|
|
|
|
private:
|
2016-09-20 16:07:25 +00:00
|
|
|
v8::internal::AccountingAllocator allocator_;
|
2014-09-04 08:44:03 +00:00
|
|
|
Zone zone_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestWithZone);
|
|
|
|
};
|
|
|
|
|
2015-01-23 16:29:50 +00:00
|
|
|
class TestWithIsolateAndZone : public virtual TestWithIsolate {
|
|
|
|
public:
|
2016-10-17 12:12:30 +00:00
|
|
|
TestWithIsolateAndZone() : zone_(&allocator_, ZONE_NAME) {}
|
2015-01-23 16:29:50 +00:00
|
|
|
virtual ~TestWithIsolateAndZone();
|
|
|
|
|
|
|
|
Zone* zone() { return &zone_; }
|
|
|
|
|
|
|
|
private:
|
2016-09-20 16:07:25 +00:00
|
|
|
v8::internal::AccountingAllocator allocator_;
|
2015-01-23 16:29:50 +00:00
|
|
|
Zone zone_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestWithIsolateAndZone);
|
|
|
|
};
|
|
|
|
|
2016-10-10 05:53:31 +00:00
|
|
|
class TestWithNativeContext : public virtual ::v8::TestWithContext,
|
|
|
|
public virtual TestWithIsolate {
|
|
|
|
public:
|
|
|
|
TestWithNativeContext() {}
|
|
|
|
virtual ~TestWithNativeContext();
|
|
|
|
|
|
|
|
Handle<Context> native_context() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestWithNativeContext);
|
|
|
|
};
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
2014-10-01 08:34:25 +00:00
|
|
|
#endif // V8_UNITTESTS_TEST_UTILS_H_
|