Flutter Engine
The Flutter Engine
Classes | Namespaces | Macros | Functions
unit_test.h File Reference
#include <functional>
#include "include/dart_native_api.h"
#include "platform/globals.h"
#include "vm/dart.h"
#include "vm/dart_api_state.h"
#include "vm/dart_entry.h"
#include "vm/globals.h"
#include "vm/isolate.h"
#include "vm/longjump.h"
#include "vm/object.h"
#include "vm/object_store.h"
#include "vm/simulator.h"
#include "vm/zone.h"

Go to the source code of this file.

Classes

class  dart::TesterState
 
class  dart::KernelBufferList
 
class  dart::TestCaseBase
 
class  dart::TestCase
 
class  dart::RawTestCase
 
class  dart::TestIsolateScope
 
struct  dart::is_void< T >
 
struct  dart::is_void< void >
 
struct  dart::is_double< T >
 
struct  dart::is_double< double >
 
class  dart::AssemblerTest
 
class  dart::CompilerTest
 
class  dart::SetFlagScope< T >
 
class  dart::DisableBackgroundCompilationScope
 

Namespaces

namespace  dart
 
namespace  dart::compiler
 
namespace  dart::bin
 

Macros

#define VM_UNIT_TEST_CASE_WITH_EXPECTATION(name, expectation)
 
#define VM_UNIT_TEST_CASE(name)   VM_UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")
 
#define UNIT_TEST_CASE_WITH_EXPECTATION(name, expectation)
 
#define UNIT_TEST_CASE(name)   UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")
 
#define ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION(name, expectation)
 
#define ISOLATE_UNIT_TEST_CASE(name)    ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")
 
#define TEST_CASE_WITH_EXPECTATION(name, expectation)
 
#define TEST_CASE(name)   TEST_CASE_WITH_EXPECTATION(name, "Pass")
 
#define ASSEMBLER_TEST_GENERATE(name, assembler)    void AssemblerTestGenerate##name(compiler::Assembler* assembler)
 
#define ASSEMBLER_TEST_EXTERN(name)    extern void AssemblerTestGenerate##name(compiler::Assembler* assembler);
 
#define ASSEMBLER_TEST_RUN_WITH_EXPECTATION(name, test, expectation)
 
#define ASSEMBLER_TEST_RUN(name, test)    ASSEMBLER_TEST_RUN_WITH_EXPECTATION(name, test, "Pass")
 
#define ZONE_STR(FMT, ...)    OS::SCreate(Thread::Current()->zone(), FMT, __VA_ARGS__)
 
#define USER_TEST_URI   "test-lib"
 
#define RESOLVED_USER_TEST_URI   "file:///test-lib"
 
#define CORELIB_TEST_URI   "dart:test-lib"
 
#define EXPECT_VALID(handle)
 
#define EXPECT_ERROR(handle, substring)
 
#define EXPECT_TRUE(handle)
 
#define EXPECT_NULL(handle)
 
#define EXPECT_NON_NULL(handle)
 

Functions

Dart_Handle NewString (const char *str)
 
void dart::SetupCoreLibrariesForUnitTest ()
 
void dart::ElideJSONSubstring (const char *prefix, const char *in, char *out, const char *postfix)
 
void dart::StripTokenPositions (char *buffer)
 

Macro Definition Documentation

◆ ASSEMBLER_TEST_EXTERN

#define ASSEMBLER_TEST_EXTERN (   name)     extern void AssemblerTestGenerate##name(compiler::Assembler* assembler);

Definition at line 94 of file unit_test.h.

◆ ASSEMBLER_TEST_GENERATE

#define ASSEMBLER_TEST_GENERATE (   name,
  assembler 
)     void AssemblerTestGenerate##name(compiler::Assembler* assembler)

Definition at line 89 of file unit_test.h.

◆ ASSEMBLER_TEST_RUN

#define ASSEMBLER_TEST_RUN (   name,
  test 
)     ASSEMBLER_TEST_RUN_WITH_EXPECTATION(name, test, "Pass")

Definition at line 127 of file unit_test.h.

