]> andersk Git - libyaml.git/blobdiff - tests/run-dumper.c
Fix -Wformat compilation errors in tests
[libyaml.git] / tests / run-dumper.c
index 149dde01e308a0f588c62fc3745f42efce946e79..6236ee1eaa7f95ebce60a56a2f858de0da10a8b0 100644 (file)
@@ -2,9 +2,13 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <assert.h>
 #include <string.h>
 
+#ifdef NDEBUG
+#undef NDEBUG
+#endif
+#include <assert.h>
+
 #define BUFFER_SIZE 65536
 #define MAX_DOCUMENTS  16
 
@@ -73,8 +77,9 @@ error:
 }
 
 int compare_nodes(yaml_document_t *document1, int index1,
-        yaml_document_t *document2, int index2)
+        yaml_document_t *document2, int index2, int level)
 {
+    if (level++ > 1000) return 0;
     yaml_node_t *node1 = yaml_document_get_node(document1, index1);
     yaml_node_t *node2 = yaml_document_get_node(document2, index2);
     int k;
@@ -100,7 +105,7 @@ int compare_nodes(yaml_document_t *document1, int index1,
                 return 0;
             for (k = 0; k < (node1->data.sequence.items.top - node1->data.sequence.items.start); k ++) {
                 if (!compare_nodes(document1, node1->data.sequence.items.start[k],
-                            document2, node2->data.sequence.items.start[k])) return 0;
+                            document2, node2->data.sequence.items.start[k], level)) return 0;
             }
             break;
         case YAML_MAPPING_NODE:
@@ -109,12 +114,14 @@ int compare_nodes(yaml_document_t *document1, int index1,
                 return 0;
             for (k = 0; k < (node1->data.mapping.pairs.top - node1->data.mapping.pairs.start); k ++) {
                 if (!compare_nodes(document1, node1->data.mapping.pairs.start[k].key,
-                            document2, node2->data.mapping.pairs.start[k].key)) return 0;
+                            document2, node2->data.mapping.pairs.start[k].key, level)) return 0;
                 if (!compare_nodes(document1, node1->data.mapping.pairs.start[k].value,
-                            document2, node2->data.mapping.pairs.start[k].value)) return 0;
+                            document2, node2->data.mapping.pairs.start[k].value, level)) return 0;
             }
             break;
-
+        default:
+            assert(0);
+            break;
     }
     return 1;
 }
@@ -146,7 +153,7 @@ int compare_documents(yaml_document_t *document1, yaml_document_t *document2)
         return 0;
 
     if (document1->nodes.top != document1->nodes.start) {
-        if (!compare_nodes(document1, 1, document2, 1))
+        if (!compare_nodes(document1, 1, document2, 1, 0))
             return 0;
     }
 
@@ -173,8 +180,8 @@ int print_output(char *name, unsigned char *buffer, size_t size, int count)
         if (feof(file)) break;
     }
     fclose(file);
-    printf("#### (length: %d)\n", total_size);
-    printf("OUTPUT:\n%s#### (length: %d)\n", buffer, size);
+    printf("#### (length: %zd)\n", total_size);
+    printf("OUTPUT:\n%s#### (length: %zd)\n", buffer, size);
     return 0;
 }
 
@@ -220,7 +227,7 @@ main(int argc, char *argv[])
         yaml_emitter_t emitter;
 
         yaml_document_t document;
-        unsigned char buffer[BUFFER_SIZE];
+        unsigned char buffer[BUFFER_SIZE+1];
         size_t written = 0;
         yaml_document_t documents[MAX_DOCUMENTS];
         size_t document_number = 0;
@@ -228,7 +235,7 @@ main(int argc, char *argv[])
         int count = 0;
         int error = 0;
         int k;
-        memset(buffer, 0, BUFFER_SIZE);
+        memset(buffer, 0, BUFFER_SIZE+1);
         memset(documents, 0, MAX_DOCUMENTS*sizeof(yaml_document_t));
 
         printf("[%d] Loading, dumping, and loading again '%s': ", number, argv[number]);
@@ -297,7 +304,7 @@ main(int argc, char *argv[])
             yaml_document_delete(documents+k);
         }
 
-        printf("PASSED (length: %d)\n", written);
+        printf("PASSED (length: %zd)\n", written);
         print_output(argv[number], buffer, written, -1);
     }
 
This page took 0.10302 seconds and 4 git commands to generate.