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 5675960980471808: Updated installer with custom action (Closed)
Patch Set: Created March 8, 2014, 5:06 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /**
2 * \file test-installer-lib-sandbox.cpp
3 *
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.
6 * In another, they rely on the operation system environment as a whole.
7 * In these cases, it's easier to verify behavior manually.
8 *
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.
11 */
12
13 #include <sstream>
14 #include <functional>
15
16 #include "session.h"
17 #include "property.h"
18 #include "database.h"
19 #include "process.h"
20 #include "interaction.h"
21
22 //-------------------------------------------------------
23 // log_all_window_handles
24 //-------------------------------------------------------
25 class log_single_window_handle
26 {
27 Immediate_Session & session ;
28
29 public:
30 log_single_window_handle( Immediate_Session & session )
31 : session( session )
32 {
33 }
34
35 bool operator()( HWND window )
36 {
37 std::stringstream s ;
38 s << "Window handle 0x" << std::hex << window ;
39 session.log( s.str() ) ;
40 return true ;
41 }
42 } ;
43
44 void log_all_window_handles( Immediate_Session & session )
45 {
46 session.log( "log_all_window_handles" ) ;
47 log_single_window_handle lp( session ) ;
48 enumerate_windows( lp ) ;
49 }
50
51 //-------------------------------------------------------
52 // log_IE_window_handles
53 //-------------------------------------------------------
54 class log_single_window_handle_only_if_IE
55 {
56 Immediate_Session & session ;
57
58 Process_Closer & pc ;
59
60 public:
61 log_single_window_handle_only_if_IE( Immediate_Session & session, Process_Clos er & pc )
62 : session( session ), pc( pc )
63 {
64 }
65
66 bool operator()( HWND window )
67 {
68 DWORD pid = creator_process( window ) ;
69 if ( pc.contains( pid ) )
70 {
71 std::stringstream s ;
72 s << "Window handle 0x" << std::hex << window ;
73 session.log( s.str() ) ;
74 }
75 return true ;
76 }
77 } ;
78
79 void log_IE_window_handles( Immediate_Session & session )
80 {
81 session.log( "log_IE_window_handles" ) ;
82 const wchar_t * IE_names[] = { L"IExplore.exe", L"AdblockPlusEngine.exe" } ;
83 Snapshot snapshot ;
84 Process_Closer iec( snapshot, IE_names, 2 ) ;
85 log_single_window_handle_only_if_IE lp( session, iec ) ;
86 enumerate_windows( lp ) ;
87 }
88
89 //-------------------------------------------------------
90 // log_only_window_handle_in_closer
91 //-------------------------------------------------------
92 void log_only_window_handle_in_closer( Immediate_Session & session )
93 {
94 session.log( "log_only_window_handle_in_closer" ) ;
95 const wchar_t * IE_names[] = { L"IExplore.exe", L"AdblockPlusEngine.exe" } ;
96 Snapshot snapshot ;
97 Process_Closer iec( snapshot, IE_names, 2 ) ;
98 iec.iterate_our_windows( log_single_window_handle( session ) ) ;
99 }
100
101 //-------------------------------------------------------
102 // sandbox
103 //-------------------------------------------------------
104 /**
105 * Exposed DLL entry point for custom action.
106 * The function signature matches the calling convention used by Windows Install er.
107
108 * \param[in] session_handle
109 * Windows installer session handle
110 *
111 * \return
112 * An integer interpreted as a custom action return value.
113 *
114 * \sa
115 * - MSDN [Custom Action Return Values](http://msdn.microsoft.com/en-us/librar y/aa368072%28v=vs.85%29.aspx)
116 */
117 extern "C" UINT __stdcall
118 sandbox( MSIHANDLE session_handle )
119 {
120 Immediate_Session session( session_handle, "sandbox" ) ;
121
122 try
123 {
124 log_only_window_handle_in_closer( session ) ;
125 }
126 catch( std::exception & e )
127 {
128 session.log_noexcept( "terminated by exception: " + std::string( e.what() ) ) ;
129 return ERROR_INSTALL_FAILURE ;
130 }
131 catch( ... )
132 {
133 session.log_noexcept( "Caught an exception" ) ;
134 return ERROR_INSTALL_FAILURE ;
135 }
136
137 return ERROR_SUCCESS ;
138 }
139
OLDNEW

Powered by Google App Engine
This is Rietveld