Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/Source/wtf/AssertionsTest.cpp

Issue 1840693002: Restore ScopedLogger and add documentation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/Assertions.cpp ('k') | third_party/WebKit/Source/wtf/ScopedLogger.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698