1 (in-package #:topic-maps.xtm.tests)
3 (defparameter *role-reifier-originals*
4 '("role-reifier" "role-duplicate-reified" "role-duplicate-reified2" "role-duplicate-reified3" "role-duplicate-reified4"))
5 (defun rrr-observe (raw key)
6 (let ((saved (symbol-function 'topic-maps.xtm::read-item-reifier)) (held nil)
7 (map nil) (native nil) (stages nil) (calls 0) (same nil) (counts nil))
10 (setf (symbol-function 'topic-maps.xtm::read-item-reifier)
11 (lambda (node item model)
12 (pushnew item held :test #'eq)
13 (dolist (i (topic-maps.tmdm::map-information-items model)) (pushnew i held :test #'eq))
14 (prog1 (funcall saved node item model)
15 (dolist (i (topic-maps.tmdm::map-information-items model)) (pushnew i held :test #'eq)))))
16 (multiple-value-setq (map native stages calls same counts) (arr-observe raw key)))
17 (setf (symbol-function 'topic-maps.xtm::read-item-reifier) saved))
18 (values map (union held native :test #'eq) stages calls same counts)))
19 (defun rrr-pure (label map held)
20 (let ((before (ik-state map)) (cx (mm-cxtm map)))
21 (check (format nil "role-reifier:~A:pure-CXTM-all-II-inverses-and-old-handles" label)
22 (and (equalp cx (mm-cxtm map)) (equal before (ik-state map)) (rrr-current-p map) (orr-held-p map held))) cx))
23 (defun rrr-original-model (name map)
24 (let* ((a (first (topic-map-associations map)))
25 (binary (member name '("role-duplicate-reified3" "role-duplicate-reified4") :test #'equal))
26 (both (equal name "role-duplicate-reified4"))
27 (players (if binary '("topic" "topic2") '("topic")))
28 (types (if binary '("roletype" "roletype2") '("roletype")))
29 (reifiers (if binary (list "reifier" (when both "reifier2")) '("reifier"))))
30 (check (format nil "role-reifier-original:~A:exact-native-Role-Parent-Type-Player-Reifier" name)
31 (and (= 1 (length (topic-map-associations map))) (= (if binary (if both 7 6) 4) (length (topic-map-topics map)))
32 (= (length players) (length (association-roles a))) (eq map (association-parent a))
33 (eq (by-id map "assoctype") (association-type a)) (null (association-scope a)) (null (item-reifier a))
34 (loop for p in players for rt in types for reifier in reifiers always
35 (some (lambda (role) (and (eq (by-id map p) (association-role-player role))
36 (eq (by-id map rt) (association-role-type role)) (eq a (association-role-parent role))
37 (equal (list role) (topic-roles-played (by-id map p)))
38 (if reifier (and (eq (by-id map reifier) (item-reifier role)) (eq role (topic-reified (by-id map reifier))))
39 (null (item-reifier role))) (null (item-identifiers role)))) (association-roles a)))
40 (null (item-identifiers a)) (null (item-identifiers map)) (null (item-reifier map))
41 (null (all-occurrences map)) (null (name-reifier-names map))
42 (every (lambda (topic) (and (= 1 (length (item-identifiers topic))) (null (topic-subject-identifiers topic))
43 (null (topic-subject-locators topic)) (null (topic-names topic)))) (topic-map-topics map)) (rrr-current-p map)))))
44 (defun rrr-condition-from (raw key)
45 ;; Preserve the actual native condition and observe only the outer real call,
46 ;; not nested disposable preflight copies. Do not add source slots to TMDM.
47 (let ((saved (symbol-function 'set-item-reifier)) (parser (symbol-function 'topic-maps.xml:parse-octets))
48 (depth 0) (frames nil) (calls 0) (same nil) (c nil))
51 (setf (symbol-function 'topic-maps.xml:parse-octets)
52 (lambda (input &rest args) (incf calls) (setf same (eq input raw)) (apply parser input args)))
53 (setf (symbol-function 'set-item-reifier)
57 (let* ((map (topic-maps.tmdm::item-topic-map item)) (before (ik-state map))
58 (prior (and topic (topic-reified topic)))
59 (both (and (typep item 'association-role) (typep prior 'association-role))))
60 (handler-case (funcall saved item topic)
63 (push (mm-fields "assignedItemKind" (string (type-of item))
64 "priorReifiedItemKind" (when prior (string (type-of prior)))
65 "actualMapAssociationCount" (length (topic-map-associations map)) "actualMapRoleCount" (length (as-roles map))
66 "sameRoleTypeAndPlayerEQ" (if (and both (eq (association-role-type item) (association-role-type prior))
67 (eq (association-role-player item) (association-role-player prior))) :true :false)
68 "differentParentsEQ" (if (and both (not (eq (association-role-parent item) (association-role-parent prior)))) :true :false)
69 "assignedParentTypeII" (coerce (when both (item-identifiers (association-type (association-role-parent item)))) 'vector)
70 "priorParentTypeII" (coerce (when both (item-identifiers (association-type (association-role-parent prior)))) 'vector)
71 "nativeAssignmentUnchanged" (if (equal before (ik-state map)) :true :false)) frames))
74 (setf c (condition-from (lambda () (deserialize-octets raw :document-iri *document* :source-key key)))))
75 (setf (symbol-function 'set-item-reifier) saved (symbol-function 'topic-maps.xml:parse-octets) parser))
76 (values c (nreverse frames) calls same)))
77 (defun rrr-negative-original ()
78 (let* ((id "xtm2/invalid/role-duplicate-reified.xtm")
79 (*document* (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" id))
80 (raw (file-bytes (corpus-path id))) (copy (copy-seq raw))
81 (spec '("role-duplicate-reified" reification-error :reifier-conflict "Topic already reifies a different information item." nil nil "XTM 4.3.2,4.19; TMDM 5.3.5,5.8: different Role Parents"))
82 (case (topic-maps.test-foundation:make-test-case :id id :category :invalid :source-pathname (corpus-path id)
83 :document-iri *document* :expected-outcome :ctm-rejection :clauses (list (seventh spec)))))
84 (multiple-value-bind (c frames calls same) (rrr-condition-from raw id)
85 (check "role-reifier-negative-original:actual-distinct-Parents-same-Type-Player-specific-native-cause"
86 (and (intended-negative-p spec c *document* id) (= 1 calls) same (equalp copy raw) (= 1 (length frames))
87 (let ((f (topic-maps.test-foundation::json-object-members (first frames))))
88 (and (equal "ASSOCIATION-ROLE" (cdr (assoc "assignedItemKind" f :test #'equal)))
89 (equal "ASSOCIATION-ROLE" (cdr (assoc "priorReifiedItemKind" f :test #'equal)))
90 (= 2 (cdr (assoc "actualMapAssociationCount" f :test #'equal))) (= 2 (cdr (assoc "actualMapRoleCount" f :test #'equal)))
91 (eq :true (cdr (assoc "sameRoleTypeAndPlayerEQ" f :test #'equal)))
92 (eq :true (cdr (assoc "differentParentsEQ" f :test #'equal)))
93 (equalp (vector (concatenate 'string *document* "#assoctype2")) (cdr (assoc "assignedParentTypeII" f :test #'equal)))
94 (equalp (vector (concatenate 'string *document* "#assoctype")) (cdr (assoc "priorParentTypeII" f :test #'equal)))
95 (eq :true (cdr (assoc "nativeAssignmentUnchanged" f :test #'equal)))))))
96 (record-negative-original-result case spec c *document* id) (setf *cases* (append *cases* (list case)))
97 (push (mm-fields "id" id "documentIRI" *document* "sourceKey" id "sourceBytes" (length raw)
98 "sourceHex" (format nil "~{~2,'0X~}" (coerce raw 'list)) "sourceText" (babel:octets-to-string raw :encoding :utf-8)
99 "qualifiedParserCalls" calls "originalOctetsEQ" (if same :true :false) "condition" (mm-condition c)
100 "actualNativeAssignments" (coerce frames 'vector) "intendedCauseReached" :true
101 "status" (string-downcase (string (topic-maps.test-foundation:test-case-status case)))) *role-reifier-outputs*)
102 (check "role-reifier-negative-original:no-preliminary-Unsupported-counted-as-PASS"
103 (and (not (typep c 'xtm-unsupported)) (eq :pass (topic-maps.test-foundation:test-case-status case)))))))
104 (defun role-reifier-original-contracts ()
105 (setf *role-reifier-outputs* nil)
106 (let ((previous (copy-list *cases*)))
107 (dolist (name *role-reifier-originals*)
108 (let* ((id (format nil "xtm2/in/~A.xtm" name))
109 (*document* (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" id))
110 (raw (file-bytes (corpus-path id))) (copy (copy-seq raw))
111 (baseline (corpus-path (format nil "xtm2/baseline/~A.xtm.cxtm" name))) (expected (file-bytes baseline))
112 (case (topic-maps.test-foundation:make-test-case :id id :category :valid :source-pathname (corpus-path id)
113 :document-iri *document* :expected-outcome :cxtm-equal :expected-baseline baseline
114 :clauses '("XTM 4.3.2,4.6,4.18-4.20" "TMDM 5.3.4-5.3.5,5.8,6.2,6.6-6.7")))
115 (map nil) (held nil) (stages nil) (calls 0) (same nil) (counts nil) (actual nil) (c nil))
116 (check (format nil "role-reifier-original:~A:unique-new-case" name)
117 (null (find id *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal)))
118 (setf *cases* (append *cases* (list case)))
121 (multiple-value-setq (map held stages calls same counts) (rrr-observe raw id))
122 (rrr-original-model name map)
123 (check (format nil "role-reifier-original:~A:actual-reads-qualified-parser-original-octets" name)
124 (and (= 1 calls) same (equalp raw copy)
125 (equal counts (if (member name '("role-reifier" "role-duplicate-reified2") :test #'equal) '(1) '(1 1)))))
126 (check (format nil "role-reifier-original:~A:old-handles-live" name) (orr-held-p map held))
127 (unless (equal name "role-reifier")
128 (check (format nil "role-reifier-original:~A:replaced-Role-handles" name)
129 (some (lambda (i) (and (typep i 'association-role) (not (eq i (canonical-association-role i))))) held)))
130 (setf actual (rrr-pure name map held))
131 (let ((other (deserialize-octets raw :document-iri *document* :source-key "different:Role-Reifier-provenance")))
132 (check (format nil "role-reifier-original:~A:source-key-independent" name)
133 (and (equalp (rrr-model map) (rrr-model other)) (equalp actual (mm-cxtm other))))))
134 (error (condition) (setf c condition)))
135 (record-original-result case actual expected c)
136 (push (mm-fields "id" id "documentIRI" *document* "sourceKey" id "sourceBytes" (length raw)
137 "sourceHex" (format nil "~{~2,'0X~}" (coerce raw 'list)) "sourceText" (babel:octets-to-string raw :encoding :utf-8)
138 "qualifiedParserCalls" calls "originalOctetsEQ" (if same :true :false) "model" (when map (rrr-model map))
139 "associationCountsAfterEachRead" (coerce counts 'vector)
140 "normalizationStages" (coerce (mapcar (lambda (s) (coerce s 'vector)) stages) 'vector)
141 "oldHandlesCanonicalAndLive" (if (and map (orr-held-p map held)) :true :false)
142 "actualBytes" (when actual (length actual)) "expectedBytes" (length expected)
143 "actualCXTM" (when actual (babel:octets-to-string actual :encoding :utf-8)) "expectedCXTM" (babel:octets-to-string expected :encoding :utf-8)
144 "firstDifferentByte" (when actual (mismatch actual expected)) "condition" (mm-condition c)
145 "status" (string-downcase (string (topic-maps.test-foundation:test-case-status case)))) *role-reifier-outputs*)
147 (check (format nil "role-reifier-original:~A:complete-original-CXTM-byte-exact" name) (equalp actual expected))))
148 (rrr-negative-original)
149 (check "role-reifier-original:requested-six-once-all-prior-PASS-preserved"
150 (and (every (lambda (case) (and (member case *cases* :test #'eq) (eq :pass (topic-maps.test-foundation:test-case-status case)))) previous)
151 (same-identifiers-p (mapcar #'topic-maps.test-foundation:test-case-id (set-difference *cases* previous :test #'eq))
152 (append (mapcar (lambda (n) (format nil "xtm2/in/~A.xtm" n)) *role-reifier-originals*) '("xtm2/invalid/role-duplicate-reified.xtm")))
153 (every (lambda (case) (= 1 (count (topic-maps.test-foundation:test-case-id case) *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal))) *cases*))))
154 (setf *role-reifier-outputs* (nreverse *role-reifier-outputs*)))
156 (defun rrr-role-xml (type player reifier &optional ids)
157 (format nil "<role~A>~A<type><topicRef href='~A'/></type><topicRef href='~A'/></role>"
158 (if reifier (format nil " reifier='~A'" reifier) "") (ik-ids ids) type player))
159 (defun rrr-xml (reifier &key association-reifier ids role-ids (type "#t") (role-type "#rt") (player "#p") themes extra-roles)
160 (format nil "<association~A>~A<type><topicRef href='~A'/></type>~A~A~A</association>"
161 (if association-reifier (format nil " reifier='~A'" association-reifier) "") (ik-ids ids) type
162 (if themes (format nil "<scope>~{<topicRef href='~A'/>~}</scope>" themes) "")
163 (rrr-role-xml role-type player reifier role-ids) (apply #'concatenate 'string extra-roles)))
164 (defun rrr-probe (label body verify &optional replaced)
165 (let* ((raw (bytes (document body))) (copy (copy-seq raw)))
166 (multiple-value-bind (map held stages calls same counts) (rrr-observe raw label)
167 (check (format nil "role-reifier:~A:productive-reader-qualified-XML-EQ-inverses" label)
168 (and (= 1 calls) same (equalp raw copy) (rrr-current-p map) (orr-held-p map held)))
170 (when replaced (check (format nil "role-reifier:~A:old-handles-replaced-and-resolvable" label)
171 (some (lambda (i) (not (eq i (topic-maps.tmdm::canonical-item i)))) held)))
172 (let ((cx (rrr-pure label map held)))
173 (push (mm-fields "label" label "sourceText" (document body) "documentIRI" *document* "sourceKey" label
174 "model" (rrr-model map) "CXTM" (babel:octets-to-string cx :encoding :utf-8)
175 "readAssociationCounts" (coerce counts 'vector) "normalizationStages" (coerce (mapcar (lambda (s) (coerce s 'vector)) stages) 'vector)
176 "oldHandlesCanonicalAndLive" :true) *role-reifier-controls*)) map)))
177 (defun rrr-error (label body class code &key map-reifier)
178 (let ((source (if map-reifier (map-reifier-xml map-reifier body) (document body))))
179 (multiple-value-bind (c frames calls same) (rrr-condition-from (bytes source) label)
180 (let ((actual (cond ((typep c 'topic-maps.xtm:xtm-error) (error-code c))
181 ((typep c 'reification-error) (reification-error-code c))
182 ((typep c 'item-identifier-error) (item-identifier-error-code c)))))
183 (check (format nil "role-reifier-error:~A:exact-class-code-parser-and-native-atomicity" label)
184 (and (eq (type-of c) class) (eq code actual) (= 1 calls) same
185 (every (lambda (f) (eq :true (cdr (assoc "nativeAssignmentUnchanged" (topic-maps.test-foundation::json-object-members f) :test #'equal)))) frames)))
186 (when (typep c 'topic-maps.xtm:xtm-error)
187 (check (format nil "role-reifier-error:~A:source-document-position-and-cause" label)
188 (and (equal *document* (error-document-iri c)) (equal label (error-source-key c))
189 (if (typep c 'xtm-xml-error) (topic-maps.xtm:error-cause c) (and (integerp (error-line c)) (integerp (error-column c)))))))
190 (push (mm-fields "label" label "sourceText" source "documentIRI" *document* "sourceKey" label
191 "condition" (mm-condition c) "actualNativeAssignments" (coerce frames 'vector)) *role-reifier-controls*) c))))
192 (defun role-reifier-tests ()
193 (setf *role-reifier-controls* nil)
194 (dolist (position '("unknown" "before" "after"))
195 (rrr-probe (concatenate 'string "definition-" position)
196 (concatenate 'string (if (equal position "before") "<topic id='r'/>" "") (rrr-xml "#r") (if (equal position "after") "<topic id='r'/>" ""))
197 (lambda (map) (let* ((role (first (as-roles map))) (r (by-id map "r")))
198 (check (format nil "role-reifier:definition-~A:one-II-Topic-no-invented-SI-SL" position)
199 (and (= 4 (length (topic-map-topics map))) (eq r (item-reifier role)) (eq role (topic-reified r))
200 (null (topic-subject-identifiers r)) (null (topic-subject-locators r))
201 (equal (list (concatenate 'string *document* "#r")) (item-identifiers r))))))))
202 (dolist (category '("itemIdentity" "subjectIdentifier" "subjectLocator"))
203 (rrr-probe (concatenate 'string "lookup-" category)
204 (format nil "<topic id='known'><~A href='urn:r'/></topic>~A" category (rrr-xml "urn:r"))
205 (lambda (map) (let* ((known (by-id map "known")) (r (item-reifier (first (as-roles map)))) (sl (equal category "subjectLocator")))
206 (check (format nil "role-reifier:lookup-~A:II-only-and-native-cross-merge" category)
207 (and (= (if sl 5 4) (length (topic-map-topics map)))
208 (if sl (and (not (eq r known)) (equal '("urn:r") (item-identifiers r))
209 (equal (list (concatenate 'string *document* "#known")) (item-identifiers known)) (null (topic-reified known)))
210 (and (eq r known) (same-identifiers-p (list (concatenate 'string *document* "#known") "urn:r") (item-identifiers r))))))))))
211 (dolist (ref '("urn:r" "../%E9%A6%AC#r"))
212 (rrr-probe (concatenate 'string "resolved-IRI:" ref) (rrr-xml ref :ids '("urn:a") :role-ids '("urn:role"))
213 (lambda (map) (let* ((a (first (topic-map-associations map))) (role (first (association-roles a))))
214 (check (format nil "role-reifier:~A:separate-Association-Role-Reifier-II" ref)
215 (and (equal '("urn:a") (item-identifiers a)) (equal '("urn:role") (item-identifiers role))
216 (equal (list (mm-child-iri ref)) (item-identifiers (item-reifier role)))))))))
217 (dolist (same-parent '(nil t))
218 (dolist (different '(nil t))
219 (let* ((label (format nil "duplicates:~A:~A" (if same-parent "same-parent" "equal-Associations") (if different "two-Reifiers" "same-Reifier")))
220 (second-role (rrr-role-xml "#rt" "#p" (if different "#u" "#r") '("urn:rb"))))
222 (if same-parent (rrr-xml "#r" :association-reifier "#ar" :ids '("urn:a") :role-ids '("urn:ra") :extra-roles (list second-role))
223 (concatenate 'string (rrr-xml "#r" :association-reifier "#ar" :ids '("urn:a") :role-ids '("urn:ra"))
224 (rrr-xml (if different "#u" "#r") :association-reifier "#ar" :ids '("urn:b") :role-ids '("urn:rb"))))
225 (lambda (map) (let* ((a (first (topic-map-associations map))) (role (first (association-roles a))))
226 (check (format nil "role-reifier:~A:native-signature-normalization-and-all-II" label)
227 (and (= 1 (length (topic-map-associations map))) (= 1 (length (as-roles map)))
228 (same-identifiers-p (if same-parent '("urn:a") '("urn:a" "urn:b")) (item-identifiers a))
229 (same-identifiers-p '("urn:ra" "urn:rb") (item-identifiers role)) (eq (by-id map "r") (item-reifier role))
230 (eq a (topic-reified (by-id map "ar"))) (or (not different) (eq (by-id map "r") (by-id map "u"))))))) t))))
231 (rrr-probe "reversed-Role-order-and-duplicates"
232 (concatenate 'string (rrr-xml "#r" :extra-roles (list (rrr-role-xml "#rt2" "#q" "#u")))
233 (rrr-xml "#u" :role-type "#rt2" :player "#q" :extra-roles (list (rrr-role-xml "#rt" "#p" "#r") (rrr-role-xml "#rt" "#p" "#r"))))
234 (lambda (map) (check "role-reifier:reversed-order:canonical-Role-Reifier-mapping"
235 (and (= 1 (length (topic-map-associations map))) (= 2 (length (as-roles map)))
236 (eq (by-id map "p") (association-role-player (topic-reified (by-id map "r"))))
237 (eq (by-id map "q") (association-role-player (topic-reified (by-id map "u"))))))) t)
238 (rrr-probe "Reifier-merge-collapses-later-Role-signatures"
239 (rrr-xml "#r" :role-ids '("urn:ra") :extra-roles
240 (list (rrr-role-xml "#rt" "#p" "#u" '("urn:rb"))
241 (rrr-role-xml "#rt2" "#r" "#r2" '("urn:later-a")) (rrr-role-xml "#rt2" "#u" "#r3" '("urn:later-b"))))
242 (lambda (map) (check "role-reifier:cascade:later-source-Roles-match-current-Parent-and-Topics"
243 (and (= 1 (length (topic-map-associations map))) (= 2 (length (as-roles map)))
244 (eq (by-id map "r") (by-id map "u")) (eq (by-id map "r2") (by-id map "r3"))
245 (same-identifiers-p '("urn:ra" "urn:rb") (item-identifiers (topic-reified (by-id map "r"))))
246 (same-identifiers-p '("urn:later-a" "urn:later-b") (item-identifiers (topic-reified (by-id map "r2"))))))) t)
250 (setf *role-reifier-controls* (nreverse *role-reifier-controls*)))
251 (defun rrr-late-merges ()
252 (dolist (category '("subjectIdentifier" "subjectLocator" "itemIdentity"))
253 (rrr-probe (concatenate 'string "late-" category)
254 (concatenate 'string (rrr-xml "#r" :association-reifier "#ar" :ids '("urn:a") :role-ids '("urn:ra") :themes '("#s"))
255 (rrr-xml "#u" :association-reifier "#au" :ids '("urn:b") :role-ids '("urn:rb") :type "#tt" :role-type "#rrt" :player "#q" :themes '("#ss"))
256 (format nil "<topic id='p'><~A href='urn:p'/></topic><topic id='q'><~A href='urn:p'/></topic><topic id='rt'><~A href='urn:rt'/></topic><topic id='rrt'><~A href='urn:rt'/></topic><topic id='s'><~A href='urn:s'/></topic><topic id='ss'><~A href='urn:s'/></topic><topic id='t'><~A href='urn:t'/></topic><topic id='tt'><~A href='urn:t'/></topic>" category category category category category category category category))
257 (lambda (map) (let* ((a (first (topic-map-associations map))) (role (first (association-roles a))))
258 (check (format nil "role-reifier:late-~A:Association-Role-Reifier-inverses-II-and-references" category)
259 (and (= 1 (length (topic-map-associations map))) (= 1 (length (as-roles map)))
260 (eq (by-id map "r") (by-id map "u")) (eq (by-id map "ar") (by-id map "au"))
261 (eq a (topic-reified (by-id map "ar"))) (eq role (topic-reified (by-id map "r")))
262 (eq (by-id map "t") (association-type a)) (eq (by-id map "p") (association-role-player role))
263 (eq (by-id map "rt") (association-role-type role)) (equal (list (by-id map "s")) (association-scope a))
264 (same-identifiers-p '("urn:a" "urn:b") (item-identifiers a)) (same-identifiers-p '("urn:ra" "urn:rb") (item-identifiers role)))))) t)))
265 (defun rrr-negative-tests ()
266 (dolist (row '(("bad-percent" "%GG" :invalid-percent-escape) ("bad-percent-UTF8" "%C3%28" :invalid-percent-utf8) ("bad-IRI" "x#y#z" :invalid-iri)))
267 (rrr-error (first row) (rrr-xml (second row)) 'xtm-rejection (third row)))
268 (dolist (row '(("extra-attribute" "<association><type><topicRef href='#t'/></type><role reifier='#r' bogus='1'><type><topicRef href='#rt'/></type><topicRef href='#p'/></role></association>" xtm-rejection :unexpected-attribute)
269 ("reifier-on-type" "<association><type><topicRef href='#t'/></type><role><type reifier='#r'><topicRef href='#rt'/></type><topicRef href='#p'/></role></association>" xtm-rejection :unexpected-attribute)
270 ("reifier-on-topicRef" "<association><type><topicRef href='#t'/></type><role><type><topicRef href='#rt'/></type><topicRef reifier='#r' href='#p'/></role></association>" xtm-rejection :unexpected-attribute)
271 ("malformed-XML" "<association><type><topicRef href='#t'/></type><role reifier='#r'></association>" xtm-xml-error :xml-not-well-formed)
272 ("missing-Type" "<association><type><topicRef href='#t'/></type><role reifier='#r'><topicRef href='#p'/></role></association>" xtm-rejection :missing-type)
273 ("missing-Player" "<association><type><topicRef href='#t'/></type><role reifier='#r'><type><topicRef href='#rt'/></type></role></association>" xtm-rejection :missing-role-player)
274 ("multiple-Players" "<association><type><topicRef href='#t'/></type><role reifier='#r'><type><topicRef href='#rt'/></type><topicRef href='#p'/><topicRef href='#q'/></role></association>" xtm-rejection :role-player-cardinality)))
275 (apply #'rrr-error row))
276 (rrr-error "different-Parents-same-Type-Player-and-Reifier" (concatenate 'string (rrr-xml "#r") (rrr-xml "#r" :type "#other")) 'reification-error :reifier-conflict)
277 (rrr-error "different-Players-same-Reifier" (rrr-xml "#r" :extra-roles (list (rrr-role-xml "#rt" "#q" "#r"))) 'reification-error :reifier-conflict)
278 (rrr-error "different-Role-Types-same-Reifier" (rrr-xml "#r" :extra-roles (list (rrr-role-xml "#rt2" "#p" "#r"))) 'reification-error :reifier-conflict)
279 (rrr-error "Role-and-Association-same-Reifier" (rrr-xml "#r" :association-reifier "#r") 'reification-error :reifier-conflict)
280 (rrr-error "Occurrence-and-Role-same-Reifier" (concatenate 'string "<topic id='owner'>" (orr-xml "#r") "</topic>" (rrr-xml "#r")) 'reification-error :reifier-conflict)
281 (rrr-error "Map-and-Role-same-Reifier" (rrr-xml "#r") 'reification-error :reifier-conflict :map-reifier "#r")
282 (dolist (category '("subjectIdentifier" "subjectLocator" "itemIdentity"))
283 (rrr-error (concatenate 'string "late-Reifier-conflict-" category)
284 (concatenate 'string (rrr-xml "#r") (rrr-xml "#u" :type "#other")
285 (format nil "<topic id='r'><~A href='urn:r'/></topic><topic id='u'><~A href='urn:r'/></topic>" category category)) 'reification-error :reifier-conflict))
286 (rrr-error "Role-II-not-Reifier-II" (rrr-xml "urn:same" :role-ids '("urn:same")) 'topic-maps.tmdm::occurrence-identifier-error :duplicate-item-identifier)
287 (rrr-error "Role-II-not-Association-II" (rrr-xml "#r" :ids '("urn:same") :role-ids '("urn:same")) 'item-identifier-error :duplicate-item-identifier)
288 (rrr-error "anyType-still-Unsupported" (concatenate 'string (rrr-xml "#r") "<topic id='owner'><occurrence><type><topicRef href='#t'/></type><resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'>V</resourceData></occurrence></topic>") 'xtm-unsupported :resource-data-datatype))
289 (defun rrr-import-test ()
290 (let* ((child (mm-child-iri "child.xtm"))
291 (raw (bytes (document (concatenate 'string "<topic id='p'><subjectIdentifier href='urn:player'/></topic>"
292 (rrr-xml "#r" :association-reifier "#ar" :ids '("urn:imported-Association") :role-ids '("urn:imported-Role") :themes '("#s")))))))
293 (mm-call "Role-Reification-import" (document (concatenate 'string (mm-directive "child.xtm") "<topic id='local'><subjectIdentifier href='urn:player'/></topic>"))
294 (list (list child raw "child:Role-Reification"))
295 (lambda (map imports calls) (declare (ignore calls))
296 (let* ((a (first (topic-map-associations map))) (role (first (association-roles a))) (r (mm-local map child "r")))
297 (check "role-reifier:import:Parents-Player-II-Role-and-Association-inverses-source-preservation"
298 (and (rrr-current-p map) (eq map (association-parent a)) (eq a (association-role-parent role))
299 (eq (by-id map "local") (association-role-player role)) (eq r (item-reifier role)) (eq role (topic-reified r))
300 (eq a (topic-reified (mm-local map child "ar"))) (null (item-identifiers map))
301 (equal '("urn:imported-Association") (item-identifiers a)) (equal '("urn:imported-Role") (item-identifiers role))
302 (every (lambda (record) (let* ((source (first record)) (resolve (second record))
303 (sa (first (topic-map-associations source))) (sr (first (association-roles sa))))
304 (and (rrr-current-p source) (eq a (funcall resolve sa)) (eq role (funcall resolve sr))
305 (eq r (funcall resolve (item-reifier sr)))))) imports))))
306 (push (mm-fields "label" "native-Role-Reification-import" "sourceText" (babel:octets-to-string raw :encoding :utf-8)
307 "model" (rrr-model map) "sourceMapPreserved" :true) *role-reifier-controls*)))))