summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2012-01-08 15:29:19 +0100
committerJoel Rosdahl <joel@rosdahl.net>2012-01-08 15:29:19 +0100
commit49f381877dcc09bce8b199b6aa818a0786b3c841 (patch)
tree5735f2b432479eaa933391989467c4fcccca6451
parente9e8f5b2099092bb746a7ac0d635120bfb7cac86 (diff)
downloadccache-49f381877dcc09bce8b199b6aa818a0786b3c841.tar.gz
Use booleans for truth values
-rw-r--r--manifest.c14
-rw-r--r--test/framework.c28
-rw-r--r--test/framework.h40
3 files changed, 41 insertions, 41 deletions
diff --git a/manifest.c b/manifest.c
index ae6c2ff4..5b216981 100644
--- a/manifest.c
+++ b/manifest.c
@@ -66,7 +66,7 @@ static const uint32_t MAGIC = 0x63436d46U;
static const uint8_t VERSION = 0;
static const uint32_t MAX_MANIFEST_ENTRIES = 100;
-#define static_assert(e) do { enum { static_assert__ = 1/(e) }; } while (0)
+#define static_assert(e) do { enum { static_assert__ = 1/(e) }; } while (false)
struct file_info {
/* Index to n_files. */
@@ -155,7 +155,7 @@ free_manifest(struct manifest *mf)
(var) <<= 8; \
(var) |= ch_ & 0xFF; \
} \
- } while (0)
+ } while (false)
#define READ_STR(var) \
do { \
@@ -176,7 +176,7 @@ free_manifest(struct manifest *mf)
goto error; \
} \
(var) = x_strdup(buf_); \
- } while (0)
+ } while (false)
#define READ_BYTES(n, var) \
do { \
@@ -189,7 +189,7 @@ free_manifest(struct manifest *mf)
} \
(var)[i_] = ch_; \
} \
- } while (0)
+ } while (false)
static struct manifest *
create_empty_manifest(void)
@@ -286,14 +286,14 @@ error:
goto error; \
} \
} \
- } while (0)
+ } while (false)
#define WRITE_STR(var) \
do { \
if (gzputs(f, var) == EOF || gzputc(f, '\0') == EOF) { \
goto error; \
} \
- } while (0)
+ } while (false)
#define WRITE_BYTES(n, var) \
do { \
@@ -303,7 +303,7 @@ error:
goto error; \
} \
} \
- } while (0)
+ } while (false)
static int
write_manifest(gzFile f, const struct manifest *mf)
diff --git a/test/framework.c b/test/framework.c
index fd6ce721..bbb04800 100644
--- a/test/framework.c
+++ b/test/framework.c
@@ -170,13 +170,13 @@ cct_check_failed(const char *file, int line, const char *what,
fprintf(stderr, "\n");
}
-int
+bool
cct_check_int_eq(const char *file, int line, const char *expression,
int64_t expected, int64_t actual)
{
if (expected == actual) {
cct_check_passed(file, line, expression);
- return 1;
+ return true;
} else {
#ifdef HAVE_LONG_LONG
char *exp_str = format("%lld", (long long)expected);
@@ -188,27 +188,27 @@ cct_check_int_eq(const char *file, int line, const char *expression,
cct_check_failed(file, line, expression, exp_str, act_str);
free(exp_str);
free(act_str);
- return 0;
+ return false;
}
}
-int
+bool
cct_check_str_eq(const char *file, int line, const char *expression,
- const char *expected, const char *actual, int free1,
- int free2)
+ const char *expected, const char *actual, bool free1,
+ bool free2)
{
- int result;
+ bool result;
if (expected && actual && str_eq(actual, expected)) {
cct_check_passed(file, line, expression);
- result = 1;
+ result = true;
} else {
char *exp_str = expected ? format("\"%s\"", expected) : x_strdup("(null)");
char *act_str = actual ? format("\"%s\"", actual) : x_strdup("(null)");
cct_check_failed(file, line, expression, exp_str, act_str);
free(exp_str);
free(act_str);
- result = 0;
+ result = false;
}
if (free1) {
@@ -220,23 +220,23 @@ cct_check_str_eq(const char *file, int line, const char *expression,
return result;
}
-int
+bool
cct_check_args_eq(const char *file, int line, const char *expression,
struct args *expected, struct args *actual,
- int free1, int free2)
+ bool free1, bool free2)
{
- int result;
+ bool result;
if (expected && actual && args_equal(actual, expected)) {
cct_check_passed(file, line, expression);
- result = 1;
+ result = true;
} else {
char *exp_str = expected ? args_to_string(expected) : x_strdup("(null)");
char *act_str = actual ? args_to_string(actual) : x_strdup("(null)");
cct_check_failed(file, line, expression, exp_str, act_str);
free(exp_str);
free(act_str);
- result = 0;
+ result = false;
}
if (free1) {
diff --git a/test/framework.h b/test/framework.h
index ac86b5d3..fc9ff8df 100644
--- a/test/framework.h
+++ b/test/framework.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2011 Joel Rosdahl
+ * Copyright (C) 2010-2012 Joel Rosdahl
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@@ -58,7 +58,7 @@
cct_suite_end(); \
return _test_counter; \
} \
- } while (0)
+ } while (false)
#define CHECK(assertion) \
CHECKM(assertion, NULL)
@@ -70,7 +70,7 @@
cct_suite_end(); \
return _test_counter; \
} \
- } while (0)
+ } while (false)
/*****************************************************************************/
@@ -82,35 +82,35 @@
cct_suite_end(); \
return _test_counter; \
} \
- } while (0)
+ } while (false)
/*****************************************************************************/
#define CHECK_STR_EQ(expected, actual) \
- CHECK_POINTER_EQ_BASE(str, expected, actual, 0, 0)
+ CHECK_POINTER_EQ_BASE(str, expected, actual, false, false)
#define CHECK_STR_EQ_FREE1(expected, actual) \
- CHECK_POINTER_EQ_BASE(str, expected, actual, 1, 0)
+ CHECK_POINTER_EQ_BASE(str, expected, actual, true, false)
#define CHECK_STR_EQ_FREE2(expected, actual) \
- CHECK_POINTER_EQ_BASE(str, expected, actual, 0, 1)
+ CHECK_POINTER_EQ_BASE(str, expected, actual, false, true)
#define CHECK_STR_EQ_FREE12(expected, actual) \
- CHECK_POINTER_EQ_BASE(str, expected, actual, 1, 1)
+ CHECK_POINTER_EQ_BASE(str, expected, actual, true, true)
/*****************************************************************************/
#define CHECK_ARGS_EQ(expected, actual) \
- CHECK_POINTER_EQ_BASE(args, expected, actual, 0, 0)
+ CHECK_POINTER_EQ_BASE(args, expected, actual, false, false)
#define CHECK_ARGS_EQ_FREE1(expected, actual) \
- CHECK_POINTER_EQ_BASE(args, expected, actual, 1, 0)
+ CHECK_POINTER_EQ_BASE(args, expected, actual, true, false)
#define CHECK_ARGS_EQ_FREE2(expected, actual) \
- CHECK_POINTER_EQ_BASE(args, expected, actual, 0, 1)
+ CHECK_POINTER_EQ_BASE(args, expected, actual, false, true)
#define CHECK_ARGS_EQ_FREE12(expected, actual) \
- CHECK_POINTER_EQ_BASE(args, expected, actual, 1, 1)
+ CHECK_POINTER_EQ_BASE(args, expected, actual, true, true)
/*****************************************************************************/
@@ -124,14 +124,14 @@ void cct_test_end(void);
void cct_check_passed(const char *file, int line, const char *assertion);
void cct_check_failed(const char *file, int line, const char *assertion,
const char *expected, const char *actual);
-int cct_check_int_eq(const char *file, int line, const char *expression,
- int64_t expected, int64_t actual);
-int cct_check_str_eq(const char *file, int line, const char *expression,
- const char *expected, const char *actual, int free1,
- int free2);
-int cct_check_args_eq(const char *file, int line, const char *expression,
- struct args *expected, struct args *actual,
- int free1, int free2);
+bool cct_check_int_eq(const char *file, int line, const char *expression,
+ int64_t expected, int64_t actual);
+bool cct_check_str_eq(const char *file, int line, const char *expression,
+ const char *expected, const char *actual, bool free1,
+ bool free2);
+bool cct_check_args_eq(const char *file, int line, const char *expression,
+ struct args *expected, struct args *actual,
+ bool free1, bool free2);
void cct_chdir(const char *path);
void cct_wipe(const char *path);
void cct_create_fresh_dir(const char *path);