mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-12-22 12:31:07 +00:00
Add comparison functions for various integer types.
This commit is contained in:
parent
4c59fd979b
commit
023d9aefaa
2 changed files with 60 additions and 0 deletions
21
t/t.h
21
t/t.h
|
@ -84,6 +84,27 @@ void t_fcloseall(void);
|
||||||
*/
|
*/
|
||||||
int t_compare_mem(const void *, const void *, size_t);
|
int t_compare_mem(const void *, const void *, size_t);
|
||||||
int t_compare_str(const char *, const char *);
|
int t_compare_str(const char *, const char *);
|
||||||
|
#define t_compare_num(n, t) int t_compare_##n(t, t);
|
||||||
|
t_compare_num(i, int);
|
||||||
|
t_compare_num(u, unsigned int);
|
||||||
|
t_compare_num(il, long);
|
||||||
|
t_compare_num(ul, unsigned long);
|
||||||
|
t_compare_num(ill, long long);
|
||||||
|
t_compare_num(ull, unsigned long long);
|
||||||
|
t_compare_num(sz, size_t);
|
||||||
|
t_compare_num(i8, int8_t);
|
||||||
|
t_compare_num(u8, uint8_t);
|
||||||
|
t_compare_num(x8, uint8_t);
|
||||||
|
t_compare_num(i16, int16_t);
|
||||||
|
t_compare_num(u16, uint16_t);
|
||||||
|
t_compare_num(x16, uint16_t);
|
||||||
|
t_compare_num(i32, int32_t);
|
||||||
|
t_compare_num(u32, uint32_t);
|
||||||
|
t_compare_num(x32, uint32_t);
|
||||||
|
t_compare_num(i64, int64_t);
|
||||||
|
t_compare_num(u64, uint64_t);
|
||||||
|
t_compare_num(x64, uint64_t);
|
||||||
|
#undef t_compare_num
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Useful constants
|
* Useful constants
|
||||||
|
|
39
t/t_util.c
39
t/t_util.c
|
@ -34,6 +34,7 @@
|
||||||
#include "cryb/impl.h"
|
#include "cryb/impl.h"
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -77,3 +78,41 @@ t_compare_str(const char *expected, const char *received)
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compare two numbers, and print a verbose message if they differ.
|
||||||
|
*/
|
||||||
|
#define t_compare_num(n, t, pf) \
|
||||||
|
int \
|
||||||
|
t_compare_##n(t expected, t received) \
|
||||||
|
{ \
|
||||||
|
\
|
||||||
|
if (received != expected) { \
|
||||||
|
t_verbose("expected %" pf "\n", expected); \
|
||||||
|
t_verbose("received %" pf "\n", received); \
|
||||||
|
return (0); \
|
||||||
|
} \
|
||||||
|
return (1); \
|
||||||
|
}
|
||||||
|
|
||||||
|
t_compare_num(i, int, "d");
|
||||||
|
t_compare_num(u, unsigned int, "u");
|
||||||
|
t_compare_num(il, long, "ld");
|
||||||
|
t_compare_num(ul, unsigned long, "lu");
|
||||||
|
t_compare_num(ill, long long, "lld");
|
||||||
|
t_compare_num(ull, unsigned long long, "llu");
|
||||||
|
t_compare_num(sz, size_t, "zu");
|
||||||
|
t_compare_num(i8, int8_t, PRId8);
|
||||||
|
t_compare_num(u8, uint8_t, PRIu8);
|
||||||
|
t_compare_num(x8, uint8_t, PRIx8);
|
||||||
|
t_compare_num(i16, int16_t, PRId16);
|
||||||
|
t_compare_num(u16, uint16_t, PRIu16);
|
||||||
|
t_compare_num(x16, uint16_t, PRIx16);
|
||||||
|
t_compare_num(i32, int32_t, PRId32);
|
||||||
|
t_compare_num(u32, uint32_t, PRIu32);
|
||||||
|
t_compare_num(x32, uint32_t, PRIx32);
|
||||||
|
t_compare_num(i64, int64_t, PRId64);
|
||||||
|
t_compare_num(u64, uint64_t, PRIu64);
|
||||||
|
t_compare_num(x64, uint64_t, PRIx64);
|
||||||
|
|
||||||
|
#undef t_compare_num
|
||||||
|
|
Loading…
Reference in a new issue