Skip to content

Commit f5c314f

Browse files
committed
Add test_boinccas_CARestoreExecutionState
Signed-off-by: Vitalii Koshura <lestat.de.lionkur@gmail.com>
1 parent d55ca6f commit f5c314f

File tree

6 files changed

+186
-133
lines changed

6 files changed

+186
-133
lines changed
Lines changed: 55 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,66 @@
1-
// Berkeley Open Infrastructure for Network Computing
2-
// http://boinc.berkeley.edu
3-
// Copyright (C) 2005 University of California
1+
// This file is part of BOINC.
2+
// https://boinc.berkeley.edu
3+
// Copyright (C) 2026 University of California
44
//
5-
// This is free software; you can redistribute it and/or
6-
// modify it under the terms of the GNU Lesser General Public
7-
// License as published by the Free Software Foundation;
8-
// either version 2.1 of the License, or (at your option) any later version.
5+
// BOINC is free software; you can redistribute it and/or modify it
6+
// under the terms of the GNU Lesser General Public License
7+
// as published by the Free Software Foundation,
8+
// either version 3 of the License, or (at your option) any later version.
99
//
10-
// This software is distributed in the hope that it will be useful,
10+
// BOINC is distributed in the hope that it will be useful,
1111
// but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1313
// See the GNU Lesser General Public License for more details.
1414
//
15-
// To view the GNU Lesser General Public License visit
16-
// http://www.gnu.org/copyleft/lesser.html
17-
// or write to the Free Software Foundation, Inc.,
18-
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19-
//
15+
// You should have received a copy of the GNU Lesser General Public License
16+
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
2017

2118
#include "stdafx.h"
2219
#include "boinccas.h"
23-
#include "CARestoreExecutionState.h"
24-
25-
#define CUSTOMACTION_NAME _T("CARestoreExecutionState")
26-
#define CUSTOMACTION_PROGRESSTITLE _T("")
27-
28-
29-
/////////////////////////////////////////////////////////////////////
30-
//
31-
// Function:
32-
//
33-
// Description:
34-
//
35-
/////////////////////////////////////////////////////////////////////
36-
CARestoreExecutionState::CARestoreExecutionState(MSIHANDLE hMSIHandle) :
37-
BOINCCABase(hMSIHandle, CUSTOMACTION_NAME, CUSTOMACTION_PROGRESSTITLE)
38-
{}
39-
4020

