Page Speed Optimization Libraries  1.7.30.4
net/instaweb/rewriter/public/custom_rewrite_test_base.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00017 
00020 
00021 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CUSTOM_REWRITE_TEST_BASE_H_
00022 #define NET_INSTAWEB_REWRITER_PUBLIC_CUSTOM_REWRITE_TEST_BASE_H_
00023 
00024 #include <utility>
00025 
00026 #include "net/instaweb/http/public/mock_url_fetcher.h"
00027 #include "net/instaweb/rewriter/public/rewrite_test_base.h"
00028 #include "net/instaweb/rewriter/public/test_distributed_fetcher.h"
00029 #include "net/instaweb/rewriter/public/test_rewrite_driver_factory.h"
00030 #include "net/instaweb/util/public/gtest.h"
00031 
00032 namespace net_instaweb {
00033 
00034 template<class OptionsClass>
00035 class CustomRewriteTestBase : public RewriteTestBase {
00036  public:
00037   class CustomTestRewriteDriverFactory : public TestRewriteDriverFactory {
00038    public:
00039     explicit CustomTestRewriteDriverFactory(
00040         MockUrlFetcher* url_fetcher,
00041         TestDistributedFetcher* distributed_fetcher)
00042         : TestRewriteDriverFactory(process_context(), GTestTempDir(),
00043                                    url_fetcher, distributed_fetcher) {
00044       InitializeDefaultOptions();
00045     }
00046 
00047     virtual OptionsClass* NewRewriteOptions() {
00048       return new OptionsClass(thread_system());
00049     }
00050   };
00051 
00052   CustomRewriteTestBase()
00053       : RewriteTestBase(MakeFactories(&mock_url_fetcher_,
00054                                       &test_distributed_fetcher_)) {
00055   }
00056 
00057   virtual ~CustomRewriteTestBase() {
00058     OptionsClass::Terminate();
00059   }
00060 
00061   virtual TestRewriteDriverFactory* MakeTestFactory() {
00062     return new CustomTestRewriteDriverFactory(&mock_url_fetcher_,
00063                                               &test_distributed_fetcher_);
00064   }
00065 
00066   OptionsClass* NewOptions() {
00067     return new OptionsClass(factory()->thread_system());
00068   }
00069 
00070  private:
00073   static std::pair<TestRewriteDriverFactory*, TestRewriteDriverFactory*>
00074       MakeFactories(MockUrlFetcher* mock_fetcher,
00075                     TestDistributedFetcher* test_distributed_fetcher) {
00076     OptionsClass::Initialize();
00077 
00078     return make_pair(
00079         new CustomTestRewriteDriverFactory(mock_fetcher,
00080                                            test_distributed_fetcher),
00081         new CustomTestRewriteDriverFactory(mock_fetcher,
00082                                            test_distributed_fetcher));
00083   }
00084 };
00085 
00086 }  
00087 
00088 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CUSTOM_REWRITE_TEST_BASE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines