| OLD | NEW |
| (Empty) |
| 1 // Copyright 2007-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 #include "omaha/base/vistautil.h" | |
| 17 #include "omaha/base/reg_key.h" | |
| 18 #include "omaha/common/const_goopdate.h" | |
| 19 #include "omaha/net/network_config.h" | |
| 20 #include "omaha/testing/omaha_unittest.h" | |
| 21 #include "omaha/testing/unit_test.h" | |
| 22 | |
| 23 namespace omaha { | |
| 24 | |
| 25 int InitializeNetwork() { | |
| 26 if (IsBuildSystem()) { | |
| 27 // Until testsource can be set outside the tests on the build system, | |
| 28 // tests that use the network must be run as admin so the it can be set. | |
| 29 ASSERT1(vista_util::IsUserAdmin()); | |
| 30 SetBuildSystemTestSource(); | |
| 31 } | |
| 32 | |
| 33 // Ensure that any system running unittests has testsource set. | |
| 34 // Some unit tests generate pings, and these must be filtered. | |
| 35 CString value; | |
| 36 HRESULT hr = | |
| 37 RegKey::GetValue(MACHINE_REG_UPDATE_DEV, kRegValueTestSource, &value); | |
| 38 if (FAILED(hr) || value.IsEmpty()) { | |
| 39 ADD_FAILURE() << _T("'") << kRegValueTestSource << _T("'") | |
| 40 << _T(" is not present in ") | |
| 41 << _T("'") << MACHINE_REG_UPDATE_DEV << _T("'") | |
| 42 << _T(" or it is empty. Since you are running Omaha unit ") | |
| 43 << _T("tests, it should probably be set to 'dev' or 'qa'."); | |
| 44 return -1; | |
| 45 } | |
| 46 | |
| 47 // Many unit tests require the network configuration be initialized. | |
| 48 // Referencing the singleton instance creats it if not exist. | |
| 49 // On Windows Vista only admins can write to HKLM therefore the | |
| 50 // initialization of the NetworkConfig must correspond to the integrity | |
| 51 // level the user is running as. | |
| 52 NetworkConfigManager::set_is_machine(vista_util::IsUserAdmin()); | |
| 53 NetworkConfigManager::Instance(); | |
| 54 | |
| 55 return 0; | |
| 56 } | |
| 57 | |
| 58 int DeinitializeNetwork() { | |
| 59 NetworkConfigManager::DeleteInstance(); | |
| 60 return 0; | |
| 61 } | |
| 62 | |
| 63 } // namespace omaha | |
| OLD | NEW |