Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
dart-lang
sdk
runtime
vm
log_test.cc
Go to the documentation of this file.
1
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2
// for details. All rights reserved. Use of this source code is governed by a
3
// BSD-style license that can be found in the LICENSE file.
4
5
#include "
platform/globals.h
"
6
7
#include "
include/dart_tools_api.h
"
8
#include "
platform/utils.h
"
9
#include "
vm/dart_api_impl.h
"
10
#include "
vm/dart_entry.h
"
11
#include "
vm/debugger.h
"
12
#include "
vm/globals.h
"
13
#include "
vm/isolate.h
"
14
#include "
vm/log.h
"
15
#include "
vm/message_handler.h
"
16
#include "
vm/unit_test.h
"
17
18
namespace
dart
{
19
20
static
const
char
*
test_output_
=
nullptr
;
21
22
static
void
TestPrinter
(
const
char
*
buffer
) {
23
if
(
test_output_
!=
nullptr
) {
24
free(
const_cast<
char
*
>
(
test_output_
));
25
test_output_
=
nullptr
;
26
}
27
test_output_
=
Utils::StrDup
(
buffer
);
28
29
// Also print to stdout to see the overall result.
30
OS::PrintErr
(
"%s"
,
test_output_
);
31
}
32
33
class
LogTestHelper
:
public
AllStatic
{
34
public
:
35
static
void
SetPrinter
(
Log
* log,
LogPrinter
printer) {
36
ASSERT
(log !=
nullptr
);
37
ASSERT
(printer !=
nullptr
);
38
log->printer_ = printer;
39
}
40
41
static
void
FreeTestOutput
() {
42
if
(
test_output_
!=
nullptr
) {
43
free(
const_cast<
char
*
>
(
test_output_
));
44
test_output_
=
nullptr
;
45
}
46
}
47
};
48
49
TEST_CASE
(Log_Macro) {
50
test_output_
=
nullptr
;
51
Log
* log =
Log::Current
();
52
LogTestHelper::SetPrinter
(log,
TestPrinter
);
53
54
THR_Print
(
"Hello %s"
,
"World"
);
55
EXPECT_STREQ(
"Hello World"
,
test_output_
);
56
THR_Print
(
"SingleArgument"
);
57
EXPECT_STREQ(
"SingleArgument"
,
test_output_
);
58
LogTestHelper::FreeTestOutput
();
59
}
60
61
TEST_CASE
(Log_Basic) {
62
test_output_
=
nullptr
;
63
Log
* log =
new
Log
(
TestPrinter
);
64
65
EXPECT_EQ(
static_cast<
const
char
*
>
(
nullptr
),
test_output_
);
66
log->Print(
"Hello %s"
,
"World"
);
67
EXPECT_STREQ(
"Hello World"
,
test_output_
);
68
69
delete
log;
70
LogTestHelper::FreeTestOutput
();
71
}
72
73
TEST_CASE
(Log_Block) {
74
test_output_
=
nullptr
;
75
Log
* log =
new
Log
(
TestPrinter
);
76
77
EXPECT_EQ(
static_cast<
const
char
*
>
(
nullptr
),
test_output_
);
78
{
79
LogBlock
ba(thread, log);
80
log->Print(
"APPLE"
);
81
EXPECT_EQ(
static_cast<
const
char
*
>
(
nullptr
),
test_output_
);
82
{
83
LogBlock
ba(thread, log);
84
log->Print(
"BANANA"
);
85
EXPECT_EQ(
static_cast<
const
char
*
>
(
nullptr
),
test_output_
);
86
}
87
EXPECT_EQ(
static_cast<
const
char
*
>
(
nullptr
),
test_output_
);
88
{
89
LogBlock
ba(thread, log);
90
log->Print(
"PEAR"
);
91
EXPECT_EQ(
static_cast<
const
char
*
>
(
nullptr
),
test_output_
);
92
}
93
EXPECT_EQ(
static_cast<
const
char
*
>
(
nullptr
),
test_output_
);
94
}
95
EXPECT_STREQ(
"APPLEBANANAPEAR"
,
test_output_
);
96
delete
log;
97
LogTestHelper::FreeTestOutput
();
98
}
99
100
}
// namespace dart
dart::AllStatic
Definition
allocation.h:33
dart::LogBlock
Definition
log.h:75
dart::LogTestHelper
Definition
log_test.cc:33
dart::LogTestHelper::FreeTestOutput
static void FreeTestOutput()
Definition
log_test.cc:41
dart::LogTestHelper::SetPrinter
static void SetPrinter(Log *log, LogPrinter printer)
Definition
log_test.cc:35
dart::Log
Definition
log.h:27
dart::Log::Current
static Log * Current()
Definition
log.cc:75
dart::OS::PrintErr
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
dart::Utils::StrDup
static char * StrDup(const char *s)
log.h
THR_Print
#define THR_Print(format,...)
Definition
log.h:20
dart_api_impl.h
dart_entry.h
dart_tools_api.h
debugger.h
ASSERT
#define ASSERT(E)
Definition
entrypoints_verification_test.cc:25
buffer
static const uint8_t buffer[]
Definition
fl_pixel_buffer_texture_test.cc:44
isolate.h
message_handler.h
dart
Definition
dart_vm.cc:33
dart::TestPrinter
static void TestPrinter(const char *buffer)
Definition
log_test.cc:22
dart::test_output_
static const char * test_output_
Definition
log_test.cc:20
dart::LogPrinter
void(* LogPrinter)(const char *data)
Definition
log.h:25
globals.h
utils.h
unit_test.h
TEST_CASE
#define TEST_CASE(name)
Definition
unit_test.h:85
globals.h
Generated on Fri Apr 26 2024 06:15:10 for Flutter Engine by
1.9.8