| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 | 6 |
| 7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
| 11 #include "vm/globals.h" | 11 #include "vm/globals.h" |
| 12 #include "vm/isolate.h" | 12 #include "vm/isolate.h" |
| 13 #include "vm/log.h" | 13 #include "vm/log.h" |
| 14 #include "vm/message_handler.h" | 14 #include "vm/message_handler.h" |
| 15 #include "vm/unit_test.h" | 15 #include "vm/unit_test.h" |
| 16 | 16 |
| 17 namespace dart { | 17 namespace dart { |
| 18 | 18 |
| 19 static const char* test_output_; | 19 static const char* test_output_; |
| 20 static void TestPrinter(const char* print, ...) { | 20 static void TestPrinter(const char* format, ...) { |
| 21 test_output_ = print; | 21 // Measure. |
| 22 va_list args; |
| 23 va_start(args, format); |
| 24 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 25 va_end(args); |
| 26 |
| 27 // Print string to buffer. |
| 28 char* buffer = reinterpret_cast<char*>(malloc(len + 1)); |
| 29 va_list args2; |
| 30 va_start(args2, format); |
| 31 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 32 va_end(args2); |
| 33 |
| 34 // Leaks buffer. |
| 35 test_output_ = buffer; |
| 22 } | 36 } |
| 23 | 37 |
| 24 class LogTestHelper : public AllStatic { | 38 class LogTestHelper : public AllStatic { |
| 25 public: | 39 public: |
| 26 static void SetPrinter(Log* log, LogPrinter printer) { | 40 static void SetPrinter(Log* log, LogPrinter printer) { |
| 27 ASSERT(log != NULL); | 41 ASSERT(log != NULL); |
| 28 ASSERT(printer != NULL); | 42 ASSERT(printer != NULL); |
| 29 log->printer_ = printer; | 43 log->printer_ = printer; |
| 30 } | 44 } |
| 31 }; | 45 }; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 LogBlock ba(isolate, log); | 83 LogBlock ba(isolate, log); |
| 70 log->Print("BANANA"); | 84 log->Print("BANANA"); |
| 71 EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_); | 85 EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_); |
| 72 } | 86 } |
| 73 EXPECT_STREQ("BANANA", test_output_); | 87 EXPECT_STREQ("BANANA", test_output_); |
| 74 } | 88 } |
| 75 EXPECT_STREQ("APPLE", test_output_); | 89 EXPECT_STREQ("APPLE", test_output_); |
| 76 } | 90 } |
| 77 | 91 |
| 78 } // namespace dart | 92 } // namespace dart |
| OLD | NEW |