]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - reports/slice-21n/failure-controls.lisp
Verify CTM/XTM semantic equivalence through TMDM and CXTM (Slice 22F)
[topic-maps.git] / reports / slice-21n / failure-controls.lisp
1 ;; Existing executor guards use excluded resourceData datatypes for Unsupported.
2 ;; Each fault targets one real Case Record in a disposable fresh ASDF process.
3 (require :asdf)
4 (assert (string= "2.5.4" (lisp-implementation-version)))
5 (setf *compile-verbose* nil *load-verbose* nil)
6 (asdf:load-asd (merge-pathnames "../../topic-maps.asd" *load-truename*))
7 (asdf:load-system "topic-maps/xtm/tests")
8 (let* ((family (uiop:getenv "TOPIC_MAPS_21N_FAMILY")) (mode (uiop:getenv "TOPIC_MAPS_21N_FAULT"))
9 (target (cond ((string= family "positive") "xtm2/in/empty.xtm")
10 ((string= family "negative") "xtm2/invalid/id-invalid.xtm")
11 ((string= family "name") "xtm2/in/name.xtm")
12 ((string= family "scope") "xtm2/in/name-scope.xtm")
13 ((string= family "iid") "xtm2/in/itemid-name.xtm")
14 ((string= family "variant") "xtm2/in/variant.xtm")
15 ((string= family "variant-negative") "xtm2/invalid/variant-missing-scope-duplicate.xtm")
16 ((string= family "merge-variant") "xtm2/in/merge-itemid-with-variants.xtm")
17 ((string= family "resource-ref") "xtm2/in/variant-resourceref.xtm")
18 ((string= family "resource-ref-relative") "xtm2/in/variant-resourceref-relative.xtm")
19 ((string= family "uri-data") "xtm2/in/variant-resourcedata-uri.xtm")
20 ((string= family "variant-iid") "xtm2/in/itemid-variant.xtm")
21 ((string= family "variant-iid-duplicate") "xtm2/in/variant-duplicate-iid.xtm")
22 ((member family '("map-reifier" "map-reifier-condition") :test #'string=) "xtm2/in/tm-reifier.xtm")
23 ((member family '("name-reifier" "name-reifier-condition") :test #'string=) "xtm2/in/name-reifier.xtm")
24 ((string= family "name-reifier-duplicate") "xtm2/in/name-duplicate-reified.xtm")
25 ((string= family "name-followup2") "xtm2/in/name-duplicate-reified2.xtm")
26 ((string= family "name-followup3") "xtm2/in/name-duplicate-reified3.xtm")
27 ((string= family "name-followup4") "xtm2/in/name-duplicate-reified4.xtm")
28 (t (error "Unknown control family ~S" family)))))
29 (if (member family '("map-reifier-condition" "name-reifier-condition") :test #'string=)
30 (let ((saved (symbol-function 'topic-maps.xtm.tests::map-reifier-error-control)))
31 (setf (symbol-function 'topic-maps.xtm.tests::map-reifier-error-control)
32 (lambda (label source class code &optional thunk map)
33 (funcall saved label source class code
34 (if (equal label (if (string= family "name-reifier-condition") "name:native-reuse-reifier" "reuse-reifier"))
35 (lambda ()
36 (let* ((other (topic-maps.tmdm:make-topic-map))
37 (foreign (topic-maps.tmdm:intern-topic other :item-identifier "urn:foreign")))
38 (topic-maps.tmdm:set-item-reifier map foreign)))
39 thunk) map))))
40 (if (string= mode "mismatch")
41 (let ((saved (symbol-function 'topic-maps.cxtm:canonicalize-octets))
42 (iri (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" target)))
43 (setf (symbol-function 'topic-maps.cxtm:canonicalize-octets)
44 (lambda (map &rest args)
45 (let ((actual (apply saved map args)))
46 (if (equal iri (getf args :base-locator))
47 (let ((changed (copy-seq actual))) (setf (aref changed 0) (logxor 1 (aref changed 0))) changed)
48 actual)))))
49 (let* ((saved (symbol-function 'topic-maps.xtm:deserialize-octets))
50 (source (cond ((string= mode "xml") "<a><b></a>")
51 ((string= mode "unsupported") (topic-maps.xtm.tests::document "<topic id='a'><name><value>N</value><variant><scope><topicRef href='#s'/></scope><resourceData datatype='http://www.w3.org/2001/XMLSchema#integer'>42</resourceData></variant></name></topic>"))
52 ((string= mode "tmdm") (topic-maps.xtm.tests::document
53 (cond ((member family '("name-reifier" "name-reifier-duplicate" "name-followup2" "name-followup3" "name-followup4") :test #'string=)
54 "<topic id='a'><name reifier='#r'><value>A</value></name><name reifier='#r'><value>B</value></name></topic>")
55 ((member family '("variant-iid" "variant-iid-duplicate") :test #'string=)
56 "<topic id='a'><name><value>N</value><variant><itemIdentity href='urn:collision'/><scope><topicRef href='#s'/></scope><resourceData>V</resourceData></variant><variant><itemIdentity href='urn:collision'/><scope><topicRef href='#s'/></scope><resourceData>W</resourceData></variant></name></topic>")
57 (t "<itemIdentity href='#a'/><topic id='a'/>"))))
58 ((string= mode "xtm") (topic-maps.xtm.tests::document "<topic id='2bad'/>"))
59 ((string= mode "wrong-cause") (topic-maps.xtm.tests::document
60 (if (string= family "variant-negative")
61 "<topic id='a'><name><scope><topicRef href='#base'/></scope><value>N</value><variant><scope><topicRef href='#extra'/></scope><resourceData>V</resourceData></variant></name></topic><topic id='base'><itemIdentity href='#extra'/></topic>"
62 "<topic/>")))
63 ((string= mode "accepted") (topic-maps.xtm.tests::document "<topic id='valid'/>"))
64 (t (error "Unknown control mode ~S" mode)))))
65 (setf (symbol-function 'topic-maps.xtm:deserialize-octets)
66 (lambda (raw &rest args)
67 (if (and (equal target (getf args :source-key)) (string= family "map-reifier") (string= mode "tmdm"))
68 ;; Generate an actual native conflict, retaining the previous
69 ;; Map-Reification executor control.
70 (let* ((map (topic-maps.tmdm:make-topic-map))
71 (r (topic-maps.tmdm:intern-topic map :item-identifier "urn:r"))
72 (owner (topic-maps.tmdm:intern-topic map :item-identifier "urn:owner"))
73 (name (topic-maps.tmdm:add-default-name owner "N")))
74 (topic-maps.tmdm:set-item-reifier map r)
75 (topic-maps.tmdm:set-item-reifier name r))
76 (apply saved (if (equal target (getf args :source-key)) (topic-maps.xtm.tests::bytes source) raw) args)))))))
77 (asdf:test-system "topic-maps/xtm"))
78 (error "Fault injection did not cause the required ASDF failure.")