stop_color());
}
+void assert_str(const char title[], const char expected[],
+ const char received[]) {
+ if (strcmp(expected, received)) {
+ failure("%s\n\tExpected: <%s>\n\tReceived: <%s>",
+ title, expected, received
+ );
+ }
+}
+
+void assert_int(const char title[], long long expected, long long received) {
+ if (received != expected) {
+ failure("%s\n\tExpected: %lld\n\tReceived: %lld",
+ title, expected, received
+ );
+ }
+}
+
+void assert_sz(const char title[], size_t expected, size_t received) {
+ if (received != expected) {
+ failure("%s\n\tExpected: %zu\n\tReceived: %zu",
+ title, expected, received
+ );
+ }
+}
+
int test_start(int more) {
int failed;
SRunner *runner;
}\
END_TEST\
-#define FAIL(...) \
-/* TODO: test_failure(); ??? */ \
-ck_abort_msg(__VA_ARGS__)\
-
-#define ASSERT_EQUALS_STR(title, expected, received) \
- do { if (strcmp(expected, received)) { \
-ck_abort_msg("%s\n\tExpected: <%s>\n\tReceived: <%s>", title, expected, received); \
-}} while(0)
-
-#define ASSERT_EQUALS_INT(title, expected, received) \
- do { if (expected != received) { \
-ck_abort_msg("%s\n\tExpected: %lld\n\tReceived: %lld", title, (long long)expected, (long long)received); \
-}} while(0)
-
-#define ASSERT_EQUALS_SIZE(title, expected, received) \
- do { if (expected != received) { \
-ck_abort_msg("%s\n\tExpected: %zu\n\tReceived: %zu", title, expected, received); \
-}} while(0)
+#define failure(...) do { \
+ test_failure(); \
+ ck_abort_msg(__VA_ARGS__); \
+} while(0)
+
+void assert_str(const char title[], const char expected[],
+ const char received[]);
+
+void assert_int(const char title[], long long expected, long long received);
+
+void assert_sz(const char title[], size_t expected, size_t received);
extern int launcher_color;
#include <sys/time.h>
+typedef struct {
+ struct timeval start;
+ struct timeval stop;
+ size_t sec;
+ int msec;
+ int usec;
+} timing_t;
+
+/**
+ * Start the timing.
+ */
+#define TIMING_START(timing) \
+ timing_t timing; \
+ gettimeofday(&(timing.start), NULL); \
+ timing.sec = timing.msec = timing.usec = 0; \
+ timing.stop.tv_sec = 0; \
+ timing.stop.tv_usec = 0; \
+while(0)
+
/**
- * Start the timer.
+ * Stop the timing and return the elapsed time in milliseconds into msec.
*/
-#define TIMING_START struct timeval TIMING_start, TIMING_stop; \
- /* 1 usec = 0.000001 s */ \
- char cusec[7]; \
- gettimeofday(&TIMING_start, NULL);
+#define TIMING_STOP(timing) \
+ gettimeofday(&(timing.stop), NULL); \
+ if (timing.stop.tv_usec >= timing.start.tv_usec) { \
+ timing.sec = timing.stop.tv_sec - timing.start.tv_sec; \
+ timing.usec = timing.stop.tv_usec - timing.start.tv_usec; \
+ } else { \
+ timing.sec = (timing.stop.tv_sec - timing.start.tv_sec) - 1; \
+ timing.usec = timing.start.tv_usec - timing.stop.tv_usec; \
+ } \
+ timing.msec = timing.usec / 1000; \
+ timing.usec = timing.usec % 1000; \
+ gettimeofday(&(timing.start), NULL); \
+while(0)
/**
- * Stop the timer and print the elapsed time to stdout.
+ * Stop the timing and print the elapsed time.
*/
-#define TIMING_STOP gettimeofday(&TIMING_stop, NULL); \
- TIMING_stop.tv_sec = TIMING_stop.tv_sec - TIMING_start.tv_sec; \
- TIMING_stop.tv_usec = TIMING_stop.tv_usec - TIMING_start.tv_usec; \
- sprintf(cusec, "%0.6d", TIMING_stop.tv_usec); \
- printf("TIME: %d.%s sec\n", TIMING_stop.tv_sec, cusec); \
- gettimeofday(&TIMING_start, NULL);
+#define TIMING_PRINT(timing) \
+ TIMING_STOP(timing); \
+ printf("TIME: %zu.%03d%03d sec\n", \
+ timing.sec, timing.msec, timing.usec); \
+while(0)
#endif // TIMING_H