◆ ASSEMBLER_TEST_RUN_WITH_EXPECTATION

#define ASSEMBLER_TEST_RUN_WITH_EXPECTATION (   name,
  test,
  expectation 
)
Value:
static void AssemblerTestRun##name(AssemblerTest* test); \
ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION(Assembler_##name, expectation) { \
volatile intptr_t far_branch_level = 0; \
while (true) { \
LongJumpScope jump(thread); \
if (setjmp(*jump.Set()) == 0) { \
compiler::ObjectPoolBuilder object_pool_builder; \
compiler::Assembler assembler(&object_pool_builder, far_branch_level); \
AssemblerTest test("" #name, &assembler, thread->zone()); \
AssemblerTestGenerate##name(test.assembler()); \
test.Assemble(); \
AssemblerTestRun##name(&test); \
return; \
} else { \
const Error& error = Error::Handle(thread->StealStickyError()); \
if (error.ptr() == Object::branch_offset_error().ptr()) { \
RELEASE_ASSERT(far_branch_level < 2); \
far_branch_level++; \
} else { \
FATAL("Unexpected error: %s\n", error.ToErrorCString()); \
} \
} \
} \
} \
static void AssemblerTestRun##name(AssemblerTest* test)
#define test(name)
const uint8_t uint32_t uint32_t GError ** error
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

Definition at line 100 of file unit_test.h.

◆ CORELIB_TEST_URI

#define CORELIB_TEST_URI   "dart:test-lib"

Definition at line 318 of file unit_test.h.

◆ EXPECT_ERROR

#define EXPECT_ERROR (   handle,
  substring 
)
Value:
do { \
Dart_Handle tmp_handle = (handle); \
if (Dart_IsError(tmp_handle)) { \
dart::Expect(__FILE__, __LINE__) \
.IsSubstring((substring), Dart_GetError(tmp_handle)); \
} else { \
dart::Expect(__FILE__, __LINE__) \
.Fail( \
"expected '%s' to be an error handle but found a valid " \
"handle.\n", \
#handle); \
} \
} while (0)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT const char * Dart_GetError(Dart_Handle handle)

Definition at line 663 of file unit_test.h.

◆ EXPECT_NON_NULL

#define EXPECT_NON_NULL (   handle)
Value:
do { \
Dart_Handle tmp_handle = (handle); \
if (Dart_IsNull(tmp_handle)) { \
dart::Expect(__FILE__, __LINE__) \
.Fail("expected '%s' to be a non-null handle.\n", #handle); \
} \
} while (0)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)

Definition at line 703 of file unit_test.h.

◆ EXPECT_NULL

#define EXPECT_NULL (   handle)
Value:
do { \
Dart_Handle tmp_handle = (handle); \
if (!Dart_IsNull(tmp_handle)) { \
dart::Expect(__FILE__, __LINE__) \
.Fail("expected '%s' to be a null handle.\n", #handle); \
} \
} while (0)

Definition at line 694 of file unit_test.h.

◆ EXPECT_TRUE

#define EXPECT_TRUE (   handle)
Value:
do { \
Dart_Handle tmp_handle = (handle); \
if (Dart_IsBoolean(tmp_handle)) { \
bool value; \
Dart_BooleanValue(tmp_handle, &value); \
if (!value) { \
dart::Expect(__FILE__, __LINE__) \
.Fail("expected True, but was '%s'\n", #handle); \
} \
} else { \
dart::Expect(__FILE__, __LINE__) \
.Fail("expected True, but was '%s'\n", #handle); \
} \
} while (0)
DART_EXPORT bool Dart_IsBoolean(Dart_Handle object)
uint8_t value

Definition at line 678 of file unit_test.h.

◆ EXPECT_VALID

#define EXPECT_VALID (   handle)
Value:
do { \
Dart_Handle tmp_handle = (handle); \
if (!Api::IsValid(tmp_handle)) { \
dart::Expect(__FILE__, __LINE__) \
.Fail( \
"expected '%s' to be a valid handle but '%s' has already been " \
"freed\n", \
#handle, #handle); \
} \
if (Dart_IsError(tmp_handle)) { \
dart::Expect(__FILE__, __LINE__) \
.Fail( \
"expected '%s' to be a valid handle but found an error " \
"handle:\n" \
" '%s'\n", \
#handle, Dart_GetError(tmp_handle)); \
} \
} while (0)

Definition at line 643 of file unit_test.h.

◆ ISOLATE_UNIT_TEST_CASE

#define ISOLATE_UNIT_TEST_CASE (   name)     ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")

Definition at line 64 of file unit_test.h.

◆ ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION

#define ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION (   name,
  expectation 
)
Value:
static void Dart_TestHelper##name(Thread* thread); \
VM_UNIT_TEST_CASE_WITH_EXPECTATION(name, expectation) { \
TestIsolateScope __test_isolate__; \
Thread* __thread__ = Thread::Current(); \
ASSERT(__thread__->isolate() == __test_isolate__.isolate()); \
TransitionNativeToVM transition(__thread__); \
StackZone __zone__(__thread__); \
HandleScope __hs__(__thread__); \
Dart_TestHelper##name(__thread__); \
} \
static void Dart_TestHelper##name(Thread* thread)

Definition at line 51 of file unit_test.h.

◆ RESOLVED_USER_TEST_URI

#define RESOLVED_USER_TEST_URI   "file:///test-lib"

Definition at line 317 of file unit_test.h.

◆ TEST_CASE

#define TEST_CASE (   name)    TEST_CASE_WITH_EXPECTATION(name, "Pass")

Definition at line 85 of file unit_test.h.

◆ TEST_CASE_WITH_EXPECTATION

#define TEST_CASE_WITH_EXPECTATION (   name,
  expectation 
)
Value:
static void Dart_TestHelper##name(Thread* thread); \
VM_UNIT_TEST_CASE_WITH_EXPECTATION(name, expectation) { \
TestIsolateScope __test_isolate__; \
Thread* __thread__ = Thread::Current(); \
ASSERT(__thread__->isolate() == __test_isolate__.isolate()); \
TransitionNativeToVM transition1(__thread__); \
StackZone __zone__(__thread__); \
HandleScope __hs__(__thread__); \
TransitionVMToNative transition2(__thread__); \
Dart_TestHelper##name(__thread__); \
} \
static void Dart_TestHelper##name(Thread* thread)

Definition at line 71 of file unit_test.h.

◆ UNIT_TEST_CASE

#define UNIT_TEST_CASE (   name)    UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")

Definition at line 44 of file unit_test.h.

◆ UNIT_TEST_CASE_WITH_EXPECTATION

#define UNIT_TEST_CASE_WITH_EXPECTATION (   name,
  expectation 
)
Value:
void Dart_Test##name(); \
static const dart::RawTestCase kRegister##name(Dart_Test##name, #name, \
void Dart_Test##name()

Definition at line 38 of file unit_test.h.

◆ USER_TEST_URI

#define USER_TEST_URI   "test-lib"

Definition at line 316 of file unit_test.h.

◆ VM_UNIT_TEST_CASE

#define VM_UNIT_TEST_CASE (   name)    VM_UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")

Definition at line 33 of file unit_test.h.

◆ VM_UNIT_TEST_CASE_WITH_EXPECTATION

#define VM_UNIT_TEST_CASE_WITH_EXPECTATION (   name,
  expectation 
)
Value:
void Dart_Test##name(); \
static const dart::TestCase kRegister##name(Dart_Test##name, #name, \
void Dart_Test##name()

Definition at line 27 of file unit_test.h.

◆ ZONE_STR

#define ZONE_STR (   FMT,
  ... 
)     OS::SCreate(Thread::Current()->zone(), FMT, __VA_ARGS__)

Definition at line 226 of file unit_test.h.

Function Documentation

◆ NewString()

Dart_Handle NewString ( const char *  str)
inline

Definition at line 229 of file unit_test.h.

229 {
230 return Dart_NewStringFromCString(str);
231}
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)