Commit 549afd16 authored by Robert Izzard's avatar Robert Izzard
Browse files

update cdict unit tests

parent 289c59a9
Loading
Loading
Loading
Loading

src/cdict_data_types.h

0 → 100644
+51 −0
Original line number Diff line number Diff line
#define __CDICT_DATA_TYPES__                                            \
    /*              cdict identifier,                       union member,           C type for sizeof,       C type for declaration, [] ?,                    C type as string,  format,derefformat,            deref C type,     group,            array->scalar,            scalar->array, numeric, test data */\
    /* scalars, can be keys or values */                                \
    X(                            STRING,                         string,                      char *,                        char *,      ,                             "string",      "%s",      NULL,                      char,     SCALAR,                      NONE,                    STRING,      NOT,                                              "test string") \
    X(                            DOUBLE,                         double,                      double,                        double,      ,                             "double",      "%g",      NULL,                __NO_DEREF,     SCALAR,                      NONE,                    DOUBLE,    FLOAT,                                                    -1.0e10) \
    X(                               INT,                            int,                         int,                           int,      ,                                "int",      "%d",      NULL,                __NO_DEREF,     SCALAR,                      NONE,                       INT,      INT,                                                         -1) \
    X(                      UNSIGNED_INT,                   unsigned_int,                unsigned int,                  unsigned int,      ,                       "unsigned int",      "%u",      NULL,                __NO_DEREF,     SCALAR,                      NONE,              UNSIGNED_INT,      INT,                                                          1) \
    X(                         SHORT_INT,                      short_int,                   short int,                     short int,      ,                          "short int",     "%hd",      NULL,                __NO_DEREF,     SCALAR,                      NONE,                 SHORT_INT,      INT,                                                         -1) \
    X(                UNSIGNED_SHORT_INT,             unsigned_short_int,          unsigned short int,            unsigned short int,      ,                 "unsigned short int",     "%hu",      NULL,                __NO_DEREF,     SCALAR,                      NONE,        UNSIGNED_SHORT_INT,      INT,                                                          1) \
    X(                          LONG_INT,                       long_int,                    long int,                      long int,      ,                           "long int",     "%ld",      NULL,                __NO_DEREF,     SCALAR,                      NONE,                  LONG_INT,      INT,                                                         -1) \
    X(                 UNSIGNED_LONG_INT,              unsigned_long_int,           unsigned long int,             unsigned long int,      ,                  "unsigned long int",     "%lu",      NULL,                __NO_DEREF,     SCALAR,                      NONE,         UNSIGNED_LONG_INT,      INT,                                                          1) \
    X(                     LONG_LONG_INT,                  long_long_int,               long long int,                 long long int,      ,                      "long long int",    "%lld",      NULL,                __NO_DEREF,     SCALAR,                      NONE,             LONG_LONG_INT,      INT,                                                         -1) \
    X(            UNSIGNED_LONG_LONG_INT,         unsigned_long_long_int,      unsigned long long int,        unsigned long long int,      ,             "unsigned long long int",    "%llu",      NULL,                __NO_DEREF,     SCALAR,                      NONE,    UNSIGNED_LONG_LONG_INT,      INT,                                                          1) \
    X(                              CHAR,                           char,                        char,                          char,      ,                               "char",      "%c",      NULL,                __NO_DEREF,     SCALAR,                      NONE,                      CHAR,      NOT,                                                        'c') \
    X(                             FLOAT,                          float,                       float,                         float,      ,                              "float",      "%g",      NULL,                __NO_DEREF,     SCALAR,                      NONE,                     FLOAT,    FLOAT,                                                    -1.0e10) \
    X(                           BOOLEAN,                        Boolean,                     Boolean,                       Boolean,      ,                            "Boolean",      "%s",      NULL,                __NO_DEREF,     SCALAR,                      NONE,                   BOOLEAN,      NOT,                                                       TRUE) \
    X(                       LONG_DOUBLE,                    long_double,                 long double,                   long double,      ,                        "long double",     "%Lg",      NULL,                __NO_DEREF,     SCALAR,                      NONE,               LONG_DOUBLE,    FLOAT,                                                    -1.0e10) \
    /* pointers, can be keys or values */                               \
    X(                    DOUBLE_POINTER,                 double_pointer,                    double *,                      double *,      ,                     "double pointer",      "%p",      "%g",                    double,    POINTER,                    DOUBLE,                      NONE,    FLOAT,                                             __TEST_POINTER) \
    X(                       INT_POINTER,                    int_pointer,                       int *,                         int *,      ,                        "int pointer",      "%p",      "%d",                       int,    POINTER,                       INT,                      NONE,      INT,                                             __TEST_POINTER) \
    X(              UNSIGNED_INT_POINTER,           unsigned_int_pointer,              unsigned int *,                unsigned int *,      ,               "unsigned int pointer",      "%p",      "%u",              unsigned int,    POINTER,              UNSIGNED_INT,                      NONE,      INT,                                             __TEST_POINTER) \
    X(                 SHORT_INT_POINTER,              short_int_pointer,                 short int *,                   short int *,      ,                  "short int pointer",      "%p",     "%hd",                 short int,    POINTER,                 SHORT_INT,                      NONE,      INT,                                             __TEST_POINTER) \
    X(        UNSIGNED_SHORT_INT_POINTER,     unsigned_short_int_pointer,        unsigned short int *,          unsigned short int *,      ,         "unsigned short int pointer",      "%p",     "%hu",        unsigned short int,    POINTER,        UNSIGNED_SHORT_INT,                      NONE,      INT,                                             __TEST_POINTER) \
    X(                  LONG_INT_POINTER,               long_int_pointer,                  long int *,                    long int *,      ,                   "long int pointer",      "%p",     "%ld",                  long int,    POINTER,                  LONG_INT,                      NONE,      INT,                                             __TEST_POINTER) \
    X(         UNSIGNED_LONG_INT_POINTER,      unsigned_long_int_pointer,         unsigned long int *,           unsigned long int *,      ,          "unsigned long int pointer",      "%p",     "%lu",         unsigned long int,    POINTER,         UNSIGNED_LONG_INT,                      NONE,      INT,                                             __TEST_POINTER) \
    X(             LONG_LONG_INT_POINTER,          long_long_int_pointer,             long long int *,               long long int *,      ,              "long long int pointer",      "%p",    "%lld",             long long int,    POINTER,             LONG_LONG_INT,                      NONE,      INT,                                             __TEST_POINTER) \
    X(    UNSIGNED_LONG_LONG_INT_POINTER, unsigned_long_long_int_pointer,    unsigned long long int *,      unsigned long long int *,      ,     "unsigned long long int pointer",      "%p",    "%llu",    unsigned long long int,    POINTER,    UNSIGNED_LONG_LONG_INT,                      NONE,      INT,                                             __TEST_POINTER) \
    X(                      VOID_POINTER,                   void_pointer,                      void *,                        void *,      ,                       "void pointer",      "%p",      NULL,                __NO_DEREF,    POINTER,                      NONE,              VOID_POINTER,      NOT,                                             __TEST_POINTER) \
    X(                     FLOAT_POINTER,                  float_pointer,                     float *,                       float *,      ,                      "float pointer",      "%p",      "%g",                     float,    POINTER,                     FLOAT,                      NONE,    FLOAT,                                             __TEST_POINTER) \
    X(               LONG_DOUBLE_POINTER,            long_double_pointer,               long double *,                 long double *,      ,                "long double pointer",      "%p",     "%Lg",               long double,    POINTER,               LONG_DOUBLE,                      NONE,    FLOAT,                                             __TEST_POINTER) \
    X(                   BOOLEAN_POINTER,                Boolean_pointer,                   Boolean *,                     Boolean *,      ,                    "Boolean pointer",      "%p",      "%s",                   Boolean,    POINTER,                   BOOLEAN,                      NONE,      NOT,                                             __TEST_POINTER) \
    /* the following types can only be values, not keys */              \
    X(                      DOUBLE_ARRAY,                   double_array,                    double *,                        double,    [],                       "double array",      "%g",      NULL,                    double,      ARRAY,                    DOUBLE,                      NONE,    FLOAT,                           __CDict_protect({(double)-1.0e10,               (double)2.0e-10})) \
    X(                 LONG_DOUBLE_ARRAY,              long_double_array,               long double *,                   long double,    [],                  "long double array",     "%Lg",      NULL,               long double,      ARRAY,               LONG_DOUBLE,                      NONE,    FLOAT,                      __CDict_protect({(long double)-1.0e10,          (long double)2.0e-10})) \
    X(                         INT_ARRAY,                      int_array,                       int *,                           int,    [],                          "int array",      "%d",      NULL,                       int,      ARRAY,                       INT,                      NONE,      INT,                                   __CDict_protect({(int)-1,                        (int)2})) \
    X(                UNSIGNED_INT_ARRAY,             unsigned_int_array,              unsigned int *,                  unsigned int,    [],                 "unsigned int array",      "%u",      NULL,              unsigned int,      ARRAY,              UNSIGNED_INT,                      NONE,      INT,                           __CDict_protect({(unsigned int)1,               (unsigned int)2})) \
    X(                   SHORT_INT_ARRAY,                short_int_array,                 short int *,                     short int,    [],                    "short int array",      "%d",      NULL,                 short int,      ARRAY,                 SHORT_INT,                      NONE,      INT,                             __CDict_protect({(short int)-1,                  (short int)2})) \
    X(          UNSIGNED_SHORT_INT_ARRAY,       unsigned_short_int_array,        unsigned short int *,            unsigned short int,    [],           "unsigned short int array",      "%u",      NULL,        unsigned short int,      ARRAY,        UNSIGNED_SHORT_INT,                      NONE,      INT,                     __CDict_protect({(unsigned short int)1,         (unsigned short int)2})) \
    X(                    LONG_INT_ARRAY,                 long_int_array,                  long int *,                      long int,    [],                     "long int array",     "%ld",      NULL,                  long int,      ARRAY,                  LONG_INT,                      NONE,      INT,                              __CDict_protect({(long int)-1,                   (long int)2})) \
    X(           UNSIGNED_LONG_INT_ARRAY,        unsigned_long_int_array,         unsigned long int *,             unsigned long int,    [],            "unsigned long int array",     "%lu",      NULL,         unsigned long int,      ARRAY,         UNSIGNED_LONG_INT,                      NONE,      INT,                      __CDict_protect({(unsigned long int)1,          (unsigned long int)2})) \
    X(                        CHAR_ARRAY,                     char_array,                      char *,                          char,    [],                         "char array",      "%c",      NULL,                      char,      ARRAY,                      CHAR,                      NONE,      NOT,                                 __CDict_protect({(char)'a',                       (char)'b',  (char)'c' })) \
    X(                       FLOAT_ARRAY,                    float_array,                     float *,                         float,    [],                        "float array",      "%g",      NULL,                     float,      ARRAY,                     FLOAT,                      NONE,    FLOAT,                            __CDict_protect({(float)-1.0e10,                (float)2.0e-10})) \
    X(                     BOOLEAN_ARRAY,                  Boolean_array,                   Boolean *,                       Boolean,    [],                      "Boolean array",      "%s",      NULL,                   Boolean,      ARRAY,                   BOOLEAN,                      NONE,      NOT,                                      __CDict_protect({TRUE,                         FALSE})) \
    X(               LONG_LONG_INT_ARRAY,            long_long_int_array,             long long int *,                 long long int,    [],                "long long int array",    "%lld",      NULL,             long long int,      ARRAY,             LONG_LONG_INT,                      NONE,      INT,                         __CDict_protect({(long long int)-1,              (long long int)2})) \
    X(      UNSIGNED_LONG_LONG_INT_ARRAY,   unsigned_long_long_int_array,    unsigned long long int *,        unsigned long long int,    [],       "unsigned long long int array",    "%llu",      NULL,    unsigned long long int,      ARRAY,    UNSIGNED_LONG_LONG_INT,                      NONE,      INT,                 __CDict_protect({(unsigned long long int)1,     (unsigned long long int)2})) \
    X(                      STRING_ARRAY,                   string_array,                     char **,                         char*,    [],                       "string array",      "%s",      NULL,                    char *,      ARRAY,                    STRING,                      NONE,      NOT,                              __CDict_protect({(char*)"abc",                  (char*)"def"})) \
    X(                VOID_POINTER_ARRAY,                   void_pointer,                     void **,                         void*,    [],                 "void pointer array",      "%p",      NULL,                    void *,      ARRAY,                      NONE,                      NONE,      NOT,                           __CDict_protect({__TEST_POINTER1,               __TEST_POINTER2})) \
    /* CDICT is a special type: cannot be a key */                      \
    X(                             CDICT,                  cdict_pointer,            struct cdict_t *,               struct cdict_t*,      ,                   "pointer to cdict",      "%p",      NULL,            struct cdict_t,      CDICT,                      NONE,                      NONE,      NOT,                                    __CDict_protect({NULL})) \
    /* unknown type, cannot be a key */                                 \
    X(                           UNKNOWN,                           char,                      char *,                         char*,      ,                            "unknown",      NULL,      NULL,                __NO_DEREF,      OTHER,                      NONE,                      NONE,      NOT,                                                      NULL)
