OpenTTD Source  20240919-master-gdf0233f4c2
strings_func.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "../stdafx.h"
11 
12 #include "../3rdparty/catch2/catch.hpp"
13 
14 #include "../strings_func.h"
15 
16 TEST_CASE("HaveDParamChanged")
17 {
18  SetDParam(0, 0);
19  SetDParamStr(1, "some string");
20 
21  std::vector<StringParameterData> backup;
22  CopyOutDParam(backup, 2);
23 
24  CHECK(HaveDParamChanged(backup) == false);
25 
26  /* A different parameter 0 (both string and numeric). */
27  SetDParam(0, 1);
28  CHECK(HaveDParamChanged(backup) == true);
29 
30  SetDParamStr(0, "some other string");
31  CHECK(HaveDParamChanged(backup) == true);
32 
33  /* Back to the original state, nothing should have changed. */
34  SetDParam(0, 0);
35  CHECK(HaveDParamChanged(backup) == false);
36 
37  /* A different parameter 1 (both string and numeric). */
38  SetDParamStr(1, "some other string");
39  CHECK(HaveDParamChanged(backup) == true);
40 
41  SetDParam(1, 0);
42  CHECK(HaveDParamChanged(backup) == true);
43 
44  /* Back to the original state, nothing should have changed. */
45  SetDParamStr(1, "some string");
46  CHECK(HaveDParamChanged(backup) == false);
47 
48  /* Changing paramter 2 should not have any effect, as the backup is only 2 long. */
49  SetDParam(2, 3);
50  CHECK(HaveDParamChanged(backup) == false);
51 
52 }
HaveDParamChanged
bool HaveDParamChanged(const std::span< const StringParameterData > backup)
Checks whether the global string parameters have changed compared to the given backup.
Definition: strings.cpp:184
CopyOutDParam
void CopyOutDParam(std::vector< StringParameterData > &backup, size_t num)
Copy num string parameters from the global string parameter array to the backup.
Definition: strings.cpp:171
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:344