From 02b3dc56f5d4c96ecd19130508a158074be4c10b Mon Sep 17 00:00:00 2001 From: Snaipe Date: Wed, 11 Mar 2015 19:02:47 +0100 Subject: [PATCH] Added assert samples --- samples/Makefile.am | 3 ++- samples/asserts.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 samples/asserts.c diff --git a/samples/Makefile.am b/samples/Makefile.am index 0cdbd5b..3fb962a 100644 --- a/samples/Makefile.am +++ b/samples/Makefile.am @@ -3,10 +3,11 @@ TESTS = \ report \ suites \ fixtures \ + asserts \ simple TESTS_ENVIRONMENT = CRITERION_ALWAYS_SUCCEED=1 check_PROGRAMS = $(TESTS) -CFLAGS = -I$(top_srcdir)/include/ +CFLAGS = -I$(top_srcdir)/include/ -std=c99 LDADD = -L$(top_srcdir)/ -lcriterion diff --git a/samples/asserts.c b/samples/asserts.c new file mode 100644 index 0000000..deec0b4 --- /dev/null +++ b/samples/asserts.c @@ -0,0 +1,43 @@ +#include + +Test(asserts, base) { + assert(true); + expect(true); + + assert(true, "Assertions may take failure messages"); + + expect(false, "assert is fatal, expect isn't"); + assert(false, "This assert runs"); + assert(false, "This does not"); +} + +Test(asserts, string) { + assert_strings_equal("hello", "hello"); + assert_strings_not_equal("hello", "olleh"); + + assert_strings_gt("hello", "hell"); + assert_strings_geq("hello", "hell"); + assert_strings_geq("hello", "hello"); + + assert_strings_lt("hell", "hello"); + assert_strings_leq("hell", "hello"); + assert_strings_leq("hello", "hello"); +} + +Test(asserts, native) { + assert_equal(1, 1); + assert_not_equal(1, 2); + + assert_lt(1, 2); + assert_leq(1, 2); + assert_leq(2, 2); + + assert_gt(2, 1); + assert_geq(2, 1); + assert_geq(2, 2); +} + +Test(asserts, float) { + assert_not_equal(0.1 * 0.1, 0.01); + assert_float_equal(0.1 * 0.1, 0.01, 0.001); +}