]> git.sven.stormbind.net Git - sven/vym.git/blob - test/vym-test-legacy.rb
New upstream version 2.9.22
[sven/vym.git] / test / vym-test-legacy.rb
1 #!/usr/bin/env ruby
2
3 require "#{ENV['PWD']}/../scripts/vym-ruby"
4 require 'colorize'
5 require 'date'
6 require 'fileutils'
7 require 'optparse'
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}".green
17     $tests_passed += 1
18     # waitkey
19   else
20     puts "Failed: #{comment}. Expected '#{v_exp}', but got '#{v_real}'".red
21     $tests_failed += 1
22     waitkey
23   end
24   $tests_total += 1
25 end
26
27 def expectInclude (comment, s, substring)
28   if s.include? substring
29     puts "    Ok: #{comment}".green
30     $tests_passed += 1
31     # waitkey
32   else
33     puts "Failed: #{comment}. Could not find '#{substring}' in string below:".red
34     puts "'#{s}'"
35     $tests_failed += 1
36     waitkey
37   end
38   $tests_total += 1
39 end
40
41 def expectNot (comment, v_real, v_exp)
42   if v_exp != v_real
43     puts "    Ok: #{comment}".green
44     $tests_passed += 1
45     # waitkey
46   else
47     puts "Failed: #{comment}. Expected not to get '#{v_exp}'".red
48     $tests_failed += 1
49     waitkey
50   end
51   $tests_total += 1
52 end
53
54 def expect_warning_only (comment, v_real, v_exp)
55   if v_exp == v_real
56     puts "    Ok: #{comment}".green
57     $tests_passed += 1
58     # waitkey
59   else
60     puts "Warning: #{comment}. Expected '#{v_exp}', but got '#{v_real}'".red
61     $tests_warnings += 1
62   end
63   $tests_total += 1
64 end
65
66 def expect_error (comment, error)
67   if error.length ==  0
68     puts "Failed: #{comment}. Command did not return error.".red
69     $tests_failed += 1
70   else
71     puts "    Ok: #{comment}".green
72     $tests_passed += 1
73   end
74   $tests_total += 1
75 end
76
77 def heading (s)
78   puts "\n#{s}\n#{'-' * s.length}\n".yellow
79 end
80
81 def init_map( mapPath, files = [])
82   # Copy the map referenced above to @testDir/test-current.[vym|xml]
83   # and try to load it
84   @currentMapPath = "#{@testDir}/test-current#{File.extname(mapPath)}"
85
86   begin
87     FileUtils.cp mapPath, @currentMapPath
88   rescue
89     puts "Failed to copy #{mapPath} to #{@currentMapPath}".red
90     exit
91   end
92
93   files.each do |fn|
94     begin
95       FileUtils.cp fn, @testDir
96       puts "# Copied #{fn} to #{@testDir}".light_black
97     rescue
98       puts "Failed to copy #{fn} to #{@testDir}".red
99       exit
100     end
101   end
102
103   if @vym.loadMap (@currentMapPath)
104     id = @vym.currentMapID
105     puts "# Loaded #{mapPath} -> #{@currentMapPath} (id: #{id})".light_black
106     return @vym.map (id)
107   end
108
109   puts "Failed to load #{mapPath}".red
110   exit
111 end
112
113 def close_current_map
114   id = @vym.currentMapID
115   r = @vym.closeMapWithID(id)
116   if r
117     puts "# Closed map (id: #{id})".light_black
118   else
119     puts "# Failed to close map with id = #{id}. CurrentMapID = #{id}".red
120   end
121 end
122
123 def summary
124   puts "\nTests done  : #{$tests_total}"
125   puts "Tests passed: #{$tests_passed}"
126   puts "Warnings:     #{$tests_warnings}"
127   puts "Tests failed: #{$tests_failed}"
128 end
129
130 #######################
131 def test_vym
132   #@vym.clearConsole
133
134   heading "Mainwindow checks:"
135   version = "2.9.0"
136   expect_warning_only "Version is #{version}", @vym.version, version
137
138   expect "Temporary directory exists at '#{@testDir}'", File.exists?(@testDir), true
139
140
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
144
145   close_current_map
146 end
147
148 #######################
149 def test_basics
150   heading "Basic checks:"
151   map = init_map @testMapDefault
152
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
157
158   map.select @main_A
159   expect "select mainbranch A", map.getSelectionString, @main_A
160   expect "getHeadingPlainText", map.getHeadingPlainText, "Main A"
161   expect "branchCount", map.branchCount, 3
162
163   map.selectLastBranch
164   expect "selectLastBranch", map.getHeadingPlainText, "Main B"
165
166   map.selectFirstBranch
167   expect "selectFirstBranch", map.getHeadingPlainText, "Main A"
168
169   map.selectParent
170   expect "selectParent", map.getHeadingPlainText, "MapCenter 0"
171
172   expect "getDestPath: Got #{map.getDestPath}", map.getDestPath, @testDir + "/test-current.vym"
173   expect "getFileDir:  Got #{map.getFileDir}", map.getFileDir, @testDir + "/"
174
175   close_current_map
176 end
177
178 #######################
179 def test_adding_branches
180   heading "Adding branches:"
181   map = init_map @testMapDefault
182   map.select @main_A
183   n = map.branchCount.to_i
184   map.addBranch()
185   expect( "addBranch", map.branchCount.to_i, n + 1 )
186
187   map.selectLatestAdded
188   expect "selectLatestAdded", map.getSelectionString, @main_A + ",bo:3"
189
190   map.undo
191   expect( "Undo: addBranch", map.branchCount.to_i, n )
192
193   close_current_map
194   map = init_map @testMapDefault
195
196   map.select @main_A
197   n = map.branchCount.to_i
198   map.select @branch_0Aa
199   map.addBranch( -3 )
200   map.addBranch( -1 )
201   map.select @main_A
202   expect "addBranchAbove/Below", map.branchCount.to_i, n + 2
203
204   map.undo
205   map.undo
206   expect "Undo: addBranchAbove/Below", map.branchCount.to_i, n
207
208   close_current_map
209   map = init_map @testMapDefault
210
211   map.select @branch_0Aa
212   map.addBranchBefore
213   map.select @main_A
214   expect "addBranchBefore: check branchcount",  map.branchCount.to_i, n
215   map.select @branch_0Aa
216   expect "addBranchBefore: check heading", map.getHeadingPlainText, ""
217
218   # Undo twice: addBranchNew and relinkTo
219   map.undo
220   map.undo
221   map.select @main_A
222   expect "Undo: addBranchBefore", map.branchCount.to_i, n
223
224   close_current_map
225 end
226
227 #######################
228 def test_adding_maps
229   heading "Adding maps"
230   map = init_map @testMapDefault
231   map.select @branch_0Aa
232   n = map.branchCount.to_i
233   map.addMapReplace @currentMapPath
234   map.select @main_A
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"
241
242   map.undo
243   map.select @main_A
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
247   close_current_map
248
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"
259
260   map.undo
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"
265   close_current_map
266 end
267
268 #######################
269 def test_attributes
270   heading "Attributes:"
271   map = init_map "maps/test-attributes.xml"
272
273   map.select @main_A
274   expect "String attribute is '6 * 9'", map.getStringAttribute("string-attribute"), "6 * 9"
275   expect "Integer attribute is 42", map.getIntAttribute("int-attribute"), 42
276
277   close_current_map
278 end
279
280 ######################
281 def test_bugfixes
282   heading "Bugfixes:"
283   map = init_map @testMapDefault
284
285   close_current_map
286 end
287
288 #######################
289 def test_copy_paste
290   heading "Copy, cut & Paste"
291
292   map = init_map @testMapDefault
293   map.select @main_A
294   n = map.branchCount.to_i
295
296   map.copy
297   map.paste
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"
301
302   map.undo
303   map.select @main_A
304   expect "Undo paste: branchCount of #{@main_A}", map.branchCount.to_i, n
305
306   map.redo
307   map.select s
308   expect "redo paste: check heading", map.getHeadingPlainText, "Main A"
309
310   map.select @branch_0Aa
311   map.cut
312   map.select @main_A
313   expect "cut: branchCount of #{@main_A}", map.branchCount.to_i, n
314
315   map.paste
316   map.selectLastChildBranch
317   s = map.getSelectionString
318   expect "Normal paste of branch, check heading of #{s}", map.getHeadingPlainText, "branch a"
319   map.cut
320
321   close_current_map
322 end
323
324 #######################
325 def test_delete_parts
326   heading "Deleting parts"
327
328   map = init_map @testMapDefault
329   map.select @main_A
330   n=map.branchCount.to_i
331   map.select @branch_0Aa
332   m=map.branchCount.to_i
333   map.remove
334   map.select @main_A
335   expect "Remove branch: branchcount",  map.branchCount.to_i, n - 1
336   map.undo
337   map.select @main_A
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
341
342   close_current_map
343
344   map = init_map @testMapDefault
345   map.select @branch_0Aa
346   n = map.branchCount.to_i
347   map.removeChildren
348   map.select @branch_0Aa
349   expect "removeChildren: branchcount", map.branchCount.to_i, 0
350   map.undo
351   map.select @branch_0Aa
352   expect "Undo: removeChildren: branchcount", map.branchCount.to_i, n
353
354   close_current_map
355   map = init_map @testMapDefault
356
357   map.select @main_A
358   n=map.branchCount.to_i
359   map.select @branch_0Aa
360   m=map.branchCount.to_i
361   map.removeKeepChildren
362   map.select @main_A
363   expect "removeKeepChildren: branchcount", map.branchCount.to_i, n + m - 1
364   map.undo
365   map.select @main_A
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
369
370   close_current_map
371   map = init_map @testMapDefault
372
373   n = map.centerCount.to_i
374   map.select @center_1
375   map.remove
376   expect "remove mapCenter: number of centers decreased", map.centerCount.to_i, n - 1
377   map.undo
378   expect "Undo remove mapCenter: number of centers increased", map.centerCount.to_i, n
379
380   close_current_map
381 end
382
383 #######################
384 def test_export
385   heading "Export:"
386   map = init_map @testMapDefault
387
388   #HTML
389   exportdir = "#{@testDir}/export-html"
390   Dir.mkdir(exportdir)
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
401   end
402   expect "exportHTML: HTML CSS exists", File.exists?(csspath), true
403   File.delete(htmlpath)
404   FileUtils.rm_r(flagdir)
405   File.delete(pngpath)
406   File.delete(csspath)
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
413   end
414   expect "exportLast: HTML CSS exists", File.exists?(csspath), true
415
416   #AO
417   exportdir = "#{@testDir}/export-ao"
418   Dir.mkdir(exportdir)
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
425
426   #ASCII
427   exportdir = "#{@testDir}/export-ascii"
428   Dir.mkdir(exportdir)
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
435
436   #CSV
437   exportdir = "#{@testDir}/export-csv"
438   Dir.mkdir(exportdir)
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
445
446   #Image
447   exportdir = "#{@testDir}/export-image"
448   Dir.mkdir(exportdir)
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
455
456   #LaTeX
457   exportdir = "#{@testDir}/export-latex"
458   Dir.mkdir(exportdir)
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
465
466   #Markdown
467   exportdir = "#{@testDir}/export-markdown"
468   Dir.mkdir(exportdir)
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
475
476   #OrgMode
477   exportdir = "#{@testDir}/export-orgmode"
478   Dir.mkdir(exportdir)
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
485
486   #PDF
487   exportdir = "#{@testDir}/export-pdf"
488   Dir.mkdir(exportdir)
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
495
496   #SVG
497   exportdir = "#{@testDir}/export-svg"
498   Dir.mkdir(exportdir)
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
505
506   #XML
507   exportdir = "#{@testDir}/export-xml"
508   Dir.mkdir(exportdir)
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
515
516   #OpenOffice Impress //FIXME-2
517   #Taskjuggler //FIXME-3
518
519   close_current_map
520 end
521
522 #######################
523 def test_extrainfo
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!"
532
533   close_current_map
534 end
535
536 ######################
537 def test_frames
538   heading "Frames:"
539   map = init_map @testMapFrames
540
541   map.select @center_0
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"
544
545   map.select @center_1
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"
548
549   map.select @center_2
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"
552
553   map.select @center_3
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"
556   close_current_map
557 end
558
559 def test_headings
560   heading "Headings:"
561   # FIXME same checks like for notes above for headings
562 end
563
564 #######################
565 def test_history
566   heading "History"
567
568   map = init_map @testMapDefault
569   map.select @main_A
570   map.setHeadingPlainText "A"
571   map.setHeadingPlainText "B"
572   map.setHeadingPlainText "C"
573   map.undo
574   map.undo
575   map.undo
576   expect "Undo 3 times, after changing heading -> 'A' -> 'B' -> 'C'", map.getHeadingPlainText, "Main A"
577   map.redo
578   expect "Redo once", map.getHeadingPlainText, "A"
579   map.copy
580   map.redo
581   expect "Redo once more", map.getHeadingPlainText, "B"
582   map.redo
583   expect "Redo yet again", map.getHeadingPlainText, "C"
584   map.setHeadingPlainText "Main A"
585   map.paste
586   map.selectLastChildBranch
587   expect "Paste from the past", map.getHeadingPlainText, "A"
588   map.remove
589
590   close_current_map
591 end
592
593 #######################
594 def test_scrolling
595   heading "Scrolling and unscrolling"
596   map = init_map @testMapDefault
597
598   map.select @main_A
599   map.toggleScroll
600   expect "toggleScroll", map.isScrolled, true
601   map.undo
602   expect "undo toggleScroll", map.isScrolled, false
603   map.scroll
604   expect "scroll", map.isScrolled, true
605   map.unscroll
606   expect "unscroll", map.isScrolled, false
607
608   map.scroll
609   map.select @branch_0Aa
610   map.scroll
611   map.select @main_A
612   map.unscrollChildren
613   map.select @branch_0Aa
614   expect "unscrollChildren", map.isScrolled, false
615   map.undo
616   expect "undo unscrollChildren", map.isScrolled, true
617
618   close_current_map
619 end
620
621 #######################
622 def test_slides
623   heading "Slides"
624   map = init_map "maps/test-slides.xml"
625
626   map.select @main_A
627   expect "Successfully loaded map with slides", map.slideCount, 3
628
629   close_current_map
630 end
631
632 #######################
633 def test_modify_branches
634   heading "Modifying branches"
635   map = init_map @testMapDefault
636
637   map.select @branch_0Aa
638   map.setHeadingPlainText "Changed!"
639   expect "setHeadingPlainText", map.getHeadingPlainText, "Changed!"
640   map.undo
641   expect "Undo: setHeadingPlainText", map.getHeadingPlainText, "branch a"
642   map.redo
643   expect "redo: setHeadingPlainText", map.getHeadingPlainText, "Changed!"
644   map.undo
645
646   close_current_map
647 end
648
649 #######################
650 def test_moving_parts
651   heading "Moving parts"
652   map = init_map @testMapDefault
653
654   map.select @branch_0Aa
655   map.moveDown
656   map.select @branch_0Aa
657   expect "Moving down", map.getHeadingPlainText, "branch b"
658   map.undo
659   map.select @branch_0Aa
660   expect "Undo Moving down", map.getHeadingPlainText, "branch a"
661
662   #map = init_map( vym )
663   map.select @branch_0Ab
664   map.moveUp
665   map.select @branch_0Aa
666   expect "Moving up", map.getHeadingPlainText, "branch b"
667   map.undo
668   map.select @branch_0Ab
669   expect "Undo Moving up", map.getHeadingPlainText, "branch b"
670
671   #map = init_map( vym )
672   map.select @main_B
673   n=map.branchCount.to_i
674   map.select @branch_0Aa
675   map.relinkTo @main_B,0,0,0
676   map.select @main_B
677   expect "RelinkTo #{@main_B}: branchCount increased there",  map.branchCount.to_i, n+1
678
679   map.undo
680   map.select @branch_0Ab
681   expect "Undo: RelinkTo #{@main_B}: branchCount decreased there", map.branchCount.to_i, n
682
683   #map = init_map( vym )
684   map.select @main_A
685   err = map.relinkTo @branch_0Aa,0,0,0
686   #FIXME-2 disabled, error not supported atm expect_error "RelinkTo myself fails.", err
687
688   #map = init_map( vym )
689   map.select @branch_0Aa
690   n=map.branchCount.to_i
691   map.select @main_B
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"
697   map.undo
698   map.select @center_0
699   expect "Undo RelinkTo pos 1: branchCount of center", map.branchCount.to_i, 2
700
701   close_current_map
702 end
703
704 ######################
705 def test_notes
706   heading "Notes:"
707
708   # Plaintext notes basic actions
709   map = init_map @testMapDefault
710
711   map.select @main_A
712   note_plain = "vymnote plaintext"
713   map.setNotePlainText(note_plain)
714   expect "Set note to \"#{note_plain}\". Still plaintext?", map.hasRichTextNote, false
715   map.select @center_0
716   map.select @main_A
717   expect "After reselect, is note plaintext?", map.hasRichTextNote, false
718
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
723   map.select @center_0
724   map.select @main_A
725   expect "After reselect, is note text unchanged?", map.getNotePlainText, note_new
726   expect "After reselect, is note plaintext?", map.hasRichTextNote, false
727
728   # Plaintext notes copy & paste
729   map.copy
730   map.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
735   map.remove
736
737   # Plaintext notes undo & redo
738   map.select @main_A
739   map.setNotePlainText('Foobar')
740   map.undo
741   expect "Undo after setNotePlainText restores previous note", map.getNotePlainText, note_plain
742   map.redo
743   map.select @main_A
744   expect "Redo restores previous note", map.getNotePlainText, 'Foobar'
745
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
758
759   # Delete note
760   map.setNotePlainText("")
761   expect "setNotePlainText(\"\") deletes note", map.hasNote, false
762
763   close_current_map
764
765   # RichText basic actions
766   map = init_map @testMapDefault
767   map.select @main_A
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
772   map.select @center_0
773   map.select @main_A
774   expect "After reselect, is note RichText?", map.hasRichTextNote, true
775
776
777   # RichText notes copy & paste
778   rt_note = map.getNoteXML
779   map.copy
780   map.paste
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
785   map.remove
786
787   # RichText notes undo & redo
788   map.select @main_A
789   map.setNotePlainText('Foobar')
790   map.undo
791   expect "Undo after setNotePlainText restores RichText note", map.getNoteXML, rt_note
792   map.redo
793   map.select @main_A
794   expect "Redo restores previous plaintext note", map.getNotePlainText, 'Foobar'
795
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=\"&lt;'", IO.read(filepath).include?("text=\"&lt;"), true
806
807   # Delete note
808   map.setNotePlainText("")
809   expect "setNotePlainText(\"\") deletes note", map.hasNote, false
810
811   # Compatibility with version < 2.5.0  # FIXME-2 missing
812
813   close_current_map
814 end
815
816 #######################
817 def test_references
818   heading "References"
819   map = init_map @testMapDefault
820
821   map.select @main_A
822   url = "www.insilmaril.de"
823   map.setURL url
824   expect "setURL to '#{url}'", map.getURL, url
825
826   map.undo
827   expect "undo setURL", map.getURL, ""
828   map.redo
829   expect "redo setURL", map.getURL, url
830   map.setURL ""
831   expect "setURL: unset URL with empty string", map.getURL, ""
832
833   vl = "default.vym"
834   map.setVymLink vl
835   s = map.getVymLink
836   expect "setVymLink returns absolute path", map.getFileDir + vl, s
837   map.undo
838   expect "undo: setVymLink", map.getVymLink, ""
839   map.redo
840   expect "redo: setVymLink", map.getVymLink, s
841   map.undo
842
843   close_current_map
844 end
845
846 #######################
847 def test_standard_flags
848   heading "Standard flags"
849   map = init_map @testMapDefault
850   map.select @main_A
851
852   def set_flags (map, flags)
853     flags.each do |f|
854       map.setFlagByName( f )
855       expect "Flag set: #{f}", map.hasActiveFlag( f ), true
856     end
857   end
858
859   def unset_flags (map, flags)
860     flags.each do |f|
861       map.unsetFlagByName( f )
862       expect "Flag unset: #{f}", map.hasActiveFlag( f ), false
863     end
864   end
865
866   # Group standard-mark
867   set_flags( map, [ "exclamationmark","questionmark"] )
868
869   # Group standard-status
870   set_flags( map, [ "hook-green",
871     "wip",
872     "cross-red",
873     "stopsign" ] )
874
875   # Group standard-smiley
876   smileys = [ "smiley-good",
877       "smiley-sad",
878       "smiley-omb" ]
879   set_flags( map, smileys )
880
881   # Group standard-arrow
882   set_flags( map, [ "arrow-up",
883     "arrow-down",
884     "2arrow-up",
885     "2arrow-down" ] )
886
887   # Group standard-thumb
888   set_flags( map, [ "thumb-up", "thumb-down" ] )
889
890   # Without group
891   set_flags( map, [ "clock",
892     "phone",
893     "lamp",
894     "rose",
895     "heart",
896     "present",
897     "flash",
898     "info",
899     "lifebelt" ] )
900
901   unset_flags( map, smileys )
902
903   map.clearFlags
904
905   expect "clearFlags cleared exclamationmark", map.hasActiveFlag( "exclamationmark" ), false
906   expect "clearFlags cleared smiley-good", map.hasActiveFlag( "smiley-good" ), false
907
908
909   # Toggling flags
910   a = ["stopsign", "lifebelt"]
911   a.each do |flag|
912     #puts "Flag is now: #{flag}"
913     map.toggleFlagByName flag
914     expect "toggleFlag: flag #{flag} activated", map.hasActiveFlag(flag), true
915
916     map.toggleFlagByName flag
917     expect "toggleFlag: flag #{flag} deactivated", map.hasActiveFlag(flag), false
918   end
919
920   close_current_map
921 end
922
923 #######################
924 def test_user_flags
925   heading "User flags"
926   map = init_map "maps/test-userflag.vym"
927
928   map.select @branch_0Aa
929   flagName = "userflag-vym"
930   expect "Has active flag '#{flagName}'", map.hasActiveFlag(flagName), true
931
932   # FIXME-2 cont here
933   close_current_map
934 end
935
936 #######################
937 def test_xlinks
938   heading "XLinks:"
939   map = init_map @testMapDefault
940
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"
948
949   map.setXLinkWidth(3)
950   expect "New width of XLink", map.getXLinkWidth.to_i, 3
951   map.undo
952   expect "Undo width of XLink", map.getXLinkWidth.to_i, 2
953
954   map.setXLinkColor("#00ff00")
955   expect "New color of XLink", map.getXLinkColor, "#00ff00"
956   map.undo
957   expect "Undo color of XLink", map.getXLinkColor, "#ff0000"
958
959   map.setXLinkStyle("Qt::SolidLine")
960   expect "New style of XLink", map.getXLinkPenStyle, "Qt::SolidLine"
961   map.undo
962   expect "Undo style of XLink", map.getXLinkPenStyle, "Qt::DashDotLine"
963
964   map.setXLinkStyleBegin("None")
965   expect "New style of XLink begin", map.getXLinkStyleBegin, "None"
966   map.undo
967   expect "Undo style of XLink begin", map.getXLinkStyleBegin, "HeadFull"
968
969   map.setXLinkStyleEnd("None")
970   expect "New style of XLink end", map.getXLinkStyleEnd, "None"
971   map.undo
972   expect "Undo style of XLink end", map.getXLinkStyleEnd, "HeadFull"
973
974   close_current_map
975 end
976
977 #######################
978 def test_tasks
979   heading "Tasks:"
980   map = init_map "maps/test-tasks.xml"
981
982   map.select @branch_0Aa
983   expect "After loading #{@branch_0Aa} has no task", map.hasTask, false
984
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
989
990   map.select @branch_0Aa
991   map.toggleTask
992   expect "Toggle task", map.hasTask, true
993
994   date_today = DateTime.now
995   delta_days = 123
996   date_later = date_today + delta_days
997   date_later_iso = date_later.strftime("%Y-%m-%dT%H:%M:%S")
998
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
1003
1004   # Input: number of seconds
1005   date_new = "10s"
1006   expect "Set task sleep to number of seconds '#{date_new}' accepts input", map.setTaskSleep(date_new),  true
1007
1008   # Input: number of hours
1009   date_new = "10h"
1010   expect "Set task sleep to number of hours '#{date_new}' accepts input", map.setTaskSleep(date_new),  true
1011
1012   # Input: Date
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
1016
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
1020
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
1024
1025   # Input: Invalid strings
1026   date_new = "invalidDate"
1027   expect "Set task sleep to '#{date_new}' should fail", map.setTaskSleep(date_new), false
1028
1029   date_new = date_later.strftime("%d %m.%Y")
1030   expect "Set task sleep to '#{date_new}' should fail", map.setTaskSleep(date_new), false
1031
1032   # DateTime
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
1036
1037   # Time only
1038   date_later = date_today
1039
1040   date_new = "12:34"
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
1045
1046   date_new = "2:4"
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
1051
1052   date_new = "03:05"
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
1057
1058   close_current_map
1059 end
1060
1061 ######################
1062 def test_saving
1063   heading "Saving:"
1064   map = init_map @testMapDefault
1065   #
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
1071
1072   close_current_map
1073
1074   map = init_map fn
1075   map.select @center_0
1076   expect "Save selection: After loading of #{fn} #{@center_0} is ok", map.getHeadingPlainText, "branch a"
1077   map.select @main_A
1078   expect "Save selection: After loading of #{fn} #{@main_A} is ok", map.getHeadingPlainText, "branch a1"
1079
1080   close_current_map
1081 end
1082
1083 ######################
1084 def test_load_legacy_maps
1085   heading "Load legacy maps:"
1086
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"
1090
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
1097
1098   close_current_map
1099
1100   map = init_map "maps/legacy/time-management-1.13.33.vym"
1101   map.select @main_A
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
1107
1108   close_current_map
1109
1110   map = init_map "maps/legacy/lifeforms-2.1.11.vym"
1111   map.select @center_0
1112
1113   s = "Life forms"
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
1117
1118   close_current_map
1119
1120   map = init_map "maps/legacy/faq-2.5.21.xml"
1121   map.select @branch_0Ab
1122
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
1127
1128   map.select @branch_0Ac
1129   s = "textMode=\"richText"
1130   expect "<heading> using characters and CDATA: creates RichText", map.getHeadingXML.include?(s), true
1131   s = "CDATA heading"
1132   expect "<heading> using characters and CDATA: includes '#{s}'", map.getHeadingPlainText.include?(s), true
1133
1134   close_current_map
1135
1136
1137   files = [
1138     "maps/legacy/external-note-plaintext.txt",
1139     "maps/legacy/external-note-richtext.html" ]
1140   map = init_map "maps/legacy/notes.xml", files
1141
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"
1148
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"
1155
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
1163
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"
1176
1177   # FIXME-2 implement and add test: xlinks in subitems of branches (pre 1.13.2)
1178   close_current_map
1179 end
1180
1181 #######################
1182 =begin
1183 # Untested commands:
1184 #
1185 addSlide
1186 centerOnID
1187 colorBranch
1188 colorSubtree
1189 cycleTask
1190 delete (image)
1191 deleteSlide
1192 importDir
1193 loadImage
1194 loadNote
1195 move
1196 moveRel
1197 moveSlideDown
1198 moveSlideUp
1199 note2URLs
1200     paste
1201 redo
1202 relinkTo (for images)
1203 saveImage
1204 saveNote
1205 selectID
1206 selectLastImage
1207 selectLatestAdd
1208 setFrameBorderWidth
1209 setFrameBrushColor
1210 setFrameIncludeChildren
1211 setFramePadding
1212 setFramePenColor
1213 setFrameType
1214     setHeading
1215 setHideExport
1216 setHideLinksUnselected
1217 setIncludeImagesHorizontally
1218 setIncludeImagesVertically
1219 setMapAnimCurve
1220 setMapAnimDuration
1221 setMapBackgroundColor
1222 setMapDefLinkColor
1223 setMapLinkStyle
1224 setMapRotation
1225 setMapZoom
1226 setNote
1227 setScale
1228 setSelectionColor
1229 setTaskSleep
1230     setURL
1231     setVymLink
1232   so far:
1233 sortChildren
1234 toggleFrameIncludeChildren
1235 toggleTarget
1236 toggleTask
1237 =end
1238
1239
1240 begin
1241   options = {}
1242   OptionParser.new do |opts|
1243     opts.banner = "Usage: vym-test.rb [options]"
1244
1245     opts.on('-d', '--directory  NAME', 'Directory name') { |s| options[:testDir] = s }
1246   end.parse!
1247
1248   @testDir = options[:testDir]
1249   @testMapDefault= "maps/test-default.vym"
1250   @testMapFrames = "maps/test-frames.vym"
1251
1252   $tests_passed    = 0
1253   $tests_failed    = 0
1254   $tests_warnings  = 0
1255   $tests_total     = 0
1256
1257   #######################
1258   @center_0 = "mc:0"
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"
1263   @main_B="mc:0,bo:1"
1264     @branch_0Ba = @main_B + ",bo:0"
1265     @branch_0Bb = @main_B + ",bo:1"
1266   @center_1 = "mc:1"
1267   @center_2 = "mc:2"
1268   @center_3 = "mc:3"
1269
1270   instance_name = 'test'
1271
1272   vym_mgr = VymManager.new
1273   #vym_mgr.show_running
1274
1275   @vym = vym_mgr.find(instance_name)
1276
1277   if !@vym
1278     puts "Couldn't find instance name \"#{instance_name}\", please start one:"
1279     puts "vym -l -n \"#{instance-name}\" -t test/default.vym"
1280     exit
1281   end
1282
1283   test_vym
1284   test_basics
1285
1286   #test_adding_branches
1287   #test_adding_maps
1288   #test_attributes
1289   #test_bugfixes
1290   #test_copy_paste
1291   #test_delete_parts
1292   #test_export
1293   #test_extrainfo
1294   #test_frames
1295   ##test_headings  # FIXME-2 no tests available
1296   #test_history
1297   test_load_legacy_maps
1298   #test_modify_branches
1299   #test_moving_parts
1300   #test_notes
1301   #test_references
1302   #test_saving
1303   #test_scrolling
1304   #test_slides
1305   #test_standard_flags
1306   #test_tasks
1307   #test_user_flags
1308   #test_xlinks
1309
1310   summary
1311
1312 end
1313