Skip to content

Commit

Permalink
Add project unit test cases (#133)
Browse files Browse the repository at this point in the history
Add project unit test cases (#133)
  • Loading branch information
shuang6 authored Apr 15, 2021
1 parent 7c352e2 commit c2aa3bc
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 22 deletions.
162 changes: 162 additions & 0 deletions extension/src/test/SourceFile/test_case/pdfMarkups.lsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
; random sample file

(defun sampleFunc (x y / a b c d)
(setq a (list 1 2 3 4) ; does this screw it all up?
d (setq b 0)
b (mapcar '+ a))
(foreach x a
(setq d (1+ d))
)

(defun SymPtrOnly ()
(setq gv 32)
)

(defun c (a b / q)
(defun q (r j / z)
(setq z (* r j))
)

(q a b)
)
)


(setq some "random" ; does this trip?
global (list "variables" "to" "test")
with (vl-sort '(lambda(a b) (setq c (< a b))) global)
)

(foreach rando global
(setq some (strcat some " " rando))
)



(defun DumpPidMarkups (/ path pdfList pdfMarkups lineList compList equpList chckList textList resp contractDrawings downloadPdfs downloadPath badFiles noMarkups)

(defun collectMarkups ( file / pchckList pcompList pequpList plineList ptextList markups fixAnno ret )
(setq ret nil)
(if (not (vl-catch-all-error-p (setq markups (vl-catch-all-apply 'NS:XfiniumPDF:GetAnnotations (list file 1))))) ; Hard code page 1
(if (> (length markups) 0)
(progn
(setq markups (vl-remove-if '(lambda (a) (or (/= (type a) 'LIST) (/= (strcase (nth 3 a)) "FREETEXT") (null (nth 5 a)) (= (nth 5 a) ""))) markups))
(setq markups (mapcar '(lambda (a) (list (vl-filename-base file) (nth 4 a) (nth 5 a) (nth 6 a))) markups))
(if (> (length markups) 0)
(progn
(foreach anno markups
(setq fixAnno (mapcar '(lambda (l) (if (= (type l) 'STR) (acet-str-replace "\r" "-" (vl-string-trim " " (vl-string-trim (chr 9) l))) l)) anno))
(cond
((vl-string-search "LINENUMBER" (strcase (nth 1 fixAnno)))
(setq plineList (cons fixAnno plineList)))
((vl-string-search "COMPONENT" (strcase (nth 1 fixAnno)))
(setq pcompList (cons fixAnno pcompList)))
((vl-string-search "EQUIPMENT" (strcase (nth 1 fixAnno)))
(setq pequpList (cons fixAnno pequpList)))
((and (null (vl-string-search "NOT IN SCOPE" (nth 2 fixAnno)))(>= (- (strlen (nth 2 fixAnno)) (strlen (acet-str-replace "-" "" (nth 2 fixAnno)))) 3))
(setq pchckList (cons fixAnno pchckList)))
(t
(setq ptextList (cons fixAnno ptextList)))
)
)
(setq ret (list plineList pcompList pequpList pchckList ptextList))
)
)
)
)
(setq ret (vl-filename-base file))
)
ret
)

(defun getPdfList ( pth / retList )
(setq retList (cadr (NS:ACAD:FilePicker "Select P&IDs to export markups" "Select files" GV:ProjPath "*.pdf")))
(cond
((null retList) (exit))
((and (vl-consp retList) (= (length retList) 1) (= (car retList) ""))
(setq retList getPdfList))
((and (vl-consp retList) (> (length retList) 1) (vl-every 'findfile retList))
(terpri)
(prompt (strcat (itoa (length retList)) " PDFs selected for processing")))
)
retList
)


(if (null GV:ProjIni) (progn (NS:ACAD:MessageBox *GV:ProjIni* "Project.ini error" 0 16)(exit)))

(setq resp (car (NS:ACAD:MessageBox "Do you want to download drawings?" "P&ID Download and Export" 3 32)))
(cond
((= resp 2) ; Cancel
(terpri)
(prompt "P&ID Markup Export Terminated")
(exit)
)
((= resp 6) ; Yes
(setq contractDrawings (vl-catch-all-apply 'NS:Sharepoint:Read (list t GV:ExePath GV:ProjUrl "Contract Drawings" "ID" "Name")))
(if (vl-catch-all-error-p contractDrawings) (progn (alert "Error reading from Sharepoint") (exit)))
(setq contractDrawings (vl-remove-if '(lambda (d) (null (vl-string-search ".pdf" (car d)))) (mapcar 'reverse contractDrawings))
downloadPdfs (cadr (NS:ACAD:ListBox "Select PDFs to Download" "Download Drawings" (acad_strlsort (mapcar 'car contractDrawings)) t)))
(if (null downloadPdfs) (exit))
(setq downloadPath (caadr (NS:ACAD:DirPicker "Select Download Path" "Download files" GV:ProjPath)))
(if (null downloadPath) (exit))
(foreach pdf downloadPdfs
(setq downloadIds (cons (cadr (assoc pdf contractDrawings)) downloadIds))
)
(NS:SharePoint:Download GV:ExePath (cadr(assoc "SITE" GV:ProjIni)) "Contract Drawings" "ID" (mapcar 'itoa downloadIds) downloadPath)
(setq defaultPath downloadPath)
)
((= resp 7) ; No
(setq defaultPath GV:ProjPath))
)
(setq pdfList (getPdfList defaultPath))
(if (and pdfList (> (length pdfList) 0))
(foreach pdf pdfList
(setq pdfMarkups (collectMarkups pdf))
(cond
((null pdfMarkups)
(setq noMarkups (cons (vl-filename-base pdf) noMarkups)))
((= (type pdfMarkups) 'STR)
(setq badFiles (cons pdfMarkups badFiles)))
((listp pdfMarkups)
(if (nth 0 pdfMarkups)
(setq lineList (append (nth 0 pdfMarkups) lineList)))
(if (nth 1 pdfMarkups)
(setq compList (append (nth 1 pdfMarkups) compList)))
(if (nth 2 pdfMarkups)
(setq equpList (append (nth 2 pdfMarkups) equpList)))
(if (nth 3 pdfMarkups)
(setq chckList (append (nth 3 pdfMarkups) chckList)))
(if (nth 4 pdfMarkups)
(setq textList (append (nth 4 pdfMarkups) textList))))
)
)
)
(if lineList (IO:WriteLines (cons (list "Page" "Subject" "LineTag" "Author") lineList) (strcat (vl-filename-directory (car pdfList)) "\\Linenumber List.csv")))
(if compList (IO:WriteLines (cons (list "Page" "Subject" "ComponentTag" "Author") compList) (strcat (vl-filename-directory (car pdfList)) "\\Components List.csv")))
(if equpList (IO:WriteLines (cons (list "Page" "Subject" "EquipmentTag" "Author") equpList) (strcat (vl-filename-directory (car pdfList)) "\\Equipment List.csv")))
(if chckList (IO:WriteLines (cons (list "Page" "Subject" "Contents" "Author") chckList) (strcat (vl-filename-directory (car pdfList)) "\\Review Required List.csv")))
(if textList (IO:WriteLines (cons (list "Page" "Subject" "Contents" "Author") textList) (strcat (vl-filename-directory (car pdfList)) "\\FreeText List.csv")))
(if badFiles (NS:ACAD:ListBox "Error reading the following files" "File Errors" (acad_strlsort badFiles) t))
(if noMarkups (NS:ACAD:ListBox "There were no markups on the following files" "No markups" (acad_strlsort noMarkups) t))
(terpri)
(prompt "P&ID Markup Export Complete")
(princ)
)


(defun doStuff (pth / retList)
(setq retList (cadr (NS:ACAD:FilePicker "Select P&IDs to export markups" "Select files" GV:ProjPath "*.pdf" )))
(cond
((null retList) (exit))
((and (vl-consp retList) (= (length retList) 1) (= (car retList) ""))
(setq retList getPdfList)
)
((and (vl-consp retList) (> (length retList) 1) (vl-every 'findfile retList))
(terpri)
(prompt (strcat (itoa (length retList)) " PDFs selected for processing"))
)
)
retList
)

16 changes: 16 additions & 0 deletions extension/src/test/SourceFile/test_case/project_no_lisp_file.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;;; VLisp project file [V2.0] project_no_lisp_file saved to:[d:\2\AutoLispExt\test_case] at:[4/13/2021]
(VLISP-PROJECT-LIST
:NAME
project_no_lisp_file
:OWN-LIST
nil
:FAS-DIRECTORY
nil
:TMP-DIRECTORY
nil
:PROJECT-KEYS
(:BUILD (:standard))
:CONTEXT-ID
:AUTOLISP
)
;;; EOF
16 changes: 16 additions & 0 deletions extension/src/test/SourceFile/test_case/project_test_file.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;;; VLisp project file [V2.0] project_test_file saved to:[d:\github\AutoLispExt\test_case] at:[6/16/2020]
(VLISP-PROJECT-LIST
:NAME
project_test_file
:OWN-LIST
("test_remove")
:FAS-DIRECTORY
nil
:TMP-DIRECTORY
nil
:PROJECT-KEYS
(:BUILD (:standard))
:CONTEXT-ID
:AUTOLISP
)
;;; EOF
3 changes: 3 additions & 0 deletions extension/src/test/SourceFile/test_case/test_remove.lsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

(print "this 55 is a test22")
(command "-layer")
5 changes: 3 additions & 2 deletions extension/src/test/suite/DocumentContainer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { LispParser } from '../../format/parser';
import { Sexpression, LispContainer } from '../../format/sexpression';
import { ReadonlyDocument } from '../../project/readOnlyDocument';

let assert = chai.assert;
let lispFileTest = path.join(__dirname + "/../../../test_case/pdfMarkups.lsp");
var assert = require('chai').assert;
let prefixpath = __filename + "/../../../../extension/src/test/SourceFile/test_case/";
let lispFileTest = path.join(prefixpath + "pdfMarkups.lsp");

suite("LispParser.DocumentContainer Tests", function () {
test("Original atomsForest vs DocumentContainer", function () {
Expand Down
4 changes: 3 additions & 1 deletion extension/src/test/suite/LispContainer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { ILispFragment, LispContainer } from '../../format/sexpression';
import { ReadonlyDocument } from '../../project/readOnlyDocument';
import { LispParser } from '../../format/parser';

let lispFileTest = path.join(__dirname + "/../../../test_case/pdfMarkups.lsp");
let prefixpath = __filename + "/../../../../extension/src/test/SourceFile/test_case/";
let lispFileTest = path.join(prefixpath + "pdfMarkups.lsp");
// let project_path = path.join(__dirname + "\\..\\..\\..\\test_case\\pdfMarkups.lsp");
let pos1: Position = new Position(98, 100); // based on line: " downloadPdfs (cadr (NS:ACAD:ListBox "Select PDFs to Download" "Download Drawings" (acad_strlsort (mapcar 'car contractDrawings)) t)))"
let pos2: Position = new Position(100, 100); // based on line: " (setq downloadPath (caadr (NS:ACAD:DirPicker "Select Download Path" "Download files" GV:ProjPath)))"

Expand Down
3 changes: 2 additions & 1 deletion extension/src/test/suite/ReadonlyDocument.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { TextDocument } from 'vscode';
import { ReadonlyDocument } from '../../project/readOnlyDocument';

var assert = require('chai').assert;
let lispFileTest = path.join(__dirname + "/../../../test_case/pdfMarkups.lsp");
let prefixpath = __filename + "/../../../../extension/src/test/SourceFile/test_case/";
let lispFileTest = path.join(prefixpath + "pdfMarkups.lsp");


suite("ReadonlyDocument Tests", function () {
Expand Down
Loading

0 comments on commit c2aa3bc

Please sign in to comment.