Page Speed Optimization Libraries  1.2.24.1
net/instaweb/util/public/shared_mem_statistics_test_base.h
Go to the documentation of this file.
00001 // Copyright 2011 Google Inc.
00016 
00017 #ifndef NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_STATISTICS_TEST_BASE_H_
00018 #define NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_STATISTICS_TEST_BASE_H_
00019 
00020 #include <set>
00021 
00022 #include "net/instaweb/util/public/abstract_shared_mem.h"
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/gtest.h"
00025 #include "net/instaweb/util/public/mem_file_system.h"
00026 #include "net/instaweb/util/public/mock_message_handler.h"
00027 #include "net/instaweb/util/public/mock_timer.h"
00028 #include "net/instaweb/util/public/scoped_ptr.h"
00029 #include "net/instaweb/util/public/shared_mem_statistics.h"
00030 #include "net/instaweb/util/public/shared_mem_test_base.h"
00031 #include "net/instaweb/util/public/string.h"
00032 #include "net/instaweb/util/public/string_util.h"
00033 #include "net/instaweb/util/public/thread_system.h"
00034 
00035 namespace net_instaweb {
00036 class SharedMemStatisticsTestBase : public testing::Test {
00037  protected:
00038   typedef void (SharedMemStatisticsTestBase::*TestMethod)();
00039 
00040   explicit SharedMemStatisticsTestBase(SharedMemTestEnv* test_env);
00041   SharedMemStatisticsTestBase() : testing::Test() {}
00042 
00043   virtual void SetUp();
00044   virtual void TearDown();
00045   GoogleString CreateHistogramDataResponse(
00046       const GoogleString & histogram_name, bool is_long_response);
00047   GoogleString CreateVariableDataResponse(
00048       bool has_unused_variable, bool first);
00049   GoogleString CreateFakeLogfile(GoogleString* var_data,
00050                                  GoogleString* hist_data,
00051                                  std::set<GoogleString>* var_titles,
00052                                  std::set<GoogleString>* hist_titles);
00053   bool CreateChild(TestMethod method);
00054 
00055   void TestCreate();
00056   void TestSet();
00057   void TestClear();
00058   void TestAdd();
00059   void TestSetReturningPrevious();
00060   void TestHistogram();
00061   void TestHistogramRender();
00062   void TestHistogramNoExtraClear();
00063   void TestHistogramExtremeBuckets();
00064   void TestTimedVariableEmulation();
00065   void TestConsoleStatisticsLogger();
00066 
00067   MockMessageHandler handler_;
00068   scoped_ptr<MemFileSystem> file_system_;
00069   scoped_ptr<SharedMemStatistics> stats_; 
00070 
00071  private:
00072   void TestCreateChild();
00073   void TestSetChild();
00074   void TestClearChild();
00075   void TestHistogramNoExtraClearChild();
00076 
00078   void TestAddChild();
00079   bool AddVars(SharedMemStatistics* stats);
00080   bool AddHistograms(SharedMemStatistics* stats);
00083   bool Contains(const StringPiece& html, const StringPiece& pattern);
00084 
00085   SharedMemStatistics* ChildInit();
00086   void ParentInit();
00087 
00088   scoped_ptr<SharedMemTestEnv> test_env_;
00089   scoped_ptr<AbstractSharedMem> shmem_runtime_;
00090   scoped_ptr<MockTimer> timer_;
00091   scoped_ptr<ThreadSystem> thread_system_;
00092 
00093   DISALLOW_COPY_AND_ASSIGN(SharedMemStatisticsTestBase);
00094 };
00095 
00096 template<typename ConcreteTestEnv>
00097 class SharedMemStatisticsTestTemplate : public SharedMemStatisticsTestBase {
00098  public:
00099   SharedMemStatisticsTestTemplate()
00100       : SharedMemStatisticsTestBase(new ConcreteTestEnv) {
00101   }
00102 };
00103 
00104 TYPED_TEST_CASE_P(SharedMemStatisticsTestTemplate);
00105 
00106 TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestCreate) {
00107   SharedMemStatisticsTestBase::TestCreate();
00108 }
00109 
00110 TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestSet) {
00111   SharedMemStatisticsTestBase::TestSet();
00112 }
00113 
00114 TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestClear) {
00115   SharedMemStatisticsTestBase::TestClear();
00116 }
00117 
00118 TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestAdd) {
00119   SharedMemStatisticsTestBase::TestAdd();
00120 }
00121 
00122 TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestSetReturningPrevious) {
00123   SharedMemStatisticsTestBase::TestAdd();
00124 }
00125 
00126 TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestHistogram) {
00127   SharedMemStatisticsTestBase::TestHistogram();
00128 }
00129 
00130 TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestHistogramRender) {
00131   SharedMemStatisticsTestBase::TestHistogramRender();
00132 }
00133 
00134 TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestHistogramExtremeBuckets) {
00135   SharedMemStatisticsTestBase::TestHistogramExtremeBuckets();
00136 }
00137 
00138 TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestHistogramNoExtraClear) {
00139   SharedMemStatisticsTestBase::TestHistogramNoExtraClear();
00140 }
00141 
00142 TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestTimedVariableEmulation) {
00143   SharedMemStatisticsTestBase::TestTimedVariableEmulation();
00144 }
00145 
00146 TYPED_TEST_P(SharedMemStatisticsTestTemplate, TestConsoleStatisticsLogger) {
00147   SharedMemStatisticsTestBase::TestConsoleStatisticsLogger();
00148 }
00149 REGISTER_TYPED_TEST_CASE_P(SharedMemStatisticsTestTemplate, TestCreate,
00150                            TestSet, TestClear, TestAdd,
00151                            TestSetReturningPrevious,
00152                            TestHistogram, TestHistogramRender,
00153                            TestHistogramNoExtraClear,
00154                            TestHistogramExtremeBuckets,
00155                            TestTimedVariableEmulation,
00156                            TestConsoleStatisticsLogger);
00157 
00158 }  
00159 
00160 #endif  ///< NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_STATISTICS_TEST_BASE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines