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

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: 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 #define ENABLE_ASSERT 1
6
7 #include "wtf/Assertions.h"
8
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "wtf/text/StringBuilder.h"
11 #include <stdio.h>
12
13 namespace WTF {
14
15 static const int kPrinterBufferSize = 256;
16 static char gBuffer[kPrinterBufferSize];
17 static StringBuilder gBuilder;
18
19 static void vprint(const char* format, va_list args)
20 {
21 int written = vsnprintf(gBuffer, kPrinterBufferSize, format, args);
22 if (written > 0 && written < kPrinterBufferSize)
23 gBuilder.append(gBuffer);
24 }
25
26 class AssertionsTest : public testing::Test {
27 protected:
28 AssertionsTest()
29 {
30 ScopedLogger::setPrintFuncForTests(vprint);
31 }
32 };
33
34 TEST_F(AssertionsTest, ScopedLogger)
35 {
36 {
37 WTF_CREATE_SCOPED_LOGGER(a, "a1");
38 {
39 WTF_CREATE_SCOPED_LOGGER_IF(b, false, "b1");
40 {
41 WTF_CREATE_SCOPED_LOGGER(c, "c");
42 {
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 }
50
51 EXPECT_EQ(
52 "( a1\n"
53 " ( c\n"
54 " ( d -1 hello )\n"
55 " )\n"
56 " a2 0.5\n"
57 ")\n", gBuilder.toString());
58 };
59
60
61 } // namespace WTF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698