Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test/mock support for long long. #847

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ option(STD_CPP "Use the standard C++ library" ON)
option(CPPUTEST_FLAGS "Use the CFLAGS/CXXFLAGS/LDFLAGS set by CppUTest" ON)
option(MEMORY_LEAK_DETECTION "Enable memory leak detection" ON)
option(EXTENSIONS "Use the CppUTest extenstion library" ON)
option(LONGLONG "Support long long" OFF)
option(MAP_FILE "Enable the creation of a map file" OFF)
option(COVERAGE "Enable running with coverage" OFF)
option(C++11 "Compile with C++11 support" OFF)
Expand Down Expand Up @@ -129,6 +130,7 @@ Current compiler options:
Features configured in CppUTest:
Memory Leak Detection: ${MEMORY_LEAK_DETECTION}
Compiling Extensions: ${EXTENSIONS}
Support Long Long: ${LONGLONG}
Use CppUTest flags: ${CPPUTEST_FLAGS}

Using Standard C library: ${STD_C}
Expand Down
4 changes: 2 additions & 2 deletions CppUTest.dsp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions CppUTest.mak
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CLEAN :
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"

CPP_PROJ=/nologo /ML /W3 /GX /O2 /I ".\include\Platforms\VisualCpp" /I ".\include" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "CPPUTEST_MEM_LEAK_DETECTION_DISABLED" /Fp"$(INTDIR)\CppUTest.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I ".\include\Platforms\VisualCpp" /I ".\include" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "CPPUTEST_MEM_LEAK_DETECTION_DISABLED" /D "CPPUTEST_USE_LONG_LONG" /Fp"$(INTDIR)\CppUTest.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\CppUTest.bsc"
BSC32_SBRS= \
Expand Down Expand Up @@ -204,7 +204,7 @@ CLEAN :
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"

CPP_PROJ=/nologo /MDd /W3 /GX /ZI /Od /I ".\include\Platforms\VisualCpp" /I ".\include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "CPPUTEST_MEM_LEAK_DETECTION_DISABLED" /FR"$(INTDIR)\\" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c
CPP_PROJ=/nologo /MDd /W3 /GX /ZI /Od /I ".\include\Platforms\VisualCpp" /I ".\include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "CPPUTEST_MEM_LEAK_DETECTION_DISABLED" /D "CPPUTEST_USE_LONG_LONG" /FR"$(INTDIR)\\" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\CppUTest.bsc"
BSC32_SBRS= \
Expand Down
4 changes: 2 additions & 2 deletions CppUTest.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include\Platforms\VisualCpp,.\include"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;STDC_WANT_SECURE_LIB"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;STDC_WANT_SECURE_LIB;CPPUTEST_USE_LONG_LONG"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\Debug/CppUTest.pch"
Expand Down Expand Up @@ -113,7 +113,7 @@
Optimization="0"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories=".\include\Platforms\VisualCpp,.\include"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;STDC_WANT_SECURE_LIB"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;STDC_WANT_SECURE_LIB;CPPUTEST_USE_LONG_LONG"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
Expand Down
6 changes: 3 additions & 3 deletions CppUTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.\include;.\include\Platforms\VisualCpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_LIB;WIN32;_DEBUG;STDC_WANT_SECURE_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_LIB;WIN32;_DEBUG;STDC_WANT_SECURE_LIB;CPPUTEST_USE_LONG_LONG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
Expand Down Expand Up @@ -81,7 +81,7 @@
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.\include;.\include\Platforms\VisualCpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;STDC_WANT_SECURE_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;STDC_WANT_SECURE_LIB;CPPUTEST_USE_LONG_LONG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
Expand Down Expand Up @@ -194,4 +194,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
9 changes: 9 additions & 0 deletions build/MakefileWorker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ ifndef CPPUTEST_USE_STD_CPP_LIB
CPPUTEST_USE_STD_CPP_LIB = Y
endif

# Use long long, off by default
ifndef CPPUTEST_USE_LONG_LONG
CPPUTEST_USE_LONG_LONG = N
endif

# Use gcov, off by default
ifndef CPPUTEST_USE_GCOV
CPPUTEST_USE_GCOV = N
Expand Down Expand Up @@ -275,6 +280,10 @@ else
endif
endif

