Skip to content

Commit

Permalink
Update test suite to properly allocation & deallocation
Browse files Browse the repository at this point in the history
  • Loading branch information
P-p-H-d committed Dec 23, 2024
1 parent 10a1278 commit 7c0592c
Show file tree
Hide file tree
Showing 29 changed files with 82 additions and 68 deletions.
3 changes: 1 addition & 2 deletions tests/test-malgo.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test-obj.h"
#include "m-list.h"
#include "m-i-list.h"
#include "m-array.h"
Expand All @@ -29,8 +30,6 @@
#include "m-tuple.h"
#include "m-algo.h"

#include "test-obj.h"

typedef struct over_s {
unsigned long data;
ILIST_INTERFACE(ilist_over, over_s);
Expand Down
3 changes: 1 addition & 2 deletions tests/test-mbitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "test-obj.h"
#include "m-string.h"
#include "coverage.h"

#include "m-bitset.h"

static void test1(void)
Expand Down
4 changes: 1 addition & 3 deletions tests/test-mbptree.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include "test-obj.h"
#include "m-string.h"
#include "m-bptree.h"
#include "test-obj.h"
#include "coverage.h"

START_COVERAGE
Expand Down
3 changes: 1 addition & 2 deletions tests/test-mbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "m-core.h"
#include "test-obj.h"
#include "coverage.h"

#include "m-bstring.h"

static void test0(void)
Expand Down
4 changes: 2 additions & 2 deletions tests/test-mbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "m-buffer.h"

#include "test-obj.h"
#include "m-buffer.h"
#include "coverage.h"

START_COVERAGE
// Define a fixed queue of unsigned int
BUFFER_DEF(buffer_uint, unsigned int, 10, BUFFER_QUEUE|BUFFER_BLOCKING)
Expand Down
2 changes: 1 addition & 1 deletion tests/test-mconcurrent.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
#include <stdio.h>
#include "test-obj.h"
#include "coverage.h"

#include "m-array.h"
#include "m-bptree.h"
Expand All @@ -35,6 +34,7 @@
#include "m-variant.h"

#include "m-concurrent.h"
#include "coverage.h"

TUPLE_DEF2(point, (x, int), (y, int))
#define M_OPL_point_t() TUPLE_OPLIST(point, M_BASIC_OPLIST, M_BASIC_OPLIST)
Expand Down
3 changes: 1 addition & 2 deletions tests/test-mcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
#define M_F(a,b) M_OVERRIDE_F(a,b)
#define M_OVERRIDE__method() , _get_method ,
#define M_OVERRIDE__method2() , _get_method2
#include "m-core.h"

#include "test-obj.h"
#include "m-core.h"

static bool tmp_init(void) { return true; }
static bool tmp_get_method(void) { return true; }
Expand Down
7 changes: 3 additions & 4 deletions tests/test-mdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include <assert.h>
#include "test-obj.h"
#include "m-dict.h"
#include "m-array.h"
#include "m-string.h"
#include "test-obj.h"
#include "coverage.h"

static inline bool oor_equal_p(int k, unsigned char n) { return k == (int)-n-1; }
static inline void oor_set(int *k, unsigned char n) { *k = (int)-n-1; }
static inline void update_value (int *p, const int p1, const int p2) { *p = p1 + p2; }
#include "coverage.h"

START_COVERAGE
DICT_DEF2(dict_str, string_t, STRING_OPLIST, string_t, STRING_OPLIST)
DICT_OA_DEF2(dict_oa_int, int, M_OPEXTEND(M_BASIC_OPLIST, OOR_EQUAL(oor_equal_p), OOR_SET(oor_set M_IPTR)), int, M_OPEXTEND(M_BASIC_OPLIST, ADD(update_value M_IPTR)))
Expand Down
1 change: 0 additions & 1 deletion tests/test-mfuncobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "test-obj.h"
#include "m-string.h"
#include "m-funcobj.h"
Expand Down
6 changes: 2 additions & 4 deletions tests/test-mgeneric.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <stdbool.h>
#include <assert.h>
#include "coverage.h"

#include "test-obj.h"
#include "m-string.h"
#include "m-array.h"
#include "m-list.h"
#include "m-generic.h"
#include "coverage.h"

// Generic is not supported if not C11
// TCC has some issues in the preprocessing.
Expand Down
3 changes: 1 addition & 2 deletions tests/test-mgenint.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "test-obj.h"
#include "m-thread.h"
#include "m-atomic.h"
#include "m-core.h"
#include "coverage.h"

#include "m-genint.h"

#define MAX_N 256
Expand Down
5 changes: 2 additions & 3 deletions tests/test-milist.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>

#include "test-obj.h"
#include "m-i-list.h"
#include "coverage.h"

typedef struct test_s {
int n;
Expand All @@ -37,7 +37,6 @@ static inline bool test_equal_p(const test_t *i1, const test_t *i2)
return i1->n == i2->n;
}

#include "coverage.h"
START_COVERAGE
ILIST_DEF(ilist_tname, test_t, M_OPEXTEND(M_POD_OPLIST, EQUAL(API_6(test_equal_p))))
END_COVERAGE
Expand Down
3 changes: 0 additions & 3 deletions tests/test-mishared.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <assert.h>
#include "test-obj.h"

#include "m-i-shared.h"

#include "m-thread.h"
#include "coverage.h"

Expand Down
3 changes: 1 addition & 2 deletions tests/test-mlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "test-obj.h"
#include "m-string.h"
#include "m-list.h"

#include "coverage.h"

START_COVERAGE
LIST_DEF(list_uint, unsigned int)
LIST_DEF(list_mpz, testobj_t, TESTOBJ_OPLIST)
Expand Down
6 changes: 2 additions & 4 deletions tests/test-mmempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <stdio.h>
#include <stdlib.h>

#include "test-obj.h"
#include "m-mempool.h"

#include "coverage.h"

START_COVERAGE
MEMPOOL_DEF(mempool_uint, unsigned int)
END_COVERAGE
Expand Down
4 changes: 1 addition & 3 deletions tests/test-mprioqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <assert.h>
#include "test-obj.h"
#include "m-string.h"
#include "m-prioqueue.h"

#include "coverage.h"

START_COVERAGE
PRIOQUEUE_DEF(int_pqueue, int)
END_COVERAGE
Expand Down
3 changes: 1 addition & 2 deletions tests/test-mrbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "test-obj.h"
#include "m-string.h"
#include "m-rbtree.h"
#include "coverage.h"

static bool uint_in_str(unsigned int *u, FILE *f)
{
Expand All @@ -49,7 +49,6 @@ static void uint_get_str(string_t str, unsigned int u, bool append)
(append ? string_cat_printf : string_printf) (str, "%u", u);
}

#include "coverage.h"
START_COVERAGE
RBTREE_DEF(rbtree_uint, unsigned int, M_OPEXTEND(M_BASIC_OPLIST, IN_STR(uint_in_str M_IPTR), OUT_STR(uint_out_str), GET_STR(uint_get_str), PARSE_STR(uint_parse_str M_IPTR)) )
END_COVERAGE
Expand Down
1 change: 1 addition & 0 deletions tests/test-mserial-bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test-obj.h"
#include "m-tuple.h"
#include "m-array.h"
#include "m-variant.h"
Expand Down
1 change: 1 addition & 0 deletions tests/test-mserial-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test-obj.h"
#include "m-tuple.h"
#include "m-array.h"
#include "m-variant.h"
Expand Down
5 changes: 1 addition & 4 deletions tests/test-mshared-ptr.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>

#include "test-obj.h"
#include "m-shared-ptr.h"

#include "m-string.h"
#include "m-array.h"
#include "m-bptree.h"
Expand All @@ -34,7 +32,6 @@
#include "m-rbtree.h"
#include "m-tuple.h"
#include "m-variant.h"

#include "coverage.h"

// TEST WITH INT
Expand Down
4 changes: 1 addition & 3 deletions tests/test-mshared.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <assert.h>
#include "test-obj.h"

#include "m-shared.h"

#include "coverage.h"

START_COVERAGE
SHARED_PTR_DEF(shared_int, int)
SHARED_RESOURCE_DEF(shared_ressource, testobj_t, TESTOBJ_OPLIST)
Expand Down
2 changes: 0 additions & 2 deletions tests/test-msnapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test-obj.h"

#include "m-snapshot.h"
#include "m-thread.h"

#include "coverage.h"

// Long Structure with a simple CRC to check for proper passing
Expand Down
9 changes: 5 additions & 4 deletions tests/test-mstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
*/

#define M_USE_ADDITIONAL_CHECKS 1
#include "m-core.h"
#include "test-obj.h"
#include "coverage.h"

#include "m-string.h"

BOUNDED_STRING_DEF(string16, 16)
Expand Down Expand Up @@ -609,16 +608,18 @@ static void test0(void)
assert (string_equal_str_p(s1, "QWERTYQWERTY"));

string_clear (s2);
size_t cap = string_capacity(s1);
char *s = string_clear_get_str (s1);
assert(strcmp(s, "QWERTYQWERTY") == 0);
free(s);
overloaded_free(1, s, cap <= sizeof (m_str1ng_heap_ct) - 1 ? strlen(s)+1 : cap );

string_t s3;
string_init(s3);
string_cat_str(s3, "ABC");
cap = string_capacity(s3);
s = string_clear_get_str(s3);
assert(strcmp(s, "ABC") == 0);
free(s);
overloaded_free(1, s, cap <= sizeof (m_str1ng_heap_ct) - 1 ? strlen(s)+1 : cap );

string_init_set_str(s1, "RESTART");
assert (string_equal_str_p(s1, "RESTART"));
Expand Down
5 changes: 1 addition & 4 deletions tests/test-mtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>

#include "m-tree.h"

#include "test-obj.h"
#include "m-tree.h"
#include "m-string.h"
#include "coverage.h"

Expand Down
1 change: 0 additions & 1 deletion tests/test-mtry.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ static bool test_final_in_progress;

#include "test-obj.h"
#include "coverage.h"

#include "m-try.h"

M_TRY_DEF_ONCE()
Expand Down
4 changes: 1 addition & 3 deletions tests/test-mtuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "test-obj.h"
#include "m-string.h"

#include "m-tuple.h"

#include "coverage.h"

START_COVERAGE
TUPLE_DEF2(pair,
(key, string_t, (INIT(string_init), INIT_SET(string_init_set), SET(string_set), CLEAR(string_clear))),
Expand Down
4 changes: 1 addition & 3 deletions tests/test-mvariant.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "test-obj.h"
#include "m-string.h"

#include "m-variant.h"

#include "coverage.h"

START_COVERAGE
VARIANT_DEF2(pair,
(key, int, M_BASIC_OPLIST),
Expand Down
Loading

0 comments on commit 7c0592c

Please sign in to comment.