Home | History | Annotate | Download | only in unittests
      1 // Copyright 2014 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef V8_UNITTESTS_TEST_UTILS_H_
      6 #define V8_UNITTESTS_TEST_UTILS_H_
      7 
      8 #include "include/v8.h"
      9 #include "src/base/macros.h"
     10 #include "src/base/utils/random-number-generator.h"
     11 #include "src/zone.h"
     12 #include "testing/gtest-support.h"
     13 
     14 namespace v8 {
     15 
     16 class ArrayBufferAllocator;
     17 
     18 
     19 class TestWithIsolate : public virtual ::testing::Test {
     20  public:
     21   TestWithIsolate();
     22   virtual ~TestWithIsolate();
     23 
     24   Isolate* isolate() const { return isolate_; }
     25 
     26   static void SetUpTestCase();
     27   static void TearDownTestCase();
     28 
     29  private:
     30   static ArrayBufferAllocator* array_buffer_allocator_;
     31   static Isolate* isolate_;
     32   Isolate::Scope isolate_scope_;
     33   HandleScope handle_scope_;
     34 
     35   DISALLOW_COPY_AND_ASSIGN(TestWithIsolate);
     36 };
     37 
     38 
     39 class TestWithContext : public virtual TestWithIsolate {
     40  public:
     41   TestWithContext();
     42   virtual ~TestWithContext();
     43 
     44   const Local<Context>& context() const { return context_; }
     45 
     46  private:
     47   Local<Context> context_;
     48   Context::Scope context_scope_;
     49 
     50   DISALLOW_COPY_AND_ASSIGN(TestWithContext);
     51 };
     52 
     53 
     54 namespace base {
     55 
     56 class TestWithRandomNumberGenerator : public ::testing::Test {
     57  public:
     58   TestWithRandomNumberGenerator();
     59   virtual ~TestWithRandomNumberGenerator();
     60 
     61   RandomNumberGenerator* rng() { return &rng_; }
     62 
     63  private:
     64   RandomNumberGenerator rng_;
     65 
     66   DISALLOW_COPY_AND_ASSIGN(TestWithRandomNumberGenerator);
     67 };
     68 
     69 }  // namespace base
     70 
     71 
     72 namespace internal {
     73 
     74 // Forward declarations.
     75 class Factory;
     76 
     77 
     78 class TestWithIsolate : public virtual ::v8::TestWithIsolate {
     79  public:
     80   TestWithIsolate() {}
     81   virtual ~TestWithIsolate();
     82 
     83   Factory* factory() const;
     84   Isolate* isolate() const {
     85     return reinterpret_cast<Isolate*>(::v8::TestWithIsolate::isolate());
     86   }
     87   base::RandomNumberGenerator* random_number_generator() const;
     88 
     89  private:
     90   DISALLOW_COPY_AND_ASSIGN(TestWithIsolate);
     91 };
     92 
     93 
     94 class TestWithZone : public virtual ::testing::Test {
     95  public:
     96   TestWithZone() {}
     97   virtual ~TestWithZone();
     98 
     99   Zone* zone() { return &zone_; }
    100 
    101  private:
    102   Zone zone_;
    103 
    104   DISALLOW_COPY_AND_ASSIGN(TestWithZone);
    105 };
    106 
    107 
    108 class TestWithIsolateAndZone : public virtual TestWithIsolate {
    109  public:
    110   TestWithIsolateAndZone() {}
    111   virtual ~TestWithIsolateAndZone();
    112 
    113   Zone* zone() { return &zone_; }
    114 
    115  private:
    116   Zone zone_;
    117 
    118   DISALLOW_COPY_AND_ASSIGN(TestWithIsolateAndZone);
    119 };
    120 
    121 }  // namespace internal
    122 }  // namespace v8
    123 
    124 #endif  // V8_UNITTESTS_TEST_UTILS_H_
    125