41-
/////////////////////////////////////////////////////////////////////
42-
//
43-
// Function:
44-
//
45-
// Description:
46-
//
47-
/////////////////////////////////////////////////////////////////////
48-
CARestoreExecutionState::~CARestoreExecutionState()
49-
{
50-
BOINCCABase::~BOINCCABase();
21+
class CARestoreExecutionState : public BOINCCABase {
22+
public:
23+
virtual ~CARestoreExecutionState() = default;
24+
explicit CARestoreExecutionState(MSIHANDLE hMSIHandle) :
25+
BOINCCABase(hMSIHandle, _T("CARestoreExecutionState"),
26+
_T("Restore previous execution state")) {
27+
}
28+
29+
UINT OnExecution() override final {
30+
tstring strLaunchProgram;
31+
GetRegistryValue(_T("LAUNCHPROGRAM"),
32+
strLaunchProgram);
33+
SetProperty(_T("LAUNCHPROGRAM"),
34+
strLaunchProgram);
35+
36+
tstring strReturnRebootRequested;
37+
GetRegistryValue(_T("RETURN_REBOOTREQUESTED"),
38+
strReturnRebootRequested);
39+
SetProperty(_T("RETURN_REBOOTREQUESTED"),
40+
strReturnRebootRequested);
41+
42+
tstring strReturnValidateInstall;
43+
GetRegistryValue(_T("RETURN_VALIDATEINSTALL"),
44+
strReturnValidateInstall);
45+
SetProperty(_T("RETURN_VALIDATEINSTALL"),
46+
strReturnValidateInstall);
47+
48+
tstring strBOINCMasterAccountUsername;
49+
GetRegistryValue(_T("RETURN_BOINC_MASTER_USERNAME"),
50+
strBOINCMasterAccountUsername);
51+
SetProperty(_T("BOINC_MASTER_USERNAME"),
52+
strBOINCMasterAccountUsername);
53+
54+
tstring strBOINCProjectAccountUsername;
55+
GetRegistryValue(_T("RETURN_BOINC_PROJECT_USERNAME"),
56+
strBOINCProjectAccountUsername);
57+
SetProperty(_T("BOINC_PROJECT_USERNAME"),
58+
strBOINCProjectAccountUsername);
59+
60+
return ERROR_SUCCESS;
61+
}
62+
};
63+
64+
UINT __stdcall RestoreExecutionState(MSIHANDLE hInstall) {
65+
return CARestoreExecutionState(hInstall).Execute();
5166
}
52-
53-
54-
/////////////////////////////////////////////////////////////////////
55-
//
56-
// Function:
57-
//
58-
// Description:
59-
//
60-
/////////////////////////////////////////////////////////////////////
61-
UINT CARestoreExecutionState::OnExecution()
62-
{
63-
tstring strLaunchProgram;
64-
tstring strReturnRebootRequested;
65-
tstring strReturnValidateInstall;
66-
tstring strRebootPrompt;
67-
tstring strBOINCMasterAccountUsername;
68-
tstring strBOINCProjectAccountUsername;
69-
70-
GetRegistryValue( _T("LAUNCHPROGRAM"), strLaunchProgram );
71-
GetRegistryValue( _T("REBOOTPROMPT"), strRebootPrompt );
72-
GetRegistryValue( _T("RETURN_REBOOTREQUESTED"), strReturnRebootRequested );
73-
GetRegistryValue( _T("RETURN_VALIDATEINSTALL"), strReturnValidateInstall );
74-
GetRegistryValue( _T("RETURN_BOINC_MASTER_USERNAME"), strBOINCMasterAccountUsername );
75-
GetRegistryValue( _T("RETURN_BOINC_PROJECT_USERNAME"), strBOINCProjectAccountUsername );
76-
77-
SetProperty( _T("LAUNCHPROGRAM"), strLaunchProgram );
78-
SetProperty( _T("REBOOTPROMPT"), strRebootPrompt );
79-
SetProperty( _T("RETURN_REBOOTREQUESTED"), strReturnRebootRequested );
80-
SetProperty( _T("RETURN_VALIDATEINSTALL"), strReturnValidateInstall );
81-
SetProperty( _T("BOINC_MASTER_USERNAME"), strBOINCMasterAccountUsername );
82-
SetProperty( _T("BOINC_PROJECT_USERNAME"), strBOINCProjectAccountUsername );
83-
84-
return ERROR_SUCCESS;
85-
}
86-
87-
88-
/////////////////////////////////////////////////////////////////////
89-
//
90-
// Function: RestoreExecutionState
91-
//
92-
// Description:
93-
//
94-
/////////////////////////////////////////////////////////////////////
95-
UINT __stdcall RestoreExecutionState(MSIHANDLE hInstall)
96-
{
97-
UINT uiReturnValue = 0;
98-
99-
CARestoreExecutionState* pCA = new CARestoreExecutionState(hInstall);
100-
uiReturnValue = pCA->Execute();
101-
delete pCA;
102-
103-
return uiReturnValue;
104-
}
105-

clientsetup/win/CARestoreExecutionState.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

clientsetup/win/boinccas.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,15 @@ UINT BOINCCABase::GetRegistryValue(
318318
if (lReturnValue != ERROR_SUCCESS) return ERROR_INSTALL_FAILURE;
319319

320320
// How large does our buffer need to be?
321-
RegQueryValueEx(
321+
lReturnValue = RegQueryValueEx(
322322
hkSetupHive,
323323
strName.c_str(),
324324
NULL,
325325
NULL,
326326
NULL,
327327
&dwSize
328328
);
329+
if (lReturnValue != ERROR_SUCCESS) return ERROR_INSTALL_FAILURE;
329330

330331
// Allocate the buffer space.
331332
lpszRegistryValue = (LPTSTR) malloc(dwSize);
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// This file is part of BOINC.
2+
// https://boinc.berkeley.edu
3+
// Copyright (C) 2026 University of California
4+
//
5+
// BOINC is free software; you can redistribute it and/or modify it
6+
// under the terms of the GNU Lesser General Public License
7+
// as published by the Free Software Foundation,
8+
// either version 3 of the License, or (at your option) any later version.
9+
//
10+
// BOINC is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13+
// See the GNU Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public License
16+
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
17+
18+
#include "boinccas_helper.h"
19+
#include "registry_helper.h"
20+
21+
namespace test_boinccas_CARestoreExecutionState {
22+
class test_boinccas_CARestoreExecutionState : public test_boinccas_TestBase {
23+
protected:
24+
test_boinccas_CARestoreExecutionState() :
25+
test_boinccas_TestBase("RestoreExecutionState") {
26+
}
27+
28+
void TearDown() override {
29+
cleanRegistryKey();
30+
}
31+
};
32+
33+
#ifdef BOINCCAS_TEST
34+
TEST_F(test_boinccas_CARestoreExecutionState,
35+
NoPreviousData_Expect_Empty_Values) {
36+
const auto result = openMsi();
37+
ASSERT_EQ(0u, result);
38+
39+
EXPECT_EQ(0u, executeAction());
40+
41+
auto [errorcode, value] = getMsiProperty("LAUNCHPROGRAM");
42+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
43+
EXPECT_TRUE(value.empty());
44+
45+
std::tie(errorcode, value) = getMsiProperty("RETURN_REBOOTREQUESTED");
46+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
47+
EXPECT_TRUE(value.empty());
48+
49+
std::tie(errorcode, value) = getMsiProperty("RETURN_VALIDATEINSTALL");
50+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
51+
EXPECT_TRUE(value.empty());
52+
53+
std::tie(errorcode, value) = getMsiProperty("BOINC_MASTER_USERNAME");
54+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
55+
EXPECT_TRUE(value.empty());
56+
57+
std::tie(errorcode, value) = getMsiProperty("BOINC_PROJECT_USERNAME");
58+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
59+
EXPECT_TRUE(value.empty());
60+
}
61+
62+
TEST_F(test_boinccas_CARestoreExecutionState,
63+
MissingPreviousData_Expect_Empty_Values) {
64+
ASSERT_TRUE(setRegistryValue("Test", "test"));
65+
66+
const auto result = openMsi();
67+
ASSERT_EQ(0u, result);
68+
69+
EXPECT_EQ(0u, executeAction());
70+
71+
auto [errorcode, value] = getMsiProperty("LAUNCHPROGRAM");
72+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
73+
EXPECT_TRUE(value.empty());
74+
75+
std::tie(errorcode, value) = getMsiProperty("RETURN_REBOOTREQUESTED");
76+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
77+
EXPECT_TRUE(value.empty());
78+
79+
std::tie(errorcode, value) = getMsiProperty("RETURN_VALIDATEINSTALL");
80+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
81+
EXPECT_TRUE(value.empty());
82+
83+
std::tie(errorcode, value) = getMsiProperty("BOINC_MASTER_USERNAME");
84+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
85+
EXPECT_TRUE(value.empty());
86+
87+
std::tie(errorcode, value) = getMsiProperty("BOINC_PROJECT_USERNAME");
88+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
89+
EXPECT_TRUE(value.empty());
90+
}
91+
92+
TEST_F(test_boinccas_CARestoreExecutionState,
93+
PreviousDataSet_Expect_Correct_Values) {
94+
ASSERT_TRUE(setRegistryValue("LAUNCHPROGRAM", "2"));
95+
ASSERT_TRUE(setRegistryValue("RETURN_REBOOTREQUESTED", "4"));
96+
ASSERT_TRUE(setRegistryValue("RETURN_VALIDATEINSTALL", "6"));
97+
ASSERT_TRUE(setRegistryValue(
98+
"RETURN_BOINC_MASTER_USERNAME", "test_master"));
99+
ASSERT_TRUE(setRegistryValue(
100+
"RETURN_BOINC_PROJECT_USERNAME", "test_project"));
101+
102+
const auto result = openMsi();
103+
ASSERT_EQ(0u, result);
104+
105+
EXPECT_EQ(0u, executeAction());
106+
107+
auto [errorcode, value] = getMsiProperty("LAUNCHPROGRAM");
108+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
109+
EXPECT_EQ("2", value);
110+
111+
std::tie(errorcode, value) = getMsiProperty("RETURN_REBOOTREQUESTED");
112+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
113+
EXPECT_EQ("4", value);
114+
115+
std::tie(errorcode, value) = getMsiProperty("RETURN_VALIDATEINSTALL");
116+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
117+
EXPECT_EQ("6", value);
118+
119+
std::tie(errorcode, value) = getMsiProperty("BOINC_MASTER_USERNAME");
120+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
121+
EXPECT_EQ("test_master", value);
122+
123+
std::tie(errorcode, value) = getMsiProperty("BOINC_PROJECT_USERNAME");
124+
EXPECT_EQ(static_cast<unsigned int>(ERROR_SUCCESS), errorcode);
125+
EXPECT_EQ("test_project", value);
126+
}
127+
#endif
128+
}

win_build/boinccas.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
</ItemGroup>
8686
<ItemGroup>
8787
<ClInclude Include="..\clientsetup\win\boinccas.h" />
88-
<ClInclude Include="..\clientsetup\win\CARestoreExecutionState.h" />
8988
<ClInclude Include="..\clientsetup\win\CARestorePermissionBOINCData.h" />
9089
<ClInclude Include="..\clientsetup\win\CARestoreSetupState.h" />
9190
<ClInclude Include="..\clientsetup\win\CARevokeBOINCAdminsRights.h" />

win_build/unittests.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<ClCompile Include="..\tests\unit-tests\boinccas\test_boinccas_CAGrantBOINCUsersRights.cpp" />
5757
<ClCompile Include="..\tests\unit-tests\boinccas\test_boinccas_CALaunchBOINCManager.cpp" />
5858
<ClCompile Include="..\tests\unit-tests\boinccas\test_boinccas_CALaunchBOINCTray.cpp" />
59+
<ClCompile Include="..\tests\unit-tests\boinccas\test_boinccas_CARestoreExecutionState.cpp" />
5960
<ClCompile Include="..\tests\unit-tests\lib\test_parse.cpp" />
6061
<ClCompile Include="..\tests\unit-tests\lib\test_str_util.cpp" />
6162
<ClCompile Include="..\tests\unit-tests\lib\test_url.cpp" />

0 commit comments

Comments
 (0)