Flutter Engine
The Flutter Engine
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
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
18namespace dart {
19
20static const char* test_output_ = nullptr;
21
22static void TestPrinter(const char* buffer) {
23 if (test_output_ != nullptr) {
24 free(const_cast<char*>(test_output_));
25 test_output_ = nullptr;
26 }
28
29 // Also print to stdout to see the overall result.
31}
32
33class 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
49TEST_CASE(Log_Macro) {
50 test_output_ = nullptr;
51 Log* log = Log::Current();
53
54 THR_Print("Hello %s", "World");
55 EXPECT_STREQ("Hello World", test_output_);
56 THR_Print("SingleArgument");
57 EXPECT_STREQ("SingleArgument", test_output_);
59}
60
61TEST_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;
71}
72
73TEST_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;
98}
99
100} // namespace dart
static void FreeTestOutput()
Definition: log_test.cc:41
static void SetPrinter(Log *log, LogPrinter printer)
Definition: log_test.cc:35
Definition: log.h:27
static Log * Current()
Definition: log.cc:75
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static char * StrDup(const char *s)
#define THR_Print(format,...)
Definition: log.h:20
#define ASSERT(E)
void Log(const char *format,...) SK_PRINTF_LIKE(1
Definition: TestRunner.cpp:137
Definition: dart_vm.cc:33
TEST_CASE(DirectoryCurrent)
static void TestPrinter(const char *buffer)
Definition: log_test.cc:22
static const char * test_output_
Definition: log_test.cc:20
void(* LogPrinter)(const char *data)
Definition: log.h:25
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126