mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-05 21:15:20 +00:00
Merge pull request #296 from Tuc-an/old-c-style-comments
switch comments to C-style to improve compatibility with pre-C99 and …
This commit is contained in:
@@ -302,7 +302,7 @@ class CMockGenerator
|
||||
|
||||
file << "#{decl}\n"
|
||||
file << "{\n"
|
||||
file << " //TODO: Implement Me!\n"
|
||||
file << " /*TODO: Implement Me!*/\n"
|
||||
function[:args].each { |arg| file << " (void)#{arg[:name]};\n" }
|
||||
file << " return (#{(function[:return][:type])})0;\n" unless function[:return][:void?]
|
||||
file << "}\n\n"
|
||||
|
||||
+45
-45
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "cmock.h"
|
||||
|
||||
//public constants to be used by mocks
|
||||
/* public constants to be used by mocks */
|
||||
const char* CMockStringOutOfMemory = "CMock has run out of memory. Please allocate more.";
|
||||
const char* CMockStringCalledMore = "Called more times than expected.";
|
||||
const char* CMockStringCalledLess = "Called fewer times than expected.";
|
||||
@@ -19,7 +19,7 @@ const char* CMockStringPtrIsNULL = "Pointer is NULL.";
|
||||
const char* CMockStringExpNULL = "Expected NULL.";
|
||||
const char* CMockStringMismatch = "Function called with unexpected argument value.";
|
||||
|
||||
//private variables
|
||||
/* private variables */
|
||||
#ifdef CMOCK_MEM_DYNAMIC
|
||||
static unsigned char* CMock_Guts_Buffer = NULL;
|
||||
static CMOCK_MEM_INDEX_TYPE CMock_Guts_BufferSize = CMOCK_MEM_ALIGN_SIZE;
|
||||
@@ -30,37 +30,37 @@ static CMOCK_MEM_INDEX_TYPE CMock_Guts_BufferSize = CMOCK_MEM_SIZE + CMOCK_MEM
|
||||
static CMOCK_MEM_INDEX_TYPE CMock_Guts_FreePtr = CMOCK_MEM_ALIGN_SIZE;
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_Guts_MemNew
|
||||
//-------------------------------------------------------
|
||||
/*-------------------------------------------------------
|
||||
* CMock_Guts_MemNew
|
||||
*-------------------------------------------------------*/
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNew(CMOCK_MEM_INDEX_TYPE size)
|
||||
{
|
||||
CMOCK_MEM_INDEX_TYPE index;
|
||||
|
||||
//verify arguments valid (we must be allocating space for at least 1 byte, and the existing chain must be in memory somewhere)
|
||||
/* verify arguments valid (we must be allocating space for at least 1 byte, and the existing chain must be in memory somewhere) */
|
||||
if (size < 1)
|
||||
return CMOCK_GUTS_NONE;
|
||||
|
||||
//verify we have enough room
|
||||
/* verify we have enough room */
|
||||
size = size + CMOCK_MEM_INDEX_SIZE;
|
||||
if (size & CMOCK_MEM_ALIGN_MASK)
|
||||
size = (size + CMOCK_MEM_ALIGN_MASK) & ~CMOCK_MEM_ALIGN_MASK;
|
||||
if ((CMock_Guts_BufferSize - CMock_Guts_FreePtr) < size)
|
||||
{
|
||||
#ifndef CMOCK_MEM_DYNAMIC
|
||||
return CMOCK_GUTS_NONE; // nothing we can do; our static buffer is out of memory
|
||||
return CMOCK_GUTS_NONE; /* nothing we can do; our static buffer is out of memory */
|
||||
#else
|
||||
// our dynamic buffer does not have enough room; request more via realloc()
|
||||
/* our dynamic buffer does not have enough room; request more via realloc() */
|
||||
CMOCK_MEM_INDEX_TYPE new_buffersize = CMock_Guts_BufferSize + CMOCK_MEM_SIZE + size;
|
||||
unsigned char* new_buffer = realloc(CMock_Guts_Buffer, (size_t)new_buffersize);
|
||||
if (new_buffer == NULL)
|
||||
return CMOCK_GUTS_NONE; // realloc() failed; out of memory
|
||||
return CMOCK_GUTS_NONE; /* realloc() failed; out of memory */
|
||||
CMock_Guts_Buffer = new_buffer;
|
||||
CMock_Guts_BufferSize = new_buffersize;
|
||||
#endif
|
||||
}
|
||||
|
||||
//determine where we're putting this new block, and init its pointer to be the end of the line
|
||||
/* determine where we're putting this new block, and init its pointer to be the end of the line */
|
||||
index = CMock_Guts_FreePtr + CMOCK_MEM_INDEX_SIZE;
|
||||
*(CMOCK_MEM_INDEX_TYPE*)(&CMock_Guts_Buffer[CMock_Guts_FreePtr]) = CMOCK_GUTS_NONE;
|
||||
CMock_Guts_FreePtr += size;
|
||||
@@ -68,9 +68,9 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNew(CMOCK_MEM_INDEX_TYPE size)
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_Guts_MemChain
|
||||
//-------------------------------------------------------
|
||||
/*-------------------------------------------------------
|
||||
* CMock_Guts_MemChain
|
||||
*-------------------------------------------------------*/
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemChain(CMOCK_MEM_INDEX_TYPE root_index, CMOCK_MEM_INDEX_TYPE obj_index)
|
||||
{
|
||||
CMOCK_MEM_INDEX_TYPE index;
|
||||
@@ -80,12 +80,12 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemChain(CMOCK_MEM_INDEX_TYPE root_index, CMOCK_
|
||||
|
||||
if (root_index == CMOCK_GUTS_NONE)
|
||||
{
|
||||
//if there is no root currently, we return this object as the root of the chain
|
||||
/* if there is no root currently, we return this object as the root of the chain */
|
||||
return obj_index;
|
||||
}
|
||||
else
|
||||
{
|
||||
//reject illegal nodes
|
||||
/* reject illegal nodes */
|
||||
if ((root_index < CMOCK_MEM_ALIGN_SIZE) || (root_index >= CMock_Guts_FreePtr))
|
||||
{
|
||||
return CMOCK_GUTS_NONE;
|
||||
@@ -98,7 +98,7 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemChain(CMOCK_MEM_INDEX_TYPE root_index, CMOCK_
|
||||
root = (void*)(&CMock_Guts_Buffer[root_index]);
|
||||
obj = (void*)(&CMock_Guts_Buffer[obj_index]);
|
||||
|
||||
//find the end of the existing chain and add us
|
||||
/* find the end of the existing chain and add us */
|
||||
next = root;
|
||||
do {
|
||||
index = *(CMOCK_MEM_INDEX_TYPE*)((CMOCK_MEM_PTR_AS_INT)next - CMOCK_MEM_INDEX_SIZE);
|
||||
@@ -112,21 +112,21 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemChain(CMOCK_MEM_INDEX_TYPE root_index, CMOCK_
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_Guts_MemNext
|
||||
//-------------------------------------------------------
|
||||
/*-------------------------------------------------------
|
||||
* CMock_Guts_MemNext
|
||||
*-------------------------------------------------------*/
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNext(CMOCK_MEM_INDEX_TYPE previous_item_index)
|
||||
{
|
||||
CMOCK_MEM_INDEX_TYPE index;
|
||||
void* previous_item;
|
||||
|
||||
//There is nothing "next" if the pointer isn't from our buffer
|
||||
/* There is nothing "next" if the pointer isn't from our buffer */
|
||||
if ((previous_item_index < CMOCK_MEM_ALIGN_SIZE) || (previous_item_index >= CMock_Guts_FreePtr))
|
||||
return CMOCK_GUTS_NONE;
|
||||
previous_item = (void*)(&CMock_Guts_Buffer[previous_item_index]);
|
||||
|
||||
//if the pointer is good, then use it to look up the next index
|
||||
//(we know the first element always goes in zero, so NEXT must always be > 1)
|
||||
/* if the pointer is good, then use it to look up the next index
|
||||
* (we know the first element always goes in zero, so NEXT must always be > 1) */
|
||||
index = *(CMOCK_MEM_INDEX_TYPE*)((CMOCK_MEM_PTR_AS_INT)previous_item - CMOCK_MEM_INDEX_SIZE);
|
||||
if ((index > 1) && (index < CMock_Guts_FreePtr))
|
||||
return index;
|
||||
@@ -134,9 +134,9 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNext(CMOCK_MEM_INDEX_TYPE previous_item_index
|
||||
return CMOCK_GUTS_NONE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_Guts_MemEndOfChain
|
||||
//-------------------------------------------------------
|
||||
/*-------------------------------------------------------
|
||||
* CMock_Guts_MemEndOfChain
|
||||
*-------------------------------------------------------*/
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemEndOfChain(CMOCK_MEM_INDEX_TYPE root_index)
|
||||
{
|
||||
CMOCK_MEM_INDEX_TYPE index = root_index;
|
||||
@@ -152,9 +152,9 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemEndOfChain(CMOCK_MEM_INDEX_TYPE root_index)
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_GetAddressFor
|
||||
//-------------------------------------------------------
|
||||
/*-------------------------------------------------------
|
||||
* CMock_GetAddressFor
|
||||
*-------------------------------------------------------*/
|
||||
void* CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index)
|
||||
{
|
||||
if ((index >= CMOCK_MEM_ALIGN_SIZE) && (index < CMock_Guts_FreePtr))
|
||||
@@ -167,41 +167,41 @@ void* CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index)
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_Guts_MemBytesCapacity
|
||||
//-------------------------------------------------------
|
||||
/*-------------------------------------------------------
|
||||
* CMock_Guts_MemBytesCapacity
|
||||
*-------------------------------------------------------*/
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesCapacity(void)
|
||||
{
|
||||
return (sizeof(CMock_Guts_Buffer) - CMOCK_MEM_ALIGN_SIZE);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_Guts_MemBytesFree
|
||||
//-------------------------------------------------------
|
||||
/*-------------------------------------------------------
|
||||
* CMock_Guts_MemBytesFree
|
||||
*-------------------------------------------------------*/
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesFree(void)
|
||||
{
|
||||
return CMock_Guts_BufferSize - CMock_Guts_FreePtr;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_Guts_MemBytesUsed
|
||||
//-------------------------------------------------------
|
||||
/*-------------------------------------------------------
|
||||
* CMock_Guts_MemBytesUsed
|
||||
*-------------------------------------------------------*/
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesUsed(void)
|
||||
{
|
||||
return CMock_Guts_FreePtr - CMOCK_MEM_ALIGN_SIZE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_Guts_MemFreeAll
|
||||
//-------------------------------------------------------
|
||||
/*-------------------------------------------------------
|
||||
* CMock_Guts_MemFreeAll
|
||||
*-------------------------------------------------------*/
|
||||
void CMock_Guts_MemFreeAll(void)
|
||||
{
|
||||
CMock_Guts_FreePtr = CMOCK_MEM_ALIGN_SIZE; //skip the very beginning
|
||||
CMock_Guts_FreePtr = CMOCK_MEM_ALIGN_SIZE; /* skip the very beginning */
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CMock_Guts_MemFreeFinal
|
||||
//-------------------------------------------------------
|
||||
/*-------------------------------------------------------
|
||||
* CMock_Guts_MemFreeFinal
|
||||
*-------------------------------------------------------*/
|
||||
void CMock_Guts_MemFreeFinal(void)
|
||||
{
|
||||
CMock_Guts_FreePtr = CMOCK_MEM_ALIGN_SIZE;
|
||||
|
||||
+5
-5
@@ -14,16 +14,16 @@
|
||||
#define CMOCK_VERSION_BUILD 1
|
||||
#define CMOCK_VERSION ((CMOCK_VERSION_MAJOR << 16) | (CMOCK_VERSION_MINOR << 8) | CMOCK_VERSION_BUILD)
|
||||
|
||||
//should be big enough to index full range of CMOCK_MEM_MAX
|
||||
/* should be big enough to index full range of CMOCK_MEM_MAX */
|
||||
#ifndef CMOCK_MEM_INDEX_TYPE
|
||||
#define CMOCK_MEM_INDEX_TYPE unsigned int
|
||||
#endif
|
||||
|
||||
#define CMOCK_GUTS_NONE (0)
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Memory API
|
||||
//-------------------------------------------------------
|
||||
/*-------------------------------------------------------
|
||||
* Memory API
|
||||
*-------------------------------------------------------*/
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNew(CMOCK_MEM_INDEX_TYPE size);
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemChain(CMOCK_MEM_INDEX_TYPE root_index, CMOCK_MEM_INDEX_TYPE obj_index);
|
||||
CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNext(CMOCK_MEM_INDEX_TYPE previous_item_index);
|
||||
@@ -37,4 +37,4 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesUsed(void);
|
||||
void CMock_Guts_MemFreeAll(void);
|
||||
void CMock_Guts_MemFreeFinal(void);
|
||||
|
||||
#endif //CMOCK_FRAMEWORK
|
||||
#endif /* end of CMOCK_FRAMEWORK_H */
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "unity.h"
|
||||
|
||||
//These are constants that the generated mocks have access to
|
||||
/* These are constants that the generated mocks have access to */
|
||||
extern const char* CMockStringOutOfMemory;
|
||||
extern const char* CMockStringCalledMore;
|
||||
extern const char* CMockStringCalledLess;
|
||||
@@ -22,8 +22,8 @@ extern const char* CMockStringPtrIsNULL;
|
||||
extern const char* CMockStringExpNULL;
|
||||
extern const char* CMockStringMismatch;
|
||||
|
||||
//define CMOCK_MEM_DYNAMIC to grab memory as needed with malloc
|
||||
//when you do that, CMOCK_MEM_SIZE is used for incremental size instead of total
|
||||
/* define CMOCK_MEM_DYNAMIC to grab memory as needed with malloc
|
||||
* when you do that, CMOCK_MEM_SIZE is used for incremental size instead of total */
|
||||
#ifdef CMOCK_MEM_STATIC
|
||||
#undef CMOCK_MEM_DYNAMIC
|
||||
#endif
|
||||
@@ -32,7 +32,7 @@ extern const char* CMockStringMismatch;
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
//this is used internally during pointer arithmetic. make sure this type is the same size as the target's pointer type
|
||||
/* this is used internally during pointer arithmetic. make sure this type is the same size as the target's pointer type */
|
||||
#ifndef CMOCK_MEM_PTR_AS_INT
|
||||
#ifdef UNITY_POINTER_WIDTH
|
||||
#ifdef UNITY_INT_WIDTH
|
||||
@@ -60,7 +60,7 @@ extern const char* CMockStringMismatch;
|
||||
#define CMOCK_MEM_PTR_AS_INT unsigned long
|
||||
#endif
|
||||
|
||||
//0 for no alignment, 1 for 16-bit, 2 for 32-bit, 3 for 64-bit
|
||||
/* 0 for no alignment, 1 for 16-bit, 2 for 32-bit, 3 for 64-bit */
|
||||
#ifndef CMOCK_MEM_ALIGN
|
||||
#ifdef UNITY_LONG_WIDTH
|
||||
#if (UNITY_LONG_WIDTH == 16)
|
||||
@@ -77,15 +77,15 @@ extern const char* CMockStringMismatch;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//amount of memory to allow cmock to use in its internal heap
|
||||
/* amount of memory to allow cmock to use in its internal heap */
|
||||
#ifndef CMOCK_MEM_SIZE
|
||||
#define CMOCK_MEM_SIZE (32768)
|
||||
#endif
|
||||
|
||||
//automatically calculated defs for easier reading
|
||||
/* automatically calculated defs for easier reading */
|
||||
#define CMOCK_MEM_ALIGN_SIZE (CMOCK_MEM_INDEX_TYPE)(1u << CMOCK_MEM_ALIGN)
|
||||
#define CMOCK_MEM_ALIGN_MASK (CMOCK_MEM_INDEX_TYPE)(CMOCK_MEM_ALIGN_SIZE - 1)
|
||||
#define CMOCK_MEM_INDEX_SIZE (CMOCK_MEM_INDEX_TYPE)(CMOCK_MEM_PTR_AS_INT)((sizeof(CMOCK_MEM_INDEX_TYPE) > CMOCK_MEM_ALIGN_SIZE) ? sizeof(CMOCK_MEM_INDEX_TYPE) : CMOCK_MEM_ALIGN_SIZE)
|
||||
|
||||
|
||||
#endif //CMOCK_FRAMEWORK_INTERNALS
|
||||
#endif /* end of CMOCK_FRAMEWORK_INTERNALS_H */
|
||||
|
||||
Reference in New Issue
Block a user