Page Speed Optimization Libraries
1.3.25.1
|
00001 // Copyright 2011 Google Inc. 00016 00017 #ifndef NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_TEST_BASE_H_ 00018 #define NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_TEST_BASE_H_ 00019 00020 #include "net/instaweb/util/public/abstract_shared_mem.h" 00021 #include "net/instaweb/util/public/basictypes.h" 00022 #include "net/instaweb/util/public/google_url.h" 00023 #include "net/instaweb/util/public/gtest.h" 00024 #include "net/instaweb/util/public/mock_message_handler.h" 00025 #include "net/instaweb/util/public/scoped_ptr.h" 00026 #include "net/instaweb/util/public/shared_mem_test_base.h" 00027 #include "net/instaweb/util/public/string.h" 00028 00029 namespace net_instaweb { 00030 00031 class SharedMemRefererStatistics; 00032 00033 00034 struct TestUrl { 00035 public: 00036 TestUrl(GoogleString input_string, 00037 GoogleString input_div_location, 00038 GoogleString query_params = GoogleString("")) 00039 : url(FormUrl(input_string, input_div_location, query_params)), 00040 div_location(input_div_location), 00041 string(input_string) { 00042 } 00043 const GoogleUrl url; 00044 const GoogleString div_location; 00045 const GoogleString string; 00046 00047 private: 00049 static GoogleString FormUrl(GoogleString input_string, 00050 GoogleString input_div_location, 00051 GoogleString query_params); 00052 }; 00053 00054 class SharedMemRefererStatisticsTestBase : public testing::Test { 00055 protected: 00056 typedef void (SharedMemRefererStatisticsTestBase::*TestMethod)(); 00057 00058 static const int kNumberOfStrings; 00059 static const int kStringSize; 00060 static const char kPrefix[]; 00061 static const char kSuffix[]; 00062 00063 explicit SharedMemRefererStatisticsTestBase(SharedMemTestEnv* test_env); 00064 00065 bool CreateChild(TestMethod method); 00066 00069 void TestGetDivLocationFromUrl(); 00072 void TestSimple(); 00074 void TestResource(); 00077 void TestIgnoreQueryParams(); 00080 void TestDivLocation(); 00082 void TestDumpFast(); 00084 void TestDumpSimple(); 00086 void TestDumpOrganized(); 00088 void TestMultiProcess(); 00089 00090 void AddChild(); 00091 00105 void LogSequenceOfPageRequests(SharedMemRefererStatistics* stats, 00106 const GoogleUrl* urls[], 00107 int number_of_urls); 00108 00110 SharedMemRefererStatistics* ChildInit(); 00112 SharedMemRefererStatistics* ParentInit(); 00113 00114 scoped_ptr<SharedMemTestEnv> test_env_; 00115 scoped_ptr<AbstractSharedMem> shmem_runtime_; 00116 MockMessageHandler message_handler_; 00117 00118 private: 00119 DISALLOW_COPY_AND_ASSIGN(SharedMemRefererStatisticsTestBase); 00120 }; 00121 00122 template<typename ConcreteTestEnv> 00123 class SharedMemRefererStatisticsTestTemplate 00124 : public SharedMemRefererStatisticsTestBase { 00125 public: 00126 SharedMemRefererStatisticsTestTemplate() 00127 : SharedMemRefererStatisticsTestBase(new ConcreteTestEnv) { 00128 } 00129 }; 00130 00131 TYPED_TEST_CASE_P(SharedMemRefererStatisticsTestTemplate); 00132 00133 TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, 00134 TestGetDivLocationFromUrl) { 00135 SharedMemRefererStatisticsTestBase::TestGetDivLocationFromUrl(); 00136 } 00137 00138 TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestSimple) { 00139 SharedMemRefererStatisticsTestBase::TestSimple(); 00140 } 00141 00142 TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestResource) { 00143 SharedMemRefererStatisticsTestBase::TestResource(); 00144 } 00145 00146 TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestIgnoreQueryParams) { 00147 SharedMemRefererStatisticsTestBase::TestIgnoreQueryParams(); 00148 } 00149 00150 TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestDivLocation) { 00151 SharedMemRefererStatisticsTestBase::TestDivLocation(); 00152 } 00153 00154 TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestDumpFast) { 00155 SharedMemRefererStatisticsTestBase::TestDumpFast(); 00156 } 00157 00158 TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestDumpSimple) { 00159 SharedMemRefererStatisticsTestBase::TestDumpSimple(); 00160 } 00161 00162 TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestDumpOrganized) { 00163 SharedMemRefererStatisticsTestBase::TestDumpOrganized(); 00164 } 00165 00166 TYPED_TEST_P(SharedMemRefererStatisticsTestTemplate, TestMultiProcess) { 00167 SharedMemRefererStatisticsTestBase::TestMultiProcess(); 00168 } 00169 00170 REGISTER_TYPED_TEST_CASE_P(SharedMemRefererStatisticsTestTemplate, 00171 TestGetDivLocationFromUrl, 00172 TestSimple, 00173 TestResource, 00174 TestIgnoreQueryParams, 00175 TestDivLocation, 00176 TestDumpFast, 00177 TestDumpSimple, 00178 TestDumpOrganized, 00179 TestMultiProcess); 00180 00181 } 00182 00183 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_TEST_BASE_H_