OLD | NEW |
(Empty) | |
| 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_debugger_api.h" |
| 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_entry.h" |
| 10 #include "vm/debugger.h" |
| 11 #include "vm/globals.h" |
| 12 #include "vm/isolate.h" |
| 13 #include "vm/log.h" |
| 14 #include "vm/message_handler.h" |
| 15 #include "vm/unit_test.h" |
| 16 |
| 17 namespace dart { |
| 18 |
| 19 static const char* test_output_; |
| 20 static void TestPrinter(const char* print, ...) { |
| 21 test_output_ = print; |
| 22 } |
| 23 |
| 24 class LogTestHelper : public AllStatic { |
| 25 public: |
| 26 static void SetPrinter(Log* log, LogPrinter printer) { |
| 27 ASSERT(log != NULL); |
| 28 ASSERT(printer != NULL); |
| 29 log->printer_ = printer; |
| 30 } |
| 31 }; |
| 32 |
| 33 |
| 34 TEST_CASE(Log_Macro) { |
| 35 test_output_ = NULL; |
| 36 Isolate* isolate = Isolate::Current(); |
| 37 Log* log = isolate->Log(); |
| 38 LogTestHelper::SetPrinter(log, TestPrinter); |
| 39 |
| 40 ISL_Print("Hello %s", "World"); |
| 41 EXPECT_STREQ("Hello World", test_output_); |
| 42 ISL_Print("SingleArgument"); |
| 43 EXPECT_STREQ("SingleArgument", test_output_); |
| 44 } |
| 45 |
| 46 |
| 47 TEST_CASE(Log_Basic) { |
| 48 test_output_ = NULL; |
| 49 Log* log = new Log(TestPrinter); |
| 50 |
| 51 EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_); |
| 52 log->Print("Hello %s", "World"); |
| 53 EXPECT_STREQ("Hello World", test_output_); |
| 54 } |
| 55 |
| 56 |
| 57 TEST_CASE(Log_Block) { |
| 58 test_output_ = NULL; |
| 59 Log* log = new Log(TestPrinter); |
| 60 |
| 61 Isolate* isolate = Isolate::Current(); |
| 62 |
| 63 EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_); |
| 64 { |
| 65 LogBlock ba(isolate, log); |
| 66 log->Print("APPLE"); |
| 67 EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_); |
| 68 { |
| 69 LogBlock ba(isolate, log); |
| 70 log->Print("BANANA"); |
| 71 EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_); |
| 72 } |
| 73 EXPECT_STREQ("BANANA", test_output_); |
| 74 } |
| 75 EXPECT_STREQ("APPLE", test_output_); |
| 76 } |
| 77 |
| 78 } // namespace dart |
OLD | NEW |