aboutsummaryrefslogtreecommitdiffstats
path: root/doc/a_simple_example.c
diff options
context:
space:
mode:
Diffstat (limited to 'doc/a_simple_example.c')
-rw-r--r--doc/a_simple_example.c73
1 files changed, 33 insertions, 40 deletions
diff --git a/doc/a_simple_example.c b/doc/a_simple_example.c
index fb7d774..2153a70 100644
--- a/doc/a_simple_example.c
+++ b/doc/a_simple_example.c
@@ -1,52 +1,45 @@
+/* keep this include at the very top of the file */
#include "simple-test.h"
+
+/* any global variables, functions, other inclusions, etc.
+ * should be declared here */
#include "header_with_stuff_to_be_tested.h"
BEGIN_TEST
-/* a simple test using only stack mem */
-TEST("description of the first test")
+/* the string is a description of the test being run */
+TEST("check add()'s return value")
{
- int var1=2;
- int var2=4;
-
- /* add is a function included from our hypothetical
- * header_with_stuff_to_be_tested */
- EXPECT_INT("error message shown on failing",
- var1+var2, add(var1, var2));
+ int var1=2;
+ int var2=4;
+
+ /* add is a function included from our hypothetical
+ * header_with_stuff_to_be_tested */
+ EXPECT_INT(var1+var2, add(var1, var2));
}
-/* this test uses heap memory, so things get a bit
- * more complicated */
-TEST("this is the second test")
+TEST("compare two arrays of strings")
{
- /* first, ensure all your pointers which will
- * point to heap mem are declared */
- char *heap_string=NULL;
-
- /* next, declare a list of statements to be
- * called to clean up memory once the test
- * is completed */
- CLEANUP(
- if(heap_string != NULL)
- free(heap_string);
- );
-
- /* then, define the body of the test */
-
- /* STATE can be used to report (with pretty
- * formatting) the current state within the
- * test, which may be useful in the case of
- * a segfault */
- STATE("grabbing heap string");
-
- heap_string=get_heap_string_value();
-
- EXPECT_STR("i suck at grabbing pointers!",
- "expected value", heap_string);
-
- /* finally, call RETURN(); to run the
- * cleanup code and continue */
- RETURN();
+ int i;
+ char array1[][10] = {
+ "str1",
+ "str2",
+ "str3",
+ };
+ char array2[][10] = {
+ "str1",
+ "str2",
+ /* matching will fail here */
+ "different",
+ };
+
+ for(i = 0; i < sizeof(array1) / sizeof(char[10]); i++) {
+ /* ECHO can be used to print (with pretty
+ * formatting) the current state within the
+ * test */
+ ECHO("checking strs at i == %i", i);
+ EXPECT_STR_EQ(array1[i], array2[i]);
+ }
}
END_TEST