Skip to content

Commit

Permalink
add support for long long integers as native types
Browse files Browse the repository at this point in the history
When testing code that needs to work on both 64-bit platforms and 32-bit
platforms, the long integer may not guarantee 64bits of width on the
32-bit platform. This makes testing calls which take and return 64bit
values difficult, as the test framework can't handle these natively.

Add support for long long integers, so that test code can natively
handle these larger values.

Note, to avoid ABI compatibility issues, use cpputest_longlong and
cpputest_ulonglong. This ensures the virtual function tables are the
same whether long long support is enabled or disabled.

With this patch, if long long support is disabled in CppUTest, then the
mock withParameter and returnParameter functions will fail indicating
that the long long support is not enabled.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
  • Loading branch information
jacob-keller committed Aug 9, 2018
1 parent 77c10f9 commit ef8a60a
Show file tree
Hide file tree
Showing 21 changed files with 1,371 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ CppUTestExtTests_SOURCES = \
tests/CppUTestExt/MockSupport_cTestCFile.c \
tests/CppUTestExt/MockStrictOrderTest.cpp \
tests/CppUTestExt/MockReturnValueTest.cpp \
tests/CppUTestExt/OrderedTestTest.cpp
tests/CppUTestExt/OrderedTestTest.cpp \
tests/CppUTestExt/MockFakeLongLong.cpp

DISTCLEANFILES = \
filename.map.txt \
Expand Down
4 changes: 2 additions & 2 deletions include/CppUTest/UtestMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@
UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)

#define LONGLONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
{ UtestShell::getCurrent()->assertLongLongsEqual(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(expected, actual, text, file, line); }
{ UtestShell::getCurrent()->assertUnsignedLongLongsEqual((unsigned long long)expected, (unsigned long long)actual, text, file, line); }

#define BYTES_EQUAL(expected, actual)\
LONGS_EQUAL((expected) & 0xff,(actual) & 0xff)
Expand Down
11 changes: 11 additions & 0 deletions include/CppUTestExt/MockActualCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#ifndef D_MockActualCall_h
#define D_MockActualCall_h

#include "CppUTest/CppUTestConfig.h"
#include "CppUTest/TestHarness.h"
#include "CppUTestExt/MockNamedValue.h"
#include "CppUTestExt/MockExpectedCallsList.h"
Expand All @@ -48,6 +49,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 +66,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 @@ -85,6 +90,12 @@ class MockActualCall
virtual long int returnLongIntValue()=0;
virtual long int returnLongIntValueOrDefault(long int default_value)=0;

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

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

virtual unsigned int returnUnsignedIntValue()=0;
virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int default_value)=0;

Expand Down
24 changes: 24 additions & 0 deletions include/CppUTestExt/MockCheckedActualCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class MockCheckedActualCall : public MockActualCall
virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override;
virtual MockActualCall& withLongIntParameter(const SimpleString& name, long int value) _override;
virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) _override;
virtual MockActualCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) _override;
virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) _override;
virtual MockActualCall& withDoubleParameter(const SimpleString& name, double value) _override;
virtual MockActualCall& withStringParameter(const SimpleString& name, const char* value) _override;
virtual MockActualCall& withPointerParameter(const SimpleString& name, void* value) _override;
Expand All @@ -69,6 +71,12 @@ class MockCheckedActualCall : public MockActualCall
virtual long int returnLongIntValue() _override;
virtual long int returnLongIntValueOrDefault(long int default_value) _override;

virtual cpputest_ulonglong returnUnsignedLongLongIntValue() _override;
virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong default_value) _override;

virtual cpputest_longlong returnLongLongIntValue() _override;
virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong default_value) _override;

virtual unsigned int returnUnsignedIntValue() _override;
virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int default_value) _override;

Expand Down Expand Up @@ -157,6 +165,8 @@ class MockActualCallTrace : public MockActualCall
virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override;
virtual MockActualCall& withLongIntParameter(const SimpleString& name, long int value) _override;
virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) _override;
virtual MockActualCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) _override;
virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) _override;
virtual MockActualCall& withDoubleParameter(const SimpleString& name, double value) _override;
virtual MockActualCall& withStringParameter(const SimpleString& name, const char* value) _override;
virtual MockActualCall& withPointerParameter(const SimpleString& name, void* value) _override;
Expand All @@ -182,6 +192,12 @@ class MockActualCallTrace : public MockActualCall
virtual long int returnLongIntValue() _override;
virtual long int returnLongIntValueOrDefault(long int default_value) _override;

virtual cpputest_ulonglong returnUnsignedLongLongIntValue() _override;
virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong default_value) _override;

virtual cpputest_longlong returnLongLongIntValue() _override;
virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong default_value) _override;

