Add tests for pointer comparison

This commit is contained in:
thomas committed 2018-03-20 14:11:21 +01:00
1 parent 498a78cd9f
commit 6c30e282ef
2 files changed
+23

No files matched your search

+3
View File
@@ -3,6 +3,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <inttypes.h>
#define TT_FAIL(error, ...) dprintf(tt_pipe[1], "\"%s\" Line %d: %s >> " error "\n", tt_current->filename, __LINE__, tt_current->name, ##__VA_ARGS__); #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_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_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_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) \ #define TEST(name) \
int ttt_##name(); \ int ttt_##name(); \
+20
View File
@@ -46,3 +46,23 @@ TEST(FAIL_two_equal_strings)
{ {
ASSERT_EQ_STR("Hello", "World", 5); 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);
}