]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - tests/xtm-association-reifier-native.lisp
test: prove CTM/XTM anyType equivalence (slice 22T)
[topic-maps.git] / tests / xtm-association-reifier-native.lisp
1 (in-package #:topic-maps.xtm.tests)
2
3 (defvar *association-reifier-native* nil)
4 (defun arr-current-p (map)
5 (and (orr-current-p map)
6 (every (lambda (a) (let ((r (item-reifier a)))
7 (or (null r) (and (eq r (canonical-topic r)) (eq map (topic-parent r)) (eq a (topic-reified r)))))) (topic-map-associations map))))
8 (defun arr-model (map)
9 (mm-fields "existingModel" (orr-model map) "canonicalAssociationReifierInverseEQ" (if (arr-current-p map) :true :false)
10 "associationReifiers" (coerce (loop for a in (topic-map-associations map) collect
11 (mm-fields "associationItemIdentifiers" (coerce (item-identifiers a) 'vector)
12 "reifierItemIdentifiers" (coerce (when (item-reifier a) (item-identifiers (item-reifier a))) 'vector)
13 "inverseReifiedEQ" (if (or (null (item-reifier a)) (eq a (topic-reified (item-reifier a)))) :true :false))) 'vector)))
14 (defun arr-native-tests ()
15 ;; Native API probes, executed before Reader edits and repeated through ASDF.
16 ;; No Reader calls or original registrations occur here.
17 (setf *association-reifier-native* nil)
18 (dolist (kind '("subjectIdentifier" "subjectLocator" "itemIdentity"))
19 (let* ((map (make-topic-map)) (type (intern-topic map :item-identifier "urn:type"))
20 (rt (intern-topic map :item-identifier "urn:role-type")) (s (intern-topic map :item-identifier "urn:scope"))
21 (p (intern-topic map :item-identifier "urn:p")) (q (intern-topic map :item-identifier "urn:q"))
22 (a (make-association map type (list (list rt p)) :scope (list s)))
23 (b (make-association map type (list (list rt q)) :scope (list s)))
24 (ra (first (association-roles a))) (rb (first (association-roles b)))
25 (r (intern-topic map :item-identifier "urn:r")) (u (intern-topic map :item-identifier "urn:u")))
26 (add-item-identifier a "urn:a") (add-item-identifier b "urn:b")
27 (add-item-identifier ra "urn:ra") (add-item-identifier rb "urn:rb")
28 (check (format nil "association-reifier-native:~A:assign-and-inverse" kind)
29 (and (eq a (set-item-reifier a r)) (eq b (set-item-reifier b u))
30 (eq r (item-reifier a)) (eq a (topic-reified r)) (eq b (topic-reified u))))
31 (let ((identity-kind (cond ((equal kind "subjectIdentifier") :subject-identifier)
32 ((equal kind "subjectLocator") :subject-locator)
33 (t :item-identifier))))
34 (add-topic-identifier p identity-kind "urn:common")
35 (add-topic-identifier q identity-kind "urn:common"))
36 (let ((c (canonical-association a)) (role (canonical-association-role ra)))
37 (check (format nil "association-reifier-native:~A:merge-signatures-all-II-and-old-handles" kind)
38 (and (= 1 (length (topic-map-associations map))) (eq c (canonical-association b))
39 (not (eq a c)) (not (eq b c)) (eq map (association-parent c)) (eq type (association-type c))
40 (equal (list s) (association-scope c)) (equal (list role) (association-roles c))
41 (eq role (canonical-association-role rb)) (eq c (association-role-parent role))
42 (eq (canonical-topic p) (canonical-topic q)) (eq (canonical-topic p) (association-role-player role))
43 (same-identifiers-p '("urn:a" "urn:b") (item-identifiers c))
44 (same-identifiers-p '("urn:ra" "urn:rb") (item-identifiers role))
45 (eq (canonical-topic r) (canonical-topic u)) (eq (canonical-topic r) (item-reifier c))
46 (same-identifiers-p '("urn:r" "urn:u") (item-identifiers (item-reifier c)))
47 (eq c (topic-reified r)) (eq c (topic-reified u)) (arr-current-p map))))
48 (push (mm-fields "label" kind "kind" "native-TMDM-probe-not-original-contract" "model" (arr-model map)
49 "oldAssociationRoleTopicHandlesResolveEQ" :true) *association-reifier-native*)))
50 (let* ((map (make-topic-map)) (type (intern-topic map :item-identifier "urn:t"))
51 (rt (intern-topic map :item-identifier "urn:rt")) (p (intern-topic map :item-identifier "urn:p"))
52 (r (intern-topic map :item-identifier "urn:r"))
53 (a (make-association map type (list (list rt p)))))
54 (set-item-reifier a r) (add-item-identifier a "urn:a")
55 (let ((b (make-association map type (list (list rt p)))))
56 (set-item-reifier b r) (add-item-identifier b "urn:b")
57 (check "association-reifier-native:equal-Associations-same-Reifier-native-normalization"
58 (and (= 1 (length (topic-map-associations map))) (eq (canonical-association a) b)
59 (eq r (item-reifier b)) (eq b (topic-reified r))
60 (same-identifiers-p '("urn:a" "urn:b") (item-identifiers b)) (arr-current-p map)))
61 (push (mm-fields "label" "same-Reifier" "kind" "native-TMDM-probe-not-original-contract" "model" (arr-model map)) *association-reifier-native*)))
62 (let* ((map (make-topic-map)) (type (intern-topic map :item-identifier "urn:t"))
63 (rt (intern-topic map :item-identifier "urn:rt")) (p (intern-topic map :item-identifier "urn:p"))
64 (q (intern-topic map :item-identifier "urn:q"))
65 (a (make-association map type (list (list rt p)))) (b (make-association map type (list (list rt q))))
66 (r (intern-topic map :item-identifier "urn:r")) (u (intern-topic map :item-identifier "urn:u"))
67 (o (add-occurrence p type "V")))
68 (set-item-reifier a r) (set-item-reifier b u)
69 (dolist (row (list (list "different-Association" (lambda () (set-item-reifier b r)))
70 (list "Occurrence-versus-Association" (lambda () (set-item-reifier o r)))
71 (list "Map-versus-Association" (lambda () (set-item-reifier map r)))
72 (list "late-Reifier-merge" (lambda () (merge-topics r u)))))
73 (let* ((before (ik-state map)) (c (condition-from (second row))))
74 (check (format nil "association-reifier-native:~A:exact-atomic-conflict" (first row))
75 (and (eq (type-of c) 'reification-error) (eq :reifier-conflict (reification-error-code c))
76 (equal before (ik-state map)) (eq a (topic-reified r)) (eq b (topic-reified u)) (arr-current-p map)))
77 (push (mm-fields "label" (first row) "kind" "native-TMDM-probe-not-original-contract" "condition" (mm-condition c)
78 "nativeOperationUnchanged" (if (equal before (ik-state map)) :true :false)) *association-reifier-native*)))
79 (add-item-identifier a "urn:association")
80 (let* ((before (ik-state map)) (c (condition-from (lambda () (intern-topic map :item-identifier "urn:association")))))
81 (check "association-reifier-native:own-II-not-Reifier-Topic-II:atomic-conflict"
82 (and (typep c 'item-identifier-error) (eq :duplicate-item-identifier (item-identifier-error-code c)) (equal before (ik-state map))))
83 (push (mm-fields "label" "own-II-not-Reifier-II" "kind" "native-TMDM-probe-not-original-contract" "condition" (mm-condition c)
84 "nativeOperationUnchanged" :true) *association-reifier-native*)))
85 (setf *association-reifier-native* (nreverse *association-reifier-native*)))