Add first test on variant.
This commit is contained in:
1 parent
0016615ce8
commit
30c08d16e3
3 files changed
+57
-6
No files matched your search
+5
-5
@@ -52,7 +52,7 @@
|
||||
// FIXME: enum shall use 'name' too to avoid collision problem§?
|
||||
#define VARIANTI_DEFINE_TYPE(name, ...) \
|
||||
typedef struct M_C(name, _s) { \
|
||||
enum { VARIANT_EMPTY, \
|
||||
enum { VARIANT_EMPTY \
|
||||
M_MAP(VARIANTI_DEFINE_UNION_ELE, __VA_ARGS__) \
|
||||
} type; \
|
||||
union { \
|
||||
@@ -76,7 +76,7 @@
|
||||
static inline void M_C(name, _init_set)(M_C(name,_t) my , M_C(name,_t) const org) { \
|
||||
my->type = org->type; \
|
||||
switch (org->type) { \
|
||||
case VARIANT_EMPTY; break; \
|
||||
case VARIANT_EMPTY: break; \
|
||||
M_MAP(VARIANTI_DEFINE_INIT_SET_FUNC, __VA_ARGS__) \
|
||||
default: assert(false); break; \
|
||||
} \
|
||||
@@ -97,7 +97,7 @@
|
||||
} else { \
|
||||
/* Same type: optimize the settings */ \
|
||||
switch (org->type) { \
|
||||
case VARIANT_EMPTY; break; \
|
||||
case VARIANT_EMPTY: break; \
|
||||
M_MAP(VARIANTI_DEFINE_SET_FUNC, __VA_ARGS__) \
|
||||
default: assert(false); break; \
|
||||
} \
|
||||
@@ -113,7 +113,7 @@
|
||||
#define VARIANTI_DEFINE_CLEAR(name, ...) \
|
||||
static inline void M_C(name, _clear)(M_C(name,_t) my) { \
|
||||
switch (my->type) { \
|
||||
case VARIANT_EMPTY; break; \
|
||||
case VARIANT_EMPTY: break; \
|
||||
M_MAP(VARIANTI_DEFINE_CLEAR_FUNC, __VA_ARGS__) \
|
||||
default: assert(false); break; \
|
||||
} \
|
||||
@@ -176,9 +176,9 @@
|
||||
#define VARIANT_DEF2(name, ...) \
|
||||
VARIANTI_DEFINE_TYPE(name, __VA_ARGS__) \
|
||||
VARIANTI_DEFINE_INIT(name, __VA_ARGS__) \
|
||||
VARIANTI_DEFINE_CLEAR(name, __VA_ARGS__) \
|
||||
VARIANTI_DEFINE_INIT_SET(name, __VA_ARGS__) \
|
||||
VARIANTI_DEFINE_SET(name, __VA_ARGS__) \
|
||||
VARIANTI_DEFINE_CLEAR(name, __VA_ARGS__) \
|
||||
VARIANTI_DEFINE_TEST_P(name, __VA_ARGS__) \
|
||||
VARIANTI_DEFINE_SETTER(name, __VA_ARGS__) \
|
||||
VARIANTI_DEFINE_GETTER(name, __VA_ARGS__) \
|
||||
|
||||
+5
-1
@@ -1,3 +1,4 @@
|
||||
#NOTE: GMP is only used for the tests
|
||||
CC=gcc -std=c99
|
||||
CFLAGS=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wno-unused-function
|
||||
CPPFLAGS=-I..
|
||||
@@ -8,7 +9,7 @@ EXE=./a.exe
|
||||
all:
|
||||
@echo "Nothing to be done."
|
||||
|
||||
check: core array list i-list string buffer shared tuple snapshot algo dict rbtree
|
||||
check: core array list i-list string buffer shared tuple snapshot algo dict rbtree variant
|
||||
|
||||
valgrind:
|
||||
make check VALGRIND=valgrind
|
||||
@@ -52,6 +53,9 @@ rbtree:
|
||||
bitset:
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -g $(COVERAGE_CFLAGS) test-mbitset.c -lgmp -o $(EXE) && $(VALGRIND) $(EXE)
|
||||
|
||||
variant:
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -g $(COVERAGE_CFLAGS) test-mvariant.c -lgmp -o $(EXE) && $(VALGRIND) $(EXE)
|
||||
|
||||
gene-list:
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -O3 -DNDEBUG -S tgen-mlist.c && less tgen-mlist.s
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Patrick Pelissier
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* + Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* + Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (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 <gmp.h>
|
||||
|
||||
#include "m-string.h"
|
||||
#include "m-variant.h"
|
||||
|
||||
VARIANT_DEF2(pair,
|
||||
(key, int, M_DEFAULT_OPLIST),
|
||||
(value, float, M_DEFAULT_OPLIST) )
|
||||
|
||||
static void test_pair(void)
|
||||
{
|
||||
pair_t p;
|
||||
pair_init (p);
|
||||
|
||||
pair_clear(p);
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_pair();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user