Changeset 13642


Ignore:
Timestamp:
Dec 10, 2012, 1:24:50 AM (9 years ago)
Author:
jordan
Message:

in libtransmission's unit tests, add a convenience check macro for comparing pointer equality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/libtransmission-test.h

    r13625 r13642  
    5353
    5454static inline bool
    55 check_eq_impl (const char * file, int line, int64_t expected, int64_t actual)
     55check_int_eq_impl (const char * file, int line, int64_t expected, int64_t actual)
    5656{
    5757  const bool pass = expected == actual;
     
    6262    else
    6363      fprintf (stderr, "FAIL %s:%d, expected \"%"PRId64"\", got \"%"PRId64"\"\n", file, line, expected, actual);
     64  }
     65
     66  return pass;
     67}
     68
     69static inline bool
     70check_ptr_eq_impl (const char * file, int line, const void * expected, const void * actual)
     71{
     72  const bool pass = expected == actual;
     73
     74  if (should_print (pass)) {
     75    if (pass)
     76      fprintf (stderr, "PASS %s:%d\n", file, line);
     77    else
     78      fprintf (stderr, "FAIL %s:%d, expected \"%p\", got \"%p\"\n", file, line, expected, actual);
    6479  }
    6580
     
    88103  do { \
    89104    ++current_test; \
    90     if (!check_eq_impl (__FILE__, __LINE__, (expected), (actual))) \
     105    if (!check_int_eq_impl (__FILE__, __LINE__, (expected), (actual))) \
     106      return current_test; \
     107  } while (0)
     108
     109#define check_ptr_eq(expected, actual) \
     110  do { \
     111    ++current_test; \
     112    if (!check_ptr_eq_impl (__FILE__, __LINE__, (expected), (actual))) \
    91113      return current_test; \
    92114  } while (0)
Note: See TracChangeset for help on using the changeset viewer.