| OLD | NEW |
| (Empty) |
| 1 // Copyright 2007-2009 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 #pragma warning(push) | |
| 17 // C4548: expression before comma has no effect | |
| 18 #pragma warning(disable : 4548) | |
| 19 #include <atlstr.h> | |
| 20 #pragma warning(pop) | |
| 21 #include <regstr.h> | |
| 22 #include "omaha/mi_exe_stub/mi_step_test.h" | |
| 23 #include "omaha/test/step_test.h" | |
| 24 | |
| 25 class MIWatcher : public StepTestWatcher { | |
| 26 public: | |
| 27 MIWatcher() : StepTestWatcher(MI_STEP_TEST_NAME), | |
| 28 system_should_be_clean_(true) { | |
| 29 } | |
| 30 | |
| 31 ~MIWatcher() { | |
| 32 } | |
| 33 | |
| 34 protected: | |
| 35 bool VerifyStep(DWORD step, bool *testing_complete) { | |
| 36 bool result = true; | |
| 37 switch (step) { | |
| 38 case MI_STEP_VERIFY_PRECONDITIONS: | |
| 39 if (system_should_be_clean_) { | |
| 40 result = VerifyCleanSystem(); | |
| 41 } else { | |
| 42 result = false; | |
| 43 _tprintf(_T("Unexpected state.\r\n")); | |
| 44 } | |
| 45 break; | |
| 46 case MI_STEP_PROGRAM_START: | |
| 47 if (system_should_be_clean_) { | |
| 48 result = VerifyCleanSystem(); | |
| 49 system_should_be_clean_ = false; | |
| 50 } else { | |
| 51 result = false; | |
| 52 _tprintf(_T("Unexpected state.\r\n")); | |
| 53 } | |
| 54 break; | |
| 55 case MI_STEP_PROGRAM_END: | |
| 56 result = VerifyTestFooInstalled(); | |
| 57 result &= VerifyOmahaInstalled(); | |
| 58 break; | |
| 59 } | |
| 60 *testing_complete = (step >= MI_STEP_PROGRAM_END); | |
| 61 return result; | |
| 62 } | |
| 63 | |
| 64 void PrintIntroduction() { | |
| 65 _tprintf( | |
| 66 _T("Ready to test mi.exe.\r\n") | |
| 67 _T("System should not have any version of Omaha installed on it.\r\n") | |
| 68 _T("System should not have any version of \"!!! Test Foo\" installed on it
.\r\n") | |
| 69 _T("Please run SampleSetup.exe now.\r\n") | |
| 70 ); | |
| 71 } | |
| 72 | |
| 73 void PrintConclusion() { | |
| 74 _tprintf( | |
| 75 _T("Test of mi.exe is complete.\r\n") | |
| 76 ); | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 bool system_should_be_clean_; | |
| 81 | |
| 82 #define TEST_FOO_REG_UNINST_KEY "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\U
ninstall\\{8EE7241A-9AFD-324A-884C-B62DC5DAE506}" | |
| 83 #define TEST_FOO_V2_REG_UNINST_KEY "SOFTWARE\\Microsoft\\Windows\\CurrentVersion
\\Uninstall\\{EE93BF87-0CDD-3F0B-A4D6-3B3A1C54E3FA}" | |
| 84 | |
| 85 bool VerifyCleanSystem() { | |
| 86 if (RegistryKeyExists(HKEY_LOCAL_MACHINE, _T(TEST_FOO_REG_UNINST_KEY))) { | |
| 87 _tprintf(_T("Product !!! Test Foo (old version) appears to be installed on
this system.\r\n")); | |
| 88 return false; | |
| 89 } | |
| 90 if (RegistryKeyExists(HKEY_LOCAL_MACHINE, _T(TEST_FOO_V2_REG_UNINST_KEY))) { | |
| 91 _tprintf(_T("Product !!! Test Foo appears to be installed on this system.\
r\n")); | |
| 92 return false; | |
| 93 } | |
| 94 if (RegistryValueExists(HKEY_LOCAL_MACHINE, REGSTR_PATH_RUN, _T("Google Upda
te"))) { | |
| 95 _tprintf(_T("Omaha Run key is present on this system.\r\n")); | |
| 96 return false; | |
| 97 } | |
| 98 return true; | |
| 99 } | |
| 100 | |
| 101 bool VerifyTestFooInstalled() { | |
| 102 if (!RegistryKeyExists(HKEY_LOCAL_MACHINE, _T(TEST_FOO_V2_REG_UNINST_KEY)))
{ | |
| 103 _tprintf(_T("Product !!! Test Foo is not installed on this system.\r\n")); | |
| 104 return false; | |
| 105 } | |
| 106 return true; | |
| 107 } | |
| 108 | |
| 109 bool VerifyOmahaInstalled() { | |
| 110 if (!RegistryValueExists(HKEY_LOCAL_MACHINE, REGSTR_PATH_RUN, _T("Google Upd
ate"))) { | |
| 111 _tprintf(_T("Omaha Run key is missing on this system.\r\n")); | |
| 112 return false; | |
| 113 } | |
| 114 return true; | |
| 115 } | |
| 116 }; | |
| 117 | |
| 118 int main() { | |
| 119 | |
| 120 MIWatcher watcher; | |
| 121 watcher.Go(); | |
| 122 return 0; | |
| 123 } | |
| OLD | NEW |