ifeq ($(CPPUTEST_USE_LONG_LONG), Y)
CPPUTEST_CPPFLAGS += -DCPPUTEST_USE_LONG_LONG
endif

ifeq ($(CPPUTEST_ENABLE_DEBUG), Y)
CPPUTEST_CXXFLAGS += -g
CPPUTEST_CFLAGS += -g
Expand Down
4 changes: 4 additions & 0 deletions cmake/Modules/CppUTestConfigurationOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ else (MEMORY_LEAK_DETECTION)
set(CPPUTEST_MEM_LEAK_DETECTION_DISABLED 1)
endif (MEMORY_LEAK_DETECTION)

if (LONGLONG)
set(CPPUTEST_USE_LONG_LONG 1)
endif (LONGLONG)

if (MAP_FILE AND NOT MSVC)
set(CPPUTEST_LD_FLAGS "${CPPUTEST_LD_FLAGS} -Wl,-map,$<.map.txt")
endif (MAP_FILE AND NOT MSVC)
Expand Down
1 change: 1 addition & 0 deletions cmake/Modules/CppUTestWarningFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ else (MSVC)
Wno-disabled-macro-expansion
Wno-reserved-id-macro
Wno-keyword-macro
Wno-long-long
)

if (NOT GMOCK AND NOT REAL_GTEST)
Expand Down
1 change: 1 addition & 0 deletions config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#cmakedefine CPPUTEST_COMPILATION @CPPUTEST_COMPILATION@

#cmakedefine CPPUTEST_MEM_LEAK_DETECTION_DISABLED
#cmakedefine CPPUTEST_USE_LONG_LONG

#cmakedefine CPPUTEST_STD_C_LIB_DISABLED
#cmakedefine CPPUTEST_STD_CPP_LIB_DISABLED
Expand Down
16 changes: 16 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
AC_TYPE_LONG_LONG_INT

# Checks for library functions.
AC_FUNC_FORK
Expand Down Expand Up @@ -186,6 +187,12 @@ AC_MSG_CHECKING([whether CC and CXX supports -Wno-keyword-macro])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wno-keyword-macro"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-keyword-macro" ], [AC_MSG_RESULT([no])])
CFLAGS="$saved_cflags"

# FLag -Wno-long-long.
CXXFLAGS="-Werror -Wno-long-long"
AC_MSG_CHECKING([whether CC and CXX supports -Wno-long-long])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes]); CPPUTEST_CWARNINGFLAGS="${CPPUTEST_CWARNINGFLAGS} -Wno-long-long"; CPPUTEST_CXXWARNINGFLAGS="${CPPUTEST_CXXWARNINGFLAGS} -Wno-long-long" ], [AC_MSG_RESULT([no])])
CFLAGS="$saved_cflags"

