1
// Copyright 2015 Google Inc.
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
7
// http://www.apache.org/licenses/LICENSE-2.0
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.
15
// Author: jefftk@google.com (Jeff Kaufman)
17
#ifndef PAGESPEED_APACHE_MOCK_APACHE_H_
18
#define PAGESPEED_APACHE_MOCK_APACHE_H_
20
#include "pagespeed/kernel/base/string_util.h"
24
namespace net_instaweb {
26
namespace MockApache {
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.
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.
38
// Most of these calls need a properly initialized request_rec. Use
39
// PrepareRequest/CleanupRequest for that.
43
// MockApache::Initialize();
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();
53
// Call once before any uses of MockApache.
55
// Call once after any uses of MockApache.
58
// Call on every request to create a pool for it and allocate initial
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);
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
67
GoogleString actions_since_last_call();
69
} // namespace MockApache
71
} // namespace net_instaweb
73
#endif // PAGESPEED_APACHE_MOCK_APACHE_H_