Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: installer/src/installer-lib/test/test-installer-lib-sandbox.cpp

Issue 29329510: Issue #1186 - Style conformity for names in installer tests (Closed)
Patch Set: Created Nov. 14, 2015, 5:55 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « installer/src/installer-lib/test/test-installer-lib-ca.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * \file test-installer-lib-sandbox.cpp 2 * \file test-installer-lib-sandbox.cpp
3 * 3 *
4 * Automatic testing of many of the units within the custom action is infeasible . 4 * Automatic testing of many of the units within the custom action is infeasible .
5 * In one case, they rely on the execution environment within an installation se ssion. 5 * In one case, they rely on the execution environment within an installation se ssion.
6 * In another, they rely on the operation system environment as a whole. 6 * In another, they rely on the operation system environment as a whole.
7 * In these cases, it's easier to verify behavior manually. 7 * In these cases, it's easier to verify behavior manually.
8 * 8 *
9 * This file contains a custom action function sandbox() as well as a number of test functions. 9 * This file contains a custom action function sandbox() as well as a number of test functions.
10 * At any given time, not all of the test functions need to be referenced within the body of custom action. 10 * At any given time, not all of the test functions need to be referenced within the body of custom action.
11 */ 11 */
12 12
13 #include <sstream> 13 #include <sstream>
14 #include <functional> 14 #include <functional>
15 15
16 #include "session.h" 16 #include "session.h"
17 #include "property.h" 17 #include "property.h"
18 #include "database.h" 18 #include "database.h"
19 #include "process.h" 19 #include "process.h"
20 #include "interaction.h" 20 #include "interaction.h"
21 21
22 //------------------------------------------------------- 22 //-------------------------------------------------------
23 // log_all_window_handles 23 // LogAllWindowHandles
24 //------------------------------------------------------- 24 //-------------------------------------------------------
25 class log_single_window_handle 25 class LogSingleWindowHandle
26 { 26 {
27 ImmediateSession& session; 27 ImmediateSession& session;
28 28
29 public: 29 public:
30 log_single_window_handle(ImmediateSession& session) 30 LogSingleWindowHandle(ImmediateSession& session)
31 : session(session) 31 : session(session)
32 { 32 {
33 } 33 }
34 34
35 bool operator()(HWND window) 35 bool operator()(HWND window)
36 { 36 {
37 std::stringstream s; 37 std::stringstream s;
38 s << "Window handle 0x" << std::hex << window; 38 s << "Window handle 0x" << std::hex << window;
39 session.Log(s.str()); 39 session.Log(s.str());
40 return true; 40 return true;
41 } 41 }
42 }; 42 };
43 43
44 void log_all_window_handles(ImmediateSession& session) 44 void LogAllWindowHandles(ImmediateSession& session)
45 { 45 {
46 session.Log("log_all_window_handles"); 46 session.Log("LogAllWindowHandles");
47 log_single_window_handle lp(session); 47 LogSingleWindowHandle lp(session);
48 EnumerateWindows(lp); 48 EnumerateWindows(lp);
49 } 49 }
50 50
51 //------------------------------------------------------- 51 //-------------------------------------------------------
52 // log_IE_window_handles 52 // LogIeWindowHandles
53 //------------------------------------------------------- 53 //-------------------------------------------------------
54 class log_single_window_handle_only_if_IE 54 class LogSingleWindowHandleOnlyIfIe
55 { 55 {
56 ImmediateSession& session; 56 ImmediateSession& session;
57 57
58 ProcessCloser& pc; 58 ProcessCloser& pc;
59 59
60 public: 60 public:
61 log_single_window_handle_only_if_IE(ImmediateSession& session, ProcessCloser& pc) 61 LogSingleWindowHandleOnlyIfIe(ImmediateSession& session, ProcessCloser& pc)
62 : session(session), pc(pc) 62 : session(session), pc(pc)
63 { 63 {
64 } 64 }
65 65
66 bool operator()(HWND window) 66 bool operator()(HWND window)
67 { 67 {
68 DWORD pid = CreatorProcess(window); 68 DWORD pid = CreatorProcess(window);
69 if (pc.Contains(pid)) 69 if (pc.Contains(pid))
70 { 70 {
71 std::stringstream s; 71 std::stringstream s;
72 s << "Window handle 0x" << std::hex << window; 72 s << "Window handle 0x" << std::hex << window;
73 session.Log(s.str()); 73 session.Log(s.str());
74 } 74 }
75 return true; 75 return true;
76 } 76 }
77 }; 77 };
78 78
79 void log_IE_window_handles(ImmediateSession& session) 79 void LogIeWindowHandles(ImmediateSession& session)
80 { 80 {
81 session.Log("log_IE_window_handles"); 81 session.Log("LogIeWindowHandles");
82 const wchar_t* IE_names[] = { L"IExplore.exe", L"AdblockPlusEngine.exe" }; 82 const wchar_t* IeNames[] = {L"IExplore.exe", L"AdblockPlusEngine.exe"};
83 ProcessSnapshot snapshot; 83 ProcessSnapshot snapshot;
84 ProcessCloser iec(snapshot, IE_names); 84 ProcessCloser iec(snapshot, IeNames);
85 log_single_window_handle_only_if_IE lp(session, iec); 85 LogSingleWindowHandleOnlyIfIe lp(session, iec);
86 EnumerateWindows(lp); 86 EnumerateWindows(lp);
87 } 87 }
88 88
89 //------------------------------------------------------- 89 //-------------------------------------------------------
90 // log_only_window_handle_in_closer 90 // LogOnlyWindowHandleInCloser
91 //------------------------------------------------------- 91 //-------------------------------------------------------
92 void log_only_window_handle_in_closer(ImmediateSession& session) 92 void LogOnlyWindowHandleInCloser(ImmediateSession& session)
93 { 93 {
94 session.Log("log_only_window_handle_in_closer"); 94 session.Log("LogOnlyWindowHandleInCloser");
95 const wchar_t* IE_names[] = { L"IExplore.exe", L"AdblockPlusEngine.exe" }; 95 const wchar_t* IeNames[] = {L"IExplore.exe", L"AdblockPlusEngine.exe"};
96 ProcessSnapshot snapshot; 96 ProcessSnapshot snapshot;
97 ProcessCloser iec(snapshot, IE_names); 97 ProcessCloser iec(snapshot, IeNames);
98 iec.IterateOurWindows(log_single_window_handle(session)); 98 iec.IterateOurWindows(LogSingleWindowHandle(session));
99 } 99 }
100 100
101 //------------------------------------------------------- 101 //-------------------------------------------------------
102 // sandbox 102 // sandbox
103 //------------------------------------------------------- 103 //-------------------------------------------------------
104 /** 104 /**
105 * Exposed DLL entry point for custom action. 105 * Exposed DLL entry point for custom action.
106 * The function signature matches the calling convention used by Windows Install er. 106 * The function signature matches the calling convention used by Windows Install er.
107 107
108 * \param[in] session_handle 108 * \param[in] sessionHandle
109 * Windows installer session handle 109 * Windows installer session handle
110 * 110 *
111 * \return 111 * \return
112 * An integer interpreted as a custom action return value. 112 * An integer interpreted as a custom action return value.
113 * 113 *
114 * \sa 114 * \sa
115 * - MSDN [Custom Action Return Values](http://msdn.microsoft.com/en-us/librar y/aa368072%28v=vs.85%29.aspx) 115 * - MSDN [Custom Action Return Values](http://msdn.microsoft.com/en-us/librar y/aa368072%28v=vs.85%29.aspx)
116 */ 116 */
117 extern "C" UINT __stdcall 117 extern "C" UINT __stdcall
118 sandbox(MSIHANDLE session_handle) 118 sandbox(MSIHANDLE sessionHandle)
119 { 119 {
120 ImmediateSession session(session_handle, "sandbox"); 120 ImmediateSession session(sessionHandle, "sandbox");
121 121
122 try 122 try
123 { 123 {
124 session.Log("Sandbox timestamp " __TIMESTAMP__); 124 session.Log("Sandbox timestamp " __TIMESTAMP__);
125 log_only_window_handle_in_closer(session); 125 LogOnlyWindowHandleInCloser(session);
126 } 126 }
127 catch (std::exception& e) 127 catch (std::exception& e)
128 { 128 {
129 session.LogNoexcept("terminated by exception: " + std::string(e.what())); 129 session.LogNoexcept("terminated by exception: " + std::string(e.what()));
130 return ERROR_INSTALL_FAILURE; 130 return ERROR_INSTALL_FAILURE;
131 } 131 }
132 catch (...) 132 catch (...)
133 { 133 {
134 session.LogNoexcept("Caught an exception"); 134 session.LogNoexcept("Caught an exception");
135 return ERROR_INSTALL_FAILURE; 135 return ERROR_INSTALL_FAILURE;
136 } 136 }
137 137
138 return ERROR_SUCCESS; 138 return ERROR_SUCCESS;
139 } 139 }
OLDNEW
« no previous file with comments | « installer/src/installer-lib/test/test-installer-lib-ca.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld