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