| OLD | NEW |
| (Empty) |
| 1 // Copyright 2010 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 // Provides a base framework for unit tests that need an App object. | |
| 17 | |
| 18 #ifndef OMAHA_GOOPDATE_APP_UNITTEST_BASE_H_ | |
| 19 #define OMAHA_GOOPDATE_APP_UNITTEST_BASE_H_ | |
| 20 | |
| 21 #include <atlbase.h> | |
| 22 #include <atlcom.h> | |
| 23 #include "base/scoped_ptr.h" | |
| 24 #include "omaha/base/app_util.h" | |
| 25 #include "omaha/goopdate/app_manager.h" | |
| 26 #include "omaha/goopdate/app_bundle_state_initialized.h" | |
| 27 #include "omaha/goopdate/model.h" | |
| 28 #include "omaha/goopdate/resource_manager.h" | |
| 29 #include "omaha/goopdate/worker_mock.h" | |
| 30 #include "omaha/testing/unit_test.h" | |
| 31 | |
| 32 using ::testing::Return; | |
| 33 | |
| 34 namespace omaha { | |
| 35 | |
| 36 // Overrides the registry. | |
| 37 class AppTestBase : public testing::Test { | |
| 38 protected: | |
| 39 AppTestBase(bool is_machine, bool use_strict_mock) | |
| 40 : is_machine_(is_machine), | |
| 41 use_strict_mock_(use_strict_mock) { | |
| 42 } | |
| 43 | |
| 44 virtual void SetUp() { | |
| 45 EXPECT_SUCCEEDED(AppManager::CreateInstance(is_machine_)); | |
| 46 | |
| 47 // Needed for error strings. | |
| 48 EXPECT_SUCCEEDED(ResourceManager::Create( | |
| 49 is_machine_, | |
| 50 app_util::GetCurrentModuleDirectory(), | |
| 51 _T("en"))); | |
| 52 | |
| 53 if (use_strict_mock_) { | |
| 54 mock_worker_.reset(new testing::StrictMock<MockWorker>); | |
| 55 } else { | |
| 56 mock_worker_.reset(new testing::NiceMock<MockWorker>); | |
| 57 } | |
| 58 | |
| 59 EXPECT_CALL(*mock_worker_, Lock()).WillRepeatedly(Return(2)); | |
| 60 EXPECT_CALL(*mock_worker_, Unlock()).WillRepeatedly(Return(1)); | |
| 61 | |
| 62 model_.reset(new Model(mock_worker_.get())); | |
| 63 | |
| 64 app_bundle_ = model_->CreateAppBundle(is_machine_); | |
| 65 ASSERT_TRUE(app_bundle_.get()); | |
| 66 | |
| 67 EXPECT_SUCCEEDED(app_bundle_->put_displayName(CComBSTR(_T("Test Bundle")))); | |
| 68 EXPECT_SUCCEEDED(app_bundle_->put_displayLanguage(CComBSTR(_T("en")))); | |
| 69 EXPECT_SUCCEEDED(app_bundle_->put_installSource(CComBSTR(_T("unittest")))); | |
| 70 // TODO(omaha3): Address with the TODO in AppBundleInitializedTest::SetUp() | |
| 71 // then remove app_bundle_state_initialized.h above. | |
| 72 if (is_machine_) { | |
| 73 SetAppBundleStateForUnitTest(app_bundle_.get(), | |
| 74 new fsm::AppBundleStateInitialized); | |
| 75 } else { | |
| 76 EXPECT_SUCCEEDED(app_bundle_->initialize()); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 virtual void TearDown() { | |
| 81 ResourceManager::Delete(); | |
| 82 AppManager::DeleteInstance(); | |
| 83 } | |
| 84 | |
| 85 const bool is_machine_; | |
| 86 const bool use_strict_mock_; | |
| 87 | |
| 88 CString hive_override_key_name_; | |
| 89 | |
| 90 scoped_ptr<MockWorker> mock_worker_; | |
| 91 scoped_ptr<Model> model_; | |
| 92 | |
| 93 shared_ptr<AppBundle> app_bundle_; | |
| 94 | |
| 95 private: | |
| 96 DISALLOW_COPY_AND_ASSIGN(AppTestBase); | |
| 97 }; | |
| 98 | |
| 99 class AppTestBaseWithRegistryOverride : public AppTestBase { | |
| 100 protected: | |
| 101 AppTestBaseWithRegistryOverride(bool is_machine, bool use_strict_mock) | |
| 102 : AppTestBase(is_machine, use_strict_mock), | |
| 103 hive_override_key_name_(kRegistryHiveOverrideRoot) {} | |
| 104 | |
| 105 // Override the registry after initializing the AppBundle so that the latter | |
| 106 // has the correct network configuration in the event there are pings to send. | |
| 107 // TODO(omaha3): Ideally we would not send pings from tests: http://b/2911608. | |
| 108 virtual void SetUp() { | |
| 109 AppTestBase::SetUp(); | |
| 110 | |
| 111 RegKey::DeleteKey(hive_override_key_name_); | |
| 112 OverrideRegistryHives(hive_override_key_name_); | |
| 113 } | |
| 114 | |
| 115 virtual void TearDown() { | |
| 116 RestoreRegistryHives(); | |
| 117 RegKey::DeleteKey(hive_override_key_name_); | |
| 118 | |
| 119 AppTestBase::TearDown(); | |
| 120 } | |
| 121 | |
| 122 CString hive_override_key_name_; | |
| 123 }; | |
| 124 | |
| 125 } // namespace omaha | |
| 126 | |
| 127 #endif // OMAHA_GOOPDATE_APP_UNITTEST_BASE_H_ | |
| OLD | NEW |