3 require "#{ENV['PWD']}/../scripts/vym-ruby"
10 puts "Press return to continue..."
14 def expect (comment, v_real, v_exp)
16 puts " Ok: #{comment}".green
20 puts "Failed: #{comment}. Expected '#{v_exp}', but got '#{v_real}'".red
27 def expectInclude (comment, s, substring)
28 if s.include? substring
29 puts " Ok: #{comment}".green
33 puts "Failed: #{comment}. Could not find '#{substring}' in string below:".red
41 def expectNot (comment, v_real, v_exp)
43 puts " Ok: #{comment}".green
47 puts "Failed: #{comment}. Expected not to get '#{v_exp}'".red
54 def expect_warning_only (comment, v_real, v_exp)
56 puts " Ok: #{comment}".green
60 puts "Warning: #{comment}. Expected '#{v_exp}', but got '#{v_real}'".red
66 def expect_error (comment, error)
68 puts "Failed: #{comment}. Command did not return error.".red
71 puts " Ok: #{comment}".green
78 puts "\n#{s}\n#{'-' * s.length}\n".yellow
81 def init_map( mapPath, files = [])
82 # Copy the map referenced above to @testDir/test-current.[vym|xml]
84 @currentMapPath = "#{@testDir}/test-current#{File.extname(mapPath)}"
87 FileUtils.cp mapPath, @currentMapPath
89 puts "Failed to copy #{mapPath} to #{@currentMapPath}".red
95 FileUtils.cp fn, @testDir
96 puts "# Copied #{fn} to #{@testDir}".light_black
98 puts "Failed to copy #{fn} to #{@testDir}".red
103 if @vym.loadMap (@currentMapPath)
104 id = @vym.currentMapID
105 puts "# Loaded #{mapPath} -> #{@currentMapPath} (id: #{id})".light_black
109 puts "Failed to load #{mapPath}".red
113 def close_current_map
114 id = @vym.currentMapID
115 r = @vym.closeMapWithID(id)
117 puts "# Closed map (id: #{id})".light_black
119 puts "# Failed to close map with id = #{id}. CurrentMapID = #{id}".red
124 puts "\nTests done : #{$tests_total}"
125 puts "Tests passed: #{$tests_passed}"
126 puts "Warnings: #{$tests_warnings}"
127 puts "Tests failed: #{$tests_failed}"
130 #######################
134 heading "Mainwindow checks:"
136 expect_warning_only "Version is #{version}", @vym.version, version
138 expect "Temporary directory exists at '#{@testDir}'", File.exists?(@testDir), true
141 map = init_map @testMapDefault
142 expect "init_map copies default testmap to '#{@currentMapPath}'", File.file?(@currentMapPath), true
143 expect "Title of copied map title is accessible and not empty", map.getMapTitle.length > 0, true
148 #######################
150 heading "Basic checks:"
151 map = init_map @testMapDefault
153 title = "vym map used for testing"
154 expect "map title is '#{title}'", map.getMapTitle, title
155 author ="Uwe Drechsel"
156 expect "Author is '#{author}'", map.getMapAuthor, author
159 expect "select mainbranch A", map.getSelectionString, @main_A
160 expect "getHeadingPlainText", map.getHeadingPlainText, "Main A"
161 expect "branchCount", map.branchCount, 3
164 expect "selectLastBranch", map.getHeadingPlainText, "Main B"
166 map.selectFirstBranch
167 expect "selectFirstBranch", map.getHeadingPlainText, "Main A"
170 expect "selectParent", map.getHeadingPlainText, "MapCenter 0"
172 expect "getDestPath: Got #{map.getDestPath}", map.getDestPath, @testDir + "/test-current.vym"
173 expect "getFileDir: Got #{map.getFileDir}", map.getFileDir, @testDir + "/"
178 #######################
179 def test_adding_branches
180 heading "Adding branches:"
181 map = init_map @testMapDefault
183 n = map.branchCount.to_i
185 expect( "addBranch", map.branchCount.to_i, n + 1 )
187 map.selectLatestAdded
188 expect "selectLatestAdded", map.getSelectionString, @main_A + ",bo:3"
191 expect( "Undo: addBranch", map.branchCount.to_i, n )
194 map = init_map @testMapDefault
197 n = map.branchCount.to_i
198 map.select @branch_0Aa
202 expect "addBranchAbove/Below", map.branchCount.to_i, n + 2
206 expect "Undo: addBranchAbove/Below", map.branchCount.to_i, n
209 map = init_map @testMapDefault
211 map.select @branch_0Aa
214 expect "addBranchBefore: check branchcount", map.branchCount.to_i, n
215 map.select @branch_0Aa
216 expect "addBranchBefore: check heading", map.getHeadingPlainText, ""
218 # Undo twice: addBranchNew and relinkTo
222 expect "Undo: addBranchBefore", map.branchCount.to_i, n
227 #######################
229 heading "Adding maps"
230 map = init_map @testMapDefault
231 map.select @branch_0Aa
232 n = map.branchCount.to_i
233 map.addMapReplace @currentMapPath
235 expect "addMapReplace: check branch count in #{@main_A}", map.branchCount.to_i, n + 1
236 map.select @branch_0Aa
237 expect "addMapReplace: check if #{@branch_0Aa} is new", map.branchCount.to_i, 2
238 expect "addMapReplace: Loaded MapCenter 0", map.getHeadingPlainText, "MapCenter 0"
239 map.select @branch_0Ab
240 expect "addMapReplace: Loaded MapCenter 1", map.getHeadingPlainText, "MapCenter 1"
244 expect "Undo: check branch count in #{@main_A}", map.branchCount.to_i, 3
245 map.select @branch_0Aa
246 expect "Undo: check if #{@branch_0Aa} is back", map.branchCount.to_i, 3
249 map = init_map @testMapDefault
250 map.select @branch_0Aa
251 n = map.branchCount.to_i
252 map.addMapInsert @currentMapPath, 1 # Create testmap with several MCs
253 map.select @branch_0Aa
254 expect "addMapInsert: branch count", map.branchCount.to_i, n + 2
255 map.select @branch_0Aa + ",bo:1"
256 expect "addMapInsert: new heading", map.getHeadingPlainText, "MapCenter 0"
257 map.select @branch_0Aa + ",bo:2"
258 expect "addMapInsert: new heading", map.getHeadingPlainText, "MapCenter 1"
261 map.select @branch_0Aa
262 expect "Undo: check branch count in #{@branch_0Aa}", map.branchCount.to_i, 3
263 map.select @branch_0Ab
264 expect "Undo: check heading of #{@branch_0Ab}", map.getHeadingPlainText, "branch b"
268 #######################
270 heading "Attributes:"
271 map = init_map "maps/test-attributes.xml"
274 expect "String attribute is '6 * 9'", map.getStringAttribute("string-attribute"), "6 * 9"
275 expect "Integer attribute is 42", map.getIntAttribute("int-attribute"), 42
280 ######################
283 map = init_map @testMapDefault
288 #######################
290 heading "Copy, cut & Paste"
292 map = init_map @testMapDefault
294 n = map.branchCount.to_i
298 map.selectLatestAdded #FIXME-2 not set for ImportAdd, which is used by paste
299 s = map.getSelectionString
300 expect "Normal paste of branch, check heading of #{s}", map.getHeadingPlainText, "Main A"
304 expect "Undo paste: branchCount of #{@main_A}", map.branchCount.to_i, n
308 expect "redo paste: check heading", map.getHeadingPlainText, "Main A"
310 map.select @branch_0Aa
313 expect "cut: branchCount of #{@main_A}", map.branchCount.to_i, n
316 map.selectLastChildBranch
317 s = map.getSelectionString
318 expect "Normal paste of branch, check heading of #{s}", map.getHeadingPlainText, "branch a"
324 #######################
325 def test_delete_parts
326 heading "Deleting parts"
328 map = init_map @testMapDefault
330 n=map.branchCount.to_i
331 map.select @branch_0Aa
332 m=map.branchCount.to_i
335 expect "Remove branch: branchcount", map.branchCount.to_i, n - 1
338 expect "Undo Remove branch: branchcount parent", map.branchCount.to_i, n
339 map.select @branch_0Aa
340 expect "Undo Remove branch: branchcount restored branch", map.branchCount.to_i, m
344 map = init_map @testMapDefault
345 map.select @branch_0Aa
346 n = map.branchCount.to_i
348 map.select @branch_0Aa
349 expect "removeChildren: branchcount", map.branchCount.to_i, 0
351 map.select @branch_0Aa
352 expect "Undo: removeChildren: branchcount", map.branchCount.to_i, n
355 map = init_map @testMapDefault
358 n=map.branchCount.to_i
359 map.select @branch_0Aa
360 m=map.branchCount.to_i
361 map.removeKeepChildren
363 expect "removeKeepChildren: branchcount", map.branchCount.to_i, n + m - 1
366 expect "Undo: removeKeepChildren: branchcount of parent", map.branchCount.to_i, n
367 map.select @branch_0Aa
368 expect "Undo: removeKeepChildren: branchcount of branch", map.branchCount.to_i, m
371 map = init_map @testMapDefault
373 n = map.centerCount.to_i
376 expect "remove mapCenter: number of centers decreased", map.centerCount.to_i, n - 1
378 expect "Undo remove mapCenter: number of centers increased", map.centerCount.to_i, n
383 #######################
386 map = init_map @testMapDefault
389 exportdir = "#{@testDir}/export-html"
391 htmlpath = "#{exportdir}/output.html"
392 flagdir = "#{exportdir}/flags"
393 pngpath = "#{exportdir}/output.png"
394 csspath = "#{exportdir}/vym.css"
395 map.exportMap("HTML", htmlpath, exportdir)
396 expect "exportHTML: HTML file exists", File.exists?(htmlpath), true
397 expect "exportHTML: HTML image exists", File.exists?(pngpath), true
398 expect "exportHTML: HTML flags dir exists", Dir.exists?(flagdir), true
399 if Dir.exists?(flagdir)
400 expect "exportHTML: HTML flags dir not empty", Dir.empty?(flagdir), false
402 expect "exportHTML: HTML CSS exists", File.exists?(csspath), true
403 File.delete(htmlpath)
404 FileUtils.rm_r(flagdir)
407 map.exportMap("Last")
408 expect "exportLast: HTML #{htmlpath} file exists", File.exists?(htmlpath), true
409 expect "exportLast: HTML image exists", File.exists?(pngpath), true
410 expect "exportHTML: HTML flags dir exists", Dir.exists?(flagdir), true
411 if Dir.exists?(flagdir)
412 expect "exportHTML: HTML flags dir not empty", Dir.empty?(flagdir), false
414 expect "exportLast: HTML CSS exists", File.exists?(csspath), true
417 exportdir = "#{@testDir}/export-ao"
419 filepath = "#{exportdir}/output.txt"
420 map.exportMap("AO", filepath)
421 expect "exportAO: AO file exists", File.exists?(filepath), true
422 File.delete(filepath)
423 map.exportMap("Last")
424 expect "exportLast: AO file exists", File.exists?(filepath), true
427 exportdir = "#{@testDir}/export-ascii"
429 filepath = "#{exportdir}/output.txt"
430 map.exportMap("ASCII", filepath, false)
431 expect "exportASCII: ASCII file exists", File.exists?(filepath), true
432 File.delete(filepath)
433 map.exportMap("Last")
434 expect "exportLast: ASCII file exists", File.exists?(filepath), true
437 exportdir = "#{@testDir}/export-csv"
439 filepath = "#{exportdir}/output.csv"
440 map.exportMap("CSV", filepath)
441 expect "exportCSV: CSV file exists", File.exists?(filepath), true
442 File.delete(filepath)
443 map.exportMap("Last")
444 expect "exportLast: CSV file exists", File.exists?(filepath), true
447 exportdir = "#{@testDir}/export-image"
449 filepath = "#{exportdir}/output.png"
450 map.exportMap("Image", filepath,"PNG")
451 expect "exportImage: PNG file exists", File.exists?(filepath), true
452 File.delete(filepath)
453 map.exportMap("Last")
454 expect "exportLast: PNG file exists", File.exists?(filepath), true
457 exportdir = "#{@testDir}/export-latex"
459 filepath = "#{exportdir}/output.tex"
460 map.exportMap("LaTeX", filepath)
461 expect "exportLaTeX: LaTeX file exists", File.exists?(filepath), true
462 File.delete(filepath)
463 map.exportMap("Last")
464 expect "exportLast: LaTeX file exists", File.exists?(filepath), true
467 exportdir = "#{@testDir}/export-markdown"
469 filepath = "#{exportdir}/output.md"
470 map.exportMap("Markdown", filepath)
471 expect "exportMarkdown: Markdown file exists", File.exists?(filepath), true
472 File.delete(filepath)
473 map.exportMap("Last")
474 expect "exportLast: Markdown file exists", File.exists?(filepath), true
477 exportdir = "#{@testDir}/export-orgmode"
479 filepath = "#{exportdir}/output.org"
480 map.exportMap("OrgMode", filepath)
481 expect "exportOrgMode: OrgMode file exists", File.exists?(filepath), true
482 File.delete(filepath)
483 map.exportMap("Last")
484 expect "exportLast: OrgMode file exists", File.exists?(filepath), true
487 exportdir = "#{@testDir}/export-pdf"
489 filepath = "#{exportdir}/output.pdf"
490 map.exportMap("PDF", filepath)
491 expect "exportPDF: PDF file exists", File.exists?(filepath), true
492 File.delete(filepath)
493 map.exportMap("Last")
494 expect "exportLast: PDF file exists", File.exists?(filepath), true
497 exportdir = "#{@testDir}/export-svg"
499 filepath = "#{exportdir}/output.svg"
500 map.exportMap("SVG", filepath)
501 expect "exportSVG: SVG file exists", File.exists?(filepath), true
502 File.delete(filepath)
503 map.exportMap("Last")
504 expect "exportLast: SVG file exists", File.exists?(filepath), true
507 exportdir = "#{@testDir}/export-xml"
509 filepath = "#{exportdir}/output.xml"
510 map.exportMap("XML", filepath, @testDir)
511 expect "exportXML: XML file exists", File.exists?(filepath), true
512 File.delete(filepath)
513 map.exportMap("Last")
514 expect "exportLast: XML file exists", File.exists?(filepath), true
516 #OpenOffice Impress //FIXME-2
517 #Taskjuggler //FIXME-3
522 #######################
524 heading "Extra information:"
525 map = init_map @testMapDefault
526 map.setMapAuthor("Fra Erasmas")
527 expect "Set and get map author", map.getMapAuthor, "Fra Erasmas"
528 map.setMapComment("xy z")
529 expect "Set and get map comment", map.getMapComment, "xy z"
530 map.setMapTitle("vym rules!")
531 expect "Set and get map title", map.getMapTitle, "vym rules!"
536 ######################
539 map = init_map @testMapFrames
542 expect "Mapcenter of #{@center_0} has no inner frame", map.getFrameType(true), "NoFrame"
543 expect "Mapcenter of #{@center_0} has no outer frame", map.getFrameType(true), "NoFrame"
546 expect "Mapcenter of #{@center_1} has no inner frame", map.getFrameType(true), "NoFrame"
547 expectNot "Mapcenter of #{@center_1} has outer frame", map.getFrameType(false), "NoFrame"
550 expectNot "Mapcenter of #{@center_2} has inner frame", map.getFrameType(true), "NoFrame"
551 expect "Mapcenter of #{@center_2} has no outer frame", map.getFrameType(false), "NoFrame"
554 expectNot "Mapcenter of #{@center_3} has inner frame", map.getFrameType(true), "NoFrame"
555 expectNot "Mapcenter of #{@center_3} has outer frame", map.getFrameType(false), "NoFrame"
561 # FIXME same checks like for notes above for headings
564 #######################
568 map = init_map @testMapDefault
570 map.setHeadingPlainText "A"
571 map.setHeadingPlainText "B"
572 map.setHeadingPlainText "C"
576 expect "Undo 3 times, after changing heading -> 'A' -> 'B' -> 'C'", map.getHeadingPlainText, "Main A"
578 expect "Redo once", map.getHeadingPlainText, "A"
581 expect "Redo once more", map.getHeadingPlainText, "B"
583 expect "Redo yet again", map.getHeadingPlainText, "C"
584 map.setHeadingPlainText "Main A"
586 map.selectLastChildBranch
587 expect "Paste from the past", map.getHeadingPlainText, "A"
593 #######################
595 heading "Scrolling and unscrolling"
596 map = init_map @testMapDefault
600 expect "toggleScroll", map.isScrolled, true
602 expect "undo toggleScroll", map.isScrolled, false
604 expect "scroll", map.isScrolled, true
606 expect "unscroll", map.isScrolled, false
609 map.select @branch_0Aa
613 map.select @branch_0Aa
614 expect "unscrollChildren", map.isScrolled, false
616 expect "undo unscrollChildren", map.isScrolled, true
621 #######################
624 map = init_map "maps/test-slides.xml"
627 expect "Successfully loaded map with slides", map.slideCount, 3
632 #######################
633 def test_modify_branches
634 heading "Modifying branches"
635 map = init_map @testMapDefault
637 map.select @branch_0Aa
638 map.setHeadingPlainText "Changed!"
639 expect "setHeadingPlainText", map.getHeadingPlainText, "Changed!"
641 expect "Undo: setHeadingPlainText", map.getHeadingPlainText, "branch a"
643 expect "redo: setHeadingPlainText", map.getHeadingPlainText, "Changed!"
649 #######################
650 def test_moving_parts
651 heading "Moving parts"
652 map = init_map @testMapDefault
654 map.select @branch_0Aa
656 map.select @branch_0Aa
657 expect "Moving down", map.getHeadingPlainText, "branch b"
659 map.select @branch_0Aa
660 expect "Undo Moving down", map.getHeadingPlainText, "branch a"
662 #map = init_map( vym )
663 map.select @branch_0Ab
665 map.select @branch_0Aa
666 expect "Moving up", map.getHeadingPlainText, "branch b"
668 map.select @branch_0Ab
669 expect "Undo Moving up", map.getHeadingPlainText, "branch b"
671 #map = init_map( vym )
673 n=map.branchCount.to_i
674 map.select @branch_0Aa
675 map.relinkTo @main_B,0,0,0
677 expect "RelinkTo #{@main_B}: branchCount increased there", map.branchCount.to_i, n+1
680 map.select @branch_0Ab
681 expect "Undo: RelinkTo #{@main_B}: branchCount decreased there", map.branchCount.to_i, n
683 #map = init_map( vym )
685 err = map.relinkTo @branch_0Aa,0,0,0
686 #FIXME-2 disabled, error not supported atm expect_error "RelinkTo myself fails.", err
688 #map = init_map( vym )
689 map.select @branch_0Aa
690 n=map.branchCount.to_i
692 map.relinkTo @branch_0Aa, 1, 0, 0
693 map.select @branch_0Aa
694 expect "RelinkTo #{@branch_0Aa}, pos 1: branchCount increased there", map.branchCount.to_i, n+1
695 map.select "#{@branch_0Aa},bo:1"
696 expect "RelinkTo #{@branch_0Aa}, pos 1: Mainbranch really moved", map.getHeadingPlainText, "Main B"
699 expect "Undo RelinkTo pos 1: branchCount of center", map.branchCount.to_i, 2
704 ######################
708 # Plaintext notes basic actions
709 map = init_map @testMapDefault
712 note_plain = "vymnote plaintext"
713 map.setNotePlainText(note_plain)
714 expect "Set note to \"#{note_plain}\". Still plaintext?", map.hasRichTextNote, false
717 expect "After reselect, is note plaintext?", map.hasRichTextNote, false
719 note_plain = "<b>plaintext, not bold!</b>"
720 map.setNotePlainText(note_plain)
721 expect "Set note to plaintext containing html tags. Still plaintext", map.hasRichTextNote, false
722 note_new = map.getNotePlainText
725 expect "After reselect, is note text unchanged?", map.getNotePlainText, note_new
726 expect "After reselect, is note plaintext?", map.hasRichTextNote, false
728 # Plaintext notes copy & paste
731 map.selectLastChildBranch
732 s=map.getSelectionString
733 expect "After copy& paste: New note unchanged?", map.getNotePlainText, note_plain
734 expect "After copy& paste: New note Still plaintext?", map.hasRichTextNote, false
737 # Plaintext notes undo & redo
739 map.setNotePlainText('Foobar')
741 expect "Undo after setNotePlainText restores previous note", map.getNotePlainText, note_plain
744 expect "Redo restores previous note", map.getNotePlainText, 'Foobar'
746 # Plaintext notes load & save
747 note_org = IO.read('notes/note-plain.txt')
748 map.loadNote("test/notes/note-plain.txt")
749 expect "Load plain text note from file. Still plaintext?", map.hasRichTextNote, false
750 expect "Note contains 'not bold'", map.getNotePlainText.include?("not bold"), true
751 filepath = "#{@testDir}/save-note.txt"
752 map.saveNote(filepath)
753 expect "Save note to file. Check if it contains 'textMode=\"plainText\"'", IO.read(filepath).include?("textMode=\"plainText\""), true
754 expect "Save note to file. Check if it contains 'not bold'", IO.read(filepath).include?("not bold"), true
755 expect "Save note to file. Check new format: no longer contains '<b>' element", IO.read(filepath).include?("<b>"), false
756 expect "Save note to file. Check new format: no longer contains '<![CDATA['", IO.read(filepath).include?("<![CDATA["), false
757 expect "Save note to file. Check new format: contains 'text=\"Plaintext'", IO.read(filepath).include?("text=\"Plaintext"), true
760 map.setNotePlainText("")
761 expect "setNotePlainText(\"\") deletes note", map.hasNote, false
765 # RichText basic actions
766 map = init_map @testMapDefault
768 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>'
769 map.parseVymText(rt_note)
770 expect "parseVymText of richText note produces note", map.hasNote, true
771 expect "parseVymText of richText note produces richText note", map.hasRichTextNote, true
774 expect "After reselect, is note RichText?", map.hasRichTextNote, true
777 # RichText notes copy & paste
778 rt_note = map.getNoteXML
781 map.selectLastChildBranch
782 s = map.getSelectionString
783 expect "After copy & paste: New note Still RichText?", map.hasRichTextNote, true
784 expect "After copy & paste: New note unchanged?", map.getNoteXML, rt_note
787 # RichText notes undo & redo
789 map.setNotePlainText('Foobar')
791 expect "Undo after setNotePlainText restores RichText note", map.getNoteXML, rt_note
794 expect "Redo restores previous plaintext note", map.getNotePlainText, 'Foobar'
796 # RichText notes load & save
797 map.loadNote("test/notes/note.html")
798 expect "Load HTML note from file and try to detect textMode. Is RichText?", map.hasRichTextNote, true
799 filepath = "#{@testDir}/save-note.txt"
800 map.saveNote(filepath)
801 expect "Save note to file. Check if it contains 'textMode=\"richText\"'", IO.read(filepath).include?("textMode=\"richText\""), true
802 expect "Save note to file. Check if it contains 'bold'", IO.read(filepath).include?("bold"), true
803 expect "Save note to file. Check new format: no longer contains '<b>' element", IO.read(filepath).include?("<b>"), false
804 expect "Save note to file. Check new format: no longer contains '<![CDATA['", IO.read(filepath).include?("<![CDATA["), false
805 expect "Save note to file. Check new format: contains 'text=\"<'", IO.read(filepath).include?("text=\"<"), true
808 map.setNotePlainText("")
809 expect "setNotePlainText(\"\") deletes note", map.hasNote, false
811 # Compatibility with version < 2.5.0 # FIXME-2 missing
816 #######################
819 map = init_map @testMapDefault
822 url = "www.insilmaril.de"
824 expect "setURL to '#{url}'", map.getURL, url
827 expect "undo setURL", map.getURL, ""
829 expect "redo setURL", map.getURL, url
831 expect "setURL: unset URL with empty string", map.getURL, ""
836 expect "setVymLink returns absolute path", map.getFileDir + vl, s
838 expect "undo: setVymLink", map.getVymLink, ""
840 expect "redo: setVymLink", map.getVymLink, s
846 #######################
847 def test_standard_flags
848 heading "Standard flags"
849 map = init_map @testMapDefault
852 def set_flags (map, flags)
854 map.setFlagByName( f )
855 expect "Flag set: #{f}", map.hasActiveFlag( f ), true
859 def unset_flags (map, flags)
861 map.unsetFlagByName( f )
862 expect "Flag unset: #{f}", map.hasActiveFlag( f ), false
866 # Group standard-mark
867 set_flags( map, [ "exclamationmark","questionmark"] )
869 # Group standard-status
870 set_flags( map, [ "hook-green",
875 # Group standard-smiley
876 smileys = [ "smiley-good",
879 set_flags( map, smileys )
881 # Group standard-arrow
882 set_flags( map, [ "arrow-up",
887 # Group standard-thumb
888 set_flags( map, [ "thumb-up", "thumb-down" ] )
891 set_flags( map, [ "clock",
901 unset_flags( map, smileys )
905 expect "clearFlags cleared exclamationmark", map.hasActiveFlag( "exclamationmark" ), false
906 expect "clearFlags cleared smiley-good", map.hasActiveFlag( "smiley-good" ), false
910 a = ["stopsign", "lifebelt"]
912 #puts "Flag is now: #{flag}"
913 map.toggleFlagByName flag
914 expect "toggleFlag: flag #{flag} activated", map.hasActiveFlag(flag), true
916 map.toggleFlagByName flag
917 expect "toggleFlag: flag #{flag} deactivated", map.hasActiveFlag(flag), false
923 #######################
926 map = init_map "maps/test-userflag.vym"
928 map.select @branch_0Aa
929 flagName = "userflag-vym"
930 expect "Has active flag '#{flagName}'", map.hasActiveFlag(flagName), true
936 #######################
939 map = init_map @testMapDefault
941 map.addXLink("mc:0,bo:0","mc:0,bo:1",2,"#ff0000","Qt::DashDotLine")
942 map.selectLatestAdded
943 expect "Default color of XLink", map.getXLinkColor, "#ff0000"
944 expect "Default width of XLink", map.getXLinkWidth.to_i, 2
945 expect "Default style of XLink", map.getXLinkPenStyle, "Qt::DashDotLine"
946 expect "Default style of XLink begin", map.getXLinkStyleBegin, "HeadFull"
947 expect "Default style of XLink end", map.getXLinkStyleEnd, "HeadFull"
950 expect "New width of XLink", map.getXLinkWidth.to_i, 3
952 expect "Undo width of XLink", map.getXLinkWidth.to_i, 2
954 map.setXLinkColor("#00ff00")
955 expect "New color of XLink", map.getXLinkColor, "#00ff00"
957 expect "Undo color of XLink", map.getXLinkColor, "#ff0000"
959 map.setXLinkStyle("Qt::SolidLine")
960 expect "New style of XLink", map.getXLinkPenStyle, "Qt::SolidLine"
962 expect "Undo style of XLink", map.getXLinkPenStyle, "Qt::DashDotLine"
964 map.setXLinkStyleBegin("None")
965 expect "New style of XLink begin", map.getXLinkStyleBegin, "None"
967 expect "Undo style of XLink begin", map.getXLinkStyleBegin, "HeadFull"
969 map.setXLinkStyleEnd("None")
970 expect "New style of XLink end", map.getXLinkStyleEnd, "None"
972 expect "Undo style of XLink end", map.getXLinkStyleEnd, "HeadFull"
977 #######################
980 map = init_map "maps/test-tasks.xml"
982 map.select @branch_0Aa
983 expect "After loading #{@branch_0Aa} has no task", map.hasTask, false
985 map.select @branch_0Ab
986 expect "After loading #{@branch_0Ab} has task", map.hasTask, true
987 expect "After loading #{@branch_0Ab} task sleeps more than 1000 days",
988 map.getTaskSleepDays.to_i > 1000, true
990 map.select @branch_0Aa
992 expect "Toggle task", map.hasTask, true
994 date_today = DateTime.now
996 date_later = date_today + delta_days
997 date_later_iso = date_later.strftime("%Y-%m-%dT%H:%M:%S")
999 # Input: number of days
1000 date_new = delta_days
1001 expect "Set task sleep to number of days '#{date_new}' accepts input", map.setTaskSleep(date_new), true
1002 expect "Set task sleep to number of days '#{date_new}' has correct sleep value '#{delta_days}' days", map.getTaskSleepDays.to_i, delta_days
1004 # Input: number of seconds
1006 expect "Set task sleep to number of seconds '#{date_new}' accepts input", map.setTaskSleep(date_new), true
1008 # Input: number of hours
1010 expect "Set task sleep to number of hours '#{date_new}' accepts input", map.setTaskSleep(date_new), true
1013 date_new = date_later.strftime("%Y-%m-%d")
1014 expect "Set task sleep to ISO Date '#{date_new}' accepts input", map.setTaskSleep(date_new), true
1015 expect "Set task sleep to ISO Date '#{date_new}' has correct sleep value '#{delta_days}' days", map.getTaskSleepDays.to_i, delta_days
1017 date_new = date_later.strftime("%d.%m.")
1018 expect "Set task sleep to German short form '#{date_new}' accepts input '#{date_new}'", map.setTaskSleep(date_new), true
1019 expect "Set task sleep to German short form '#{date_new}' has correct sleep value (days)", map.getTaskSleepDays.to_i, delta_days
1021 date_new = date_later.strftime("%d.%m.%Y")
1022 expect "Set task sleep to German long form '#{date_new}' accepts input '#{date_new}'", map.setTaskSleep(date_new), true
1023 expect "Set task sleep to German long form '#{date_new}' has correct sleep value (days)", map.getTaskSleepDays.to_i, delta_days
1025 # Input: Invalid strings
1026 date_new = "invalidDate"
1027 expect "Set task sleep to '#{date_new}' should fail", map.setTaskSleep(date_new), false
1029 date_new = date_later.strftime("%d %m.%Y")
1030 expect "Set task sleep to '#{date_new}' should fail", map.setTaskSleep(date_new), false
1033 date_new = date_later_iso
1034 expect "Set task sleep to ISO DateTime '#{date_new}' accepts input", map.setTaskSleep(date_new), true
1035 expect "Set task sleep to ISO DateTime '#{date_new}' returns correct sleep value '#{date_later_iso}'", map.getTaskSleep, date_later_iso
1038 date_later = date_today
1041 date_later_iso = date_today.strftime("%Y-%m-%dT12:34:00")
1042 expect "Set task sleep to time '#{date_new}' accepts input", map.setTaskSleep(date_new), true
1043 expect "Set task sleep to time '#{date_new}' returns correct sleep value '#{date_later_iso}'",
1044 map.getTaskSleep, date_later_iso
1047 date_later_iso = date_today.strftime("%Y-%m-%dT02:04:00")
1048 expect "Set task sleep to time '#{date_new}' accepts input", map.setTaskSleep(date_new), true
1049 expect "Set task sleep to time '#{date_new}' returns correct sleep value '#{date_later_iso}'",
1050 map.getTaskSleep, date_later_iso
1053 date_later_iso = date_today.strftime("%Y-%m-%dT03:05:00")
1054 expect "Set task sleep to time '#{date_new}' accepts input", map.setTaskSleep(date_new), true
1055 expect "Set task sleep to time '#{date_new}' returns correct sleep value '#{date_later_iso}'",
1056 map.getTaskSleep, date_later_iso
1061 ######################
1064 map = init_map @testMapDefault
1066 # Save selection without overwriting original map
1067 map.select @branch_0Aa
1068 fn = @testDir + "/test-saveSelection.vyp"
1069 map.saveSelection(fn)
1070 expect "#Save selection: #{@branch_0Aa} to #{fn}", File.file?(fn), true
1075 map.select @center_0
1076 expect "Save selection: After loading of #{fn} #{@center_0} is ok", map.getHeadingPlainText, "branch a"
1078 expect "Save selection: After loading of #{fn} #{@main_A} is ok", map.getHeadingPlainText, "branch a1"
1083 ######################
1084 def test_load_legacy_maps
1085 heading "Load legacy maps:"
1087 map = init_map "maps/legacy/legacy-text-2.4.0.xml"
1088 map.select @branch_0Aa
1089 expect "Heading with plaintext as characters is read", map.getHeadingPlainText, "Heading in characters"
1091 # map.select @center_0
1092 # expect "Checking parsing 'absPos': x-position of #{@center_0} is ok", map.getPosX().to_f, 314
1093 # expect "Checking parsing 'absPos': y-position of #{@center_0} is ok", map.getPosY().to_f, 0
1094 # map.select @main_A
1095 # expect "Checking parsing 'relPos': x-position of #{@main_A} is ok", map.getPosX().to_f, 123
1096 # expect "Checking parsing 'relPos': y-position of #{@main_A} is ok", map.getPosY().to_f, 42
1100 map = init_map "maps/legacy/time-management-1.13.33.vym"
1102 s = "To see an explanation"
1103 expect "<heading> using characters: Heading includes '#{s}'", map.getHeadingPlainText.include?(s), true
1104 expect "<vymnote> using <html>: creates RichText note", map.hasRichTextNote, true
1105 s = "time management"
1106 expect "<vymnote> using <html>: Note contains '#{s}'", map.getNotePlainText.include?(s), true
1110 map = init_map "maps/legacy/lifeforms-2.1.11.vym"
1111 map.select @center_0
1114 expect "<heading> using characters and HTML: includes '#{s}'", map.getHeadingXML.include?(s), true
1115 s = "textMode=\"richText"
1116 expect "<heading> using characters creates RichText", map.getHeadingXML.include?(s), true
1120 map = init_map "maps/legacy/faq-2.5.21.xml"
1121 map.select @branch_0Ab
1123 s = "libqt5-devel.rpm"
1124 expect "<vymnote> using characters and CDATA: has RichText note", map.hasRichTextNote, true
1125 expect "<vymnote> using characters and CDATA: includes '#{s}'", map.getNotePlainText.include?(s), true
1126 expect "<vymnote> using characters and CDATA: has RichText note", map.hasRichTextNote, true
1128 map.select @branch_0Ac
1129 s = "textMode=\"richText"
1130 expect "<heading> using characters and CDATA: creates RichText", map.getHeadingXML.include?(s), true
1132 expect "<heading> using characters and CDATA: includes '#{s}'", map.getHeadingPlainText.include?(s), true
1138 "maps/legacy/external-note-plaintext.txt",
1139 "maps/legacy/external-note-richtext.html" ]
1140 map = init_map "maps/legacy/notes.xml", files
1142 map.select @branch_0Aa
1143 expect"<note> with plaintext in external file: text has type PlainText",
1144 map.hasRichTextNote, false
1145 expectInclude "<note> with plaintext in external file: text is read correctly",
1146 map.getNotePlainText,
1147 "PlainText note in file"
1149 map.select @branch_0Ab
1150 expect"<note> with plaintext in characters: text has type PlainText",
1151 map.hasRichTextNote, false
1152 expectInclude "<note> reads plaintext from characters",
1153 map.getNotePlainText,
1154 "PlainText note in characters"
1156 map.select @branch_0Ac
1157 expect"<note> with RichText in external file: text has type RichText",
1158 map.hasRichTextNote, true
1159 expectInclude "<note> reads RichText from external file",
1160 map.getNotePlainText,
1161 "RichText note in file"
1162 map.select @branch_0Ab
1164 map.select @branch_0Ba
1165 expect"<htmlnote> with PlainText in characters: text has type PlainText",
1166 map.hasRichTextNote, false
1167 expectInclude "<htmlnote> reads PlainText from characters",
1168 map.getNotePlainText,
1169 "PlainText note in characters"
1170 map.select @branch_0Bb
1171 expect"<htmlnote> with RichText in characters: text has type RichText",
1172 map.hasRichTextNote, true
1173 expectInclude "<htmlnote> reads RichText from characters",
1174 map.getNotePlainText,
1175 "RichText note in characters"
1177 # FIXME-2 implement and add test: xlinks in subitems of branches (pre 1.13.2)
1181 #######################
1183 # Untested commands:
1202 relinkTo (for images)
1210 setFrameIncludeChildren
1216 setHideLinksUnselected
1217 setIncludeImagesHorizontally
1218 setIncludeImagesVertically
1221 setMapBackgroundColor
1234 toggleFrameIncludeChildren
1242 OptionParser.new do |opts|
1243 opts.banner = "Usage: vym-test.rb [options]"
1245 opts.on('-d', '--directory NAME', 'Directory name') { |s| options[:testDir] = s }
1248 @testDir = options[:testDir]
1249 @testMapDefault= "maps/test-default.vym"
1250 @testMapFrames = "maps/test-frames.vym"
1257 #######################
1259 @main_A = "mc:0,bo:0"
1260 @branch_0Aa = @main_A + ",bo:0"
1261 @branch_0Ab = @main_A + ",bo:1"
1262 @branch_0Ac = @main_A + ",bo:2"
1264 @branch_0Ba = @main_B + ",bo:0"
1265 @branch_0Bb = @main_B + ",bo:1"
1270 instance_name = 'test'
1272 vym_mgr = VymManager.new
1273 #vym_mgr.show_running
1275 @vym = vym_mgr.find(instance_name)
1278 puts "Couldn't find instance name \"#{instance_name}\", please start one:"
1279 puts "vym -l -n \"#{instance-name}\" -t test/default.vym"
1286 #test_adding_branches
1295 ##test_headings # FIXME-2 no tests available
1297 test_load_legacy_maps
1298 #test_modify_branches
1305 #test_standard_flags