+346 −0
Original line number Diff line number Diff line
char * __cdict_test_variables_expected[] = {

//Test variable string (CTYPE char *)
R""""({
    "test data" : {
        "test of type string" : "test string"
    }
}
)"""",
//Test variable double (CTYPE double)
R""""({
    "test data" : {
        "test of type double" : -1e10
    }
}
)"""",
//Test variable int (CTYPE int)
R""""({
    "test data" : {
        "test of type int" : -1
    }
}
)"""",
//Test variable unsigned int (CTYPE unsigned int)
R""""({
    "test data" : {
        "test of type unsigned int" : 1
    }
}
)"""",
//Test variable short int (CTYPE short int)
R""""({
    "test data" : {
        "test of type short int" : -1
    }
}
)"""",
//Test variable unsigned short int (CTYPE unsigned short int)
R""""({
    "test data" : {
        "test of type unsigned short int" : 1
    }
}
)"""",
//Test variable long int (CTYPE long int)
R""""({
    "test data" : {
        "test of type long int" : -1
    }
}
)"""",
//Test variable unsigned long int (CTYPE unsigned long int)
R""""({
    "test data" : {
        "test of type unsigned long int" : 1
    }
}
)"""",
//Test variable long long int (CTYPE long long int)
R""""({
    "test data" : {
        "test of type long long int" : -1
    }
}
)"""",
//Test variable unsigned long long int (CTYPE unsigned long long int)
R""""({
    "test data" : {
        "test of type unsigned long long int" : 1
    }
}
)"""",
//Test variable char (CTYPE char)
R""""({
    "test data" : {
        "test of type char" : "c"
    }
}
)"""",
//Test variable float (CTYPE float)
R""""({
    "test data" : {
        "test of type float" : -1e10
    }
}
)"""",
//Test variable Boolean (CTYPE Boolean)
R""""({
    "test data" : {
        "test of type Boolean" : true
    }
}
)"""",
//Test variable long double (CTYPE long double)
R""""({
    "test data" : {
        "test of type long double" : -1e+10
    }
}
)"""",
//Test variable double pointer (CTYPE double *)
R""""({
    "test data" : {
        "test of type double pointer" : "0x1"
    }
}
)"""",
//Test variable int pointer (CTYPE int *)
R""""({
    "test data" : {
        "test of type int pointer" : "0x1"
    }
}
)"""",
//Test variable unsigned int pointer (CTYPE unsigned int *)
R""""({
    "test data" : {
        "test of type unsigned int pointer" : "0x1"
    }
}
)"""",
//Test variable short int pointer (CTYPE short int *)
R""""({
    "test data" : {
        "test of type short int pointer" : "0x1"
    }
}
)"""",
//Test variable unsigned short int pointer (CTYPE unsigned short int *)
R""""({
    "test data" : {
        "test of type unsigned short int pointer" : "0x1"
    }
}
)"""",
//Test variable long int pointer (CTYPE long int *)
R""""({
    "test data" : {
        "test of type long int pointer" : "0x1"
    }
}
)"""",
//Test variable unsigned long int pointer (CTYPE unsigned long int *)
R""""({
    "test data" : {
        "test of type unsigned long int pointer" : "0x1"
    }
}
)"""",
//Test variable long long int pointer (CTYPE long long int *)
R""""({
    "test data" : {
        "test of type long long int pointer" : "0x1"
    }
}
)"""",
//Test variable unsigned long long int pointer (CTYPE unsigned long long int *)
R""""({
    "test data" : {
        "test of type unsigned long long int pointer" : "0x1"
    }
}
)"""",
//Test variable void pointer (CTYPE void *)
R""""({
    "test data" : {
        "test of type void pointer" : "0x1"
    }
}
)"""",
//Test variable float pointer (CTYPE float *)
R""""({
    "test data" : {
        "test of type float pointer" : "0x1"
    }
}
)"""",
//Test variable long double pointer (CTYPE long double *)
R""""({
    "test data" : {
        "test of type long double pointer" : "0x1"
    }
}
)"""",
//Test variable Boolean pointer (CTYPE Boolean *)
R""""({
    "test data" : {
        "test of type Boolean pointer" : "0x1"
    }
}
)"""",
//Test variable double array (CTYPE double[])
R""""({
    "test data" : {
        "test of type double array" : [
            -1e+10,
            2e-10
        ]
    }
}
)"""",
//Test variable long double array (CTYPE long double[])
R""""({
    "test data" : {
        "test of type long double array" : [
            -1e+10,
            2e-10
        ]
    }
}
)"""",
//Test variable int array (CTYPE int[])
R""""({
    "test data" : {
        "test of type int array" : [
            -1,
            2
        ]
    }
}
)"""",
//Test variable unsigned int array (CTYPE unsigned int[])
R""""({
    "test data" : {
        "test of type unsigned int array" : [
            1,
            2
        ]
    }
}
)"""",
//Test variable short int array (CTYPE short int[])
R""""({
    "test data" : {
        "test of type short int array" : [
            -1,
            2
        ]
    }
}
)"""",
//Test variable unsigned short int array (CTYPE unsigned short int[])
R""""({
    "test data" : {
        "test of type unsigned short int array" : [
            1,
            2
        ]
    }
}
)"""",
//Test variable long int array (CTYPE long int[])
R""""({
    "test data" : {
        "test of type long int array" : [
            -1,
            2
        ]
    }
}
)"""",
//Test variable unsigned long int array (CTYPE unsigned long int[])
R""""({
    "test data" : {
        "test of type unsigned long int array" : [
            1,
            2
        ]
    }
}
)"""",
//Test variable char array (CTYPE char[])
R""""({
    "test data" : {
        "test of type char array" : "abc"
    }
}
)"""",
//Test variable float array (CTYPE float[])
R""""({
    "test data" : {
        "test of type float array" : [
            -1e+10,
            2e-10
        ]
    }
}
)"""",
//Test variable Boolean array (CTYPE Boolean[])
R""""({
    "test data" : {
        "test of type Boolean array" : [
            true,
            false
        ]
    }
}
)"""",
//Test variable long long int array (CTYPE long long int[])
R""""({
    "test data" : {
        "test of type long long int array" : [
            -1,
            2
        ]
    }
}
)"""",
//Test variable unsigned long long int array (CTYPE unsigned long long int[])
R""""({
    "test data" : {
        "test of type unsigned long long int array" : [
            1,
            2
        ]
    }
}
)"""",
//Test variable string array (CTYPE char*[])
R""""({
    "test data" : {
        "test of type string array" : [
            "abc",
            "def"
        ]
    }
}
)"""",
//Test variable void pointer array (CTYPE void*[])
R""""({
    "test data" : {
        "test of type void pointer array" : [
            "0x1",
            "0x2"
        ]
    }
}
)"""",
//Test variable pointer to cdict (CTYPE struct cdict_t*)
R""""({
    "test data" : {
        "test of type pointer to cdict" : "(nil)"
    }
}
)""""
};
+285 −14

File changed.

Preview size limit exceeded, changes collapsed.

src/cdict_tests.c.old

0 → 100644
+1529 −0

File added.

Preview size limit exceeded, changes collapsed.

src/cdict_tests.h

0 → 100644
+57 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading