Page Speed Optimization Libraries  1.7.30.1
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(GTestTempDir(), url_fetcher,
00043                                    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   static void SetUpTestCase() {
00067   }
00068 
00069   static void TearDownTestCase() {
00070   }
00071 
00072   OptionsClass* NewOptions() {
00073     return new OptionsClass(factory()->thread_system());
00074   }
00075 
00076  private:
00079   static std::pair<TestRewriteDriverFactory*, TestRewriteDriverFactory*>
00080       MakeFactories(MockUrlFetcher* mock_fetcher,
00081                     TestDistributedFetcher* test_distributed_fetcher) {
00082     OptionsClass::Initialize();
00083 
00084     return make_pair(
00085         new CustomTestRewriteDriverFactory(mock_fetcher,
00086                                            test_distributed_fetcher),
00087         new CustomTestRewriteDriverFactory(mock_fetcher,
00088                                            test_distributed_fetcher));
00089   }
00090 };
00091 
00092 }  
00093 
00094 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CUSTOM_REWRITE_TEST_BASE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines