Browse Source

Add test for multi-read introspection

master
Macoy Madson 2 months ago
parent
commit
3dbdefafcd
  1. 3
      .gitignore
  2. 58
      src/Introspection.cake

3
.gitignore

@ -74,4 +74,5 @@ test/imgui.ini
test/TestSerialize.cakedata
test/TestDynamicArraySerialize.cakedata
test/TestDictionarySerialize.cakedata
test/TestDictionarySerializeStrDict.cakedata
test/TestDictionarySerializeStrDict.cakedata
test/MultiReads.cakedata

58
src/Introspection.cake

@ -1511,10 +1511,66 @@
;; (pointer overrides)
null))
(fprintf stderr "Struct A baseline:\n")
(unless (introspect-test-struct my-struct--metadata (addr a) "TestSerialize.cakedata")
(return 1))
(scope ;; Test multi-reads
(fprintf stderr "\nMulti-reads:\n")
(scope ;; Write to a file
(var out-file (* FILE) (fopen "MultiReads.cakedata" "w"))
(unless out-file (return false))
(unless (write-introspect-struct-s-expr my-struct--metadata (addr a) out-file
write-introspect-struct-add-newline)
(fclose out-file)
(return false))
(unless (write-introspect-struct-s-expr my-struct--metadata (addr a) out-file
write-introspect-struct-add-newline)
(fclose out-file)
(return false))
(fclose out-file))
(scope
(var read-struct-a my-struct (array 0))
(var read-struct-b my-struct (array 0))
(var in-file (* FILE) (fopen "MultiReads.cakedata" "r"))
(unless in-file (return 1))
(var file-contents (* (const char)) (read-file-into-memory in-file))
(fclose in-file)
(var num-chars-read (unsigned int) 0)
(unless (read-introspect-struct-s-expr my-struct--metadata (addr read-struct-a)
file-contents malloc (addr num-chars-read))
(free-introspect-struct-fields
my-struct--metadata (addr read-struct-a) free)
(free (type-cast file-contents (* void)))
(return 1))
(unless (read-introspect-struct-s-expr my-struct--metadata (addr read-struct-b)
(+ num-chars-read file-contents) malloc null)
(free-introspect-struct-fields
my-struct--metadata (addr read-struct-b) free)
(free (type-cast file-contents (* void)))
(return 1))
(var succeeded bool true)
(unless (= 0 (compare-introspect-struct-print-result my-struct--metadata
(addr read-struct-a)
(addr read-struct-b)))
(fprintf stderr "error: structs read in do not equal each other\n")
(set succeeded false))
(unless (= 0 (compare-introspect-struct-print-result my-struct--metadata
(addr a)
(addr read-struct-b)))
(fprintf stderr "error: structs read in do not equal baseline\n")
(set succeeded false))
(free (type-cast file-contents (* void)))
(free-introspect-struct-fields
my-struct--metadata (addr read-struct-a) free)
(free-introspect-struct-fields
my-struct--metadata (addr read-struct-b) free)
(unless succeeded (return 1))
(fprintf stderr "Succeeded\n")))
(scope ;; Test errors
(var read-struct my-struct (array 0))
(scope

Loading…
Cancel
Save