~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/base/mock_message_handler.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2010 Google Inc.
3
 
 *
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
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
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.
15
 
 */
16
 
 
17
 
// Author: morlovich@google.com (Maksim Orlovich)
18
 
 
19
 
#ifndef PAGESPEED_KERNEL_BASE_MOCK_MESSAGE_HANDLER_H_
20
 
#define PAGESPEED_KERNEL_BASE_MOCK_MESSAGE_HANDLER_H_
21
 
 
22
 
#include <cstdarg>
23
 
#include <map>
24
 
 
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"
31
 
 
32
 
namespace net_instaweb {
33
 
 
34
 
class AbstractMutex;
35
 
class Writer;
36
 
 
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 {
40
 
 public:
41
 
  // Takes ownership of the mutex.
42
 
  explicit MockMessageHandler(AbstractMutex* mutex);
43
 
 
44
 
  virtual ~MockMessageHandler();
45
 
 
46
 
  // Returns number of messages of given type issued
47
 
  int MessagesOfType(MessageType type) const;
48
 
 
49
 
  // Returns total number of messages issued
50
 
  int TotalMessages() const;
51
 
 
52
 
  // Returns number of messages which are not printed
53
 
  int SkippedMessagesOfType(MessageType type) const;
54
 
 
55
 
  // Returns total number of messages which are not printed
56
 
  int TotalSkippedMessages() const;
57
 
 
58
 
  // Returns number of messages of severity higher than info
59
 
  int SeriousMessages() const;
60
 
 
61
 
  // Takes ownership of the mutex.
62
 
  void set_mutex(AbstractMutex* mutex);
63
 
 
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);
67
 
 
68
 
  // Dumps contents of String Buffer.
69
 
  virtual bool Dump(Writer* writer);
70
 
 
71
 
 protected:
72
 
  virtual void MessageVImpl(MessageType type, const char* msg, va_list args);
73
 
 
74
 
  virtual void FileMessageVImpl(MessageType type, const char* filename,
75
 
                                int line, const char* msg, va_list args);
76
 
 
77
 
 private:
78
 
  // Returns whether the message should be printed.
79
 
  bool ShouldPrintMessage(const char* msg);
80
 
 
81
 
 private:
82
 
  typedef std::map<MessageType, int> MessageCountMap;
83
 
 
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;
88
 
 
89
 
  scoped_ptr<AbstractMutex> mutex_;
90
 
  MessageCountMap message_counts_;
91
 
  MessageCountMap skipped_message_counts_;
92
 
  FastWildcardGroup patterns_to_skip_;
93
 
  GoogleString buffer_;
94
 
  // This handler is only for internal use in Dump method.
95
 
  GoogleMessageHandler internal_handler_;
96
 
 
97
 
  DISALLOW_COPY_AND_ASSIGN(MockMessageHandler);
98
 
};
99
 
 
100
 
}  // namespace net_instaweb
101
 
 
102
 
#endif  // PAGESPEED_KERNEL_BASE_MOCK_MESSAGE_HANDLER_H_