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 | |
22 // Overview | |
23 // | |
24 // The program to be tested instantiates a StepTestStepper, passing in a | |
25 // unique identifier (by convention, a GUID in registry format). It then | |
26 // calls StepTestStepper::Step() with values representing specific points in | |
27 // execution of the program. | |
28 // | |
29 // Then in test/omaha_system_test.cpp, derive a concrete subclass of | |
30 // StepTestWatcher. In particular, implement VerifyStep(), which takes each of | |
31 // the values passed in through the tested program's StepTestStepper::Step() | |
32 // function, and verifies that the state of the system matches what it should | |
33 // be. | |
34 | |
35 class StepTestBase { | |
36 public: | |
37 StepTestBase(const TCHAR *name); | |
38 virtual ~StepTestBase(); | |
39 | |
40 protected: | |
41 HANDLE step_reached_event_; | |
42 HANDLE resume_event_; | |
43 HKEY state_key_; | |
44 | |
45 static const TCHAR *RESUME_EVENT_TEMPLATE; | |
46 static const TCHAR *STEP_REACHED_EVENT_TEMPLATE; | |
47 static const TCHAR *STATE_REG_KEY_TEMPLATE; | |
48 static const TCHAR *STATE_REG_VALUE_NAME; | |
49 | |
50 void Terminate(); | |
51 }; | |
52 | |
53 class StepTestStepper : public StepTestBase { | |
54 public: | |
55 StepTestStepper(const TCHAR *name); | |
56 virtual ~StepTestStepper(); | |
57 | |
58 void Step(DWORD step); | |
59 private: | |
60 bool is_someone_listening_; | |
61 }; | |
62 | |
63 class StepTestWatcher : public StepTestBase { | |
64 public: | |
65 StepTestWatcher(const TCHAR *name); | |
66 virtual ~StepTestWatcher(); | |
67 | |
68 void Go(); | |
69 | |
70 protected: | |
71 // Checks the state of the machine once the tested program has reached the | |
72 // given step. | |
73 // | |
74 // @param step: the step to be verified | |
75 // @param testing_complete: pointer to bool that should be set to true iff | |
76 // the testing instance is done testing and should now terminate. | |
77 // @return true iff the test of this step passed. | |
78 virtual bool VerifyStep(DWORD step, bool *testing_complete) = 0; | |
79 | |
80 // Prints instructions to the console telling the human tester what the | |
81 // expected setup of the system should be. | |
82 virtual void PrintIntroduction() = 0; | |
83 | |
84 // Prints a statement to the console indicating that testing is complete. | |
85 virtual void PrintConclusion() = 0; | |
86 | |
87 // Returns true iff the given registry key exists on this machine. | |
88 bool RegistryKeyExists(HKEY root, const TCHAR *name); | |
89 | |
90 // Returns true iff the given registry value exists on this machine. | |
91 bool RegistryValueExists(HKEY root, const TCHAR *key_name, | |
92 const TCHAR *value_name); | |
93 | |
94 CString name_; | |
95 }; | |
OLD | NEW |