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

Overhauled tests for structure types containing structure types and pointers to them #296

Merged
merged 2 commits into from
Feb 1, 2022
Merged
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: 1 addition & 1 deletion libtest/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export MACOSX_DEPLOYMENT_TARGET=10.5

CCACHE := $(strip $(realpath $(shell which ccache 2> /dev/null)))

TEST_SRCS = $(wildcard $(SRC_DIR)/*.c)
TEST_SRCS = $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/*/*.c)
TEST_OBJS := $(patsubst $(SRC_DIR)/%.c, $(TEST_BUILD_DIR)/%.o, $(TEST_SRCS))

#
Expand Down
76 changes: 76 additions & 0 deletions libtest/struct/NestedStruct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "StructTypes.h"

#define SET_VAL(TYPE) \
TYPE nested_struct_inner_struct_get_##TYPE(NestedStruct *s) { \
return s->inner_NumericStruct.val_##TYPE; \
} \
TYPE nested_struct_ptr_struct_get_##TYPE(NestedStruct *s) { \
return s->ptr_NumericStruct->val_##TYPE; \
} \
TYPE nested_struct_inner_union_get_##TYPE(NestedStruct *s) { \
return s->inner_NumericUnion.val_##TYPE; \
} \
TYPE nested_struct_ptr_union_get_##TYPE(NestedStruct *s) { \
return s->ptr_NumericUnion->val_##TYPE; \
}

#define GET_VAL(TYPE) \
void nested_struct_inner_struct_set_##TYPE(NestedStruct *s, TYPE v) { \
s->inner_NumericStruct.val_##TYPE = v; \
} \
void nested_struct_ptr_struct_set_##TYPE(NestedStruct *s, TYPE v) { \
s->ptr_NumericStruct->val_##TYPE = v; \
} \
void nested_struct_inner_union_set_##TYPE(NestedStruct *s, TYPE v) { \
s->inner_NumericUnion.val_##TYPE = v; \
} \
void nested_struct_ptr_union_set_##TYPE(NestedStruct *s, TYPE v) { \
s->ptr_NumericUnion->val_##TYPE = v; \
}


// ============================= Set Functions ======================

SET_VAL(int8_t);
SET_VAL(int16_t);
SET_VAL(int32_t);
SET_VAL(long);
SET_VAL(int64_t);

SET_VAL(uint8_t);
SET_VAL(uint16_t);
SET_VAL(uint32_t);
SET_VAL(ulong);
SET_VAL(uint64_t);

SET_VAL(float);
SET_VAL(double);

SET_VAL(bool);
SET_VAL(Enum);
SET_VAL(pointer);

// ============================= Get Functions ======================

GET_VAL(int8_t);
GET_VAL(int16_t);
GET_VAL(int32_t);
GET_VAL(long);
GET_VAL(int64_t);

GET_VAL(uint8_t);
GET_VAL(uint16_t);
GET_VAL(uint32_t);
GET_VAL(ulong);
GET_VAL(uint64_t);

GET_VAL(float);
GET_VAL(double);

GET_VAL(bool);
GET_VAL(Enum);
GET_VAL(pointer);

int nested_struct_size() {
return sizeof(NestedStruct);
}
76 changes: 76 additions & 0 deletions libtest/struct/NestedUnion.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "StructTypes.h"

#define SET_VAL(TYPE) \
TYPE nested_union_inner_struct_get_##TYPE(NestedUnion *s) { \
return s->inner_NumericStruct.val_##TYPE; \
} \
TYPE nested_union_ptr_struct_get_##TYPE(NestedUnion *s) { \
return s->ptr_NumericStruct->val_##TYPE; \
} \
TYPE nested_union_inner_union_get_##TYPE(NestedUnion *s) { \
return s->inner_NumericUnion.val_##TYPE; \
} \
TYPE nested_union_ptr_union_get_##TYPE(NestedUnion *s) { \
return s->ptr_NumericUnion->val_##TYPE; \
}

#define GET_VAL(TYPE) \
void nested_union_inner_struct_set_##TYPE(NestedUnion *s, TYPE v) { \
s->inner_NumericStruct.val_##TYPE = v; \
} \
void nested_union_ptr_struct_set_##TYPE(NestedUnion *s, TYPE v) { \
s->ptr_NumericStruct->val_##TYPE = v; \
} \
void nested_union_inner_union_set_##TYPE(NestedUnion *s, TYPE v) { \
s->inner_NumericUnion.val_##TYPE = v; \
} \
void nested_union_ptr_union_set_##TYPE(NestedUnion *s, TYPE v) { \
s->ptr_NumericUnion->val_##TYPE = v; \
}


// ============================= Set Functions ======================

SET_VAL(int8_t);
SET_VAL(int16_t);
SET_VAL(int32_t);
SET_VAL(long);
SET_VAL(int64_t);

SET_VAL(uint8_t);
SET_VAL(uint16_t);
SET_VAL(uint32_t);
SET_VAL(ulong);
SET_VAL(uint64_t);

SET_VAL(float);
SET_VAL(double);

SET_VAL(bool);
SET_VAL(Enum);
SET_VAL(pointer);

// ============================= Get Functions ======================

GET_VAL(int8_t);
GET_VAL(int16_t);
GET_VAL(int32_t);
GET_VAL(long);
GET_VAL(int64_t);

