Let all equality macros follow a common naming and logging schema.
ret = sstrncpy (ptr, "foobar", 8);
OK(ret == ptr);
- STREQ ("foobar", ptr);
+ EXPECT_EQ_STR ("foobar", ptr);
OK(buffer[3] == buffer[12]);
ret = sstrncpy (ptr, "abc", 8);
OK(ret == ptr);
- STREQ ("abc", ptr);
+ EXPECT_EQ_STR ("abc", ptr);
OK(buffer[3] == buffer[12]);
ret = sstrncpy (ptr, "collectd", 8);
OK(ret == ptr);
OK(ptr[7] == 0);
- STREQ ("collect", ptr);
+ EXPECT_EQ_STR ("collect", ptr);
OK(buffer[3] == buffer[12]);
return (0);
status = ssnprintf (ptr, 8, "%i", 1337);
OK(status == 4);
- STREQ ("1337", ptr);
+ EXPECT_EQ_STR ("1337", ptr);
status = ssnprintf (ptr, 8, "%s", "collectd");
OK(status == 8);
OK(ptr[7] == 0);
- STREQ ("collect", ptr);
+ EXPECT_EQ_STR ("collect", ptr);
OK(buffer[3] == buffer[12]);
return (0);
ptr = sstrdup ("collectd");
OK(ptr != NULL);
- STREQ ("collectd", ptr);
+ EXPECT_EQ_STR ("collectd", ptr);
sfree(ptr);
OK(ptr == NULL);
strncpy (buffer, "foo bar", sizeof (buffer));
status = strsplit (buffer, fields, 8);
OK(status == 2);
- STREQ ("foo", fields[0]);
- STREQ ("bar", fields[1]);
+ EXPECT_EQ_STR ("foo", fields[0]);
+ EXPECT_EQ_STR ("bar", fields[1]);
strncpy (buffer, "foo \t bar", sizeof (buffer));
status = strsplit (buffer, fields, 8);
OK(status == 2);
- STREQ ("foo", fields[0]);
- STREQ ("bar", fields[1]);
+ EXPECT_EQ_STR ("foo", fields[0]);
+ EXPECT_EQ_STR ("bar", fields[1]);
strncpy (buffer, "one two\tthree\rfour\nfive", sizeof (buffer));
status = strsplit (buffer, fields, 8);
OK(status == 5);
- STREQ ("one", fields[0]);
- STREQ ("two", fields[1]);
- STREQ ("three", fields[2]);
- STREQ ("four", fields[3]);
- STREQ ("five", fields[4]);
+ EXPECT_EQ_STR ("one", fields[0]);
+ EXPECT_EQ_STR ("two", fields[1]);
+ EXPECT_EQ_STR ("three", fields[2]);
+ EXPECT_EQ_STR ("four", fields[3]);
+ EXPECT_EQ_STR ("five", fields[4]);
strncpy (buffer, "\twith trailing\n", sizeof (buffer));
status = strsplit (buffer, fields, 8);
OK(status == 2);
- STREQ ("with", fields[0]);
- STREQ ("trailing", fields[1]);
+ EXPECT_EQ_STR ("with", fields[0]);
+ EXPECT_EQ_STR ("trailing", fields[1]);
strncpy (buffer, "1 2 3 4 5 6 7 8 9 10 11 12 13", sizeof (buffer));
status = strsplit (buffer, fields, 8);
OK(status == 8);
- STREQ ("7", fields[6]);
- STREQ ("8", fields[7]);
+ EXPECT_EQ_STR ("7", fields[6]);
+ EXPECT_EQ_STR ("8", fields[7]);
strncpy (buffer, "single", sizeof (buffer));
status = strsplit (buffer, fields, 8);
OK(status == 1);
- STREQ ("single", fields[0]);
+ EXPECT_EQ_STR ("single", fields[0]);
strncpy (buffer, "", sizeof (buffer));
status = strsplit (buffer, fields, 8);
status = strjoin (buffer, sizeof (buffer), fields, 2, "!");
OK(status == 7);
- STREQ ("foo!bar", buffer);
+ EXPECT_EQ_STR ("foo!bar", buffer);
status = strjoin (buffer, sizeof (buffer), fields, 1, "!");
OK(status == 3);
- STREQ ("foo", buffer);
+ EXPECT_EQ_STR ("foo", buffer);
status = strjoin (buffer, sizeof (buffer), fields, 0, "!");
OK(status < 0);
status = strjoin (buffer, sizeof (buffer), fields, 2, "rcht");
OK(status == 10);
- STREQ ("foorchtbar", buffer);
+ EXPECT_EQ_STR ("foorchtbar", buffer);
status = strjoin (buffer, sizeof (buffer), fields, 4, "");
OK(status == 12);
- STREQ ("foobarbazqux", buffer);
+ EXPECT_EQ_STR ("foobarbazqux", buffer);
status = strjoin (buffer, sizeof (buffer), fields, 4, "!");
OK(status == 15);
- STREQ ("foo!bar!baz!qux", buffer);
+ EXPECT_EQ_STR ("foo!bar!baz!qux", buffer);
fields[0] = "0123";
fields[1] = "4567";
strncpy (buffer, cases[i].str, sizeof (buffer));
OK(escape_slashes (buffer, sizeof (buffer)) == 0);
- STREQ(cases[i].want, buffer);
+ EXPECT_EQ_STR(cases[i].want, buffer);
}
return 0;
strncpy (buffer, cases[i].str, sizeof (buffer));
OK(escape_string (buffer, sizeof (buffer)) == 0);
- STREQ(cases[i].want, buffer);
+ EXPECT_EQ_STR(cases[i].want, buffer);
}
return 0;
strncpy (buffer, "foo\\tbar", sizeof (buffer));
status = strunescape (buffer, sizeof (buffer));
OK(status == 0);
- STREQ ("foo\tbar", buffer);
+ EXPECT_EQ_STR ("foo\tbar", buffer);
strncpy (buffer, "\\tfoo\\r\\n", sizeof (buffer));
status = strunescape (buffer, sizeof (buffer));
OK(status == 0);
- STREQ ("\tfoo\r\n", buffer);
+ EXPECT_EQ_STR ("\tfoo\r\n", buffer);
strncpy (buffer, "With \\\"quotes\\\"", sizeof (buffer));
status = strunescape (buffer, sizeof (buffer));
OK(status == 0);
- STREQ ("With \"quotes\"", buffer);
+ EXPECT_EQ_STR ("With \"quotes\"", buffer);
/* Backslash before null byte */
strncpy (buffer, "\\tbackslash end\\", sizeof (buffer));
status = strunescape (buffer, sizeof (buffer));
OK(status != 0);
- STREQ ("\tbackslash end", buffer);
+ EXPECT_EQ_STR ("\tbackslash end", buffer);
return (0);
/* Backslash at buffer end */
};
int status = parse_values (cases[i].buffer, &vl, &ds);
- EXPECT_INTEQ (cases[i].status, status);
+ EXPECT_EQ_INT (cases[i].status, status);
if (status != 0)
continue;
- DBLEQ (cases[i].value, vl.values[0].gauge);
+ EXPECT_EQ_DOUBLE (cases[i].value, vl.values[0].gauge);
}
return (0);
}
OK(value_to_rate (&got, cases[i].v1, cases[i].ds_type, TIME_T_TO_CDTIME_T(cases[i].t1), &state) == 0);
- DBLEQ(cases[i].want, got);
+ EXPECT_EQ_DOUBLE(cases[i].want, got);
}
return 0;
/* retrieve and check all values */
CHECK_ZERO (meta_data_get_string (m, "string", &s));
- STREQ ("foobar", s);
+ EXPECT_EQ_STR ("foobar", s);
sfree (s);
CHECK_ZERO (meta_data_get_signed_int (m, "signed_int", &si));
- EXPECT_INTEQ (-1, (int) si);
+ EXPECT_EQ_INT (-1, (int) si);
CHECK_ZERO (meta_data_get_unsigned_int (m, "unsigned_int", &ui));
- EXPECT_INTEQ (1, (int) ui);
+ EXPECT_EQ_INT (1, (int) ui);
CHECK_ZERO (meta_data_get_double (m, "double", &d));
- DBLEQ (47.11, d);
+ EXPECT_EQ_DOUBLE (47.11, d);
CHECK_ZERO (meta_data_get_boolean (m, "boolean", &b));
OK1 (b, "b evaluates to true");
/* retrieving the wrong type always fails */
- EXPECT_INTEQ (-2, meta_data_get_boolean (m, "string", &b));
- EXPECT_INTEQ (-2, meta_data_get_string (m, "signed_int", &s));
- EXPECT_INTEQ (-2, meta_data_get_string (m, "unsigned_int", &s));
- EXPECT_INTEQ (-2, meta_data_get_string (m, "double", &s));
- EXPECT_INTEQ (-2, meta_data_get_string (m, "boolean", &s));
+ EXPECT_EQ_INT (-2, meta_data_get_boolean (m, "string", &b));
+ EXPECT_EQ_INT (-2, meta_data_get_string (m, "signed_int", &s));
+ EXPECT_EQ_INT (-2, meta_data_get_string (m, "unsigned_int", &s));
+ EXPECT_EQ_INT (-2, meta_data_get_string (m, "double", &s));
+ EXPECT_EQ_INT (-2, meta_data_get_string (m, "boolean", &s));
/* replace existing keys */
CHECK_ZERO (meta_data_add_signed_int (m, "string", 666));
CHECK_ZERO (meta_data_add_signed_int (m, "signed_int", 666));
CHECK_ZERO (meta_data_get_signed_int (m, "signed_int", &si));
- EXPECT_INTEQ (666, (int) si);
+ EXPECT_EQ_INT (666, (int) si);
/* deleting keys */
CHECK_ZERO (meta_data_delete (m, "signed_int"));
- EXPECT_INTEQ (-2, meta_data_delete (m, "doesnt exist"));
+ EXPECT_EQ_INT (-2, meta_data_delete (m, "doesnt exist"));
meta_data_destroy (m);
return 0;
}
OK(subst (buffer, sizeof (buffer), cases[i].str, cases[i].off1, cases[i].off2, cases[i].rplmt) == &buffer[0]);
- STREQ(cases[i].want, buffer);
+ EXPECT_EQ_STR(cases[i].want, buffer);
}
return 0;
}
OK(subst_string (buffer, sizeof (buffer), cases[i].str, cases[i].srch, cases[i].rplmt) == buffer);
- STREQ(cases[i].want, buffer);
+ EXPECT_EQ_STR(cases[i].want, buffer);
}
return 0;
EXPECT_EQ_UINT64 (cases[i].ts.tv_nsec, ts.tv_nsec);
// cdtime -> double
- DBLEQ (cases[i].d, CDTIME_T_TO_DOUBLE (cases[i].t));
+ EXPECT_EQ_DOUBLE (cases[i].d, CDTIME_T_TO_DOUBLE (cases[i].t));
}
return 0;
} while (0)
#define OK(cond) OK1(cond, #cond)
-#define STREQ(expect, actual) do { \
+#define EXPECT_EQ_STR(expect, actual) do { \
if (strcmp (expect, actual) != 0) { \
- printf ("not ok %i - %s incorrect: expected \"%s\", got \"%s\"\n", \
- ++check_count__, #actual, expect, actual); \
+ printf ("not ok %i - %s = \"%s\", want \"%s\"\n", \
+ ++check_count__, #actual, actual, expect); \
return (-1); \
} \
- printf ("ok %i - %s evaluates to \"%s\"\n", ++check_count__, #actual, expect); \
+ printf ("ok %i - %s = \"%s\"\n", ++check_count__, #actual, actual); \
} while (0)
-#define EXPECT_EQ(expect, actual, format) do { \
- if ((expect) != (actual)) {\
- printf ("not ok %i - %s incorrect: expected " format ", got " format "\n", \
- ++check_count__, #actual, expect, actual); \
- return (-1); \
- } \
- printf ("ok %i - %s evaluates to " format "\n", ++check_count__, #actual, expect); \
-} while (0)
-
-#define EXPECT_INTEQ(expect, actual) do { \
- if ((expect) != (actual)) {\
- printf ("not ok %i - %s incorrect: expected %d, got %d\n", \
- ++check_count__, #actual, expect, actual); \
+#define EXPECT_EQ_INT(expect, actual) do { \
+ int want__ = (int) expect; \
+ int got__ = (int) actual; \
+ if (got__ != want__) { \
+ printf ("not ok %i - %s = %d, want %d\n", \
+ ++check_count__, #actual, got__, want__); \
return (-1); \
} \
- printf ("ok %i - %s evaluates to %d\n", ++check_count__, #actual, expect); \
+ printf ("ok %i - %s = %d\n", ++check_count__, #actual, got__); \
} while (0)
#define EXPECT_EQ_UINT64(expect, actual) do { \
printf ("ok %i - %s = %"PRIu64"\n", ++check_count__, #actual, got__); \
} while (0)
-#define DBLEQ(expect, actual) do { \
- double e = (expect); double a = (actual); \
- if (isnan (e) && !isnan (a)) { \
- printf ("not ok %i - %s incorrect: expected %.15g, got %.15g\n", \
- ++check_count__, #actual, e, a); \
+#define EXPECT_EQ_DOUBLE(expect, actual) do { \
+ double want__ = (double) expect; \
+ double got__ = (double) actual; \
+ if (isnan (want__) && !isnan (got__)) { \
+ printf ("not ok %i - %s = %.15g, want %.15g\n", \
+ ++check_count__, #actual, got__, want__); \
return (-1); \
- } else if (!isnan (e) && (((e-a) < -DBL_PRECISION) || ((e-a) > DBL_PRECISION))) { \
- printf ("not ok %i - %s incorrect: expected %.15g, got %.15g\n", \
- ++check_count__, #actual, e, a); \
+ } else if (!isnan (want__) && (((want__-got__) < -DBL_PRECISION) || ((want__-got__) > DBL_PRECISION))) { \
+ printf ("not ok %i - %s = %.15g, want %.15g\n", \
+ ++check_count__, #actual, got__, want__); \
return (-1); \
} \
- printf ("ok %i - %s evaluates to %.15g\n", ++check_count__, #actual, e); \
+ printf ("ok %i - %s = %.15g\n", ++check_count__, #actual, got__); \
} while (0)
#define CHECK_NOT_NULL(expr) do { \
i, cases[i].val, DOUBLE_TO_CDTIME_T (cases[i].val));
latency_counter_add (l, DOUBLE_TO_CDTIME_T (cases[i].val));
- DBLEQ (cases[i].min, CDTIME_T_TO_DOUBLE (latency_counter_get_min (l)));
- DBLEQ (cases[i].max, CDTIME_T_TO_DOUBLE (latency_counter_get_max (l)));
- DBLEQ (cases[i].sum, CDTIME_T_TO_DOUBLE (latency_counter_get_sum (l)));
- DBLEQ (cases[i].avg, CDTIME_T_TO_DOUBLE (latency_counter_get_average (l)));
+ EXPECT_EQ_DOUBLE (cases[i].min, CDTIME_T_TO_DOUBLE (latency_counter_get_min (l)));
+ EXPECT_EQ_DOUBLE (cases[i].max, CDTIME_T_TO_DOUBLE (latency_counter_get_max (l)));
+ EXPECT_EQ_DOUBLE (cases[i].sum, CDTIME_T_TO_DOUBLE (latency_counter_get_sum (l)));
+ EXPECT_EQ_DOUBLE (cases[i].avg, CDTIME_T_TO_DOUBLE (latency_counter_get_average (l)));
}
latency_counter_destroy (l);
latency_counter_add (l, TIME_T_TO_CDTIME_T (((time_t) i) + 1));
}
- DBLEQ ( 1.0, CDTIME_T_TO_DOUBLE (latency_counter_get_min (l)));
- DBLEQ (100.0, CDTIME_T_TO_DOUBLE (latency_counter_get_max (l)));
- DBLEQ (100.0 * 101.0 / 2.0, CDTIME_T_TO_DOUBLE (latency_counter_get_sum (l)));
- DBLEQ ( 50.5, CDTIME_T_TO_DOUBLE (latency_counter_get_average (l)));
+ EXPECT_EQ_DOUBLE ( 1.0, CDTIME_T_TO_DOUBLE (latency_counter_get_min (l)));
+ EXPECT_EQ_DOUBLE (100.0, CDTIME_T_TO_DOUBLE (latency_counter_get_max (l)));
+ EXPECT_EQ_DOUBLE (100.0 * 101.0 / 2.0, CDTIME_T_TO_DOUBLE (latency_counter_get_sum (l)));
+ EXPECT_EQ_DOUBLE ( 50.5, CDTIME_T_TO_DOUBLE (latency_counter_get_average (l)));
- DBLEQ (50.0, CDTIME_T_TO_DOUBLE (latency_counter_get_percentile (l, 50.0)));
- DBLEQ (80.0, CDTIME_T_TO_DOUBLE (latency_counter_get_percentile (l, 80.0)));
- DBLEQ (95.0, CDTIME_T_TO_DOUBLE (latency_counter_get_percentile (l, 95.0)));
- DBLEQ (99.0, CDTIME_T_TO_DOUBLE (latency_counter_get_percentile (l, 99.0)));
+ EXPECT_EQ_DOUBLE (50.0, CDTIME_T_TO_DOUBLE (latency_counter_get_percentile (l, 50.0)));
+ EXPECT_EQ_DOUBLE (80.0, CDTIME_T_TO_DOUBLE (latency_counter_get_percentile (l, 80.0)));
+ EXPECT_EQ_DOUBLE (95.0, CDTIME_T_TO_DOUBLE (latency_counter_get_percentile (l, 95.0)));
+ EXPECT_EQ_DOUBLE (99.0, CDTIME_T_TO_DOUBLE (latency_counter_get_percentile (l, 99.0)));
CHECK_ZERO (latency_counter_get_percentile (l, -1.0));
CHECK_ZERO (latency_counter_get_percentile (l, 101.0));
char line_opts[] = "foo=one,bar=two,qux=three";
char line_bool[] = "one,two,three";
- STREQ ("one", cu_mount_getoptionvalue (line_opts, "foo="));
- STREQ ("two", cu_mount_getoptionvalue (line_opts, "bar="));
- STREQ ("three", cu_mount_getoptionvalue (line_opts, "qux="));
+ EXPECT_EQ_STR ("one", cu_mount_getoptionvalue (line_opts, "foo="));
+ EXPECT_EQ_STR ("two", cu_mount_getoptionvalue (line_opts, "bar="));
+ EXPECT_EQ_STR ("three", cu_mount_getoptionvalue (line_opts, "qux="));
OK (NULL == cu_mount_getoptionvalue (line_opts, "unknown="));
- STREQ ("", cu_mount_getoptionvalue (line_bool, "one"));
- STREQ ("", cu_mount_getoptionvalue (line_bool, "two"));
- STREQ ("", cu_mount_getoptionvalue (line_bool, "three"));
+ EXPECT_EQ_STR ("", cu_mount_getoptionvalue (line_bool, "one"));
+ EXPECT_EQ_STR ("", cu_mount_getoptionvalue (line_bool, "two"));
+ EXPECT_EQ_STR ("", cu_mount_getoptionvalue (line_bool, "three"));
OK (NULL == cu_mount_getoptionvalue (line_bool, "four"));
return (0);