OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "wtf/Assertions.h" |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "wtf/text/StringBuilder.h" |
| 9 #include <stdio.h> |
| 10 |
| 11 #if !LOG_DISABLED |
| 12 namespace WTF { |
| 13 |
| 14 static const int kPrinterBufferSize = 256; |
| 15 static char gBuffer[kPrinterBufferSize]; |
| 16 static StringBuilder gBuilder; |
| 17 |
| 18 static void vprint(const char* format, va_list args) |
| 19 { |
| 20 int written = vsnprintf(gBuffer, kPrinterBufferSize, format, args); |
| 21 if (written > 0 && written < kPrinterBufferSize) |
| 22 gBuilder.append(gBuffer); |
| 23 } |
| 24 |
| 25 TEST(AssertionsTest, ScopedLogger) |
| 26 { |
| 27 ScopedLogger::setPrintFuncForTests(vprint); |
| 28 { |
| 29 WTF_CREATE_SCOPED_LOGGER(a, "a1"); |
| 30 { |
| 31 WTF_CREATE_SCOPED_LOGGER_IF(b, false, "b1"); |
| 32 { |
| 33 WTF_CREATE_SCOPED_LOGGER(c, "c"); |
| 34 { |
| 35 WTF_CREATE_SCOPED_LOGGER(d, "d %d %s", -1, "hello"); |
| 36 } |
| 37 } |
| 38 WTF_APPEND_SCOPED_LOGGER(b, "b2"); |
| 39 } |
| 40 WTF_APPEND_SCOPED_LOGGER(a, "a2 %.1f", 0.5); |
| 41 } |
| 42 |
| 43 EXPECT_EQ( |
| 44 "( a1\n" |
| 45 " ( c\n" |
| 46 " ( d -1 hello )\n" |
| 47 " )\n" |
| 48 " a2 0.5\n" |
| 49 ")\n", gBuilder.toString()); |
| 50 }; |
| 51 |
| 52 } // namespace WTF |
| 53 #endif // !LOG_DISABLED |
OLD | NEW |