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 6202981292703744: Whole installer (Closed)
Patch Set: Created June 24, 2014, 7:27 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 const wchar_t * ABP_names[] = { L"AdblockPlus32.dll", L"AdblockPlus64.dll" } ;
84 Process_Snapshot snapshot ;
85 Process_Closer iec( snapshot, IE_names, ABP_names) ;
86 log_single_window_handle_only_if_IE lp( session, iec ) ;
87 enumerate_windows( lp ) ;
88 }
89
90 //-------------------------------------------------------
91 // log_only_window_handle_in_closer
92 //-------------------------------------------------------
93 void log_only_window_handle_in_closer( Immediate_Session & session )
94 {
95 session.log( "log_only_window_handle_in_closer" ) ;
96 const wchar_t * IE_names[] = { L"IExplore.exe", L"AdblockPlusEngine.exe" } ;
97 const wchar_t * ABP_names[] = { L"AdblockPlus32.dll", L"AdblockPlus64.dll" } ;
98 Process_Snapshot snapshot ;
99 Process_Closer iec( snapshot, IE_names, ABP_names) ;
100 iec.iterate_our_windows( log_single_window_handle( session ) ) ;
101 }
102
103 //-------------------------------------------------------
104 // sandbox
105 //-------------------------------------------------------
106 /**
107 * Exposed DLL entry point for custom action.
108 * The function signature matches the calling convention used by Windows Install er.
109
110 * \param[in] session_handle
111 * Windows installer session handle
112 *
113 * \return
114 * An integer interpreted as a custom action return value.
115 *
116 * \sa
117 * - MSDN [Custom Action Return Values](http://msdn.microsoft.com/en-us/librar y/aa368072%28v=vs.85%29.aspx)
118 */
119 extern "C" UINT __stdcall
120 sandbox( MSIHANDLE session_handle )
121 {
122 Immediate_Session session( session_handle, "sandbox" ) ;
123
124 try
125 {
126 session.log( "Sandbox timestamp " __TIMESTAMP__ ) ;
127 log_only_window_handle_in_closer( session ) ;
128 }
129 catch( std::exception & e )
130 {
131 session.log_noexcept( "terminated by exception: " + std::string( e.what() ) ) ;
132 return ERROR_INSTALL_FAILURE ;
133 }
134 catch( ... )
135 {
136 session.log_noexcept( "Caught an exception" ) ;
137 return ERROR_INSTALL_FAILURE ;
138 }
139
140 return ERROR_SUCCESS ;
141 }
142
OLDNEW

Powered by Google App Engine
This is Rietveld