virtual unsigned int returnUnsignedIntValue() _override;
virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int default_value) _override;

Expand Down Expand Up @@ -222,6 +238,8 @@ class MockIgnoredActualCall: public MockActualCall
virtual MockActualCall& withUnsignedIntParameter(const SimpleString&, unsigned int) _override { return *this; }
virtual MockActualCall& withLongIntParameter(const SimpleString&, long int) _override { return *this; }
virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString&, unsigned long int) _override { return *this; }
virtual MockActualCall& withLongLongIntParameter(const SimpleString&, cpputest_longlong) _override { return *this; }
virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString&, cpputest_ulonglong) _override { return *this; }
virtual MockActualCall& withDoubleParameter(const SimpleString&, double) _override { return *this; }
virtual MockActualCall& withStringParameter(const SimpleString&, const char*) _override { return *this; }
virtual MockActualCall& withPointerParameter(const SimpleString& , void*) _override { return *this; }
Expand All @@ -247,6 +265,12 @@ class MockIgnoredActualCall: public MockActualCall
virtual long int returnLongIntValue() _override { return 0; }
virtual long int returnLongIntValueOrDefault(long int value) _override { return value; }

virtual cpputest_ulonglong returnUnsignedLongLongIntValue() _override { return 0; }
virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong value) _override { return value; }

virtual cpputest_longlong returnLongLongIntValue() _override { return 0; }
virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong value) _override { return value; }

virtual unsigned int returnUnsignedIntValue() _override { return 0; }
virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int value) _override { return value; }

Expand Down
8 changes: 8 additions & 0 deletions include/CppUTestExt/MockCheckedExpectedCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class MockCheckedExpectedCall : public MockExpectedCall
virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override;
virtual MockExpectedCall& withLongIntParameter(const SimpleString& name, long int value) _override;
virtual MockExpectedCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) _override;
virtual MockExpectedCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) _override;
virtual MockExpectedCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) _override;
virtual MockExpectedCall& withDoubleParameter(const SimpleString& name, double value) _override;
virtual MockExpectedCall& withStringParameter(const SimpleString& name, const char* value) _override;
virtual MockExpectedCall& withPointerParameter(const SimpleString& name, void* value) _override;
Expand All @@ -63,6 +65,8 @@ class MockCheckedExpectedCall : public MockExpectedCall
virtual MockExpectedCall& andReturnValue(unsigned int value) _override;
virtual MockExpectedCall& andReturnValue(long int value) _override;
virtual MockExpectedCall& andReturnValue(unsigned long int value) _override;
virtual MockExpectedCall& andReturnValue(cpputest_longlong value) _override;
virtual MockExpectedCall& andReturnValue(cpputest_ulonglong value) _override;
virtual MockExpectedCall& andReturnValue(double value) _override;
virtual MockExpectedCall& andReturnValue(const char* value) _override;
virtual MockExpectedCall& andReturnValue(void* value) _override;
Expand Down Expand Up @@ -153,6 +157,8 @@ class MockIgnoredExpectedCall: public MockExpectedCall
virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString&, unsigned int) _override{ return *this; }
virtual MockExpectedCall& withLongIntParameter(const SimpleString&, long int) _override { return *this; }
virtual MockExpectedCall& withUnsignedLongIntParameter(const SimpleString&, unsigned long int) _override { return *this; }
virtual MockExpectedCall& withLongLongIntParameter(const SimpleString&, cpputest_longlong) _override { return *this; }
virtual MockExpectedCall& withUnsignedLongLongIntParameter(const SimpleString&, cpputest_ulonglong) _override { return *this; }
virtual MockExpectedCall& withDoubleParameter(const SimpleString&, double) _override { return *this; }
virtual MockExpectedCall& withStringParameter(const SimpleString&, const char*) _override { return *this; }
virtual MockExpectedCall& withPointerParameter(const SimpleString& , void*) _override { return *this; }
Expand All @@ -169,6 +175,8 @@ class MockIgnoredExpectedCall: public MockExpectedCall
virtual MockExpectedCall& andReturnValue(unsigned int) _override { return *this; }
virtual MockExpectedCall& andReturnValue(long int) _override { return *this; }
virtual MockExpectedCall& andReturnValue(unsigned long int) _override { return *this; }
virtual MockExpectedCall& andReturnValue(cpputest_longlong) _override { return *this; }
virtual MockExpectedCall& andReturnValue(cpputest_ulonglong) _override { return *this; }
virtual MockExpectedCall& andReturnValue(double) _override { return *this;}
virtual MockExpectedCall& andReturnValue(const char*) _override { return *this; }
virtual MockExpectedCall& andReturnValue(void*) _override { return *this; }
Expand Down
8 changes: 8 additions & 0 deletions include/CppUTestExt/MockExpectedCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#ifndef D_MockExpectedCall_h
#define D_MockExpectedCall_h

