From 6c30e282ef347e44e3346fc857061bc4c9b77fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Wed, 14 Feb 2018 16:11:59 +0100 Subject: [PATCH] Add tests for pointer comparison --- toolchain/ttest.h | 3 +++ toolchain/ttest.tt | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/toolchain/ttest.h b/toolchain/ttest.h index 6e6a9e2..1f92aaa 100644 --- a/toolchain/ttest.h +++ b/toolchain/ttest.h @@ -3,6 +3,7 @@ #include #include #include +#include #define TT_FAIL(error, ...) dprintf(tt_pipe[1], "\"%s\" Line %d: %s >> " error "\n", tt_current->filename, __LINE__, tt_current->name, ##__VA_ARGS__); @@ -56,6 +57,8 @@ #define ASSERT_EQ_CHR(lhs, rhs) ASSERT_EQUAL(char, "c", lhs, rhs) #define ASSERT_NEQ_CHR(lhs, rhs) ASSERT_NOT_EQUAL(char, "c", lhs, rhs) #define ASSERT_EQ_STR(lhs, rhs, n) ASSERT_STRN(lhs, rhs, n) +#define ASSERT_EQ_PTR(lhs, rhs) ASSERT_EQUAL(uintptr_t, PRIxPTR, lhs, rhs) +#define ASSERT_NEQ_PTR(lhs, rhs) ASSERT_NOT_EQUAL(uintptr_t, PRIxPTR, lhs, rhs) #define TEST(name) \ int ttt_##name(); \ diff --git a/toolchain/ttest.tt b/toolchain/ttest.tt index 6aad2e1..6ec825a 100644 --- a/toolchain/ttest.tt +++ b/toolchain/ttest.tt @@ -46,3 +46,23 @@ TEST(FAIL_two_equal_strings) { ASSERT_EQ_STR("Hello", "World", 5); } + +int a, b; + +TEST(two_equal_pointers) +{ + ASSERT_EQ_PTR(&a, &a); +} +TEST(FAIL_two_equal_pointers) +{ + ASSERT_EQ_PTR(&a, &b); +} + +TEST(two_different_pointers) +{ + ASSERT_NEQ_PTR(&a, &b); +} +TEST(FAIL_two_different_pointers) +{ + ASSERT_NEQ_PTR(&a, &a); +}