;; ============================================================ ;; test_lastent.lsp - Szenario-Test fuer ssg-lastent-ohne-attribute (ssg_core) ;; ;; Stellt den realen Bug nach: ein Block MIT Attributen (z.B. eine per ;; Strg+C/V eingefuegte GR_-Kopie) ist das letzte Objekt der Zeichnung. ;; Ein Makro merkt sich die Startmarke, zeichnet neue Objekte, sammelt ;; "alles ab (entnext marke)" ein und wickelt es per _.-BLOCK zu einem Block. ;; Mit nacktem (entlast) als Marke landeten dabei die ATTRIBs des alten ;; Blocks im Auswahlsatz und wurden entfernt. ;; ;; Aufruf in BricsCAD: ;; (load (strcat (getenv "DXFMAKRO") "/tests/test_lastent.lsp")) ;; TEST_LASTENT ;; ;; Speichert tests/output/lastent_results.json (Konvention test_run_all). ;; ============================================================ (setq *tle-pass* 0 *tle-fail* 0 *tle-fails* '()) ;; Ein Assert: erwartet-Wert gleich ist-Wert (equal). Loggt Pass/Fail. (defun tle-eq (name erwartet ist) (if (equal erwartet ist) (progn (setq *tle-pass* (1+ *tle-pass*)) (princ (strcat "\n [PASS] " name))) (progn (setq *tle-fail* (1+ *tle-fail*)) (setq *tle-fails* (cons name *tle-fails*)) (princ (strcat "\n [FAIL] " name "\n erwartet: " (vl-princ-to-string erwartet) "\n ist: " (vl-princ-to-string ist)))))) ;; Blockdefinition mit zwei ATTDEFs anlegen (falls noch nicht vorhanden). (defun tle-blockdef (name) (if (not (tblsearch "BLOCK" name)) (progn (entmake (list '(0 . "BLOCK") (cons 2 name) '(70 . 2) '(10 0.0 0.0 0.0))) (entmake '((0 . "LINE") (8 . "0") (10 0.0 0.0 0.0) (11 100.0 0.0 0.0))) (foreach tag '("ID" "ARTINR") (entmake (list '(0 . "ATTDEF") '(8 . "0") '(10 0.0 0.0 0.0) '(40 . 10.0) '(1 . "") (cons 2 tag) (cons 3 tag) '(70 . 0)))) (entmake '((0 . "ENDBLK"))))) name) ;; INSERT mit Attributen per entmake (INSERT 66=1, ATTRIBs, SEQEND). ;; Rueckgabe: ename des INSERT. (defun tle-insert-mit-attributen (name pt werte / ins) (entmake (list '(0 . "INSERT") (cons 2 name) (cons 10 pt) '(66 . 1))) (setq ins (entlast)) (foreach paar werte (entmake (list '(0 . "ATTRIB") '(8 . "0") (cons 10 pt) '(40 . 10.0) (cons 1 (cdr paar)) (cons 2 (car paar)) '(70 . 0)))) (entmake '((0 . "SEQEND"))) ins) (defun lastent:tests ( / bname werte ins marke line ss e neu anz) (setvar "CMDECHO" 0) (setq bname (tle-blockdef "TLE_ATT_BLOCK")) (setq werte (list (cons "ID" "4711") (cons "ARTINR" "A1,A2"))) (setq ins (tle-insert-mit-attributen bname '(0.0 0.0 0.0) werte)) ;; --- Vorbedingung: Attribute lesbar, INSERT ist (entlast) --- (tle-eq "vorher: attribute lesbar" werte (ssg-attrib-read ins)) (tle-eq "vorher: entlast = insert" ins (entlast)) ;; --- Marke steht auf dem SEQEND des Attribut-Blocks --- (setq marke (ssg-lastent-ohne-attribute)) (tle-eq "marke ist SEQEND" "SEQEND" (cdr (assoc 0 (entget marke)))) ;; --- Neues Objekt zeichnen: entnext der Marke ist genau dieses Objekt --- (entmake '((0 . "LINE") (8 . "0") (10 0.0 50.0 0.0) (11 100.0 50.0 0.0))) (setq line (entlast)) (tle-eq "entnext marke = neues objekt" line (entnext marke)) ;; --- Einsammeln + _.-BLOCK wie geruest-block-bauen --- (setq ss (ssadd) anz 0 e (entnext marke)) (while e (ssadd e ss) (setq anz (1+ anz)) (setq e (entnext e))) (tle-eq "genau 1 objekt eingesammelt" 1 anz) (setq neu (strcat "TLE_NEU_" (ssg-timestamp))) (command "_.-BLOCK" neu '(0.0 0.0 0.0) ss "") ;; --- Kern des Bugs: der alte Block behaelt seine Attribute --- (tle-eq "nachher: attribute erhalten" werte (ssg-attrib-read ins)) (tle-eq "nachher: neuer block existiert" T (if (tblsearch "BLOCK" neu) T nil)) ;; --- Leere Zeichnung wird hier nicht getestet (Testzeichnung ist nie leer); ;; ohne Attribute liefert der Helfer (entlast) unveraendert --- (entmake '((0 . "LINE") (8 . "0") (10 0.0 90.0 0.0) (11 10.0 90.0 0.0))) (tle-eq "ohne attribute: marke = entlast" (entlast) (ssg-lastent-ohne-attribute)) ;; Aufraeumen (entdel ins) (entdel (entlast)) (princ)) (defun lastent:export-results (out-dir / f pfad) (setq pfad (strcat out-dir "/lastent_results.json")) (setq f (open pfad "w")) (if f (progn (write-line "{" f) (write-line (strcat " \"pass\": " (itoa *tle-pass*) ",") f) (write-line (strcat " \"fail\": " (itoa *tle-fail*) ",") f) (write-line (strcat " \"status\": \"" (if (= *tle-fail* 0) "OK" "FEHLER") "\"") f) (write-line "}" f) (close f) (princ (strcat "\n Ergebnis: " pfad)))) (princ)) (defun c:TEST_LASTENT ( / ) (setq *tle-pass* 0 *tle-fail* 0 *tle-fails* '()) (princ "\n================================================================") (princ "\n TEST_LASTENT - ssg-lastent-ohne-attribute (ssg_core.lsp)") (princ "\n================================================================") (lastent:tests) (princ "\n\n----------------------------------------------------------------") (princ (strcat "\n Ergebnis: " (itoa *tle-pass*) " PASS, " (itoa *tle-fail*) " FAIL")) (if (> *tle-fail* 0) (progn (princ "\n Fehlgeschlagen:") (foreach n (reverse *tle-fails*) (princ (strcat "\n - " n))))) (princ "\n================================================================") (princ)) (princ "\nTEST_LASTENT geladen. Aufruf: TEST_LASTENT") (princ)