2
* Copyright 2010 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: morlovich@google.com (Maksim Orlovich)
19
#ifndef PAGESPEED_KERNEL_BASE_MOCK_MESSAGE_HANDLER_H_
20
#define PAGESPEED_KERNEL_BASE_MOCK_MESSAGE_HANDLER_H_
25
#include "pagespeed/kernel/base/basictypes.h"
26
#include "pagespeed/kernel/base/fast_wildcard_group.h"
27
#include "pagespeed/kernel/base/google_message_handler.h"
28
#include "pagespeed/kernel/base/message_handler.h"
29
#include "pagespeed/kernel/base/scoped_ptr.h"
30
#include "pagespeed/kernel/base/string.h"
32
namespace net_instaweb {
37
// A version of GoogleMessageHandler to use in testcases that keeps
38
// track of number of messages output, to validate diagnostics
39
class MockMessageHandler : public GoogleMessageHandler {
41
// Takes ownership of the mutex.
42
explicit MockMessageHandler(AbstractMutex* mutex);
44
virtual ~MockMessageHandler();
46
// Returns number of messages of given type issued
47
int MessagesOfType(MessageType type) const;
49
// Returns total number of messages issued
50
int TotalMessages() const;
52
// Returns number of messages which are not printed
53
int SkippedMessagesOfType(MessageType type) const;
55
// Returns total number of messages which are not printed
56
int TotalSkippedMessages() const;
58
// Returns number of messages of severity higher than info
59
int SeriousMessages() const;
61
// Takes ownership of the mutex.
62
void set_mutex(AbstractMutex* mutex);
64
// If a message contains any of the added patterns (sub-strings),
65
// it will not be printed, but will still be counted.
66
void AddPatternToSkipPrinting(const char* pattern);
68
// Dumps contents of String Buffer.
69
virtual bool Dump(Writer* writer);
72
virtual void MessageVImpl(MessageType type, const char* msg, va_list args);
74
virtual void FileMessageVImpl(MessageType type, const char* filename,
75
int line, const char* msg, va_list args);
78
// Returns whether the message should be printed.
79
bool ShouldPrintMessage(const char* msg);
82
typedef std::map<MessageType, int> MessageCountMap;
84
// The Impl versions don't grab the lock themselves
85
int TotalMessagesImpl(const MessageCountMap& counts) const;
86
int MessagesOfTypeImpl(const MessageCountMap& counts,
87
MessageType type) const;
89
scoped_ptr<AbstractMutex> mutex_;
90
MessageCountMap message_counts_;
91
MessageCountMap skipped_message_counts_;
92
FastWildcardGroup patterns_to_skip_;
94
// This handler is only for internal use in Dump method.
95
GoogleMessageHandler internal_handler_;
97
DISALLOW_COPY_AND_ASSIGN(MockMessageHandler);
100
} // namespace net_instaweb
102
#endif // PAGESPEED_KERNEL_BASE_MOCK_MESSAGE_HANDLER_H_