GET_VAL(uint8_t);
GET_VAL(uint16_t);
GET_VAL(uint32_t);
GET_VAL(ulong);
GET_VAL(uint64_t);

GET_VAL(float);
GET_VAL(double);

GET_VAL(bool);
GET_VAL(Enum);
GET_VAL(pointer);

int nested_union_size() {
return sizeof(NestedUnion);
}
57 changes: 57 additions & 0 deletions libtest/struct/NumericStruct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "StructTypes.h"

#define SET_VAL(TYPE) \
TYPE struct_num_get_##TYPE(NumericStruct *s) { \
return s->val_##TYPE; \
}

#define GET_VAL(TYPE) \
void struct_num_set_##TYPE(NumericStruct *s, TYPE v) { \
s->val_##TYPE = v; \
}

// ============================= Set Functions ======================

SET_VAL(int8_t);
SET_VAL(int16_t);
SET_VAL(int32_t);
SET_VAL(long);
SET_VAL(int64_t);

SET_VAL(uint8_t);
SET_VAL(uint16_t);
SET_VAL(uint32_t);
SET_VAL(ulong);
SET_VAL(uint64_t);

SET_VAL(float);
SET_VAL(double);

SET_VAL(bool);
SET_VAL(Enum);
SET_VAL(pointer);

// ============================= Get Functions ======================

GET_VAL(int8_t);
GET_VAL(int16_t);
GET_VAL(int32_t);
GET_VAL(long);
GET_VAL(int64_t);

GET_VAL(uint8_t);
GET_VAL(uint16_t);
GET_VAL(uint32_t);
GET_VAL(ulong);
GET_VAL(uint64_t);

GET_VAL(float);
GET_VAL(double);

GET_VAL(bool);
GET_VAL(Enum);
GET_VAL(pointer);

int struct_num_size() {
return sizeof(NumericStruct);
}
57 changes: 57 additions & 0 deletions libtest/struct/NumericUnion.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "StructTypes.h"

#define SET_VAL(TYPE) \
TYPE union_num_get_##TYPE(NumericUnion *s) { \
return s->val_##TYPE; \
}

#define GET_VAL(TYPE) \
void union_num_set_##TYPE(NumericUnion *s, TYPE v) { \
s->val_##TYPE = v; \
}

// ============================= Set Functions ======================

SET_VAL(int8_t);
SET_VAL(int16_t);
SET_VAL(int32_t);
SET_VAL(long);
SET_VAL(int64_t);

SET_VAL(uint8_t);
SET_VAL(uint16_t);
SET_VAL(uint32_t);
SET_VAL(ulong);
SET_VAL(uint64_t);

SET_VAL(float);
SET_VAL(double);

SET_VAL(bool);
SET_VAL(Enum);
SET_VAL(pointer);

// ============================= Get Functions ======================

GET_VAL(int8_t);
GET_VAL(int16_t);
GET_VAL(int32_t);
GET_VAL(long);
GET_VAL(int64_t);

GET_VAL(uint8_t);
GET_VAL(uint16_t);
GET_VAL(uint32_t);
GET_VAL(ulong);
GET_VAL(uint64_t);

GET_VAL(float);
GET_VAL(double);

GET_VAL(bool);
GET_VAL(Enum);
GET_VAL(pointer);

int union_num_size() {
return sizeof(NumericUnion);
}
59 changes: 59 additions & 0 deletions libtest/struct/StructTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "../types.h"

typedef struct NumericStruct_t {
int8_t val_int8_t;
int16_t val_int16_t;
int32_t val_int32_t;
long val_long;
int64_t val_int64_t;

uint8_t val_uint8_t;
uint16_t val_uint16_t;
uint32_t val_uint32_t;
ulong val_ulong;
uint64_t val_uint64_t;

float val_float;
double val_double;

bool val_bool;
Enum val_Enum;
pointer val_pointer;
} NumericStruct;

typedef union NumericUnion_t {
int8_t val_int8_t;
int16_t val_int16_t;
int32_t val_int32_t;
long val_long;
int64_t val_int64_t;

uint8_t val_uint8_t;
uint16_t val_uint16_t;
uint32_t val_uint32_t;
ulong val_ulong;
uint64_t val_uint64_t;

float val_float;
double val_double;

bool val_bool;
Enum val_Enum;
pointer val_pointer;
} NumericUnion;

typedef struct NestedStruct_t {
NumericStruct inner_NumericStruct;
NumericUnion inner_NumericUnion;

NumericStruct *ptr_NumericStruct;
NumericUnion *ptr_NumericUnion;
} NestedStruct;

typedef union NestedUnion_t {
NumericStruct inner_NumericStruct;
NumericUnion inner_NumericUnion;

NumericStruct *ptr_NumericStruct;
NumericUnion *ptr_NumericUnion;
} NestedUnion;
22 changes: 22 additions & 0 deletions libtest/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdbool.h>
#if !defined(__mips___) || defined(__PASE__)
# include <stdint.h>
#endif

// Let's define the stdint.h typedefs ourselves if they can't be found
#if !defined (_STDINT_H_) && !defined(_STDINT_H) && !defined(_SYS__STDINT_H_) && !defined(_H_STDINT)
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
#endif

typedef unsigned long ulong;
typedef long double ldouble;
typedef void* pointer;
typedef enum Enum_t {e0, e1, e2, e3} Enum;
Loading