Page Speed Optimization Libraries  1.4.26.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_rewrite_driver_factory.h"
00029 #include "net/instaweb/util/public/gtest.h"
00030 
00031 namespace net_instaweb {
00032 
00033 template<class OptionsClass>
00034 class CustomRewriteTestBase : public RewriteTestBase {
00035  public:
00036   class CustomTestRewriteDriverFactory : public TestRewriteDriverFactory {
00037    public:
00038     explicit CustomTestRewriteDriverFactory(MockUrlFetcher* url_fetcher,
00039                                             MockUrlFetcher* distributed_fetcher)
00040         : TestRewriteDriverFactory(GTestTempDir(), url_fetcher,
00041                                    distributed_fetcher) {
00042       InitializeDefaultOptions();
00043     }
00044 
00045     virtual OptionsClass* NewRewriteOptions() {
00046       return new OptionsClass;
00047     }
00048   };
00049 
00050   CustomRewriteTestBase()
00051       : RewriteTestBase(MakeFactories(&mock_url_fetcher_,
00052                                       &mock_distributed_fetcher_)) {
00053   }
00054 
00055   virtual ~CustomRewriteTestBase() {
00056     OptionsClass::Terminate();
00057   }
00058 
00059   virtual TestRewriteDriverFactory* MakeTestFactory() {
00060     return new CustomTestRewriteDriverFactory(&mock_url_fetcher_,
00061                                               &mock_distributed_fetcher_);
00062   }
00063 
00064   static void SetUpTestCase() {
00065   }
00066 
00067   static void TearDownTestCase() {
00068   }
00069 
00070  private:
00073   static std::pair<TestRewriteDriverFactory*, TestRewriteDriverFactory*>
00074       MakeFactories(MockUrlFetcher* mock_fetcher,
00075                     MockUrlFetcher* mock_distributed_fetcher) {
00076     OptionsClass::Initialize();
00077 
00078     return make_pair(
00079         new CustomTestRewriteDriverFactory(mock_fetcher,
00080                                            mock_distributed_fetcher),
00081         new CustomTestRewriteDriverFactory(mock_fetcher,
00082                                            mock_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