2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "TestEventPrinter.h"
36 #include <wtf/Assertions.h>
38 class DRTPrinter : public TestEventPrinter {
41 void handleTestHeader(const char* url) const;
42 void handleTimedOut() const;
43 void handleTextHeader() const;
44 void handleTextFooter() const;
45 void handleAudioHeader() const;
46 void handleImage(const char* actualHash, const char* expectedHash, const unsigned char* imageData, size_t imageSize, const char* fileName) const;
47 void handleImageFooter() const;
48 void handleTestFooter(bool dumpedAnything) const;
51 class TestShellPrinter : public TestEventPrinter {
53 TestShellPrinter() { }
54 void handleTestHeader(const char* url) const;
55 void handleTimedOut() const;
56 void handleTextHeader() const;
57 void handleTextFooter() const;
58 void handleAudioHeader() const;
59 void handleImage(const char* actualHash, const char* expectedHash, const unsigned char* imageData, size_t imageSize, const char* fileName) const;
60 void handleImageFooter() const;
61 void handleTestFooter(bool dumpedAnything) const;
64 TestEventPrinter::~TestEventPrinter()
68 PassOwnPtr<TestEventPrinter> TestEventPrinter::createDRTPrinter()
70 return adoptPtr(new DRTPrinter);
73 PassOwnPtr<TestEventPrinter> TestEventPrinter::createTestShellPrinter()
75 return adoptPtr(new TestShellPrinter);
78 // ----------------------------------------------------------------
80 void DRTPrinter::handleTestHeader(const char*) const
84 void DRTPrinter::handleTimedOut() const
86 fprintf(stderr, "FAIL: Timed out waiting for notifyDone to be called\n");
87 fprintf(stdout, "FAIL: Timed out waiting for notifyDone to be called\n");
90 void DRTPrinter::handleTextHeader() const
92 printf("Content-Type: text/plain\n");
95 void DRTPrinter::handleTextFooter() const
100 void DRTPrinter::handleAudioHeader() const
102 printf("Content-Type: audio/wav\n");
105 void DRTPrinter::handleImage(const char* actualHash, const char* expectedHash, const unsigned char* imageData, size_t imageSize, const char*) const
108 printf("\nActualHash: %s\n", actualHash);
109 if (expectedHash && expectedHash[0])
110 printf("\nExpectedHash: %s\n", expectedHash);
111 if (imageData && imageSize) {
112 printf("Content-Type: image/png\n");
113 // Printf formatting for size_t on 32-bit, 64-bit, and on Windows is hard so just cast to an int.
114 printf("Content-Length: %d\n", static_cast<int>(imageSize));
115 if (fwrite(imageData, 1, imageSize, stdout) != imageSize) {
116 fprintf(stderr, "Short write to stdout.\n");
122 void DRTPrinter::handleImageFooter() const
127 void DRTPrinter::handleTestFooter(bool) const
131 // ----------------------------------------------------------------
133 void TestShellPrinter::handleTestHeader(const char* url) const
135 printf("#URL:%s\n", url);
138 void TestShellPrinter::handleTimedOut() const
140 puts("#TEST_TIMED_OUT\n");
143 void TestShellPrinter::handleTextHeader() const
147 void TestShellPrinter::handleTextFooter() const
151 void TestShellPrinter::handleAudioHeader() const
153 printf("Content-Type: audio/wav\n");
156 void TestShellPrinter::handleImage(const char* actualHash, const char*, const unsigned char* imageData, size_t imageSize, const char* fileName) const
159 if (imageData && imageSize) {
161 FILE* fp = fopen(fileName, "wb");
166 if (fwrite(imageData, 1, imageSize, fp) != imageSize) {
173 printf("#MD5:%s\n", actualHash);
176 void TestShellPrinter::handleImageFooter() const
180 void TestShellPrinter::handleTestFooter(bool dumpedAnything) const