3 require "#{ENV['PWD']}/scripts/vym-ruby"
10 OptionParser.new do |opts|
11 opts.banner = "Usage: vym-test.rb [options]"
13 opts.on('-d', '--directory NAME', 'Directory name') { |s| options[:testdir] = s }
16 @testdir = options[:testdir]
23 puts "Press return to continue..."
27 def expect (comment, v_real, v_exp)
29 puts " Ok: #{comment}"
32 puts "Failed: #{comment}. Expected '#{v_exp}', but got '#{v_real}'"
39 def expect_error (comment, error)
41 puts "Failed: #{comment}. Command did not return error."
44 puts " Ok: #{comment}"
51 puts "\n#{s}\n#{'-' * s.length}\n"
55 # FIXME-2 Missing: check or init default map
68 puts "\nTests done : #{$tests_total}"
69 puts "Tests passed: #{$tests_passed}"
70 puts "Tests failed: #{$tests_failed}"
73 vym_mgr=VymManager.new
76 vym=vym_mgr.find(instance_name)
78 puts "Couldn't find instance name \"#{instance_name}\", please start one:"
79 puts "vym -l -n \"#{instance-name}\" -t test/default.vym"
84 #######################
88 @branch_a=@main_a+",bo:0"
89 @branch_b=@main_a+",bo:1"
90 @branch_c=@main_a+",bo:2"
95 #######################
97 heading "Basic checks:"
100 expect "select mainbranch A", vym.getSelectString, @main_a
101 expect "getHeadingPlainText", vym.getHeadingPlainText, "Main A"
102 expect "branchCount", vym.branchCount, 3
105 expect "selectLastBranch", vym.getHeadingPlainText, "branch c"
108 expect "selectParent", vym.getHeadingPlainText, "Main A"
110 expect "getDestPath: Got #{vym.getDestPath}", vym.getDestPath, @testdir + "/testmap.vym"
111 expect "getFileDir: Got #{vym.getFileDir}", vym.getFileDir, @testdir + "/"
114 #######################
115 def test_export (vym)
120 mapname = "export-html"
121 htmlpath = "#{@testdir}/#{mapname}.html"
122 flagpath = "#{@testdir}/flags/flag-stopsign.png"
123 pngpath = "#{@testdir}/#{mapname}.png"
124 csspath = "#{@testdir}/vym.css"
125 vym.exportHTML(@testdir,htmlpath)
126 expect "exportHTML: HTML file exists", File.exists?(htmlpath), true
127 expect "exportHTML: HTML image exists", File.exists?(pngpath), true
128 expect "exportHTML: HTML flags exists", File.exists?(flagpath), true
129 expect "exportHTML: HTML CSS exists", File.exists?(csspath), true
130 File.delete(htmlpath)
131 File.delete(flagpath)
135 expect "exportLast: HTML #{htmlpath} file exists", File.exists?(htmlpath), true
136 expect "exportLast: HTML image exists", File.exists?(pngpath), true
137 expect "exportLast: HTML flags exists", File.exists?(flagpath), true
138 expect "exportLast: HTML CSS exists", File.exists?(csspath), true
141 filepath = "#{@testdir}/export-ao.txt"
142 vym.exportAO(filepath)
143 expect "exportAO: AO file exists", File.exists?(filepath), true
144 File.delete(filepath)
146 expect "exportLast: AO file exists", File.exists?(filepath), true
149 filepath = "#{@testdir}/export-ascii.txt"
150 vym.exportASCII(filepath,false)
151 expect "exportASCII: ASCII file exists", File.exists?(filepath), true
152 File.delete(filepath)
154 expect "exportLast: ASCII file exists", File.exists?(filepath), true
157 filepath = "#{@testdir}/export-csv.txt"
158 vym.exportCSV(filepath)
159 expect "exportCSV: CSV file exists", File.exists?(filepath), true
160 File.delete(filepath)
162 expect "exportLast: CSV file exists", File.exists?(filepath), true
165 filepath = "#{@testdir}/export-image.png"
166 vym.exportImage(filepath,"PNG")
167 expect "exportImage: PNG file exists", File.exists?(filepath), true
168 File.delete(filepath)
170 expect "exportLast: PNG file exists", File.exists?(filepath), true
173 filepath = "#{@testdir}/export-LaTeX.tex"
174 vym.exportLaTeX(filepath)
175 expect "exportLaTeX: LaTeX file exists", File.exists?(filepath), true
176 File.delete(filepath)
178 expect "exportLast: LaTeX file exists", File.exists?(filepath), true
181 filepath = "#{@testdir}/export-orgmode.org"
182 vym.exportOrgMode(filepath)
183 expect "exportOrgMode: OrgMode file exists", File.exists?(filepath), true
184 File.delete(filepath)
186 expect "exportLast: OrgMode file exists", File.exists?(filepath), true
189 filepath = "#{@testdir}/export-pdf.pdf"
190 vym.exportPDF(filepath)
191 expect "exportPDF: PDF file exists", File.exists?(filepath), true
192 File.delete(filepath)
194 expect "exportLast: PDF file exists", File.exists?(filepath), true
197 filepath = "#{@testdir}/export-svg.svg"
198 vym.exportSVG(filepath)
199 expect "exportSVG: SVG file exists", File.exists?(filepath), true
200 File.delete(filepath)
202 expect "exportLast: SVG file exists", File.exists?(filepath), true
205 filepath = "#{@testdir}/export-xml.xml"
206 vym.exportXML(@testdir, filepath)
207 expect "exportXML: XML file exists", File.exists?(filepath), true
208 File.delete(filepath)
210 expect "exportLast: XML file exists", File.exists?(filepath), true
212 #OpenOffice Impress //FIXME-2
213 #KDE4 Bookmarks //FIXME-2
214 #Taskjuggler //FIXME-3
217 #######################
218 def test_extrainfo (vym)
219 heading "Extra information:"
221 vym.setMapAuthor("Fra Erasmas")
222 expect "Set and get map author", vym.getMapAuthor, "Fra Erasmas"
223 vym.setMapComment("xy z")
224 expect "Set and get map comment", vym.getMapComment, "xy z"
225 vym.setMapTitle("vym rules!")
226 expect "Set and get map title", vym.getMapTitle, "vym rules!"
229 #######################
230 def test_adding_branches (vym)
231 heading "Adding branches:"
236 expect( "addBranch", vym.branchCount, n+1 )
238 vym.selectLatestAdded
239 expect "selectLatestAdded", vym.getSelectString, @main_a+",bo:3"
242 expect( "Undo: addBranch", vym.branchCount, n )
251 expect "addBranchAbove/Below", vym.branchCount, n+2
255 expect "Undo: addBranchAbove/Below", vym.branchCount, n
261 expect "addBranchBefore: check branchcount", vym.branchCount, n
263 expect "addBranchBefore: check heading", vym.getHeadingPlainText, ""
266 expect "Undo: addBranchBefore", vym.branchCount, n
269 #######################
270 def test_adding_maps (vym)
271 heading "Adding maps"
275 vym.addMapReplace "test/default.vym"
277 expect "addMapReplace: check branch count in #{@main_a}", vym.branchCount, n + @n_centers -1
279 expect "addMapReplace: check if #{@branch_a} is new", vym.branchCount, 2
283 expect "Undo: check branch count in #{@main_a}", vym.branchCount, 3
285 expect "Undo: check if #{@branch_a} is back", vym.branchCount, 3
289 vym.addMapInsert "test/default.vym",1
291 expect "addMapInsert: branch count", vym.branchCount, n+2
292 vym.select @main_a + ",bo:1"
293 expect "addMapInsert: new heading", vym.getHeadingPlainText, "MapCenter 0"
297 expect "Undo: check branch count in #{@main_a}", vym.branchCount, 3
299 expect "Undo: check heading of #{@branch_b}", vym.getHeadingPlainText, "branch b"
302 #######################
303 def test_scrolling (vym)
304 heading "Scrolling and unscrolling"
308 expect "toggleScroll", vym.isScrolled, true
310 expect "undo toggleScroll", vym.isScrolled, false
312 expect "scroll", vym.isScrolled, true
314 expect "unscroll", vym.isScrolled, false
323 expect "unscrollChildren", vym.isScrolled, false
325 expect "undo unscrollChildren", vym.isScrolled, true
331 #######################
332 def test_moving_parts (vym)
333 heading "Moving parts"
338 expect "Moving down", vym.getHeadingPlainText, "branch b"
341 expect "Undo Moving down", vym.getHeadingPlainText, "branch a"
347 expect "Moving up", vym.getHeadingPlainText, "branch b"
350 expect "Undo Moving up", vym.getHeadingPlainText, "branch b"
356 vym.relinkTo @main_b,0,0,0
358 expect "RelinkTo #{@main_b}: branchCount increased there", vym.branchCount, n+1
362 expect "Undo: RelinkTo #{@main_b}: branchCount decreased there", vym.branchCount, n
366 err = vym.relinkTo @branch_a,0,0,0
367 expect_error "RelinkTo myself fails.", err
374 vym.relinkTo @branch_a, 1, 0, 0
376 expect "RelinkTo #{@branch_a}, pos 1: branchCount increased there", vym.branchCount, n+1
377 vym.select "#{@branch_a},bo:1"
378 expect "RelinkTo #{@branch_a}, pos 1: Mainbranch really moved", vym.getHeadingPlainText, "Main B"
381 expect "Undo RelinkTo pos 1: branchCount of center", vym.branchCount, 2
382 # FIXME-2 still has wrong position, check position
387 #######################
388 def test_modify_branches (vym)
389 heading "Modifying branches"
392 vym.setHeadingPlainText "Changed!"
393 expect "setHeadingPlainText", vym.getHeadingPlainText, "Changed!"
395 expect "Undo: setHeadingPlainText", vym.getHeadingPlainText, "branch a"
397 expect "redo: setHeadingPlainText", vym.getHeadingPlainText, "Changed!"
401 #######################
410 expect "Flag set: #{f}", v.hasActiveFlag(f), true
414 def unset_flags (v,a)
417 expect "Flag unset: #{f}", v.hasActiveFlag(f), false
421 # Group standard-mark
422 set_flags vym,[ "exclamationmark","questionmark"]
424 # Group standard-status
425 set_flags vym, [ "hook-green",
430 # Group standard-smiley
431 smileys = [ "smiley-good",
434 set_flags vym, smileys
436 # Group standard-arrow
437 set_flags vym, [ "arrow-up",
442 # Group standard-thumb
443 set_flags vym, [ "thumb-up", "thumb-down" ]
446 set_flags vym, [ "clock",
456 unset_flags vym, smileys
459 expect "clearFlags cleared exclamationmark", vym.hasActiveFlag( "exclamationmark" ), false
460 expect "clearFlags cleared smiley-good", vym.hasActiveFlag( "smiley-good" ), false
462 vym.toggleFlag "lifebelt"
463 expect "toggleFlag: flag activated", vym.hasActiveFlag("lifebelt"),true
464 vym.toggleFlag "lifebelt"
465 expect "toggleFlag: flag deactivated", vym.hasActiveFlag("lifebelt"),false
468 #######################
469 def test_delete_parts (vym)
470 heading "Deleting parts"
478 expect "Delete branch: branchcount", vym.branchCount, n-1
481 expect "Undo Delete branch: branchcount parent", vym.branchCount, n
483 expect "Undo Delete branch: branchcount restored branch", vym.branchCount, m
490 expect "deleteChildren: branchcount", vym.branchCount, 0
493 expect "Undo: deleteChildren: branchcount", vym.branchCount, n
500 vym.deleteKeepChildren
502 expect "deleteKeepChildren: branchcount", vym.branchCount, n+m-1
505 expect "Undo: deleteKeepChildren: branchcount of parent", vym.branchCount, n
507 expect "Undo: deleteKeepChildren: branchcount of branch", vym.branchCount, m
513 expect "Delete mapCenter: number of centers decreased", vym.centerCount, n-1
515 expect "Undo Delete mapCenter: number of centers increased", vym.centerCount, n
518 #######################
519 def test_copy_paste (vym)
520 heading "Copy, cut & Paste"
528 s=vym.getSelectString
529 expect "Normal paste of branch, check heading of #{s}", vym.getHeadingPlainText, "Main A"
533 expect "Undo paste: branchCount of #{@main_a}", vym.branchCount, n
537 expect "redo paste: check heading", vym.getHeadingPlainText, "Main A"
541 expect "cut: branchCount of #{@main_a}", vym.branchCount, n
544 s=vym.getSelectString
545 expect "Normal paste of branch, check heading of #{s}", vym.getHeadingPlainText, "Main A"
549 #######################
550 def test_references (vym)
554 vym.setURL "www.insilmaril.de"
555 expect "setURL:", vym.getURL, "www.insilmaril.de"
557 expect "undo setURL", vym.getURL, ""
559 expect "redo setURL", vym.getURL, "www.insilmaril.de"
561 expect "setURL: unset URL with empty string", vym.getURL, ""
566 expect "setVymLink returns absolute path", vym.getVymLink, vym.getFileDir + vl
568 expect "undo: setVymLink", vym.getVymLink, ""
570 expect "redo: setVymLink", vym.getVymLink, s
574 #######################
575 def test_history (vym)
579 vym.setHeadingPlainText "A"
580 vym.setHeadingPlainText "B"
581 vym.setHeadingPlainText "C"
585 expect "Undo 3 times", vym.getHeadingPlainText, "Main A"
587 expect "Redo once", vym.getHeadingPlainText, "A"
590 expect "Redo once more", vym.getHeadingPlainText, "B"
592 expect "Redo yet again", vym.getHeadingPlainText, "C"
593 vym.setHeadingPlainText "Main A"
596 expect "Paste from the past", vym.getHeadingPlainText, "A"
600 #######################
601 def test_xlinks (vym)
604 vym.addXLink("mc:0,bo:0","mc:0,bo:1",2,"#ff0000","Qt::DashDotLine")
605 vym.selectLatestAdded
606 expect "Default color of XLink", vym.getXLinkColor, "#ff0000"
607 expect "Default width of XLink", vym.getXLinkWidth, 2
608 expect "Default style of XLink", vym.getXLinkPenStyle, "Qt::DashDotLine"
609 expect "Default style of XLink begin", vym.getXLinkStyleBegin, "HeadFull"
610 expect "Default style of XLink end", vym.getXLinkStyleEnd, "HeadFull"
613 expect "New width of XLink", vym.getXLinkWidth, 3
615 expect "Undo width of XLink", vym.getXLinkWidth, 2
617 vym.setXLinkColor("#00ff00")
618 expect "New color of XLink", vym.getXLinkColor, "#00ff00"
620 expect "Undo color of XLink", vym.getXLinkColor, "#ff0000"
622 vym.setXLinkLineStyle("Qt::SolidLine")
623 expect "New style of XLink", vym.getXLinkPenStyle, "Qt::SolidLine"
625 expect "Undo style of XLink", vym.getXLinkPenStyle, "Qt::DashDotLine"
627 vym.setXLinkStyleBegin("None")
628 expect "New style of XLink begin", vym.getXLinkStyleBegin, "None"
630 expect "Undo style of XLink begin", vym.getXLinkStyleBegin, "HeadFull"
632 vym.setXLinkStyleEnd("None")
633 expect "New style of XLink end", vym.getXLinkStyleEnd, "None"
635 expect "Undo style of XLink end", vym.getXLinkStyleEnd, "HeadFull"
640 #######################
645 expect "Branch has no task before test", vym.hasTask, false
647 expect "Toggle task", vym.hasTask, true
648 expect "Setting sleep days to 10", vym.setTaskSleep(10), true
649 expect "Task sleep when setting to integer", vym.getTaskSleepDays, 10
651 date_today = DateTime.now
652 date_later = date_today + 123
653 date_s = date_later.strftime("%Y-%m-%d")
654 vym.setTaskSleep(date_s)
655 expect "Task sleep when setting to ISO date (#{date_s})", vym.getTaskSleepDays, 123
658 ######################
662 # Plaintext notes basic actions
665 note_plain = "vymnote plaintext"
666 vym.setNotePlainText(note_plain)
667 expect "Set note to \"#{note_plain}\". Still plaintext?", vym.hasRichTextNote, false
670 expect "After reselect, is note plaintext?", vym.hasRichTextNote, false
672 note_plain = "<b>plaintext, not bold!</b>"
673 vym.setNotePlainText(note_plain)
674 expect "Set note to plaintext containing html tags. Still plaintext", vym.hasRichTextNote, false
675 note_new = vym.getNotePlainText
678 expect "After reselect, is note text unchanged?", vym.getNotePlainText, note_new
679 expect "After reselect, is note plaintext?", vym.hasRichTextNote, false
681 # Plaintext notes copy & paste
685 s=vym.getSelectString
686 expect "After copy& paste: New note unchanged?", vym.getNotePlainText, note_plain
687 expect "After copy& paste: New note Still plaintext?", vym.hasRichTextNote, false
690 # Plaintext notes undo & redo
692 vym.setNotePlainText('Foobar')
694 expect "Undo after setNotePlainText restores previous note", vym.getNotePlainText, note_plain
697 expect "Redo restores previous note", vym.getNotePlainText, 'Foobar'
699 # Plaintext notes load & save
700 note_org = IO.read('test/note-plain.txt')
701 vym.loadNote("test/note-plain.txt")
702 expect "Load plain text note from file. Still plaintext?", vym.hasRichTextNote, false
703 expect "Note contains 'not bold'", vym.getNotePlainText.include?("not bold"), true
704 filepath = "#{@testdir}/save-note.txt"
705 vym.saveNote(filepath)
706 expect "Save note to file. Check if it contains 'textMode=\"plainText\"'", IO.read(filepath).include?("textMode=\"plainText\""), true
707 expect "Save note to file. Check if it contains 'not bold'", IO.read(filepath).include?("not bold"), true
708 expect "Save note to file. Check if it contains '<b>' element", IO.read(filepath).include?("<b>"), true
709 expect "Save note to file. Check if it contains '<![CDATA['", IO.read(filepath).include?("<![CDATA["), true
712 vym.setNotePlainText("")
713 expect "setNotePlainText(\"\") deletes note", vym.hasNote, false
715 # RichText basic actions
718 rt_note = '<vymnote textMode="richText"><![CDATA[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:\'Arial\'; font-size:12pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:\'DejaVu Sans Mono\'; color:#000000;">Rich Text note with <b>not bold text</b></span></p></body></html>]]></vymnote>'
719 vym.parseVymText(rt_note)
720 expect "parseVymText of richText note produces note", vym.hasNote, true
721 expect "parseVymText of richText note produces richText note", vym.hasRichTextNote, true
724 expect "After reselect, is note RichText?", vym.hasRichTextNote, true
727 # RichText notes copy & paste
728 rt_note = vym.getNoteXML
732 s=vym.getSelectString
733 expect "After copy& paste: New note Still RichText?", vym.hasRichTextNote, true
734 expect "After copy& paste: New note unchanged?", vym.getNoteXML, rt_note
737 # RichText notes undo & redo
739 vym.setNotePlainText('Foobar')
741 expect "Undo after setNotePlainText restores RichText note", vym.getNoteXML, rt_note
744 expect "Redo restores previous plaintext note", vym.getNotePlainText, 'Foobar'
746 # RichText notes load & save
747 vym.loadNote("test/note.html")
748 expect "Load HTML note from file and try to detect textMode. Is RichText?", vym.hasRichTextNote, true
749 filepath = "#{@testdir}/save-note.txt"
750 vym.saveNote(filepath)
751 expect "Save note to file. Check if it contains 'textMode=\"richText\"'", IO.read(filepath).include?("textMode=\"richText\""), true
752 expect "Save note to file. Check if it contains 'bold'", IO.read(filepath).include?("bold"), true
753 expect "Save note to file. Check if it contains '<b>' element", IO.read(filepath).include?("<b>"), true
754 expect "Save note to file. Check if it contains '<![CDATA['", IO.read(filepath).include?("<![CDATA["), true
757 vym.setNotePlainText("")
758 expect "setNotePlainText(\"\") deletes note", vym.hasNote, false
760 # Compatibility with version < 2.5.0 # FIXME missing
763 def test_headings (vym)
765 # FIXME same checks like for notes above for headings
768 ######################
769 def test_bugfixes (vym)
773 expect "Mapcenter of #{@center_1} has no frame", vym.getFrameType, "NoFrame"
776 #######################
780 test_adding_branches(vym)
781 test_adding_maps(vym)
783 test_moving_parts(vym)
784 test_modify_branches(vym)
786 test_delete_parts(vym)
817 relinkTo (for images)
825 setFrameIncludeChildren
831 setHideLinksUnselected
832 setIncludeImagesHorizontally
833 setIncludeImagesVertically
836 setMapBackgroundColor
849 toggleFrameIncludeChildren