Skip to content

Commit

Permalink
Merge pull request #58 from fperrad/20210808_test_cleanup
Browse files Browse the repository at this point in the history
some cleanup in test/
  • Loading branch information
camgunz authored Aug 8, 2021
2 parents 9cbddb3 + 24a8b22 commit eb289e4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 44 deletions.
34 changes: 17 additions & 17 deletions test/buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ void M_BufferInitWithCapacity(buf_t *buf, size_t capacity) {
M_BufferEnsureTotalCapacity(buf, capacity);
}

size_t M_BufferGetCapacity(buf_t *buf) {
size_t M_BufferGetCapacity(const buf_t *buf) {
return buf->capacity;
}

size_t M_BufferGetSize(buf_t *buf) {
size_t M_BufferGetSize(const buf_t *buf) {
return buf->size;
}

size_t M_BufferGetCursor(buf_t *buf) {
size_t M_BufferGetCursor(const buf_t *buf) {
return buf->cursor;
}

char* M_BufferGetData(buf_t *buf) {
char* M_BufferGetData(const buf_t *buf) {
return buf->data;
}

char* M_BufferGetDataAtCursor(buf_t *buf) {
char* M_BufferGetDataAtCursor(const buf_t *buf) {
return buf->data + buf->cursor;
}

Expand Down Expand Up @@ -123,11 +123,11 @@ void M_BufferEnsureTotalCapacity(buf_t *buf, size_t capacity) {
}
}

void M_BufferCopy(buf_t *dst, buf_t *src) {
void M_BufferCopy(buf_t *dst, const buf_t *src) {
M_BufferSetData(dst, M_BufferGetData(src), M_BufferGetSize(src));
}

void M_BufferCursorCopy(buf_t *dst, buf_t *src) {
void M_BufferCursorCopy(buf_t *dst, const buf_t *src) {
M_BufferWrite(
dst,
M_BufferGetDataAtCursor(src),
Expand Down Expand Up @@ -158,8 +158,8 @@ void M_BufferSetString(buf_t *buf, const char *data, size_t length) {
}

bool M_BufferSetFile(buf_t *buf, const char *filename) {
FILE *fp = NULL;
size_t length = 0;
FILE *fp;
size_t length;
bool out = false;

if ((fp = fopen(filename, "rb")) == NULL)
Expand Down Expand Up @@ -210,7 +210,7 @@ bool M_BufferSeekForward(buf_t *buf, size_t count) {
return true;
}

uint8_t M_BufferPeek(buf_t *buf) {
uint8_t M_BufferPeek(const buf_t *buf) {
return *(buf->data + buf->cursor);
}

Expand Down Expand Up @@ -339,14 +339,14 @@ void M_BufferWriteZeros(buf_t *buf, size_t count) {
check_cursor(buf);
}

bool M_BufferEqualsString(buf_t *buf, const char *s) {
bool M_BufferEqualsString(const buf_t *buf, const char *s) {
if (strncmp(buf->data + buf->cursor, s, buf->size - buf->cursor) == 0)
return true;

return false;
}

bool M_BufferEqualsData(buf_t *buf, const void *d, size_t size) {
bool M_BufferEqualsData(const buf_t *buf, const void *d, size_t size) {
if (buf->cursor + size > buf->size)
return false;

Expand Down Expand Up @@ -464,7 +464,7 @@ bool M_BufferReadString(buf_t *buf, char *s, size_t length) {
return M_BufferRead(buf, s, length);
}

bool M_BufferReadStringDup(buf_t *buf, char **s) {
bool M_BufferReadStringDup(const buf_t *buf, char **s) {
char *d = buf->data + buf->cursor;
size_t length = strlen(d);

Expand All @@ -475,7 +475,7 @@ bool M_BufferReadStringDup(buf_t *buf, char **s) {
return true;
}

bool M_BufferCopyString(buf_t *dst, buf_t *src) {
bool M_BufferCopyString(buf_t *dst, const buf_t *src) {
char *s = src->data + src->cursor;
size_t length = strlen(s);

Expand Down Expand Up @@ -515,7 +515,7 @@ void M_BufferTruncate(buf_t *buf, size_t new_size) {
buf->cursor = buf->size - 1;
}

void M_BufferZero(buf_t *buf) {
void M_BufferZero(const buf_t *buf) {
memset(buf->data, 0, buf->capacity);
}

Expand All @@ -531,7 +531,7 @@ void M_BufferFree(buf_t *buf) {
buf->data = NULL;
}

void M_BufferPrint(buf_t *buf) {
void M_BufferPrint(const buf_t *buf) {
printf("Buffer capacity, size and cursor: [%zu, %zu, %zu].\n",
buf->capacity,
buf->size,
Expand All @@ -548,7 +548,7 @@ void M_BufferPrint(buf_t *buf) {
printf("\n");
}

void M_BufferPrintAll(buf_t *buf) {
void M_BufferPrintAll(const buf_t *buf) {
printf("Buffer capacity, size and cursor: [%zu, %zu, %zu].\n",
buf->capacity,
buf->size,
Expand Down
30 changes: 15 additions & 15 deletions test/buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ buf_t* M_BufferNewWithCapacity(size_t capacity);
void M_BufferInit(buf_t *buf);
void M_BufferInitWithCapacity(buf_t *buf, size_t capacity);

size_t M_BufferGetCapacity(buf_t *buf);
size_t M_BufferGetSize(buf_t *buf);
size_t M_BufferGetCursor(buf_t *buf);
char* M_BufferGetData(buf_t *buf);
char* M_BufferGetDataAtCursor(buf_t *buf);
size_t M_BufferGetCapacity(const buf_t *buf);
size_t M_BufferGetSize(const buf_t *buf);
size_t M_BufferGetCursor(const buf_t *buf);
char* M_BufferGetData(const buf_t *buf);
char* M_BufferGetDataAtCursor(const buf_t *buf);

void M_BufferEnsureCapacity(buf_t *buf, size_t capacity);
void M_BufferEnsureTotalCapacity(buf_t *buf, size_t capacity);

void M_BufferCopy(buf_t *dst, buf_t *src);
void M_BufferCursorCopy(buf_t *dst, buf_t *src);
void M_BufferCopy(buf_t *dst, const buf_t *src);
void M_BufferCursorCopy(buf_t *dst, const buf_t *src);
bool M_BufferMove(buf_t *buf, size_t dpos, size_t spos, size_t count);

void M_BufferSetData(buf_t *buf, const void *data, size_t size);
Expand All @@ -58,7 +58,7 @@ bool M_BufferSeek(buf_t *buf, size_t pos);
bool M_BufferSeekBackward(buf_t *buf, size_t count);
bool M_BufferSeekForward(buf_t *buf, size_t count);

uint8_t M_BufferPeek(buf_t *buf);
uint8_t M_BufferPeek(const buf_t *buf);

void M_BufferWrite(buf_t *buf, const void *data, size_t size);
void M_BufferWriteBool(buf_t *buf, bool b);
Expand Down Expand Up @@ -91,8 +91,8 @@ void M_BufferWriteDoubles(buf_t *buf, const double *doubles, size_t count);
void M_BufferWriteString(buf_t *buf, const char *string, size_t length);
void M_BufferWriteZeros(buf_t *buf, size_t count);

bool M_BufferEqualsString(buf_t *buf, const char *s);
bool M_BufferEqualsData(buf_t *buf, const void *d, size_t size);
bool M_BufferEqualsString(const buf_t *buf, const char *s);
bool M_BufferEqualsData(const buf_t *buf, const void *d, size_t size);

bool M_BufferRead(buf_t *buf, void *data, size_t size);
bool M_BufferReadBool(buf_t *buf, bool *b);
Expand Down Expand Up @@ -120,17 +120,17 @@ bool M_BufferReadDouble(buf_t *buf, double *d);
bool M_BufferReadDoubles(buf_t *buf, double *d, size_t count);
#endif
bool M_BufferReadString(buf_t *buf, char *s, size_t length);
bool M_BufferReadStringDup(buf_t *buf, char **s);
bool M_BufferCopyString(buf_t *dst, buf_t *src);
bool M_BufferReadStringDup(const buf_t *buf, char **s);
bool M_BufferCopyString(buf_t *dst, const buf_t *src);

void M_BufferCompact(buf_t *buf);
void M_BufferTruncate(buf_t *buf, size_t new_size);
void M_BufferZero(buf_t *buf);
void M_BufferZero(const buf_t *buf);
void M_BufferClear(buf_t *buf);
void M_BufferFree(buf_t *buf);

void M_BufferPrint(buf_t *buf);
void M_BufferPrintAll(buf_t *buf);
void M_BufferPrint(const buf_t *buf);
void M_BufferPrintAll(const buf_t *buf);

#endif

Expand Down
2 changes: 1 addition & 1 deletion test/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include <stdarg.h>
#include <stdlib.h>

#include "tests.h"

Expand Down
1 change: 1 addition & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ THE SOFTWARE.
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>

#include <cmocka.h>

Expand Down
11 changes: 0 additions & 11 deletions test/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include <setjmp.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#include <cmocka.h>

void test_msgpack(void **state);
void test_fixedint(void **state);
void test_numbers(void **state);
Expand Down

0 comments on commit eb289e4

Please sign in to comment.