Skip to content

Commit 9044a17

Browse files
Fix wrong config defines in boost/windows.cfg (#6492)
**Fix defines for boost test macros** The _MESSAGE macros were causing an unusedScopedObject warning because the created string was not used. Casting the message to void fixed the warnings. Add missing `BOOST_AUTO_TEST_CASE_TEMPLATE` macro accidentally removed with d1b3670 **Fix wrong defined in windows.cfg** INVALID_HANDLE_VALUE is defined as `-1` in the windows sdk INVALID_SOCKET is defined as `~0` in the windwos sdk Add missing generic rights
1 parent 9e548af commit 9044a17

4 files changed

Lines changed: 53 additions & 6 deletions

File tree

cfg/boost.cfg

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@
3535
<define name="BOOST_TEST(condition, ...)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;(condition))" />
3636
<define name="BOOST_TEST_REQUIRE(condition, ...)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;(condition))" />
3737
<define name="BOOST_WARN(condition)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;(condition))" />
38-
<define name="BOOST_WARN_MESSAGE(condition, msg)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;(condition)); std::string(msg)" />
38+
<define name="BOOST_WARN_MESSAGE(condition, msg)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;(condition)); static_cast&lt;void&gt;(msg)" />
3939
<define name="BOOST_WARN_EQUAL(a, b)" value="static_cast&lt;void&gt;((a) == (b))" />
4040
<define name="BOOST_WARN_NE(a, b)" value="static_cast&lt;void&gt;((a) != (b))" />
4141
<define name="BOOST_WARN_GT(a, b)" value="static_cast&lt;void&gt;((a) &gt; (b))" />
4242
<define name="BOOST_WARN_GE(a, b)" value="static_cast&lt;void&gt;((a) &gt;= (b))" />
4343
<define name="BOOST_WARN_LT(a, b)" value="static_cast&lt;void&gt;((a) &lt; (b))" />
4444
<define name="BOOST_WARN_LE(a, b)" value="static_cast&lt;void&gt;((a) &lt;= (b))" />
4545
<define name="BOOST_CHECK(condition)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;(condition))" />
46-
<define name="BOOST_CHECK_MESSAGE(condition, msg)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;(condition)); std::string(msg)" />
46+
<define name="BOOST_CHECK_MESSAGE(condition, msg)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;(condition)); static_cast&lt;void&gt;(msg)" />
4747
<define name="BOOST_CHECK_EQUAL(a, b)" value="static_cast&lt;void&gt;((a) == (b))" />
4848
<define name="BOOST_CHECK_NE(a, b)" value="static_cast&lt;void&gt;((a) != (b))" />
4949
<define name="BOOST_CHECK_GT(a, b)" value="static_cast&lt;void&gt;((a) &gt; (b))" />
5050
<define name="BOOST_CHECK_GE(a, b)" value="static_cast&lt;void&gt;((a) &gt;= (b))" />
5151
<define name="BOOST_CHECK_LT(a, b)" value="static_cast&lt;void&gt;((a) &lt; (b))" />
5252
<define name="BOOST_CHECK_LE(a, b)" value="static_cast&lt;void&gt;((a) &lt;= (b))" />
5353
<define name="BOOST_REQUIRE(condition)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;(condition))" />
54-
<define name="BOOST_REQUIRE_MESSAGE(condition, msg)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;(condition)); std::string(msg)" />
54+
<define name="BOOST_REQUIRE_MESSAGE(condition, msg)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;(condition)); static_cast&lt;void&gt;(msg)" />
5555
<define name="BOOST_REQUIRE_EQUAL(a, b)" value="static_cast&lt;void&gt;(static_cast&lt;bool&gt;((a) == (b)))" />
5656
<define name="BOOST_REQUIRE_NE(a, b)" value="static_cast&lt;void&gt;((a) != (b))" />
5757
<define name="BOOST_REQUIRE_GT(a, b)" value="static_cast&lt;void&gt;((a) &gt; (b))" />
@@ -84,6 +84,7 @@
8484
<define name="BOOST_MATH_INT_VALUE_SUFFIX" value=""/>
8585
<!-- Tell cppcheck to interpret BOOST_AUTO_TEST_CASE as a function definition -->
8686
<define name="BOOST_AUTO_TEST_CASE(...)" value="void BOOST_AUTO_TEST_CASE_run(__VA_ARGS__)"/>
87+
<define name="BOOST_AUTO_TEST_CASE_TEMPLATE(test_name, type_name, TL)" value="template&lt;typename type_name&gt;void test_name()"/>
8788
<define name="BOOST_FIXTURE_TEST_CASE(name, fixture, ...)" value="struct name : fixture { void test_method(); }; void name::test_method()" />
8889
<define name="BOOST_FIXTURE_TEST_CASE_TEMPLATE(test_name, type_name, TL, F)" value="template&lt;typename type_name&gt; struct test_name : public F { void test_method(); }; template&lt;typename type_name&gt; void test_name&lt;type_name&gt;::test_method()" />
8990
<define name="BOOST_DATA_TEST_CASE(...)" value="void BOOST_DATA_TEST_CASE_run(__VA_ARGS__)"/>

cfg/windows.cfg

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7119,8 +7119,8 @@ HFONT CreateFont(
71197119
<define name="afx_msg" value=""/>
71207120
<define name="AFX_EXT_CLASS" value=""/>
71217121
<define name="DEBUG_NEW" value="new"/>
7122-
<define name="INVALID_HANDLE_VALUE" value="0"/>
7123-
<define name="INVALID_SOCKET" value="0"/>
7122+
<define name="INVALID_HANDLE_VALUE" value="-1"/>
7123+
<define name="INVALID_SOCKET" value="~0"/>
71247124
<define name="WINAPI" value="__stdcall"/>
71257125
<define name="STDMETHODCALLTYPE" value="__stdcall"/>
71267126
<define name="STDMETHODIMP" value="HRESULT STDMETHODCALLTYPE"/>
@@ -14182,6 +14182,10 @@ HFONT CreateFont(
1418214182
<define name="SIID_CLUSTEREDDRIVE" value="140"/>
1418314183
<define name="SIID_MAX_ICONS" value="181"/>
1418414184
<!-- constants from winnt.h -->
14185+
<define name="GENERIC_READ" value="0x80000000L" />
14186+
<define name="GENERIC_WRITE" value="0x40000000L" />
14187+
<define name="GENERIC_EXECUTE" value="0x20000000L" />
14188+
<define name="GENERIC_ALL" value="0x10000000L" />
1418514189
<define name="LANG_AFRIKAANS" value="0x36"/>
1418614190
<define name="LANG_ALBANIAN" value="0x1c"/>
1418714191
<define name="LANG_ALSATIAN" value="0x84"/>

test/cfg/boost.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <boost/smart_ptr/scoped_array.hpp>
1818
#include <boost/thread/mutex.hpp>
1919
#include <boost/thread/lock_guard.hpp>
20+
#include <boost/test/unit_test.hpp>
2021

2122
BOOST_FORCEINLINE void boost_forceinline_test()
2223
{}
@@ -104,4 +105,25 @@ void lock_guard_finiteLifetime(boost::mutex& m)
104105
{
105106
// cppcheck-suppress unusedScopedObject
106107
boost::lock_guard<boost::mutex>{ m };
107-
}
108+
}
109+
110+
BOOST_AUTO_TEST_SUITE(my_auto_test_suite)
111+
112+
BOOST_AUTO_TEST_CASE(test_message_macros)
113+
{
114+
bool my_bool = false;
115+
BOOST_WARN_MESSAGE(my_bool, "warn");
116+
BOOST_CHECK_MESSAGE(my_bool, "check");
117+
BOOST_REQUIRE_MESSAGE(my_bool, "require");
118+
119+
BOOST_WARN_MESSAGE(my_bool, "my_bool was: " << my_bool);
120+
}
121+
122+
using test_types_w_tuples = std::tuple<int, long, unsigned char>;
123+
BOOST_AUTO_TEST_CASE_TEMPLATE(my_tuple_test, T, test_types_w_tuples)
124+
{
125+
// cppcheck-suppress valueFlowBailoutIncompleteVar
126+
BOOST_TEST(sizeof(T) == 4U);
127+
}
128+
129+
BOOST_AUTO_TEST_SUITE_END()

test/cfg/windows.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@
2222
#include <atlstr.h>
2323
#include <string>
2424

25+
void invalidHandle_CreateFile(LPCWSTR lpFileName)
26+
{
27+
HANDLE file = CreateFile(lpFileName, GENERIC_READ, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
28+
29+
// INVALID_HANDLE_VALUE is not the same as 0
30+
if (file != INVALID_HANDLE_VALUE && file) {}
31+
32+
// cppcheck-suppress resourceLeak
33+
}
34+
35+
void invalid_socket()
36+
{
37+
SOCKET sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
38+
39+
// INVALID_SOCKET is not the same as 0
40+
if (sock != INVALID_SOCKET && sock) {}
41+
42+
// cppcheck-suppress resourceLeak
43+
}
44+
2545
void resourceLeak_OpenThread(const DWORD dwDesiredAccess, const BOOL bInheritHandle, const DWORD dwThreadId)
2646
{
2747
HANDLE proc = OpenThread(dwDesiredAccess, bInheritHandle, dwThreadId);

0 commit comments

Comments
 (0)