# FLag -Wno-global-constructors.
AC_LANG_PUSH([C++])
CXXFLAGS="-Werror -Wno-global-constructors"
Expand Down Expand Up @@ -310,6 +317,9 @@ AC_ARG_ENABLE([memory-leak-detection], [AC_HELP_STRING([--disable-memory-leak-de
AC_ARG_ENABLE([extensions], [AC_HELP_STRING([--disable-extensions], [disable CppUTest extension library])],
[cpputest_ext=${enableval}], [cpputest_ext=yes])

AC_ARG_ENABLE([longlong], [AC_HELP_STRING([--enable-longlong], [enable support for long long type])],
[use_longlong=${enableval}], [use_longlong=no])

AC_ARG_ENABLE([generate-map-file], [AC_HELP_STRING([--enable-generate-map-file], [enable the creation of a map file])],
[generate_map_file=${enableval}], [generate_map_file=no])

Expand Down Expand Up @@ -358,6 +368,11 @@ else
CPPUTEST_CPPFLAGS="${CPPUTEST_CPPFLAGS} -include ${srcdir}/include/CppUTest/MemoryLeakDetectorMallocMacros.h"
fi

# Support for long long
if test "x${use_longlong}" = xyes; then
AC_DEFINE([CPPUTEST_USE_LONG_LONG], 1, [enable long long])
fi

# Generating map files.
if test "x${generate_map_file}" = xyes; then
CPPUTEST_LDFLAGS="${CPPUTEST_LDFLAGS} ${CPPUTEST_LD_MAP_GENERATION}"
Expand Down Expand Up @@ -477,6 +492,7 @@ Current compiler options:
Features configured in ${PACKAGE_NAME}:
Memory Leak Detection: ${memory_leak_detection}
Compiling extensions: ${cpputest_ext}
Long Long support: ${use_longlong}
Disable CppUTest compile/link flags: ${cpputest_flags}

Using Standard C++ Library: ${use_std_cpp}
Expand Down
21 changes: 21 additions & 0 deletions include/CppUTest/CppUTestConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,27 @@
#define CPPUTEST_CHAR_BIT 8
#endif

/* Support for "long long" type */
#ifdef CPPUTEST_USE_LONG_LONG
typedef long long cpputest_longlong;
typedef unsigned long long cpputest_ulonglong;
#define CPPUTEST_LONGLONG_DEFAULT ((cpputest_longlong)0)
#define CPPUTEST_ULONGLONG_DEFAULT ((cpputest_ulonglong)0U)
#else
/* Define some placeholders to disable the overloaded methods.
* It's not required to have these match the size of the "real" type, but it's occasionally convenient.
*/
#if defined(CPPUTEST_64BIT) && !defined(CPPUTEST_64BIT_32BIT_LONGS)
typedef struct { char dummy[16]; } cpputest_longlong;
typedef struct { char dummy[16]; } cpputest_ulonglong;
#else
typedef struct { char dummy[8]; } cpputest_longlong;
typedef struct { char dummy[8]; } cpputest_ulonglong;
#endif
#define CPPUTEST_LONGLONG_DEFAULT cpputest_longlong()
#define CPPUTEST_ULONGLONG_DEFAULT cpputest_ulonglong()
#endif

/* Visual C++ 10.0+ (2010+) supports the override keyword, but doesn't define the C++ version as C++11 */
#if defined(__cplusplus) && ((__cplusplus >= 201103L) || (defined(_MSC_VER) && (_MSC_VER >= 1600)))
#define CPPUTEST_COMPILER_FULLY_SUPPORTS_CXX11
Expand Down
4 changes: 4 additions & 0 deletions include/CppUTest/SimpleString.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ SimpleString StringFrom(int value);
SimpleString StringFrom(unsigned int value);
SimpleString StringFrom(long value);
SimpleString StringFrom(unsigned long value);
SimpleString StringFrom(cpputest_longlong value);
SimpleString StringFrom(cpputest_ulonglong value);
SimpleString HexStringFrom(long value);
SimpleString HexStringFrom(unsigned long value);
SimpleString HexStringFrom(cpputest_longlong value);
SimpleString HexStringFrom(cpputest_ulonglong value);
SimpleString HexStringFrom(const void* value);
SimpleString HexStringFrom(void (*value)());
SimpleString StringFrom(double value, int precision = 6);
Expand Down
18 changes: 18 additions & 0 deletions include/CppUTest/TestFailure.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ class UnsignedLongsEqualFailure : public TestFailure
UnsignedLongsEqualFailure(UtestShell* test, const char* fileName, int lineNumber, unsigned long expected, unsigned long actual, const SimpleString& text);
};

class LongLongsEqualFailure : public TestFailure
{
public:
LongLongsEqualFailure(UtestShell* test, const char* fileName, int lineNumber, cpputest_longlong expected, cpputest_longlong actual, const SimpleString& text);
};

class UnsignedLongLongsEqualFailure : public TestFailure
{
public:
UnsignedLongLongsEqualFailure(UtestShell* test, const char* fileName, int lineNumber, cpputest_ulonglong expected, cpputest_ulonglong actual, const SimpleString& text);
};

class StringEqualFailure : public TestFailure
{
public:
Expand All @@ -159,4 +171,10 @@ class BitsEqualFailure : public TestFailure
BitsEqualFailure(UtestShell* test, const char* fileName, int lineNumber, unsigned long expected, unsigned long actual, unsigned long mask, size_t byteCount, const SimpleString& text);
};

class FeatureUnsupportedFailure : public TestFailure
{
public:
FeatureUnsupportedFailure(UtestShell* test, const char* fileName, int lineNumber, const SimpleString& featureName, const SimpleString& text);
};

#endif
2 changes: 2 additions & 0 deletions include/CppUTest/Utest.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class UtestShell
virtual void assertCstrNoCaseContains(const char *expected, const char *actual, const char* text, const char *fileName, int lineNumber);
virtual void assertLongsEqual(long expected, long actual, const char* text, const char *fileName, int lineNumber, const TestTerminator& testTerminator = NormalTestTerminator());
virtual void assertUnsignedLongsEqual(unsigned long expected, unsigned long actual, const char* text, const char *fileName, int lineNumber, const TestTerminator& testTerminator = NormalTestTerminator());
virtual void assertLongLongsEqual(cpputest_longlong expected, cpputest_longlong actual, const char* text, const char *fileName, int lineNumber, const TestTerminator& testTerminator = NormalTestTerminator());
virtual void assertUnsignedLongLongsEqual(cpputest_ulonglong expected, cpputest_ulonglong actual, const char* text, const char *fileName, int lineNumber, const TestTerminator& testTerminator = NormalTestTerminator());
virtual void assertPointersEqual(const void *expected, const void *actual, const char* text, const char *fileName, int lineNumber, const TestTerminator& testTerminator = NormalTestTerminator());
virtual void assertFunctionPointersEqual(void (*expected)(), void (*actual)(), const char* text, const char* fileName, int lineNumber, const TestTerminator& testTerminator = NormalTestTerminator());
virtual void assertDoublesEqual(double expected, double actual, double threshold, const char* text, const char *fileName, int lineNumber, const TestTerminator& testTerminator = NormalTestTerminator());
Expand Down
23 changes: 23 additions & 0 deletions include/CppUTest/UtestMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,29 @@
#define UNSIGNED_LONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
{ UtestShell::getCurrent()->assertUnsignedLongsEqual((unsigned long)expected, (unsigned long)actual, text, file, line); }

#ifdef CPPUTEST_USE_LONG_LONG

#define LONGLONGS_EQUAL(expected, actual)\
LONGLONGS_EQUAL_LOCATION(expected, actual, NULL, __FILE__, __LINE__)

#define LONGLONGS_EQUAL_TEXT(expected, actual, text)\
LONGLONGS_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)

#define UNSIGNED_LONGLONGS_EQUAL(expected, actual)\
UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, NULL, __FILE__, __LINE__)

#define UNSIGNED_LONGLONGS_EQUAL_TEXT(expected, actual, text)\
UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)

