MongoDB  2.7.0
startup_test.h
1 // mongo/util/startup_test.h
2 
3 /* Copyright 2009 10gen Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include <vector>
21 
22 namespace mongo {
23 
24  /* The idea here is to let all initialization of global variables (classes inheriting from StartupTest)
25  complete before we run the tests -- otherwise order of initilization being arbitrary may mess
26  us up. The app's main() function should call runTests().
27 
28  To define a unit test, inherit from this and implement run. instantiate one object for the new class
29  as a global.
30 
31  These tests are ran on *every* startup of mongod, so they have to be very lightweight. But it is a
32  good quick check for a bad build.
33  */
34  class StartupTest {
35  public:
36  static void runTests();
37 
38  static bool testsInProgress() { return running; }
39 
40  protected:
41  StartupTest();
42  virtual ~StartupTest();
43 
44  private:
45  static std::vector<StartupTest*> *tests;
46  static bool running;
47 
48  static void registerTest(StartupTest *t);
49 
50  // assert if fails
51  virtual void run() = 0;
52 
53  };
54 
55 
56 } // namespace mongo
Definition: startup_test.h:34