~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/apache/mock_apache.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
 
// Copyright 2015 Google Inc.
2
 
//
3
 
// Licensed under the Apache License, Version 2.0 (the "License");
4
 
// you may not use this file except in compliance with the License.
5
 
// You may obtain a copy of the License at
6
 
//
7
 
//      http://www.apache.org/licenses/LICENSE-2.0
8
 
//
9
 
// Unless required by applicable law or agreed to in writing, software
10
 
// distributed under the License is distributed on an "AS IS" BASIS,
11
 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 
// See the License for the specific language governing permissions and
13
 
// limitations under the License.
14
 
//
15
 
// Author: jefftk@google.com (Jeff Kaufman)
16
 
 
17
 
#ifndef PAGESPEED_APACHE_MOCK_APACHE_H_
18
 
#define PAGESPEED_APACHE_MOCK_APACHE_H_
19
 
 
20
 
#include "pagespeed/kernel/base/string_util.h"
21
 
 
22
 
struct request_rec;
23
 
 
24
 
namespace net_instaweb {
25
 
 
26
 
namespace MockApache {
27
 
 
28
 
// When unit testing code that manipulates and Apache request_rec by calling
29
 
// apache functions like ap_rwrite or ap_rflush we don't want to actually run
30
 
// Apache.  Instead, we link in mock implementations of these functions that
31
 
// actually just write to a global variable indicating that they were called.
32
 
//
33
 
// If you link mock_apache.cc to supply any of these function mocks you must
34
 
// call Initialize() before any ap_* calls and Terminate() after them.  To
35
 
// verify that higher level calls led to the correct lower level actions, call
36
 
// actions_since_last_call() to get a text representation of past actions.
37
 
//
38
 
// Most of these calls need a properly initialized request_rec.  Use
39
 
// PrepareRequest/CleanupRequest for that.
40
 
//
41
 
// Example:
42
 
//
43
 
//    MockApache::Initialize();
44
 
//    request_rec r;
45
 
//    MockApache::PrepareRequest(&r);
46
 
//    SomethingThatCallsApRWrite("foo", &r)
47
 
//    SomethingThatCallsApRFlush(&r)
48
 
//    EXPECT_EQ("ap_rwrite(foo) ap_rflush()",
49
 
//              MockApache::actions_since_last_call());
50
 
//    MockApache::CleanupRequest(&r);
51
 
//    MockApache::Terminate();
52
 
 
53
 
// Call once before any uses of MockApache.
54
 
void Initialize();
55
 
// Call once after any uses of MockApache.
56
 
void Terminate();
57
 
 
58
 
// Call on every request to create a pool for it and allocate initial
59
 
// structures.
60
 
void PrepareRequest(request_rec* request);
61
 
// Call on every request when you're done with it to clean up its pool.
62
 
void CleanupRequest(request_rec* request);
63
 
 
64
 
// Call to verify that the correct underlying apache calls were made.  Returns a
65
 
// space separated string of the calls along with serialized arguments when
66
 
// appropriate.
67
 
GoogleString actions_since_last_call();
68
 
 
69
 
}  // namespace MockApache
70
 
 
71
 
}  // namespace net_instaweb
72
 
 
73
 
#endif  // PAGESPEED_APACHE_MOCK_APACHE_H_
74