Skip to content

Commit 6e669ae

Browse files
committed
Merge pull request #216 from peternewman/licence_enforcer
Fix some Coverity issues
2 parents 6b4b347 + 9ffeb94 commit 6e669ae

4 files changed

Lines changed: 37 additions & 24 deletions

File tree

Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ TESTS =
2828

2929
###################
3030

31+
if BUILD_UNIT_TESTS
3132
include Bootloader/firmware/src/Makefile.mk
3233
include firmware/src/Makefile.mk
3334
include tests/Makefile.mk
35+
endif
36+
3437
include tools/Makefile.mk
3538

3639
check_PROGRAMS = $(TESTS)

configure.ac

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ AC_LANG_PUSH(C)
2525
AC_PROG_CC_C99
2626
AC_LANG_POP(C)
2727

28-
# Check we have -std=c++11 support
29-
AX_CXX_COMPILE_STDCXX_11(noext,mandatory)
28+
# Allow us to just build the tools without the unit tests
29+
AC_ARG_ENABLE(
30+
[unit-tests],
31+
[AS_HELP_STRING([--disable-unit-tests],
32+
[Just build the tools without the unit tests])])
33+
AM_CONDITIONAL(BUILD_UNIT_TESTS, test "x$enable_unit_tests" != xno)
34+
35+
# Check we have -std=c++11 support if required
36+
AM_COND_IF([BUILD_UNIT_TESTS],
37+
[AX_CXX_COMPILE_STDCXX_11(noext,mandatory)])
3038

3139
# Checks for header files.
3240
AC_CHECK_HEADERS([arpa/inet.h stdint.h stdlib.h string.h])
@@ -84,7 +92,10 @@ GTEST_LIBS="$with_gmock/googletest/lib/libgtest.la $with_gmock/googletest/lib/li
8492
old_cppflags=$CPPFLAGS
8593
CPPFLAGS="$GMOCK_INCLUDES $GTEST_INCLUDES"
8694

87-
AC_CHECK_HEADER([gmock/gmock.h], [], [AC_MSG_ERROR([Missing gmock/gmock.h])])
95+
AM_COND_IF([BUILD_UNIT_TESTS],
96+
[AC_CHECK_HEADER([gmock/gmock.h],
97+
[],
98+
[AC_MSG_ERROR([Missing gmock/gmock.h])])])
8899

89100
# restore CPPFLAGS
90101
CPPFLAGS=$old_cppflags
@@ -104,12 +115,11 @@ AC_ARG_WITH(
104115
[ola],
105116
[AS_HELP_STRING([--without-ola],
106117
[Skip OLA checks, unittests will not work correctly])])
107-
AS_IF([test "x$with_ola" != xno],
108-
[PKG_CHECK_MODULES(
109-
OLA,
110-
[libola],
111-
[],
112-
[AC_MSG_ERROR([Missing OLA, please install])])])
118+
AS_IF([test "x$enable_unit_tests" != xno && test "x$with_ola" != xno],
119+
[PKG_CHECK_MODULES(OLA,
120+
[libola],
121+
[],
122+
[AC_MSG_ERROR([Missing OLA, please install])])])
113123

114124
# Output
115125
#####################################################
@@ -125,6 +135,8 @@ C++ Compiler: '${CXX} ${CXXFLAGS} ${CPPFLAGS}'
125135
C Compiler: '${CC} ${CFLAGS} ${CPPFLAGS}'
126136
Linker: '${LD} ${LDFLAGS} ${LIBS}'
127137

138+
Unit Tests: ${enable_unit_tests}
139+
128140
Now type 'make @<:@<target>@:>@'
129141
where the optional <target> is:
130142
check - run the tests

tests/mocks/Matchers.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "Matchers.h"
2222

23+
#include <cctype>
2324
#include <gmock/gmock.h>
2425

2526

@@ -48,15 +49,14 @@ bool MemoryCompare(
4849
uint8_t expected = reinterpret_cast<const uint8_t*>(expected_data)[i];
4950

5051
*listener
51-
<< "\n" << std::dec << i << ": 0x" << std::hex
52+
<< "\n" << i << ": 0x" << std::hex
5253
<< static_cast<int>(expected)
5354
<< (expected == actual ? " == " : " != ")
5455
<< "0x" << static_cast<int>(actual) << " ("
55-
<< ((expected >= '!' && expected <= '~') ?
56-
static_cast<char>(expected) : ' ')
56+
<< (std::isprint(expected) ? static_cast<char>(expected) : ' ')
5757
<< (expected == actual ? " == " : " != ")
58-
<< (actual >= '!' && actual <= '~' ? static_cast<char>(actual) : ' ')
59-
<< ")";
58+
<< (std::isprint(actual) ? static_cast<char>(actual) : ' ')
59+
<< ")" << std::dec;
6060

6161
}
6262
listener->stream()->flags(ostream_flags);
@@ -175,15 +175,14 @@ bool PayloadMatcher::MatchAndExplain(
175175

176176
if (listener->IsInterested()) {
177177
*listener
178-
<< "\n" << std::dec << i << ": 0x" << std::hex
178+
<< "\n" << i << ": 0x" << std::hex
179179
<< static_cast<int>(expected)
180180
<< (expected == actual ? " == " : " != ")
181181
<< "0x" << static_cast<int>(actual) << " ("
182-
<< ((expected >= '!' && expected <= '~') ?
183-
static_cast<char>(expected) : ' ')
182+
<< (std::isprint(expected) ? static_cast<char>(expected) : ' ')
184183
<< (expected == actual ? " == " : " != ")
185-
<< (actual >= '!' && actual <= '~' ? static_cast<char>(actual) : ' ')
186-
<< ")";
184+
<< (std::isprint(actual) ? static_cast<char>(actual) : ' ')
185+
<< ")" << std::dec;
187186
}
188187

189188
matched &= (expected == actual);

tests/mocks/MessageHandlerMock.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,14 @@ bool MessageMatcher::MatchAndExplain(
6161
uint8_t expected = reinterpret_cast<const uint8_t*>(m_payload)[i];
6262

6363
*listener
64-
<< "\n" << std::dec << i << ": 0x" << std::hex
64+
<< "\n" << i << ": 0x" << std::hex
6565
<< static_cast<int>(expected)
6666
<< (expected == actual ? " == " : " != ")
6767
<< "0x" << static_cast<int>(actual) << " ("
68-
<< ((expected >= '!' && expected <= '~') ?
69-
static_cast<char>(expected) : ' ')
68+
<< (std::isprint(expected) ? static_cast<char>(expected) : ' ')
7069
<< (expected == actual ? " == " : " != ")
71-
<< (actual >= '!' && actual <= '~' ? static_cast<char>(actual) : ' ')
72-
<< ")";
70+
<< (std::isprint(actual) ? static_cast<char>(actual) : ' ')
71+
<< ")" << std::dec;
7372

7473
matched &= (expected == actual);
7574
}

0 commit comments

Comments
 (0)