#define LONGLONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
{ UtestShell::getCurrent()->assertLongLongsEqual((long long)expected, (long long)actual, text, file, line); }

#define UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
{ UtestShell::getCurrent()->assertUnsignedLongLongsEqual((unsigned long long)expected, (unsigned long long)actual, text, file, line); }

#endif /* CPPUTEST_USE_LONG_LONG */


#define BYTES_EQUAL(expected, actual)\
LONGS_EQUAL((expected) & 0xff,(actual) & 0xff)

Expand Down
10 changes: 10 additions & 0 deletions include/CppUTestExt/MockActualCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class MockActualCall
MockActualCall& withParameter(const SimpleString& name, unsigned int value) { return withUnsignedIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, long int value) { return withLongIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, unsigned long int value) { return withUnsignedLongIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, cpputest_longlong value) { return withLongLongIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, cpputest_ulonglong value) { return withUnsignedLongLongIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, double value) { return withDoubleParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, const char* value) { return withStringParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, void* value) { return withPointerParameter(name, value); }
Expand All @@ -63,6 +65,8 @@ class MockActualCall
virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value)=0;
virtual MockActualCall& withLongIntParameter(const SimpleString& name, long int value)=0;
virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value)=0;
virtual MockActualCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) = 0;
virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) = 0;
virtual MockActualCall& withDoubleParameter(const SimpleString& name, double value)=0;
virtual MockActualCall& withStringParameter(const SimpleString& name, const char* value)=0;
virtual MockActualCall& withPointerParameter(const SimpleString& name, void* value)=0;
Expand All @@ -88,6 +92,12 @@ class MockActualCall
virtual unsigned int returnUnsignedIntValue()=0;
virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int default_value)=0;

virtual cpputest_longlong returnLongLongIntValue() = 0;
virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong default_value) = 0;

virtual cpputest_ulonglong returnUnsignedLongLongIntValue() = 0;
virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong default_value) = 0;

virtual const char * returnStringValueOrDefault(const char * default_value)=0;
virtual const char * returnStringValue()=0;

Expand Down
Loading