Browse Source

Added in hooks test

Samuel W. Flint 7 years ago
parent
commit
31a7904586
1 changed files with 25 additions and 17 deletions
  1. 25 17
      main.c

+ 25 - 17
main.c

@@ -5,24 +5,32 @@
 #include "linkedList.h"
 #endif
 
-/* #ifndef HOOKS */
-/* #include "hooks.h" */
-/* #endif */
+#ifndef HOOKS
+#include "hooks.h"
+#endif
+
+void printA() {
+  printf("A\n");  
+}
+
+void printB() {
+  printf("B\n");
+}
+
+void printC() {
+  printf("C\n");
+}
 
 int main(int argc, char **argv)
 {
-  LISTEL *start = malloc(sizeof(LISTEL));
-  long number = 1;
-  start->data = (void *) number;
-  for(number = 2 ; number <= 10 ; number ++) {
-    LISTEL *insertAfterElement = start;
-    while (insertAfterElement->next != NULL)
-      insertAfterElement = insertAfterElement->next;
-    insertAfter((void *) number, insertAfterElement);
-  }
-  LISTEL *next = start;
-  while(next != NULL) {
-    printf("%ld\n", (long)next->data);
-    next = next->next;
-  }
+  HOOK * theHook = initializeHook(1);
+  addToHook(theHook, printA);
+  printf("Running with just printA:\n");
+  runHook(theHook);
+  addToHook(theHook, printB);
+  printf("With printA and printB:\n");
+  runHook(theHook);
+  addToHook(theHook, printC);
+  printf("With printA, printB and printC:\n");
+  runHook(theHook);
 }