]> git.sven.stormbind.net Git - sven/vym.git/blob - test/vym-test.rb
New upstream version 2.9.22
[sven/vym.git] / test / vym-test.rb
1 #!/usr/bin/env ruby
2
3 require "#{ENV['PWD']}/scripts/vym-ruby"
4 require 'date'
5 require 'fileutils'
6 require 'optparse'
7
8
9 def waitkey
10   puts "Press return to continue..."
11   STDIN.gets
12 end
13
14 def expect (comment, v_real, v_exp)
15   if v_exp == v_real
16     puts "    Ok: #{comment}"
17     $tests_passed += 1
18     # waitkey
19   else  
20     puts "Failed: #{comment}. Expected '#{v_exp}', but got '#{v_real}'"
21     $tests_failed += 1
22     waitkey
23   end  
24   $tests_total += 1
25 end    
26
27 def expect_warning_only (comment, v_real, v_exp)
28   if v_exp == v_real
29     puts "    Ok: #{comment}"
30     $tests_passed += 1
31     # waitkey
32   else  
33     puts "Warning: #{comment}. Expected '#{v_exp}', but got '#{v_real}'"
34     $tests_warnings += 1
35   end  
36   $tests_total += 1
37 end    
38
39 def expect_error (comment, error)
40   if error.length ==  0
41     puts "Failed: #{comment}. Command did not return error."
42     $tests_failed += 1
43   else  
44     puts "    Ok: #{comment}"
45     $tests_passed += 1
46   end
47   $tests_total += 1
48 end
49
50 def heading (s)
51   puts "\n#{s}\n#{'-' * s.length}\n"
52 end
53
54 def init_map( vym )
55   # FIXME-2 Missing: check or init default map 
56   # Map Structure:
57   # MapCenter 0
58   #   Main A
59   #     branch a
60   #       branch a1
61   #       branch a2
62   #       branch a3
63   #   Main B
64   # MapCenter 1
65
66   #n = vym.mapCount.to_i
67   #vym.loadMap (@testmap)
68   return vym.map (1)
69 end
70
71 def summary
72   puts "\nTests done  : #{$tests_total}"
73   puts "Tests passed: #{$tests_passed}"
74   puts "Warnings:     #{$tests_warnings}"
75   puts "Tests failed: #{$tests_failed}"
76 end
77
78 #######################
79 def test_vym (vym)
80   heading "Mainwindow checks:"
81   version = "2.9.0"
82   expect_warning_only "Version is #{version}", vym.version, version
83
84   expect "Loading map '#{@testmap}'", vym.loadMap(@testmap), true
85
86   vym.clearConsole
87 end
88
89 #######################
90 def test_basics (vym)
91   heading "Basic checks:"
92   map = init_map( vym )
93
94   title = "vym map used for testing"
95   expect "map title is '#{title}'", map.getMapTitle, title
96   author ="Uwe Drechsel"
97   expect "Author is '#{author}'", map.getMapAuthor, author
98
99   map.select @main_a
100   expect "select mainbranch A", map.getSelectionString, @main_a
101   expect "getHeadingPlainText", map.getHeadingPlainText, "Main A"
102   expect "branchCount", map.branchCount, 3
103
104   map.selectLastBranch
105   expect "selectLastBranch", map.getHeadingPlainText, "Main B"
106
107   map.selectFirstBranch
108   expect "selectFirstBranch", map.getHeadingPlainText, "Main A"
109
110   map.selectParent
111   expect "selectParent", map.getHeadingPlainText, "MapCenter 0"
112
113   expect "getDestPath: Got #{map.getDestPath}", map.getDestPath, @testdir + "/testmap.vym" 
114   expect "getFileDir:  Got #{map.getFileDir}", map.getFileDir, @testdir + "/" 
115 end
116
117 #######################
118 def test_export (vym)
119   heading "Export:"
120   map = init_map( vym )
121
122   #HTML
123   exportdir = "#{@testdir}/export-html"
124   Dir.mkdir(exportdir)
125   htmlpath = "#{exportdir}/output.html"
126   flagdir  = "#{exportdir}/flags"
127   pngpath = "#{exportdir}/output.png"
128   csspath = "#{exportdir}/vym.css"
129   map.exportMap("HTML", htmlpath, exportdir)
130   expect "exportHTML: HTML file exists", File.exists?(htmlpath), true
131   expect "exportHTML: HTML image exists", File.exists?(pngpath), true
132   expect "exportHTML: HTML flags dir exists", Dir.exists?(flagdir), true
133   if Dir.exists?(flagdir)
134     expect "exportHTML: HTML flags dir not empty", Dir.empty?(flagdir), false
135   end
136   expect "exportHTML: HTML CSS exists", File.exists?(csspath), true
137   File.delete(htmlpath)
138   FileUtils.rm_r(flagdir)
139   File.delete(pngpath)
140   File.delete(csspath)
141   map.exportMap("Last")
142   expect "exportLast: HTML #{htmlpath} file exists", File.exists?(htmlpath), true
143   expect "exportLast: HTML image exists", File.exists?(pngpath), true
144   expect "exportHTML: HTML flags dir exists", Dir.exists?(flagdir), true
145   if Dir.exists?(flagdir)
146     expect "exportHTML: HTML flags dir not empty", Dir.empty?(flagdir), false
147   end
148   expect "exportLast: HTML CSS exists", File.exists?(csspath), true
149
150   #AO
151   exportdir = "#{@testdir}/export-ao"
152   Dir.mkdir(exportdir)
153   filepath = "#{exportdir}/output.txt"
154   map.exportMap("AO", filepath)
155   expect "exportAO:    AO file exists", File.exists?(filepath), true
156   File.delete(filepath)
157   map.exportMap("Last")
158   expect "exportLast:  AO file exists", File.exists?(filepath), true
159
160   #ASCII
161   exportdir = "#{@testdir}/export-ascii"
162   Dir.mkdir(exportdir)
163   filepath = "#{exportdir}/output.txt"
164   map.exportMap("ASCII", filepath, false)
165   expect "exportASCII: ASCII file exists", File.exists?(filepath), true
166   File.delete(filepath)
167   map.exportMap("Last")
168   expect "exportLast:  ASCII file exists", File.exists?(filepath), true
169
170   #CSV
171   exportdir = "#{@testdir}/export-csv"
172   Dir.mkdir(exportdir)
173   filepath = "#{exportdir}/output.csv"
174   map.exportMap("CSV", filepath)
175   expect "exportCSV:    CSV file exists", File.exists?(filepath), true
176   File.delete(filepath)
177   map.exportMap("Last")
178   expect "exportLast:  CSV file exists", File.exists?(filepath), true
179
180   #Image
181   exportdir = "#{@testdir}/export-image"
182   Dir.mkdir(exportdir)
183   filepath = "#{exportdir}/output.png"
184   map.exportMap("Image", filepath,"PNG")
185   expect "exportImage: PNG file exists", File.exists?(filepath), true
186   File.delete(filepath)
187   map.exportMap("Last")
188   expect "exportLast:  PNG file exists", File.exists?(filepath), true
189
190   #LaTeX
191   exportdir = "#{@testdir}/export-latex"
192   Dir.mkdir(exportdir)
193   filepath = "#{exportdir}/output.tex"
194   map.exportMap("LaTeX", filepath)
195   expect "exportLaTeX:  LaTeX file exists", File.exists?(filepath), true
196   File.delete(filepath)
197   map.exportMap("Last")
198   expect "exportLast:   LaTeX file exists", File.exists?(filepath), true
199
200   #Markdown
201   exportdir = "#{@testdir}/export-markdown"
202   Dir.mkdir(exportdir)
203   filepath = "#{exportdir}/output.md"
204   map.exportMap("Markdown", filepath)
205   expect "exportMarkdown:  Markdown file exists", File.exists?(filepath), true
206   File.delete(filepath)
207   map.exportMap("Last")
208   expect "exportLast:     Markdown file exists", File.exists?(filepath), true
209
210   #OrgMode
211   exportdir = "#{@testdir}/export-orgmode"
212   Dir.mkdir(exportdir)
213   filepath = "#{exportdir}/output.org"
214   map.exportMap("OrgMode", filepath)
215   expect "exportOrgMode:  OrgMode file exists", File.exists?(filepath), true
216   File.delete(filepath)
217   map.exportMap("Last")
218   expect "exportLast:     OrgMode file exists", File.exists?(filepath), true
219
220   #PDF
221   exportdir = "#{@testdir}/export-pdf"
222   Dir.mkdir(exportdir)
223   filepath = "#{exportdir}/output.pdf"
224   map.exportMap("PDF", filepath)
225   expect "exportPDF:  PDF file exists", File.exists?(filepath), true
226   File.delete(filepath)
227   map.exportMap("Last")
228   expect "exportLast: PDF file exists", File.exists?(filepath), true
229
230   #SVG
231   exportdir = "#{@testdir}/export-svg"
232   Dir.mkdir(exportdir)
233   filepath = "#{exportdir}/output.svg"
234   map.exportMap("SVG", filepath)
235   expect "exportSVG:  SVG file exists", File.exists?(filepath), true
236   File.delete(filepath)
237   map.exportMap("Last")
238   expect "exportLast: SVG file exists", File.exists?(filepath), true
239
240   #XML
241   exportdir = "#{@testdir}/export-xml"
242   Dir.mkdir(exportdir)
243   filepath = "#{exportdir}/output.xml"
244   map.exportMap("XML", filepath, @testdir)
245   expect "exportXML: XML file exists", File.exists?(filepath), true
246   File.delete(filepath)
247   map.exportMap("Last")
248   expect "exportLast: XML file exists", File.exists?(filepath), true
249
250   #OpenOffice Impress //FIXME-2
251   #Taskjuggler //FIXME-3
252 end
253
254 #######################
255 def test_extrainfo (vym)
256   heading "Extra information:"
257   map = init_map( vym )
258   map.setMapAuthor("Fra Erasmas")
259   expect "Set and get map author", map.getMapAuthor, "Fra Erasmas"
260   map.setMapComment("xy z")
261   expect "Set and get map comment", map.getMapComment, "xy z"
262   map.setMapTitle("vym rules!")
263   expect "Set and get map title", map.getMapTitle, "vym rules!"
264 end
265
266 #######################
267 def test_adding_branches (vym)
268   heading "Adding branches:"
269   map = init_map( vym )
270   map.select @main_a
271   n = map.branchCount.to_i
272   map.addBranch()
273   expect( "addBranch", map.branchCount.to_i, n + 1 )
274
275   map.selectLatestAdded
276   expect "selectLatestAdded", map.getSelectionString, @main_a + ",bo:3"
277
278   map.undo
279   expect( "Undo: addBranch", map.branchCount.to_i, n )
280
281   map = init_map( vym )
282   map.select @main_a
283   n = map.branchCount.to_i
284   map.select @branch_a
285   map.addBranch( -3 )
286   map.addBranch( -1 )
287   map.select @main_a
288   expect "addBranchAbove/Below", map.branchCount.to_i, n + 2
289
290   map.undo
291   map.undo
292   expect "Undo: addBranchAbove/Below", map.branchCount.to_i, n
293
294   map = init_map( vym )
295   map.select @branch_a
296   map.addBranchBefore
297   map.select @main_a
298   expect "addBranchBefore: check branchcount",  map.branchCount.to_i, n
299   map.select @branch_a
300   expect "addBranchBefore: check heading", map.getHeadingPlainText, ""
301
302   # Undo twice: addBranchNew and relinkTo
303   map.undo
304   map.undo
305   map.select @main_a
306   expect "Undo: addBranchBefore", map.branchCount.to_i, n  
307 end
308
309 #######################
310 def test_adding_maps (vym)
311   heading "Adding maps"
312   map = init_map( vym )
313   map.select @branch_a
314   n=map.branchCount.to_i
315   map.addMapReplace "test/default.vym"
316   map.select @main_a
317   expect "addMapReplace: check branch count in #{@main_a}", map.branchCount.to_i, n + @n_centers -1
318   map.select @branch_a
319   expect "addMapReplace: check if #{@branch_a} is new", map.branchCount.to_i, 2
320   
321   map.undo
322   map.select @main_a
323   expect "Undo: check branch count in #{@main_a}", map.branchCount.to_i, 3
324   map.select @branch_a
325   expect "Undo: check if #{@branch_a} is back", map.branchCount.to_i, 3 
326   
327   map = init_map( vym )
328   map.select @main_a
329   map.addMapInsert "test/default.vym", 1
330   map.select @main_a
331   expect "addMapInsert: branch count",  map.branchCount.to_i, n + 2 
332   map.select @main_a + ",bo:1"
333   expect "addMapInsert: new heading", map.getHeadingPlainText, "MapCenter 0"
334   
335   map.undo
336   map.select @main_a
337   expect "Undo: check branch count in #{@main_a}", map.branchCount.to_i, 3 
338   map.select @branch_b
339   expect "Undo: check heading of  #{@branch_b}",  map.getHeadingPlainText, "branch b"
340 end
341
342 #######################
343 def test_scrolling (vym)
344   heading "Scrolling and unscrolling"
345   map = init_map( vym )
346   map.select @main_a
347   map.toggleScroll
348   expect "toggleScroll", map.isScrolled, true
349   map.undo
350   expect "undo toggleScroll", map.isScrolled, false
351   map.scroll
352   expect "scroll", map.isScrolled, true
353   map.unscroll
354   expect "unscroll", map.isScrolled, false
355
356   map = init_map( vym )
357   map.scroll
358   map.select @branch_a
359   map.scroll
360   map.select @main_a
361   map.unscrollChildren
362   map.select @branch_a
363   expect "unscrollChildren", map.isScrolled, false
364   map.undo
365   expect "undo unscrollChildren", map.isScrolled, true
366   map.unscroll
367   map.select @branch_a
368   map.unscroll
369 end
370
371 #######################
372 def test_moving_parts (vym)
373   heading "Moving parts"
374   map = init_map( vym )
375   map.select @branch_a
376   map.moveDown
377   map.select @branch_a
378   expect "Moving down", map.getHeadingPlainText, "branch b"
379   map.undo
380   map.select @branch_a
381   expect "Undo Moving down", map.getHeadingPlainText, "branch a"
382   
383   map = init_map( vym )
384   map.select @branch_b
385   map.moveUp
386   map.select @branch_a
387   expect "Moving up", map.getHeadingPlainText, "branch b"
388   map.undo
389   map.select @branch_b
390   expect "Undo Moving up", map.getHeadingPlainText, "branch b"
391   
392   map = init_map( vym )
393   map.select @main_b
394   n=map.branchCount.to_i
395   map.select @branch_a
396   map.relinkTo @main_b,0,0,0
397   map.select @main_b
398   expect "RelinkTo #{@main_b}: branchCount increased there",  map.branchCount.to_i, n+1
399
400   map.undo
401   map.select @branch_b
402   expect "Undo: RelinkTo #{@main_b}: branchCount decreased there", map.branchCount.to_i, n
403   
404   map = init_map( vym )
405   map.select @main_a
406   err = map.relinkTo @branch_a,0,0,0
407   expect_error "RelinkTo myself fails.", err
408
409   map
410   map = init_map( vym )
411   map.select @branch_a
412   n=map.branchCount.to_i
413   map.select @main_b
414   map.relinkTo @branch_a, 1, 0, 0
415   map.select @branch_a
416   expect "RelinkTo #{@branch_a}, pos 1: branchCount increased there",  map.branchCount.to_i, n+1
417   map.select "#{@branch_a},bo:1"
418   expect "RelinkTo #{@branch_a}, pos 1: Mainbranch really moved", map.getHeadingPlainText, "Main B"
419   map.undo
420   map.select @center_0
421   expect "Undo RelinkTo pos 1: branchCount of center", map.branchCount.to_i, 2
422   # FIXME-2 still has wrong position, check position
423   map.select @main_b
424   map.moveRel 100,100
425 end
426
427 #######################
428 def test_modify_branches (vym)
429   heading "Modifying branches"
430   map = init_map( vym )
431   map.select @branch_a
432   map.setHeadingPlainText "Changed!"
433   expect "setHeadingPlainText", map.getHeadingPlainText, "Changed!"
434   map.undo
435   expect "Undo: setHeadingPlainText", map.getHeadingPlainText, "branch a"
436   map.redo
437   expect "redo: setHeadingPlainText", map.getHeadingPlainText, "Changed!" 
438   map.undo
439 end  
440   
441 #######################
442 def test_flags (vym)
443   heading "Flags"
444   map = init_map( vym ) 
445   map.select @main_a
446   
447   def set_flags (map, flags)
448     flags.each do |f|
449       map.setFlagByName( f )
450       expect "Flag set: #{f}", map.hasActiveFlag( f ), true
451     end
452   end
453   
454   def unset_flags (map, flags)
455     flags.each do |f|
456       map.unsetFlagByName( f )
457       expect "Flag unset: #{f}", map.hasActiveFlag( f ), false
458     end
459   end
460   
461   # Group standard-mark
462   set_flags( map, [ "exclamationmark","questionmark"] )
463   
464   # Group standard-status
465   set_flags( map, [ "hook-green", 
466     "wip", 
467     "cross-red", 
468     "stopsign" ] )
469   
470   # Group standard-smiley
471   smileys = [ "smiley-good",
472       "smiley-sad",
473       "smiley-omb" ]
474   set_flags( map, smileys )
475   
476   # Group standard-arrow
477   set_flags( map, [ "arrow-up", 
478     "arrow-down", 
479     "2arrow-up", 
480     "2arrow-down" ] )
481   
482   # Group standard-thumb
483   set_flags( map, [ "thumb-up", "thumb-down" ] )
484   
485   # Without group
486   set_flags( map, [ "clock",
487     "phone",
488     "lamp",
489     "rose",
490     "heart",
491     "present",
492     "flash",
493     "info",
494     "lifebelt" ] )
495   
496   unset_flags( map, smileys )
497   
498   map.clearFlags
499   expect "clearFlags cleared exclamationmark", map.hasActiveFlag( "exclamationmark" ), false
500   expect "clearFlags cleared smiley-good", map.hasActiveFlag( "smiley-good" ), false
501   
502
503   # Toggling flags
504   a = ["stopsign", "lifebelt"]
505   a.each do |flag|
506     puts "Flag is now: #{flag}"
507     map.toggleFlagByName flag
508     expect "toggleFlag: flag #{flag} activated", map.hasActiveFlag(flag), true
509
510     map.toggleFlagByName flag
511     expect "toggleFlag: flag #{flag} deactivated", map.hasActiveFlag(flag), false
512   end
513 end
514
515 #######################
516 def test_delete_parts (vym)
517   heading "Deleting parts"
518   map = init_map( vym ) 
519   map.select @main_a
520   n = map.branchCount.to_i
521   map.select @branch_a
522   m = map.branchCount.to_i
523   map.remove
524   map.select @main_a
525   expect "Remove branch: branchcount",  map.branchCount.to_i, n - 1
526   map.undo
527   map.select @main_a
528   expect "Undo Remove branch: branchcount parent", map.branchCount.to_i, n
529   map.select @branch_a
530   expect "Undo Remove branch: branchcount restored branch", map.branchCount.to_i, m
531   
532   map = init_map( vym )
533   map.select @branch_a
534   n = map.branchCount.to_i
535   map.removeChildren
536   map.select @branch_a
537   expect "removeChildren: branchcount", map.branchCount.to_i, 0
538   map.undo
539   map.select @branch_a
540   expect "Undo: removeChildren: branchcount", map.branchCount.to_i, n
541   
542   map = init_map( vym )
543   map.select @main_a
544   n=map.branchCount.to_i
545   map.select @branch_a
546   m=map.branchCount.to_i
547   map.removeKeepChildren
548   map.select @main_a
549   expect "removeKeepChildren: branchcount", map.branchCount.to_i, n + m - 1
550   map.undo
551   map.select @main_a
552   expect "Undo: removeKeepChildren: branchcount of parent", map.branchCount.to_i, n
553   map.select @branch_a
554   expect "Undo: removeKeepChildren: branchcount of branch", map.branchCount.to_i, m
555
556   map = init_map( vym )
557   n = map.centerCount.to_i
558   map.select @center_1
559   map.remove
560   expect "remove mapCenter: number of centers decreased", map.centerCount.to_i, n - 1
561   map.undo
562   expect "Undo remove mapCenter: number of centers increased", map.centerCount.to_i, n
563 end  
564
565 #######################
566 def test_copy_paste (vym)
567   heading "Copy, cut & Paste"
568   map = init_map( vym )
569   map.select @main_a
570   n = map.branchCount.to_i
571   
572   map.copy
573   map.paste
574   map.selectLatestAdded     #FIXME-2 not set for ImportAdd, which is used by paste
575   s = map.getSelectionString
576   expect "Normal paste of branch, check heading of #{s}", map.getHeadingPlainText, "Main A"
577   
578   map.undo
579   map.select @main_a
580   expect "Undo paste: branchCount of #{@main_a}", map.branchCount.to_i, n
581   
582   map.redo
583   map.select s
584   expect "redo paste: check heading", map.getHeadingPlainText, "Main A"
585   
586   map.select @branch_a
587   map.cut
588   map.select @main_a
589   expect "cut: branchCount of #{@main_a}", map.branchCount.to_i, n
590
591   map.paste
592   map.selectLastChildBranch
593   s = map.getSelectionString
594   expect "Normal paste of branch, check heading of #{s}", map.getHeadingPlainText, "branch a"
595   map.cut 
596 end 
597
598 #######################
599 def test_references (vym)
600   heading "References"
601   map = init_map( vym )
602   map.select @main_a
603   url = "www.insilmaril.de"
604   map.setURL url
605   expect "setURL to '#{url}'", map.getURL, url
606
607   map.undo
608   expect "undo setURL", map.getURL, ""
609   map.redo
610   expect "redo setURL", map.getURL, url
611   map.setURL ""
612   expect "setURL: unset URL with empty string", map.getURL, ""
613   
614   vl="default.vym"
615   map.setVymLink vl
616   s=map.getVymLink
617   expect "setVymLink returns absolute path", map.getVymLink, map.getFileDir + vl
618   map.undo
619   expect "undo: setVymLink", map.getVymLink, ""
620   map.redo
621   expect "redo: setVymLink", map.getVymLink, s
622   map.undo
623 end
624
625 #######################
626 def test_history (vym)
627   heading "History"
628   map = init_map( vym )
629   map.select @main_a
630   map.setHeadingPlainText "A"
631   map.setHeadingPlainText "B"
632   map.setHeadingPlainText "C"
633   map.undo
634   map.undo
635   map.undo
636   expect "Undo 3 times", map.getHeadingPlainText, "Main A"
637   map.redo
638   expect "Redo once", map.getHeadingPlainText, "A"
639   map.copy
640   map.redo
641   expect "Redo once more", map.getHeadingPlainText, "B"
642   map.redo
643   expect "Redo yet again", map.getHeadingPlainText, "C"
644   map.setHeadingPlainText "Main A"
645   map.paste
646   map.selectLastChildBranch
647   expect "Paste from the past", map.getHeadingPlainText, "A"
648   map.remove
649 end  
650
651 #######################
652 def test_xlinks (vym)
653   heading "XLinks:"
654   map = init_map( vym )
655   map.addXLink("mc:0,bo:0","mc:0,bo:1",2,"#ff0000","Qt::DashDotLine")
656   map.selectLatestAdded
657   expect "Default color of XLink", map.getXLinkColor, "#ff0000"
658   expect "Default width of XLink", map.getXLinkWidth.to_i, 2
659   expect "Default style of XLink", map.getXLinkPenStyle, "Qt::DashDotLine"
660   expect "Default style of XLink begin", map.getXLinkStyleBegin, "HeadFull"
661   expect "Default style of XLink end",   map.getXLinkStyleEnd, "HeadFull"
662
663   map.setXLinkWidth(3)
664   expect "New width of XLink", map.getXLinkWidth.to_i, 3
665   map.undo
666   expect "Undo width of XLink", map.getXLinkWidth.to_i, 2
667
668   map.setXLinkColor("#00ff00")
669   expect "New color of XLink", map.getXLinkColor, "#00ff00"
670   map.undo
671   expect "Undo color of XLink", map.getXLinkColor, "#ff0000"
672
673   map.setXLinkStyle("Qt::SolidLine")
674   expect "New style of XLink", map.getXLinkPenStyle, "Qt::SolidLine"
675   map.undo
676   expect "Undo style of XLink", map.getXLinkPenStyle, "Qt::DashDotLine"
677
678   map.setXLinkStyleBegin("None")
679   expect "New style of XLink begin", map.getXLinkStyleBegin, "None"
680   map.undo
681   expect "Undo style of XLink begin", map.getXLinkStyleBegin, "HeadFull"
682
683   map.setXLinkStyleEnd("None")
684   expect "New style of XLink end", map.getXLinkStyleEnd, "None"
685   map.undo
686   expect "Undo style of XLink end", map.getXLinkStyleEnd, "HeadFull"
687
688   map.remove
689 end
690
691 #######################
692 def test_tasks (vym)
693   heading "Tasks:"
694   map = init_map( vym )
695   map.select @main_a
696   expect "Branch has no task before test", map.hasTask, false
697   map.toggleTask
698   expect "Toggle task", map.hasTask, true
699
700   date_today = DateTime.now
701   delta_days = 123
702   date_later = date_today + delta_days
703   date_later_iso = date_later.strftime("%Y-%m-%dT%H:%M:%S") 
704
705   # Input: number of days
706   date_new = delta_days
707   expect "Set task sleep to number of days '#{date_new}' accepts input", map.setTaskSleep(date_new),  true
708   expect "Set task sleep to number of days '#{date_new}' has correct sleep value '#{delta_days}' days", map.getTaskSleepDays.to_i, delta_days
709
710   # Input: number of seconds
711   date_new = "10s"
712   expect "Set task sleep to number of seconds '#{date_new}' accepts input", map.setTaskSleep(date_new),  true
713
714   # Input: number of hours
715   date_new = "10h"
716   expect "Set task sleep to number of hours '#{date_new}' accepts input", map.setTaskSleep(date_new),  true
717   
718   # Input: Date
719   date_new = date_later.strftime("%Y-%m-%d") 
720   expect "Set task sleep to ISO Date '#{date_new}' accepts input", map.setTaskSleep(date_new), true
721   expect "Set task sleep to ISO Date '#{date_new}' has correct sleep value '#{delta_days}' days", map.getTaskSleepDays.to_i, delta_days
722
723   date_new = date_later.strftime("%d.%m.") 
724   expect "Set task sleep to German short form '#{date_new}' accepts input '#{date_new}'", map.setTaskSleep(date_new), true
725   expect "Set task sleep to German short form '#{date_new}' has correct sleep value (days)", map.getTaskSleepDays.to_i, delta_days
726
727   date_new = date_later.strftime("%d.%m.%Y") 
728   expect "Set task sleep to German long form '#{date_new}' accepts input '#{date_new}'", map.setTaskSleep(date_new), true
729   expect "Set task sleep to German long form '#{date_new}' has correct sleep value (days)", map.getTaskSleepDays.to_i, delta_days
730
731   # Input: Invalid strings
732   date_new = "invalidDate"
733   expect "Set task sleep to '#{date_new}' should fail", map.setTaskSleep(date_new), false
734
735   date_new = date_later.strftime("%d %m.%Y") 
736   expect "Set task sleep to '#{date_new}' should fail", map.setTaskSleep(date_new), false
737
738   # DateTime
739   date_new = date_later_iso
740   expect "Set task sleep to ISO DateTime '#{date_new}' accepts input", map.setTaskSleep(date_new), true
741   expect "Set task sleep to ISO DateTime '#{date_new}' returns correct sleep value '#{date_later_iso}'", map.getTaskSleep, date_later_iso
742   
743   # Time only
744   date_later = date_today
745
746   date_new = "12:34"
747   date_later_iso = date_today.strftime("%Y-%m-%dT12:34:00") 
748   expect "Set task sleep to time '#{date_new}' accepts input", map.setTaskSleep(date_new), true
749   expect "Set task sleep to time '#{date_new}' returns correct sleep value '#{date_later_iso}'", 
750     map.getTaskSleep, date_later_iso
751   
752   date_new = "2:4"
753   date_later_iso = date_today.strftime("%Y-%m-%dT02:04:00") 
754   expect "Set task sleep to time '#{date_new}' accepts input", map.setTaskSleep(date_new), true
755   expect "Set task sleep to time '#{date_new}' returns correct sleep value '#{date_later_iso}'", 
756     map.getTaskSleep, date_later_iso
757
758   date_new = "03:05"
759   date_later_iso = date_today.strftime("%Y-%m-%dT03:05:00") 
760   expect "Set task sleep to time '#{date_new}' accepts input", map.setTaskSleep(date_new), true
761   expect "Set task sleep to time '#{date_new}' returns correct sleep value '#{date_later_iso}'", 
762     map.getTaskSleep, date_later_iso
763 end
764
765 ######################
766 def test_notes (vym)
767   heading "Notes:"
768
769   # Plaintext notes basic actions 
770   map = init_map( vym )
771   map.select @main_a
772   note_plain = "vymnote plaintext"
773   map.setNotePlainText(note_plain)
774   expect "Set note to \"#{note_plain}\". Still plaintext?", map.hasRichTextNote, false
775   map.select @center_0
776   map.select @main_a
777   expect "After reselect, is note plaintext?", map.hasRichTextNote, false
778
779   note_plain = "<b>plaintext, not bold!</b>"
780   map.setNotePlainText(note_plain)
781   expect "Set note to plaintext containing html tags. Still plaintext", map.hasRichTextNote, false
782   note_new = map.getNotePlainText
783   map.select @center_0
784   map.select @main_a
785   expect "After reselect, is note text unchanged?", map.getNotePlainText, note_new
786   expect "After reselect, is note plaintext?", map.hasRichTextNote, false
787
788   # Plaintext notes copy & paste
789   map.copy
790   map.paste
791   map.selectLastChildBranch
792   s=map.getSelectionString
793   expect "After copy& paste: New note unchanged?", map.getNotePlainText, note_plain
794   expect "After copy& paste: New note Still plaintext?", map.hasRichTextNote, false
795   map.remove
796
797   # Plaintext notes undo & redo
798   map.select @main_a
799   map.setNotePlainText('Foobar')
800   map.undo
801   expect "Undo after setNotePlainText restores previous note", map.getNotePlainText, note_plain
802   map.redo
803   map.select @main_a
804   expect "Redo restores previous note", map.getNotePlainText, 'Foobar'
805
806   # Plaintext notes load & save
807   note_org = IO.read('test/note-plain.txt')
808   map.loadNote("test/note-plain.txt") 
809   expect "Load plain text note from file. Still plaintext?", map.hasRichTextNote, false
810   expect "Note contains 'not bold'", map.getNotePlainText.include?("not bold"), true
811   filepath = "#{@testdir}/save-note.txt"
812   map.saveNote(filepath)
813   expect "Save note to file. Check if it contains 'textMode=\"plainText\"'", IO.read(filepath).include?("textMode=\"plainText\""), true
814   expect "Save note to file. Check if it contains 'not bold'", IO.read(filepath).include?("not bold"), true
815   expect "Save note to file. Check new format: no longer contains '<b>' element", IO.read(filepath).include?("<b>"), false
816   expect "Save note to file. Check new format: no longer contains '<![CDATA['", IO.read(filepath).include?("<![CDATA["), false
817   expect "Save note to file. Check new format: contains 'text=\"Plaintext'", IO.read(filepath).include?("text=\"Plaintext"), true
818   
819   # Delete note
820   map.setNotePlainText("")
821   expect "setNotePlainText(\"\") deletes note", map.hasNote, false
822   
823   # RichText basic actions
824   map = init_map( vym )
825   map.select @main_a
826   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>'
827   map.parseVymText(rt_note)
828   expect "parseVymText of richText note produces note", map.hasNote, true
829   expect "parseVymText of richText note produces richText note", map.hasRichTextNote, true
830   map.select @center_0
831   map.select @main_a
832   expect "After reselect, is note RichText?", map.hasRichTextNote, true
833
834
835   # RichText notes copy & paste
836   rt_note = map.getNoteXML  
837   map.copy
838   map.paste
839   map.selectLastChildBranch
840   s = map.getSelectionString
841   expect "After copy & paste: New note Still RichText?", map.hasRichTextNote, true
842   expect "After copy & paste: New note unchanged?", map.getNoteXML, rt_note
843   map.remove
844
845   # RichText notes undo & redo
846   map.select @main_a
847   map.setNotePlainText('Foobar')
848   map.undo
849   expect "Undo after setNotePlainText restores RichText note", map.getNoteXML, rt_note
850   map.redo
851   map.select @main_a
852   expect "Redo restores previous plaintext note", map.getNotePlainText, 'Foobar'
853
854   # RichText notes load & save
855   map.loadNote("test/note.html") 
856   expect "Load HTML note from file and try to detect textMode. Is RichText?", map.hasRichTextNote, true
857   filepath = "#{@testdir}/save-note.txt"
858   map.saveNote(filepath)
859   expect "Save note to file. Check if it contains 'textMode=\"richText\"'", IO.read(filepath).include?("textMode=\"richText\""), true
860   expect "Save note to file. Check if it contains 'bold'", IO.read(filepath).include?("bold"), true
861   expect "Save note to file. Check new format: no longer contains '<b>' element", IO.read(filepath).include?("<b>"), false
862   expect "Save note to file. Check new format: no longer contains '<![CDATA['", IO.read(filepath).include?("<![CDATA["), false
863   expect "Save note to file. Check new format: contains 'text=\"&lt;'", IO.read(filepath).include?("text=\"&lt;"), true
864   
865   # Delete note
866   map.setNotePlainText("")
867   expect "setNotePlainText(\"\") deletes note", map.hasNote, false
868
869   # Compatibility with version < 2.5.0  # FIXME missing
870 end
871
872 def test_headings (vym)
873   heading "Headings:"
874   # FIXME same checks like for notes above for headings
875 end
876   
877 ######################
878 def test_bugfixes (vym)
879   heading "Bugfixes:"
880   map = init_map( vym )
881   map.select @main_b
882   expect "Mapcenter of #{@center_1} has no frame", map.getFrameType, "NoFrame"
883 end
884
885 #######################
886 =begin
887 # Untested commands:
888 #
889 addSlide
890 centerOnID
891 colorBranch
892 colorSubtree
893 cycleTask
894 delete (image)
895 deleteSlide
896 importDir
897 loadImage
898 loadNote
899 move
900 moveRel
901 moveSlideDown
902 moveSlideUp
903 note2URLs
904     paste
905 redo  
906 relinkTo (for images)
907 saveImage
908 saveNote
909 selectID
910 selectLastImage
911 selectLatestAdd
912 setFrameBorderWidth
913 setFrameBrushColor
914 setFrameIncludeChildren
915 setFramePadding
916 setFramePenColor
917 setFrameType
918     setHeading
919 setHideExport
920 setHideLinksUnselected
921 setIncludeImagesHorizontally
922 setIncludeImagesVertically
923 setMapAnimCurve
924 setMapAnimDuration
925 setMapBackgroundColor
926 setMapDefLinkColor
927 setMapLinkStyle
928 setMapRotation
929 setMapZoom
930 setNote
931 setScale
932 setSelectionColor
933 setTaskSleep
934     setURL
935     setVymLink
936   so far:
937 sortChildren
938 toggleFrameIncludeChildren
939 toggleTarget
940 toggleTask
941 =end
942
943
944 begin
945   options = {}
946   OptionParser.new do |opts|
947     opts.banner = "Usage: vym-test.rb [options]"
948
949     opts.on('-d', '--directory  NAME', 'Directory name') { |s| options[:testdir] = s }
950   end.parse!
951
952   @testdir = options[:testdir]
953   @testmap = ARGV[0]
954
955   $tests_passed    = 0
956   $tests_failed    = 0
957   $tests_warnings  = 0
958   $tests_total     = 0
959
960   #######################
961   @center_0="mc:0"
962   @center_1="mc:1"
963   @main_a="mc:0,bo:0"
964     @branch_a=@main_a+",bo:0"
965     @branch_b=@main_a+",bo:1"
966     @branch_c=@main_a+",bo:2"
967   @main_b="mc:0,bo:1"
968
969   @n_centers=2
970
971   instance_name = 'test'
972
973   vym_mgr = VymManager.new
974   #vym_mgr.show_running
975
976   vym = vym_mgr.find(instance_name)
977
978   if !vym
979     puts "Couldn't find instance name \"#{instance_name}\", please start one:"
980     puts "vym -l -n \"#{instance-name}\" -t test/default.vym"
981     exit
982   end
983
984   test_vym(vym)
985   test_basics(vym)
986   test_export(vym)
987   test_extrainfo(vym)
988   test_adding_branches(vym)
989   test_adding_maps(vym)
990   test_scrolling(vym)
991   test_moving_parts(vym)
992   test_modify_branches(vym)
993   test_flags(vym)
994   test_delete_parts(vym)
995   test_copy_paste(vym)
996   test_references(vym)
997   test_history(vym)
998   test_xlinks(vym)
999   test_tasks(vym)
1000   test_notes(vym)
1001   test_headings(vym)
1002   test_bugfixes(vym)
1003   summary
1004
1005 end
1006