OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
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 | |
13 * distribution. | |
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. | |
17 * | |
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. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "TestEventPrinter.h" | |
33 | |
34 #include <stdio.h> | |
35 #include <stdlib.h> | |
36 #include <wtf/Assertions.h> | |
37 #include <wtf/text/Base64.h> | |
38 | |
39 TestEventPrinter::TestEventPrinter() | |
40 : m_encodeBinary(false) | |
41 { | |
42 } | |
43 | |
44 TestEventPrinter::~TestEventPrinter() | |
45 { | |
46 } | |
47 | |
48 // ---------------------------------------------------------------- | |
49 | |
50 void TestEventPrinter::handleTestHeader(const char*) const | |
51 { | |
52 } | |
53 | |
54 void TestEventPrinter::handleTimedOut() const | |
55 { | |
56 fprintf(stderr, "FAIL: Timed out waiting for notifyDone to be called\n"); | |
57 fprintf(stdout, "FAIL: Timed out waiting for notifyDone to be called\n"); | |
58 } | |
59 | |
60 void TestEventPrinter::handleTextHeader() const | |
61 { | |
62 printf("Content-Type: text/plain\n"); | |
63 } | |
64 | |
65 void TestEventPrinter::handleTextFooter() const | |
66 { | |
67 printf("#EOF\n"); | |
68 } | |
69 | |
70 void TestEventPrinter::handleAudio(const void* audioData, size_t audioSize) cons
t | |
71 { | |
72 printf("Content-Type: audio/wav\n"); | |
73 handleBinary(audioData, audioSize); | |
74 } | |
75 | |
76 void TestEventPrinter::handleAudioFooter() const | |
77 { | |
78 printf("#EOF\n"); | |
79 fprintf(stderr, "#EOF\n"); | |
80 } | |
81 | |
82 void TestEventPrinter::handleImage(const char* actualHash, const char* expectedH
ash, const void* imageData, size_t imageSize) const | |
83 { | |
84 ASSERT(actualHash); | |
85 printf("\nActualHash: %s\n", actualHash); | |
86 if (expectedHash && expectedHash[0]) | |
87 printf("\nExpectedHash: %s\n", expectedHash); | |
88 if (imageData && imageSize) { | |
89 printf("Content-Type: image/png\n"); | |
90 handleBinary(imageData, imageSize); | |
91 } | |
92 } | |
93 | |
94 void TestEventPrinter::handleTestFooter(bool) const | |
95 { | |
96 printf("#EOF\n"); | |
97 fprintf(stderr, "#EOF\n"); | |
98 } | |
99 | |
100 void TestEventPrinter::handleBinary(const void* data, size_t size) const | |
101 { | |
102 Vector<char> base64; | |
103 if (m_encodeBinary) { | |
104 base64Encode(static_cast<const char*>(data), size, base64, Base64InsertL
Fs); | |
105 data = base64.data(); | |
106 size = base64.size(); | |
107 printf("Content-Transfer-Encoding: base64\n"); | |
108 } | |
109 // Printf formatting for size_t on 32-bit, 64-bit, and on Windows is hard so
just cast to an int. | |
110 printf("Content-Length: %d\n", static_cast<int>(size)); | |
111 if (fwrite(data, 1, size, stdout) != size) { | |
112 fprintf(stderr, "Short write to stdout.\n"); | |
113 exit(1); | |
114 } | |
115 } | |
OLD | NEW |