#include "CppUTest/CppUTestConfig.h"

class MockNamedValue;

extern SimpleString StringFrom(const MockNamedValue& parameter);
Expand All @@ -46,6 +48,8 @@ class MockExpectedCall
MockExpectedCall& withParameter(const SimpleString& name, unsigned int value) { return withUnsignedIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, long int value) { return withLongIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, unsigned long int value) { return withUnsignedLongIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, cpputest_longlong value) { return withLongLongIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, cpputest_ulonglong value) { return withUnsignedLongLongIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, double value) { return withDoubleParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, const char* value) { return withStringParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, void* value) { return withPointerParameter(name, value); }
Expand All @@ -62,6 +66,8 @@ class MockExpectedCall
virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value)=0;
virtual MockExpectedCall& withLongIntParameter(const SimpleString& name, long int value)=0;
virtual MockExpectedCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value)=0;
virtual MockExpectedCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value)=0;
virtual MockExpectedCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value)=0;
virtual MockExpectedCall& withDoubleParameter(const SimpleString& name, double value)=0;
virtual MockExpectedCall& withStringParameter(const SimpleString& name, const char* value)=0;
virtual MockExpectedCall& withPointerParameter(const SimpleString& name, void* value)=0;
Expand All @@ -73,6 +79,8 @@ class MockExpectedCall
virtual MockExpectedCall& andReturnValue(unsigned int value)=0;
virtual MockExpectedCall& andReturnValue(long int value)=0;
virtual MockExpectedCall& andReturnValue(unsigned long int value)=0;
virtual MockExpectedCall& andReturnValue(cpputest_longlong value)=0;
virtual MockExpectedCall& andReturnValue(cpputest_ulonglong value)=0;
virtual MockExpectedCall& andReturnValue(double value)=0;
virtual MockExpectedCall& andReturnValue(const char* value)=0;
virtual MockExpectedCall& andReturnValue(void* value)=0;
Expand Down
14 changes: 14 additions & 0 deletions include/CppUTestExt/MockNamedValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

#ifndef D_MockNamedValue_h
#define D_MockNamedValue_h

#include "CppUTest/CppUTestConfig.h"

/*
* MockNamedValueComparator is an interface that needs to be used when creating Comparators.
* This is needed when comparing values of non-native type.
Expand Down Expand Up @@ -106,6 +109,8 @@ class MockNamedValue
virtual void setValue(unsigned int value);
virtual void setValue(long int value);
virtual void setValue(unsigned long int value);
virtual void setValue(cpputest_longlong value);
virtual void setValue(cpputest_ulonglong value);
virtual void setValue(double value);
virtual void setValue(void* value);
virtual void setValue(const void* value);
Expand All @@ -131,6 +136,8 @@ class MockNamedValue
virtual unsigned int getUnsignedIntValue() const;
virtual long int getLongIntValue() const;
virtual unsigned long int getUnsignedLongIntValue() const;
virtual cpputest_longlong getLongLongIntValue() const;
virtual cpputest_ulonglong getUnsignedLongLongIntValue() const;
virtual double getDoubleValue() const;
virtual const char* getStringValue() const;
virtual void* getPointerValue() const;
Expand All @@ -141,6 +148,7 @@ class MockNamedValue
virtual void* getObjectPointer() const;
virtual size_t getSize() const;


virtual MockNamedValueComparator* getComparator() const;
virtual MockNamedValueCopier* getCopier() const;

Expand All @@ -154,6 +162,12 @@ class MockNamedValue
unsigned int unsignedIntValue_;
long int longIntValue_;
unsigned long int unsignedLongIntValue_;
#ifdef CPPUTEST_USE_LONG_LONG
cpputest_longlong longLongIntValue_;
cpputest_ulonglong unsignedLongLongIntValue_;
#else
char longLongPlaceholder_[CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE];
#endif
double doubleValue_;
const char* stringValue_;
void* pointerValue_;
Expand Down
4 changes: 4 additions & 0 deletions include/CppUTestExt/MockSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class MockSupport
virtual long int returnLongIntValueOrDefault(long int defaultValue);
virtual unsigned long int unsignedLongIntReturnValue();
virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int defaultValue);
virtual cpputest_longlong longLongIntReturnValue();
virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong defaultValue);
virtual cpputest_ulonglong unsignedLongLongIntReturnValue();
virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong defaultValue);
virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int defaultValue);
virtual const char* stringReturnValue();
virtual const char* returnStringValueOrDefault(const char * defaultValue);
Expand Down
Loading

0 comments on commit ef8a60a

Please sign in to comment.