Fix compiler warning due to missing function prototype.
[svn.git] / subversion / bindings / swig / ruby / test / test_client.rb
blobfb2f9e806e4cd6cc8d1cf51eff488491b08c8224
1 require "my-assertions"
2 require "util"
4 require "svn/core"
5 require "svn/client"
7 class SvnClientTest < Test::Unit::TestCase
8   include SvnTestUtil
10   def setup
11     setup_basic(true)
12   end
14   def teardown
15     teardown_basic
16   end
18   def test_version
19     assert_equal(Svn::Core.subr_version, Svn::Client.version)
20   end
22   def test_add_not_recurse
23     log = "sample log"
24     dir = "dir"
25     dir_path = File.join(@wc_path, dir)
26     path = File.join(dir_path, dir)
27     uri = "#{@repos_uri}/#{dir}/#{dir}"
29     ctx = make_context(log)
30     FileUtils.mkdir(dir_path)
31     FileUtils.mkdir(path)
32     ctx.add(dir_path, false)
33     ctx.commit(@wc_path)
35     assert_raise(Svn::Error::FS_NOT_FOUND) do
36       ctx.cat(uri)
37     end
38   end
40   def test_add_recurse
41     log = "sample log"
42     file = "hello.txt"
43     src = "Hello"
44     dir = "dir"
45     dir_path = File.join(@wc_path, dir)
46     path = File.join(dir_path, file)
47     uri = "#{@repos_uri}/#{dir}/#{file}"
49     ctx = make_context(log)
50     FileUtils.mkdir(dir_path)
51     File.open(path, "w") {|f| f.print(src)}
52     ctx.add(dir_path)
53     ctx.commit(@wc_path)
55     assert_equal(src, ctx.cat(uri))
56   end
58   def test_add_force
59     log = "sample log"
60     file = "hello.txt"
61     src = "Hello"
62     dir = "dir"
63     dir_path = File.join(@wc_path, dir)
64     path = File.join(dir_path, file)
65     uri = "#{@repos_uri}/#{dir}/#{file}"
67     ctx = make_context(log)
68     FileUtils.mkdir(dir_path)
69     File.open(path, "w") {|f| f.print(src)}
70     ctx.add(dir_path, false)
71     ctx.commit(@wc_path)
73     assert_raise(Svn::Error::ENTRY_EXISTS) do
74       ctx.add(dir_path, true, false)
75     end
77     ctx.add(dir_path, true, true)
78     ctx.commit(@wc_path)
79     assert_equal(src, ctx.cat(uri))
80   end
82   def test_add_no_ignore
83     log = "sample log"
84     file = "hello.txt"
85     src = "Hello"
86     dir = "dir"
87     dir_path = File.join(@wc_path, dir)
88     path = File.join(dir_path, file)
89     uri = "#{@repos_uri}/#{dir}/#{file}"
91     ctx = make_context(log)
92     FileUtils.mkdir(dir_path)
93     ctx.add(dir_path, false)
94     ctx.propset(Svn::Core::PROP_IGNORE, file, dir_path)
95     ctx.commit(@wc_path)
97     File.open(path, "w") {|f| f.print(src)}
99     ctx.add(dir_path, true, true, false)
100     ctx.commit(@wc_path)
101     assert_raise(Svn::Error::FS_NOT_FOUND) do
102       ctx.cat(uri)
103     end
105     ctx.add(dir_path, true, true, true)
106     ctx.commit(@wc_path)
107     assert_equal(src, ctx.cat(uri))
108   end
110   def test_mkdir
111     log = "sample log"
112     dir = "dir"
113     deep_dir = ["d", "e", "e", "p"]
114     dir2 = "dir2"
115     dir_uri = "#{@repos_uri}/#{dir}"
116     deep_dir_uri = "#{@repos_uri}/#{deep_dir.join('/')}"
117     dir2_uri = "#{@repos_uri}/#{dir2}"
118     dir_path = File.join(@wc_path, dir)
119     deep_dir_path = File.join(@wc_path, *deep_dir)
120     dir2_path = File.join(@wc_path, dir2)
122     ctx = make_context(log)
124     assert(!File.exist?(dir_path))
125     ctx.mkdir(dir_path)
126     assert(File.exist?(dir_path))
127     assert_raises(Svn::Error::EntryExists) do
128       ctx.add(dir_path)
129     end
130     old_rev = ctx.commit(@wc_path).revision
132     new_rev = ctx.mkdir(dir2_uri).revision
133     assert_equal(old_rev + 1, new_rev)
134     assert_raises(Svn::Error::FsAlreadyExists) do
135       ctx.mkdir(dir2_uri)
136     end
137     assert(!File.exist?(dir2_path))
138     ctx.update(@wc_path)
139     assert(File.exist?(dir2_path))
141     assert_raises(Svn::Error::SvnError) do
142       ctx.mkdir(deep_dir_path)
143     end
144   end
146   def test_mkdir_multiple
147     log = "sample log"
148     dir = "dir"
149     dir2 = "dir2"
150     dirs = [dir, dir2]
151     dirs_path = dirs.collect{|d| File.join(@wc_path, d)}
152     dirs_uri = dirs.collect{|d| "#{@repos_uri}/#{d}"}
154     ctx = make_context(log)
156     infos = []
157     ctx.set_notify_func do |notify|
158       infos << [notify.path, notify]
159     end
161     dirs_path.each do |path|
162       assert(!File.exist?(path))
163     end
164     ctx.mkdir(dirs_path)
165     assert_equal(dirs_path.sort,
166                  infos.collect{|path, notify| path}.sort)
167     assert_equal(dirs_path.collect{true},
168                  infos.collect{|path, notify| notify.add?})
169     dirs_path.each do |path|
170       assert(File.exist?(path))
171     end
173     infos.clear
174     ctx.commit(@wc_path)
175     assert_equal(dirs_path.sort,
176                  infos.collect{|path, notify| path}.sort)
177     assert_equal(dirs_path.collect{true},
178                  infos.collect{|path, notify| notify.commit_added?})
179   end
181   def test_mkdir_multiple2
182     log = "sample log"
183     dir = "dir"
184     dir2 = "dir2"
185     dirs = [dir, dir2]
186     dirs_path = dirs.collect{|d| File.join(@wc_path, d)}
187     dirs_uri = dirs.collect{|d| "#{@repos_uri}/#{d}"}
189     ctx = make_context(log)
191     infos = []
192     ctx.set_notify_func do |notify|
193       infos << [notify.path, notify]
194     end
196     dirs_path.each do |path|
197       assert(!File.exist?(path))
198     end
199     ctx.mkdir(*dirs_path)
200     assert_equal(dirs_path.sort,
201                  infos.collect{|path, notify| path}.sort)
202     assert_equal(dirs_path.collect{true},
203                  infos.collect{|path, notify| notify.add?})
204     dirs_path.each do |path|
205       assert(File.exist?(path))
206     end
208     infos.clear
209     ctx.commit(@wc_path)
210     assert_equal(dirs_path.sort,
211                  infos.collect{|path, notify| path}.sort)
212     assert_equal(dirs_path.collect{true},
213                  infos.collect{|path, notify| notify.commit_added?})
214   end
216   def test_delete
217     log = "sample log"
218     src = "sample source\n"
219     file = "file.txt"
220     dir = "dir"
221     path = File.join(@wc_path, file)
222     dir_path = File.join(@wc_path, dir)
224     ctx = make_context(log)
226     File.open(path, "w") {|f| f.print(src)}
227     ctx.add(path)
228     ctx.mkdir(dir_path)
229     ctx.commit(@wc_path)
231     ctx.delete([path, dir_path])
232     ctx.commit(@wc_path)
233     assert(!File.exist?(path))
234     assert(!File.exist?(dir_path))
237     File.open(path, "w") {|f| f.print(src)}
238     ctx.add(path)
239     ctx.commit(@wc_path)
241     File.open(path, "w") {|f| f.print(src * 2)}
242     assert_raises(Svn::Error::ClientModified) do
243       ctx.delete(path)
244     end
245     assert_nothing_raised do
246       ctx.delete(path, true)
247       ctx.commit(@wc_path)
248     end
249     assert(!File.exist?(path))
250   end
252   def test_delete_alias
253     log = "sample log"
254     src = "sample source\n"
255     file = "file.txt"
256     dir = "dir"
257     path = File.join(@wc_path, file)
258     dir_path = File.join(@wc_path, dir)
260     ctx = make_context(log)
262     File.open(path, "w") {|f| f.print(src)}
263     ctx.add(path)
264     ctx.mkdir(dir_path)
265     ctx.commit(@wc_path)
267     ctx.rm([path, dir_path])
268     ctx.commit(@wc_path)
269     assert(!File.exist?(path))
270     assert(!File.exist?(dir_path))
273     File.open(path, "w") {|f| f.print(src)}
274     ctx.add(path)
275     ctx.commit(@wc_path)
277     File.open(path, "w") {|f| f.print(src * 2)}
278     assert_raises(Svn::Error::ClientModified) do
279       ctx.rm(path)
280     end
281     assert_nothing_raised do
282       ctx.rm_f(path)
283       ctx.commit(@wc_path)
284     end
285     assert(!File.exist?(path))
287     File.open(path, "w") {|f| f.print(src)}
288     ctx.add(path)
289     ctx.mkdir(dir_path)
290     ctx.commit(@wc_path)
292     ctx.rm_f(path, dir_path)
293     ctx.commit(@wc_path)
294     assert(!File.exist?(path))
295     assert(!File.exist?(dir_path))
296   end
298   def test_import
299     src = "source\n"
300     log = "sample log"
301     deep_dir = File.join(%w(a b c d e))
302     file = "sample.txt"
303     deep_dir_path = File.join(@wc_path, deep_dir)
304     path = File.join(deep_dir_path, file)
305     tmp_deep_dir_path = File.join(@tmp_path, deep_dir)
306     tmp_path = File.join(tmp_deep_dir_path, file)
308     ctx = make_context(log)
310     FileUtils.mkdir_p(tmp_deep_dir_path)
311     File.open(tmp_path, "w") {|f| f.print(src)}
313     ctx.import(@tmp_path, @repos_uri)
315     ctx.up(@wc_path)
316     assert_equal(src, File.open(path){|f| f.read})
317   end
319   def test_commit
320     log = "sample log"
321     dir1 = "dir1"
322     dir2 = "dir2"
323     dir1_path = File.join(@wc_path, dir1)
324     dir2_path = File.join(dir1_path, dir2)
326     ctx = make_context(log)
327     assert_equal(Svn::Core::INVALID_REVNUM,ctx.commit(@wc_path).revision)
328     ctx.mkdir(dir1_path)
329     assert_equal(0, youngest_rev)
330     assert_equal(1, ctx.commit(@wc_path).revision)
331     ctx.mkdir(dir2_path)
332     assert_equal(Svn::Core::INVALID_REVNUM,ctx.commit(@wc_path, false).revision)
333     assert_equal(2, ctx.ci(@wc_path).revision)
334   end
336   def test_status
337     log = "sample log"
338     file1 = "sample1.txt"
339     file2 = "sample2.txt"
340     dir = "dir"
341     dir_path = File.join(@wc_path, dir)
342     path1 = File.join(@wc_path, file1)
343     path2 = File.join(dir_path, file2)
345     ctx = make_context(log)
346     File.open(path1, "w") {}
347     ctx.add(path1)
348     rev1 = ctx.commit(@wc_path).revision
351     ctx.mkdir(dir_path)
352     File.open(path2, "w") {}
354     infos = []
355     rev = ctx.status(@wc_path) do |path, status|
356       infos << [path, status]
357     end
359     assert_equal(youngest_rev, rev)
360     assert_equal([dir_path, path2].sort,
361                  infos.collect{|path, status| path}.sort)
362     dir_status = infos.assoc(dir_path).last
363     assert(dir_status.text_added?)
364     assert(dir_status.entry.dir?)
365     assert(dir_status.entry.add?)
366     path2_status = infos.assoc(path2).last
367     assert(!path2_status.text_added?)
368     assert_nil(path2_status.entry)
371     infos = []
372     rev = ctx.st(@wc_path, rev1, true, true) do |path, status|
373       infos << [path, status]
374     end
376     assert_equal(rev1, rev)
377     assert_equal([@wc_path, dir_path, path1, path2].sort,
378                  infos.collect{|path, status| path}.sort)
379     wc_status = infos.assoc(@wc_path).last
380     assert(wc_status.text_normal?)
381     assert(wc_status.entry.dir?)
382     assert(wc_status.entry.normal?)
383     dir_status = infos.assoc(dir_path).last
384     assert(dir_status.text_added?)
385     assert(dir_status.entry.dir?)
386     assert(dir_status.entry.add?)
387     path1_status = infos.assoc(path1).last
388     assert(path1_status.text_normal?)
389     assert(path1_status.entry.file?)
390     assert(path1_status.entry.normal?)
391     path2_status = infos.assoc(path2).last
392     assert(!path2_status.text_added?)
393     assert_nil(path2_status.entry)
396     ctx.prop_set(Svn::Core::PROP_IGNORE, file2, dir_path)
398     infos = []
399     rev = ctx.status(@wc_path, nil, true, true, true, false) do |path, status|
400       infos << [path, status]
401     end
403     assert_equal(rev1, rev)
404     assert_equal([@wc_path, dir_path, path1].sort,
405                  infos.collect{|path, status| path}.sort)
408     infos = []
409     rev = ctx.status(@wc_path, nil, true, true, true, true) do |path, status|
410       infos << [path, status]
411     end
413     assert_equal(rev1, rev)
414     assert_equal([@wc_path, dir_path, path1, path2].sort,
415                  infos.collect{|path, status| path}.sort)
416   end
418   def test_status_with_depth
419     setup_greek_tree
421     log = "sample log"
422     ctx = make_context(log)
424     # make everything out-of-date
425     ctx.prop_set('propname', 'propvalue', @greek.path(:b), :infinity)
427     recurse_and_depth_choices.each do |rd|
428       ctx.status(@greek.path(:mu), nil, rd) do |path, status|
429         assert_equal @greek.uri(:mu), status.url
430       end
431     end
433     expected_statuses_by_depth = {
434       true => [:beta, :b, :lambda, :e, :f, :alpha],
435       false => [:b, :lambda, :e, :f],
436       'empty' => [:b],
437       'files' => [:b, :lambda],
438       'immediates' => [:b, :lambda, :e, :f],
439       'infinity' => [:beta, :b, :lambda, :e, :f, :alpha],
440     }
442     recurse_and_depth_choices.each do |rd|
443       urls = []
444       ctx.status(@greek.path(:b), nil, rd) do |path, status|
445         urls << status.url
446       end
447       assert_equal(expected_statuses_by_depth[rd].map{|s| @greek.uri(s)}.sort,
448                    urls.sort,
449                    "depth '#{rd}")
450     end
451   end
453   def test_checkout
454     log = "sample log"
455     file = "hello.txt"
456     dir = "dir"
457     dir_path = File.join(@wc_path, dir)
458     path = File.join(dir_path, file)
459     content = "Hello"
461     ctx = make_context(log)
462     ctx.mkdir(dir_path)
463     File.open(path, "w"){|f| f.print(content)}
464     ctx.add(path)
465     ctx.commit(@wc_path)
467     FileUtils.rm_rf(@wc_path)
468     ctx.checkout(@repos_uri, @wc_path)
469     assert(File.exist?(path))
471     FileUtils.rm_rf(@wc_path)
472     ctx.co(@repos_uri, @wc_path, nil, nil, false)
473     assert(!File.exist?(path))
474   end
476   def test_update
477     log = "sample log"
478     file = "hello.txt"
479     path = File.join(@wc_path, file)
480     content = "Hello"
481     File.open(path, "w"){|f| f.print(content)}
483     ctx = make_context(log)
485     assert_nothing_raised do
486       ctx.update(File.join(@wc_path, "non-exist"), youngest_rev)
487     end
489     ctx.add(path)
490     commit_info = ctx.commit(@wc_path)
492     FileUtils.rm(path)
493     assert(!File.exist?(path))
494     assert_equal(commit_info.revision,
495                  ctx.update(path, commit_info.revision))
496     assert_equal(content, File.read(path))
498     FileUtils.rm(path)
499     assert(!File.exist?(path))
500     assert_equal([commit_info.revision],
501                  ctx.update([path], commit_info.revision))
502     assert_equal(content, File.read(path))
504     assert_raise(Svn::Error::FS_NO_SUCH_REVISION) do
505       begin
506         ctx.update(path, commit_info.revision + 1)
507       ensure
508         ctx.cleanup(@wc_path)
509       end
510     end
511     assert_nothing_raised do
512       ctx.update(path + "non-exist", commit_info.revision)
513     end
514   end
516   def test_revert
517     log = "sample log"
518     file1 = "hello1.txt"
519     file2 = "hello2.txt"
520     file3 = "hello3.txt"
521     dir = "dir"
522     dir_path = File.join(@wc_path, dir)
523     path1 = File.join(@wc_path, file1)
524     path2 = File.join(@wc_path, file2)
525     path3 = File.join(dir_path, file3)
526     content = "Hello"
528     ctx = make_context(log)
529     File.open(path1, "w"){|f| f.print(content)}
530     File.open(path2, "w"){|f| f.print(content)}
531     ctx.add(path1)
532     ctx.add(path2)
533     ctx.mkdir(dir_path)
534     File.open(path3, "w"){|f| f.print(content)}
535     ctx.add(path3)
536     commit_info = ctx.commit(@wc_path)
538     File.open(path1, "w"){}
539     assert_equal("", File.open(path1){|f| f.read})
541     ctx.revert(path1)
542     assert_equal(content, File.open(path1){|f| f.read})
544     File.open(path1, "w"){}
545     File.open(path2, "w"){}
546     assert_equal("", File.open(path1){|f| f.read})
547     assert_equal("", File.open(path2){|f| f.read})
548     ctx.revert([path1, path2])
549     assert_equal(content, File.open(path1){|f| f.read})
550     assert_equal(content, File.open(path2){|f| f.read})
552     File.open(path1, "w"){}
553     File.open(path2, "w"){}
554     File.open(path3, "w"){}
555     assert_equal("", File.open(path1){|f| f.read})
556     assert_equal("", File.open(path2){|f| f.read})
557     assert_equal("", File.open(path3){|f| f.read})
558     ctx.revert(@wc_path)
559     assert_equal(content, File.open(path1){|f| f.read})
560     assert_equal(content, File.open(path2){|f| f.read})
561     assert_equal(content, File.open(path3){|f| f.read})
563     File.open(path1, "w"){}
564     File.open(path2, "w"){}
565     File.open(path3, "w"){}
566     assert_equal("", File.open(path1){|f| f.read})
567     assert_equal("", File.open(path2){|f| f.read})
568     assert_equal("", File.open(path3){|f| f.read})
569     ctx.revert(@wc_path, false)
570     assert_equal("", File.open(path1){|f| f.read})
571     assert_equal("", File.open(path2){|f| f.read})
572     assert_equal("", File.open(path3){|f| f.read})
574     File.open(path1, "w"){}
575     File.open(path2, "w"){}
576     File.open(path3, "w"){}
577     assert_equal("", File.open(path1){|f| f.read})
578     assert_equal("", File.open(path2){|f| f.read})
579     assert_equal("", File.open(path3){|f| f.read})
580     ctx.revert(dir_path)
581     assert_equal("", File.open(path1){|f| f.read})
582     assert_equal("", File.open(path2){|f| f.read})
583     assert_equal(content, File.open(path3){|f| f.read})
584   end
586   def test_log
587     log1 = "sample log1"
588     log2 = "sample log2"
589     log3 = "sample log3"
590     src1 = "source1\n"
591     src2 = "source2\n"
592     src3 = "source3\n"
593     file1 = "sample1.txt"
594     file2 = "sample2.txt"
595     file3 = "sample3.txt"
596     path1 = File.join(@wc_path, file1)
597     path2 = File.join(@wc_path, file2)
598     path3 = File.join(@wc_path, file3)
599     abs_path1 = File.join('', file1)
600     abs_path2 = File.join('', file2)
601     abs_path3 = File.join('', file3)
603     ctx = make_context(log1)
604     File.open(path1, "w") {|f| f.print(src1)}
605     ctx.add(path1)
606     rev1 = ctx.ci(@wc_path).revision
608     ctx = make_context(log2)
609     ctx.cp(path1, path2)
610     rev2 = ctx.ci(@wc_path).revision
612     ctx = make_context(log3)
613     ctx.cp(path1, path3)
614     File.open(path1, "w") {|f| f.print(src2)}
615     File.open(path3, "w") {|f| f.print(src3)}
616     rev3 = ctx.ci(@wc_path).revision
618     changed_paths_lists = {}
619     revs = {}
620     messages = {}
621     keys = [@wc_path, path1, path2, path3]
622     keys.each do |key|
623       revs[key] = []
624       changed_paths_lists[key] = []
625       messages[key] = []
626       args = [key, 1, "HEAD", 0, true, nil]
627       ctx.log(*args) do |changed_paths, rev, author, date, message|
628         revs[key] << rev
629         changed_paths_lists[key] << changed_paths
630         messages[key] << message
631       end
632     end
633     changed_paths_list = changed_paths_lists[@wc_path]
635     assert_equal([rev1, rev2, rev3], revs[@wc_path])
636     assert_equal([rev1, rev3], revs[path1])
637     assert_equal([rev1, rev2], revs[path2])
638     assert_equal([rev1, rev3], revs[path3])
639     assert_equal([log1, log2, log3], messages[@wc_path])
641     expected = [[abs_path1], [abs_path2], [abs_path1, abs_path3]]
642     actual = changed_paths_list.collect {|changed_paths| changed_paths.keys}
643     assert_nested_sorted_array(expected, actual)
645     assert_equal('A', changed_paths_list[0][abs_path1].action)
646     assert_false(changed_paths_list[0][abs_path1].copied?)
647     assert_equal('A', changed_paths_list[1][abs_path2].action)
648     assert_true(changed_paths_list[1][abs_path2].copied?)
649     assert_equal(abs_path1, changed_paths_list[1][abs_path2].copyfrom_path)
650     assert_equal(rev1, changed_paths_list[1][abs_path2].copyfrom_rev)
651     assert_equal('M', changed_paths_list[2][abs_path1].action)
652     assert_equal('A', changed_paths_list[2][abs_path3].action)
653   end
655   def test_log_message
656     log = "sample log"
657     file = "hello.txt"
658     path = File.join(@wc_path, file)
659     FileUtils.touch(path)
661     ctx = make_context(log)
662     ctx.add(path)
663     commit_info = ctx.commit(@wc_path)
664     rev = commit_info.revision
666     assert_equal(log, ctx.log_message(path, rev))
667   end
669   def test_blame
670     log = "sample log"
671     file = "hello.txt"
672     srcs = %w(first second third)
673     infos = []
674     path = File.join(@wc_path, file)
676     ctx = make_context(log)
678     File.open(path, "w") {|f| f.puts(srcs[0])}
679     ctx.add(path)
680     commit_info = ctx.commit(@wc_path)
681     infos << [0, commit_info.revision, @author, commit_info.date, srcs[0]]
683     File.open(path, "a") {|f| f.puts(srcs[1])}
684     commit_info = ctx.commit(@wc_path)
685     infos << [1, commit_info.revision, @author, commit_info.date, srcs[1]]
687     File.open(path, "a") {|f| f.puts(srcs[2])}
688     commit_info = ctx.commit(@wc_path)
689     infos << [2, commit_info.revision, @author, commit_info.date, srcs[2]]
691     result = []
692     ctx.blame(path) do |line_no, revision, author, date, line|
693       result << [line_no, revision, author, date, line]
694     end
695     assert_equal(infos, result)
698     ctx.prop_set(Svn::Core::PROP_MIME_TYPE, "image/DUMMY", path)
699     ctx.commit(@wc_path)
701     assert_raise(Svn::Error::CLIENT_IS_BINARY_FILE) do
702       ctx.ann(path) {}
703     end
704   end
706   def test_diff
707     log = "sample log"
708     before = "before\n"
709     after = "after\n"
710     file = "hello.txt"
711     path = File.join(@wc_path, file)
713     File.open(path, "w") {|f| f.print(before)}
715     ctx = make_context(log)
716     ctx.add(path)
717     commit_info = ctx.commit(@wc_path)
718     rev1 = commit_info.revision
720     File.open(path, "w") {|f| f.print(after)}
722     out_file = Tempfile.new("svn")
723     err_file = Tempfile.new("svn")
724     ctx.diff([], path, rev1, path, "WORKING", out_file.path, err_file.path)
725     out_file.open
726     assert_match(/-#{before}\+#{after}\z/, out_file.read)
728     commit_info = ctx.commit(@wc_path)
729     rev2 = commit_info.revision
730     out_file = Tempfile.new("svn")
731     ctx.diff([], path, rev1, path, rev2, out_file.path, err_file.path)
732     out_file.open
733     assert_match(/-#{before}\+#{after}\z/, out_file.read)
734   end
736   def test_diff_peg
737     log = "sample log"
738     before = "before\n"
739     after = "after\n"
740     file = "hello.txt"
741     path = File.join(@wc_path, file)
743     File.open(path, "w") {|f| f.print(before)}
745     ctx = make_context(log)
746     ctx.add(path)
747     commit_info = ctx.commit(@wc_path)
748     rev1 = commit_info.revision
750     File.open(path, "w") {|f| f.print(after)}
752     out_file = Tempfile.new("svn")
753     err_file = Tempfile.new("svn")
754     ctx.diff_peg([], path, rev1, "WORKING", out_file.path, err_file.path)
755     out_file.open
756     assert_match(/-#{before}\+#{after}\z/, out_file.read)
758     commit_info = ctx.commit(@wc_path)
759     rev2 = commit_info.revision
760     out_file = Tempfile.new("svn")
761     ctx.diff_peg([], path, rev1, rev2, out_file.path, err_file.path)
762     out_file.open
763     assert_match(/-#{before}\+#{after}\z/, out_file.read)
764   end
766   def test_diff_summarize
767     log = "sample log"
768     before = "before\n"
769     after = "after\n"
770     file = "hello.txt"
771     path = File.join(@wc_path, file)
773     File.open(path, "w") {|f| f.print(before)}
775     ctx = make_context(log)
776     ctx.add(path)
777     commit_info = ctx.commit(@wc_path)
778     rev1 = commit_info.revision
780     File.open(path, "w") {|f| f.print(after)}
782     commit_info = ctx.commit(@wc_path)
783     rev2 = commit_info.revision
785     diffs = []
786     ctx.diff_summarize(@wc_path, rev1, @wc_path, rev2) do |diff|
787       diffs << diff
788     end
789     assert_equal([file], diffs.collect {|d| d.path})
790     kinds = diffs.collect do |d|
791       [d.kind_normal?, d.kind_added?, d.kind_modified?, d.kind_deleted?]
792     end
793     assert_equal([[false, false, true, false]], kinds)
794     assert_equal([false], diffs.collect {|d| d.prop_changed?})
795     node_kinds = diffs.collect do |d|
796       [d.node_kind_none?, d.node_kind_file?,
797        d.node_kind_dir?, d.node_kind_unknown?]
798     end
799     assert_equal([[false, true, false, false]], node_kinds)
800   end
802   def test_diff_summarize_peg
803     log = "sample log"
804     before = "before\n"
805     after = "after\n"
806     before_file = "before.txt"
807     after_file = "after.txt"
808     moved_file = "moved.txt"
809     before_path = File.join(@wc_path, before_file)
810     after_path = File.join(@wc_path, after_file)
811     moved_path = File.join(@wc_path, moved_file)
813     File.open(before_path, "w") {|f| f.print(before)}
815     ctx = make_context(log)
816     ctx.add(before_path)
817     commit_info = ctx.commit(@wc_path)
818     rev1 = commit_info.revision
820     ctx.mv(before_path, after_path)
821     commit_info = ctx.commit(@wc_path)
822     rev2 = commit_info.revision
824     File.open(after_path, "w") {|f| f.print(after)}
825     commit_info = ctx.commit(@wc_path)
826     rev3 = commit_info.revision
828     File.open(after_path, "w") {|f| f.print(before)}
829     commit_info = ctx.commit(@wc_path)
830     rev4 = commit_info.revision
832     ctx.mv(after_path, moved_path)
833     commit_info = ctx.commit(@wc_path)
834     rev5 = commit_info.revision
836     diffs = []
837     ctx.diff_summarize_peg(@repos_uri, rev3, rev4, rev3) do |diff|
838       diffs << diff
839     end
840     assert_equal([after_file], diffs.collect {|d| d.path})
841     kinds = diffs.collect do |d|
842       [d.kind_normal?, d.kind_added?, d.kind_modified?, d.kind_deleted?]
843     end
844     assert_equal([[false, false, true, false]], kinds)
845     assert_equal([false], diffs.collect {|d| d.prop_changed?})
846     node_kinds = diffs.collect do |d|
847       [d.node_kind_none?, d.node_kind_file?,
848        d.node_kind_dir?, d.node_kind_unknown?]
849     end
850     assert_equal([[false, true, false, false]], node_kinds)
851   end
853   def assert_merge
854     log = "sample log"
855     file = "sample.txt"
856     src = "sample\n"
857     trunk = File.join(@wc_path, "trunk")
858     branch = File.join(@wc_path, "branch")
859     branch_relative_uri = "/branch"
860     branch_uri = "#{@repos_uri}#{branch_relative_uri}"
861     trunk_path = File.join(trunk, file)
862     trunk_path_uri = "#{@repos_uri}/trunk/#{file}"
863     branch_path = File.join(branch, file)
864     branch_path_relative_uri = "#{branch_relative_uri}/#{file}"
865     branch_path_uri = "#{@repos_uri}#{branch_path_relative_uri}"
867     ctx = make_context(log)
868     ctx.mkdir(trunk, branch)
869     File.open(trunk_path, "w") {}
870     File.open(branch_path, "w") {}
871     ctx.add(trunk_path)
872     ctx.add(branch_path)
873     rev1 = ctx.commit(@wc_path).revision
875     File.open(branch_path, "w") {|f| f.print(src)}
876     rev2 = ctx.commit(@wc_path).revision
878     merged_entries = []
879     ctx.log_merged(trunk, nil, branch_uri, nil) do |entry|
880       merged_entries << entry
881     end
882     assert_equal_log_entries([], merged_entries)
883     assert_nil(ctx.merged(trunk))
885     merged_entries = []
886     yield(ctx, branch, rev1, rev2, trunk)
887     ctx.log_merged(trunk, nil, branch_uri, nil) do |entry|
888       merged_entries << entry
889     end
890     assert_equal_log_entries([
891                               [
892                                {branch_path_relative_uri => ["M", nil, -1]},
893                                rev2,
894                                {
895                                  "svn:author" => @author,
896                                  "svn:log" => log,
897                                },
898                                false,
899                               ]
900                              ],
901                              merged_entries)
902     mergeinfo = ctx.merged(trunk)
903     assert_not_nil(mergeinfo)
904     assert_equal([branch_uri], mergeinfo.keys)
905     ranges = mergeinfo[branch_uri].collect {|range| range.to_a}
906     assert_equal([[1, 2, true]], ranges)
908     rev3 = ctx.commit(@wc_path).revision
910     assert_equal(normalize_line_break(src), ctx.cat(trunk_path, rev3))
912     ctx.rm(branch_path)
913     rev4 = ctx.commit(@wc_path).revision
915     yield(ctx, branch, rev3, rev4, trunk)
916     assert(!File.exist?(trunk_path))
918     merged_entries = []
919     ctx.log_merged(trunk, rev4, branch_uri, rev4) do |entry|
920       merged_entries << entry
921     end
922     assert_equal_log_entries([
923                               [
924                                {branch_path_relative_uri => ["D", nil, -1]},
925                                rev4,
926                                {
927                                  "svn:author" => @author,
928                                  "svn:log" => log,
929                                },
930                                false,
931                               ]
932                              ] * 2, merged_entries)
934     ctx.propdel("svn:mergeinfo", trunk)
935     merged_entries = []
936     ctx.log_merged(trunk, rev4, branch_uri, rev4) do |entry|
937       merged_entries << entry
938     end
939     assert_equal_log_entries([], merged_entries)
941     ctx.revert(trunk)
942     ctx.revert(trunk_path)
943     File.open(trunk_path, "a") {|f| f.print(src)}
944     yield(ctx, branch, rev3, rev4, trunk)
945     rev5 = ctx.commit(@wc_path).revision
946     assert(File.exist?(trunk_path))
948     yield(ctx, branch, rev3, rev4, trunk, nil, false, true, true)
949     statuses = []
950     ctx.status(trunk) do |path, status|
951       statuses << status
952     end
953     assert_equal([], statuses)
955     yield(ctx, branch, rev3, rev4, trunk, nil, false, true)
956     statuses = []
957     ctx.status(trunk) do |path, status|
958       statuses << status
959     end
960     assert_not_equal([], statuses)
961   end
963   def test_merge
964     assert_merge do |ctx, from, from_rev1, from_rev2, to, *rest|
965       ctx.merge(from, from_rev1, from, from_rev2, to, *rest)
966     end
967   end
969   def test_merge_peg
970     assert_merge do |ctx, from, from_rev1, from_rev2, to, *rest|
971       ctx.merge_peg(from, from_rev1, from_rev2, to, nil, *rest)
972     end
973   end
975   def test_cleanup
976     log = "sample log"
977     file = "sample.txt"
978     src = "sample\n"
979     path = File.join(@wc_path, file)
981     ctx = make_context(log)
982     File.open(path, "w") {|f| f.print(src)}
983     ctx.add(path)
984     rev = ctx.commit(@wc_path).revision
986     ctx.up(@wc_path, rev - 1)
987     File.open(path, "w") {|f| f.print(src)}
989     assert_raise(Svn::Error::WC_OBSTRUCTED_UPDATE) do
990       ctx.up(@wc_path, rev)
991     end
993     Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1) do |access|
994       assert_raise(Svn::Error::WC_LOCKED) do
995         ctx.commit(@wc_path)
996       end
997     end
999     ctx.set_cancel_func do
1000       raise Svn::Error::CANCELLED
1001     end
1002     Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1) do |access|
1003       assert_raise(Svn::Error::CANCELLED) do
1004         ctx.cleanup(@wc_path)
1005       end
1006       assert_raise(Svn::Error::WC_LOCKED) do
1007         ctx.commit(@wc_path)
1008       end
1009     end
1011     ctx.set_cancel_func(nil)
1012     access = Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1)
1013     assert_nothing_raised do
1014       ctx.cleanup(@wc_path)
1015     end
1016     assert_nothing_raised do
1017       ctx.commit(@wc_path)
1018     end
1019     assert_raises(Svn::Error::SvnError) do
1020       access.close
1021     end
1022   end
1024   def test_relocate
1025     log = "sample log"
1026     file = "sample.txt"
1027     src = "sample\n"
1028     path = File.join(@wc_path, file)
1030     ctx = make_context(log)
1031     File.open(path, "w") {|f| f.print(src)}
1032     ctx.add(path)
1033     ctx.commit(@wc_path)
1035     assert_nothing_raised do
1036       ctx.cat(path)
1037     end
1039     ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1040       cred.username = @author
1041       cred.password = @password
1042       cred.may_save = true
1043     end
1044     ctx.relocate(@wc_path, @repos_uri, @repos_svnserve_uri)
1046     ctx = make_context(log)
1047     assert_raises(Svn::Error::AuthnNoProvider) do
1048       ctx.cat(path)
1049     end
1050   end
1052   def test_resolved
1053     log = "sample log"
1054     file = "sample.txt"
1055     dir = "dir"
1056     src1 = "before\n"
1057     src2 = "after\n"
1058     dir_path = File.join(@wc_path, dir)
1059     path = File.join(dir_path, file)
1061     ctx = make_context(log)
1062     ctx.mkdir(dir_path)
1063     File.open(path, "w") {}
1064     ctx.add(path)
1065     rev1 = ctx.ci(@wc_path).revision
1067     File.open(path, "w") {|f| f.print(src1)}
1068     rev2 = ctx.ci(@wc_path).revision
1070     ctx.up(@wc_path, rev1)
1072     File.open(path, "w") {|f| f.print(src2)}
1073     ctx.up(@wc_path)
1075     assert_raises(Svn::Error::WcFoundConflict) do
1076       ctx.ci(@wc_path)
1077     end
1079     ctx.resolved(dir_path, false)
1080     assert_raises(Svn::Error::WcFoundConflict) do
1081       ctx.ci(@wc_path)
1082     end
1084     ctx.resolved(dir_path)
1085     info = nil
1086     assert_nothing_raised do
1087       info = ctx.ci(@wc_path)
1088     end
1089     assert_not_nil(info)
1090     assert_equal(rev2 + 1, info.revision)
1091   end
1093   def test_copy
1094     log = "sample log"
1095     src = "source\n"
1096     file1 = "sample1.txt"
1097     file2 = "sample2.txt"
1098     path1 = File.join(@wc_path, file1)
1099     path2 = File.join(@wc_path, file2)
1101     ctx = make_context(log)
1102     File.open(path1, "w") {|f| f.print(src)}
1103     ctx.add(path1)
1105     ctx.ci(@wc_path)
1107     ctx.cp(path1, path2)
1109     infos = []
1110     ctx.set_notify_func do |notify|
1111       infos << [notify.path, notify]
1112     end
1113     ctx.ci(@wc_path)
1115     assert_equal([path2].sort,
1116                  infos.collect{|path, notify| path}.sort)
1117     path2_notify = infos.assoc(path2)[1]
1118     assert(path2_notify.commit_added?)
1119     assert_equal(File.open(path1) {|f| f.read},
1120                  File.open(path2) {|f| f.read})
1121   end
1123   def test_move
1124     log = "sample log"
1125     src = "source\n"
1126     file1 = "sample1.txt"
1127     file2 = "sample2.txt"
1128     path1 = File.join(@wc_path, file1)
1129     path2 = File.join(@wc_path, file2)
1131     ctx = make_context(log)
1132     File.open(path1, "w") {|f| f.print(src)}
1133     ctx.add(path1)
1135     ctx.ci(@wc_path)
1137     ctx.mv(path1, path2)
1139     infos = []
1140     ctx.set_notify_func do |notify|
1141       infos << [notify.path, notify]
1142     end
1143     ctx.ci(@wc_path)
1145     assert_equal([path1, path2].sort,
1146                  infos.collect{|path, notify| path}.sort)
1147     path1_notify = infos.assoc(path1)[1]
1148     assert(path1_notify.commit_deleted?)
1149     path2_notify = infos.assoc(path2)[1]
1150     assert(path2_notify.commit_added?)
1151     assert_equal(src, File.open(path2) {|f| f.read})
1152   end
1154   def test_move_force
1155     log = "sample log"
1156     src1 = "source1\n"
1157     src2 = "source2\n"
1158     file1 = "sample1.txt"
1159     file2 = "sample2.txt"
1160     path1 = File.join(@wc_path, file1)
1161     path2 = File.join(@wc_path, file2)
1163     ctx = make_context(log)
1164     File.open(path1, "w") {|f| f.print(src1)}
1165     ctx.add(path1)
1166     ctx.ci(@wc_path)
1168     File.open(path1, "w") {|f| f.print(src2)}
1169     assert_nothing_raised do
1170       ctx.mv(path1, path2)
1171     end
1172     ctx.revert([path1, path2])
1173     FileUtils.rm(path2)
1175     File.open(path1, "w") {|f| f.print(src2)}
1176     assert_nothing_raised do
1177       ctx.mv_f(path1, path2)
1178     end
1180     notifies = []
1181     ctx.set_notify_func do |notify|
1182       notifies << notify
1183     end
1184     ctx.ci(@wc_path)
1186     paths = notifies.collect do |notify|
1187       notify.path
1188     end
1189     assert_equal([path1, path2, path2].sort, paths.sort)
1191     deleted_paths = notifies.find_all do |notify|
1192       notify.commit_deleted?
1193     end.collect do |notify|
1194       notify.path
1195     end
1196     assert_equal([path1].sort, deleted_paths.sort)
1198     added_paths = notifies.find_all do |notify|
1199       notify.commit_added?
1200     end.collect do |notify|
1201       notify.path
1202     end
1203     assert_equal([path2].sort, added_paths.sort)
1205     postfix_txdelta_paths = notifies.find_all do |notify|
1206       notify.commit_postfix_txdelta?
1207     end.collect do |notify|
1208       notify.path
1209     end
1210     assert_equal([path2].sort, postfix_txdelta_paths.sort)
1212     assert_equal(src2, File.open(path2) {|f| f.read})
1213   end
1215   def test_prop
1216     log = "sample log"
1217     dir = "dir"
1218     file = "sample.txt"
1219     dir_path = File.join(@wc_path, dir)
1220     dir_uri = "#{@repos_uri}/#{dir}"
1221     path = File.join(dir_path, file)
1222     uri = "#{dir_uri}/#{file}"
1223     prop_name = "sample-prop"
1224     prop_value = "sample value"
1225     invalid_mime_type_prop_value = "image"
1227     ctx = make_context(log)
1229     ctx.mkdir(dir_path)
1230     File.open(path, "w") {}
1231     ctx.add(path)
1233     ctx.commit(@wc_path)
1235     assert_equal({}, ctx.prop_get(prop_name, path))
1236     ctx.prop_set(prop_name, prop_value, path)
1237     ctx.commit(@wc_path)
1238     assert_equal({uri => prop_value}, ctx.pget(prop_name, path))
1240     ctx.prop_del(prop_name, path)
1241     ctx.commit(@wc_path)
1242     assert_equal({}, ctx.pg(prop_name, path))
1244     ctx.ps(prop_name, prop_value, path)
1245     ctx.commit(@wc_path)
1246     assert_equal({uri => prop_value}, ctx.pg(prop_name, path))
1248     ctx.ps(prop_name, nil, path)
1249     ctx.commit(@wc_path)
1250     assert_equal({}, ctx.pg(prop_name, path))
1252     ctx.up(@wc_path)
1253     ctx.ps(prop_name, prop_value, dir_path)
1254     ctx.ci(@wc_path)
1255     assert_equal({
1256                    dir_uri => prop_value,
1257                    uri => prop_value,
1258                  },
1259                  ctx.pg(prop_name, dir_path))
1261     ctx.up(@wc_path)
1262     ctx.pdel(prop_name, dir_path, false)
1263     ctx.ci(@wc_path)
1264     assert_equal({uri => prop_value}, ctx.pg(prop_name, dir_path))
1266     ctx.up(@wc_path)
1267     ctx.pd(prop_name, dir_path)
1268     ctx.ci(@wc_path)
1269     assert_equal({}, ctx.pg(prop_name, dir_path))
1271     ctx.up(@wc_path)
1272     ctx.ps(prop_name, prop_value, dir_path, false)
1273     ctx.ci(@wc_path)
1274     assert_equal({dir_uri => prop_value}, ctx.pg(prop_name, dir_path))
1276     assert_raises(Svn::Error::BadMimeType) do
1277       ctx.ps(Svn::Core::PROP_MIME_TYPE,
1278              invalid_mime_type_prop_value,
1279              path)
1280     end
1281     ctx.cleanup(@wc_path)
1283     assert_nothing_raised do
1284       ctx.ps(Svn::Core::PROP_MIME_TYPE,
1285              invalid_mime_type_prop_value,
1286              path, false, true)
1287     end
1288     ctx.commit(@wc_path)
1289     assert_equal({uri => invalid_mime_type_prop_value},
1290                  ctx.pg(Svn::Core::PROP_MIME_TYPE, path))
1291   end
1293   def test_prop_list
1294     log = "sample log"
1295     dir = "dir"
1296     file = "sample.txt"
1297     dir_path = File.join(@wc_path, dir)
1298     path = File.join(dir_path, file)
1299     dir_uri = "#{@repos_uri}/#{dir}"
1300     uri = "#{dir_uri}/#{file}"
1301     name1 = "name1"
1302     name2 = "name2"
1303     value1 = "value1"
1304     value2 = "value2"
1306     ctx = make_context(log)
1308     ctx.mkdir(dir_path)
1309     File.open(path, "w") {}
1310     ctx.add(path)
1312     ctx.ci(@wc_path)
1314     assert_equal([], ctx.prop_list(path))
1316     ctx.ps(name1, value1, path)
1317     ctx.ci(@wc_path)
1318     assert_equal([uri], ctx.prop_list(path).collect{|item| item.node_name})
1319     assert_equal([{name1 => value1}],
1320                  ctx.plist(path).collect{|item| item.prop_hash})
1321     assert_equal([value1], ctx.pl(path).collect{|item| item[name1]})
1323     ctx.up(@wc_path)
1324     ctx.ps(name2, value2, dir_path)
1325     ctx.ci(@wc_path)
1326     assert_equal([uri, dir_uri].sort,
1327                  ctx.prop_list(dir_path).collect{|item| item.name})
1328     prop_list = ctx.plist(dir_path).collect{|item| [item.name, item.props]}
1329     props = prop_list.assoc(uri)[1]
1330     dir_props = prop_list.assoc(dir_uri)[1]
1331     assert_equal({name1 => value1, name2 => value2}, props)
1332     assert_equal({name2 => value2}, dir_props)
1333   end
1335   def recurse_and_depth_choices
1336     [false, true, 'empty', 'files', 'immediates', 'infinity']
1337   end
1339   def test_file_prop
1340     setup_greek_tree
1342     log = "sample log"
1343     ctx = make_context(log)
1345     # when no props set, everything is empty
1346     recurse_and_depth_choices.each do |rd|
1347       assert_equal([],
1348                    ctx.prop_list(@greek.path(:mu), nil, nil, rd),
1349                    "prop_list with Depth '#{rd}'")
1350     end
1352     recurse_and_depth_choices.each do |rd|
1353       assert_equal({},
1354                    ctx.prop_get(rd.to_s, @greek.path(:mu), nil, nil, rd),
1355                    "prop_get with Depth '#{rd}'")
1356     end
1358     # set some props
1359     recurse_and_depth_choices.each do |rd|
1360       ctx.prop_set(rd.to_s, rd.to_s, @greek.path(:mu), rd)
1361     end
1362     ctx.commit(@greek.path(:mu))
1364     # get the props
1365     recurse_and_depth_choices.each do |rd|
1366       assert_equal({@greek.uri(:mu) => rd.to_s},
1367                    ctx.prop_get(rd.to_s, @greek.path(:mu), nil, nil, rd),
1368                    "prop_get with Depth '#{rd}'")
1369     end
1371     prop_hash = {}
1372     recurse_and_depth_choices.each {|rd| prop_hash[rd.to_s] = rd.to_s}
1374     # list the props
1375     recurse_and_depth_choices.each do |rd|
1376       props = ctx.prop_list(@greek.path(:mu), nil, nil, rd)
1377       assert_equal([@greek.uri(:mu)],
1378                    props.collect {|item| item.node_name},
1379                    "prop_list (node_name) with Depth '#{rd}'")
1381       props = ctx.plist(@greek.path(:mu), nil, nil, rd)
1382       assert_equal([prop_hash],
1383                    props.collect {|item| item.prop_hash},
1384                    "prop_list (prop_hash) with Depth '#{rd}'")
1386       recurse_and_depth_choices.each do |rd1|
1387         props = ctx.plist(@greek.path(:mu), nil, nil, rd)
1388         assert_equal([rd1.to_s],
1389                      props.collect {|item| item[rd1.to_s]},
1390                      "prop_list (#{rd1.to_s}]) with Depth '#{rd}'")
1391       end
1392     end
1394   end
1396   def test_dir_prop
1397     setup_greek_tree
1399     log = "sample log"
1400     ctx = make_context(log)
1402     # when no props set, everything is empty
1403     recurse_and_depth_choices.each do |rd|
1404       assert_equal([],
1405                    ctx.prop_list(@greek.path(:b), nil, nil, rd),
1406                    "prop_list with Depth '#{rd}'")
1407     end
1409     recurse_and_depth_choices.each do |rd|
1410       assert_equal({},
1411                    ctx.prop_get(rd.to_s, @greek.path(:b), nil, nil, rd),
1412                    "prop_get with Depth '#{rd}'")
1413     end
1415     # set some props with various depths
1416     recurse_and_depth_choices.each do |rd|
1417       ctx.prop_set(rd.to_s, rd.to_s, @greek.path(:b), rd)
1418     end
1419     ctx.commit(@greek.path(:b))
1421     expected_props = {
1422       true => [:beta, :b, :lambda, :e, :f, :alpha],
1423       false => [:b],
1424       'empty' => [:b],
1425       'files' => [:b, :lambda],
1426       'immediates' => [:b, :lambda, :e, :f],
1427       'infinity' => [:beta, :b, :lambda, :e, :f, :alpha],
1428     }
1430     paths = [:b, :e, :alpha, :beta, :f, :lambda]
1432     # how are the props set?
1433     recurse_and_depth_choices.each do |rd|
1434       paths.each do |path|
1435         if expected_props[rd].include?(path)
1436           expected = {@greek.uri(path) => rd.to_s}
1437         else
1438           expected = {}
1439         end
1440         assert_equal(expected,
1441                      ctx.prop_get(rd.to_s, @greek.path(path), nil, nil, false),
1442                      "prop_get #{@greek.resolve(path)} with Depth '#{rd}'")
1443       end
1444     end
1446     recurse_and_depth_choices.each do |rd_for_prop|
1447       recurse_and_depth_choices.each do |rd_for_depth|
1448         expected = {}
1449         expected_paths = expected_props[rd_for_depth]
1450         expected_paths &= expected_props[rd_for_prop]
1451         expected_paths.each do |path|
1452           expected[@greek.uri(path)] = rd_for_prop.to_s
1453         end
1455         assert_equal(expected,
1456                      ctx.prop_get(rd_for_prop.to_s, @greek.path(:b),
1457                                   nil, nil, rd_for_depth),
1458                      "prop_get '#{rd_for_prop}' with Depth '#{rd_for_depth}'")
1460       end
1461     end
1463     recurse_and_depth_choices.each do |rd|
1464       props = ctx.prop_list(@greek.path(:b), nil, nil, rd)
1465       assert_equal(expected_props[rd].collect {|path| @greek.uri(path)}.sort,
1466                    props.collect {|item| item.node_name}.sort,
1467                    "prop_list (node_name) with Depth '#{rd}'")
1468     end
1469   end
1471   def test_cat
1472     log = "sample log"
1473     src1 = "source1\n"
1474     src2 = "source2\n"
1475     file = "sample.txt"
1476     path = File.join(@wc_path, file)
1478     File.open(path, "w") {|f| f.print(src1)}
1480     ctx = make_context(log)
1481     ctx.add(path)
1482     commit_info = ctx.commit(@wc_path)
1483     rev1 = commit_info.revision
1485     assert_equal(normalize_line_break(src1), ctx.cat(path, rev1))
1486     assert_equal(normalize_line_break(src1), ctx.cat(path))
1488     File.open(path, "w") {|f| f.print(src2)}
1490     commit_info = ctx.commit(@wc_path)
1491     rev2 = commit_info.revision
1493     assert_equal(normalize_line_break(src1), ctx.cat(path, rev1))
1494     assert_equal(normalize_line_break(src2), ctx.cat(path, rev2))
1495     assert_equal(normalize_line_break(src2), ctx.cat(path))
1496   end
1498   def test_lock
1499     log = "sample log"
1500     src = "source\n"
1501     file = "sample.txt"
1502     path = File.join(@wc_path, file)
1504     File.open(path, "w") {|f| f.print(src)}
1506     ctx = make_context(log)
1507     ctx.add(path)
1508     ctx.commit(@wc_path)
1510     infos = []
1511     ctx.set_notify_func do |notify|
1512       infos << [notify.path, notify]
1513     end
1514     ctx.lock(path)
1516     assert_equal([file], infos.collect{|path, notify| path})
1517     file_notify = infos.assoc(file)[1]
1518     assert(file_notify.locked?)
1519   end
1521   def test_unlock
1522     log = "sample log"
1523     src = "source\n"
1524     file = "sample.txt"
1525     path = File.join(@wc_path, file)
1527     File.open(path, "w") {|f| f.print(src)}
1529     ctx = make_context(log)
1530     ctx.add(path)
1531     ctx.commit(@wc_path)
1533     ctx.lock(path)
1535     infos = []
1536     ctx.set_notify_func do |notify|
1537       infos << [notify.path, notify]
1538     end
1539     ctx.unlock(path)
1540     assert_equal([file], infos.collect{|path, notify| path})
1541     file_notify = infos.assoc(file)[1]
1542     assert(file_notify.unlocked?)
1543   end
1545   def test_info
1546     log = "sample log"
1547     ctx = make_context(log)
1548     repos_base = File.basename(@repos_path)
1550     infos = []
1551     ctx.info(@wc_path) do |path, info|
1552       infos << [path, info]
1553     end
1554     assert_equal([repos_base],
1555                  infos.collect{|path, info| path})
1556     top_info = infos.assoc(repos_base)[1]
1557     assert_equal(@repos_uri, top_info.url)
1558   end
1560   def test_info_with_depth
1561     setup_greek_tree
1563     log = "sample log"
1564     ctx = make_context(log)
1566     recurse_and_depth_choices.each do |rd|
1567       ctx.info(@greek.path(:mu),nil,nil,rd) do |path, info|
1568         assert_equal @greek.uri(:mu), info.URL
1569       end
1570     end
1572     expected_info_by_depth = {
1573       true => [:beta, :b, :lambda, :e, :f, :alpha],
1574       false => [:b],
1575       'empty' => [:b],
1576       'files' => [:b, :lambda],
1577       'immediates' => [:b, :lambda, :e, :f],
1578       'infinity' => [:beta, :b, :lambda, :e, :f, :alpha],
1579     }
1581     recurse_and_depth_choices.each do |rd|
1582       urls = []
1583       ctx.info(@greek.path(:b),nil,nil,rd) do |path, info|
1584         urls << info.URL
1585       end
1586       assert_equal expected_info_by_depth[rd].map{|s| @greek.uri(s)}.sort,
1587                    urls.sort,
1588                    "depth '#{rd}"
1589     end
1590   end
1592   def test_url_from_path
1593     log = "sample log"
1594     ctx = make_context(log)
1595     assert_equal(@repos_uri, ctx.url_from_path(@wc_path))
1596     assert_equal(@repos_uri, Svn::Client.url_from_path(@wc_path))
1597   end
1599   def test_uuid
1600     log = "sample log"
1601     ctx = make_context(log)
1602     Svn::Wc::AdmAccess.open(nil, @wc_path, false, 0) do |adm|
1603       assert_equal(ctx.uuid_from_url(@repos_uri),
1604                    ctx.uuid_from_path(@wc_path, adm))
1605     end
1606   end
1608   def test_open_ra_session
1609     log = "sample log"
1610     ctx = make_context(log)
1612     assert_instance_of(Svn::Ra::Session, ctx.open_ra_session(@repos_uri))
1613   end
1615   def test_revprop
1616     log = "sample log"
1617     new_log = "new sample log"
1618     src = "source\n"
1619     file = "sample.txt"
1620     path = File.join(@wc_path, file)
1622     File.open(path, "w") {|f| f.print(src)}
1624     ctx = make_context(log)
1625     ctx.add(path)
1626     info = ctx.commit(@wc_path)
1628     assert_equal([
1629                    {
1630                      Svn::Core::PROP_REVISION_AUTHOR => @author,
1631                      Svn::Core::PROP_REVISION_DATE => info.date,
1632                      Svn::Core::PROP_REVISION_LOG => log,
1633                    },
1634                    info.revision
1635                  ],
1636                  ctx.revprop_list(@repos_uri, info.revision))
1638     assert_equal([log, info.revision],
1639                  ctx.revprop_get(Svn::Core::PROP_REVISION_LOG,
1640                                  @repos_uri, info.revision))
1641     assert_equal(log,
1642                  ctx.revprop(Svn::Core::PROP_REVISION_LOG,
1643                              @repos_uri, info.revision))
1645     assert_equal(info.revision,
1646                  ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
1647                                  @repos_uri, info.revision))
1648     assert_equal([new_log, info.revision],
1649                  ctx.rpget(Svn::Core::PROP_REVISION_LOG,
1650                            @repos_uri, info.revision))
1651     assert_equal(new_log,
1652                  ctx.rp(Svn::Core::PROP_REVISION_LOG,
1653                         @repos_uri, info.revision))
1654     assert_equal([
1655                    {
1656                      Svn::Core::PROP_REVISION_AUTHOR => @author,
1657                      Svn::Core::PROP_REVISION_DATE => info.date,
1658                      Svn::Core::PROP_REVISION_LOG => new_log,
1659                    },
1660                    info.revision
1661                  ],
1662                  ctx.rplist(@repos_uri, info.revision))
1664     assert_equal(info.revision,
1665                  ctx.revprop_del(Svn::Core::PROP_REVISION_LOG,
1666                                  @repos_uri, info.revision))
1667     assert_equal([nil, info.revision],
1668                  ctx.rpg(Svn::Core::PROP_REVISION_LOG,
1669                          @repos_uri, info.revision))
1670     assert_equal(nil,
1671                  ctx.rp(Svn::Core::PROP_REVISION_LOG,
1672                         @repos_uri, info.revision))
1674     assert_equal(info.revision,
1675                  ctx.rpset(Svn::Core::PROP_REVISION_LOG, new_log,
1676                            @repos_uri, info.revision))
1677     assert_equal(new_log,
1678                  ctx.rp(Svn::Core::PROP_REVISION_LOG,
1679                         @repos_uri, info.revision))
1680     assert_equal(info.revision,
1681                  ctx.rps(Svn::Core::PROP_REVISION_LOG, nil,
1682                          @repos_uri, info.revision))
1683     assert_equal(nil,
1684                  ctx.rp(Svn::Core::PROP_REVISION_LOG,
1685                         @repos_uri, info.revision))
1687     assert_equal([
1688                    {
1689                      Svn::Core::PROP_REVISION_AUTHOR => @author,
1690                      Svn::Core::PROP_REVISION_DATE => info.date,
1691                    },
1692                    info.revision
1693                  ],
1694                  ctx.rpl(@repos_uri, info.revision))
1695   end
1697   def test_export
1698     log = "sample log"
1699     src = "source\n"
1700     file = "sample.txt"
1701     dir = "sample"
1702     dir_path = File.join(@wc_path, dir)
1703     path = File.join(dir_path, file)
1704     tmp_base_path = File.join(@tmp_path, "tmp")
1705     tmp_dir_path = File.join(tmp_base_path, dir)
1706     tmp_path = File.join(tmp_dir_path, file)
1708     ctx = make_context(log)
1710     ctx.mkdir(dir_path)
1711     File.open(path, "w") {|f| f.print(src)}
1712     ctx.add(path)
1713     rev = ctx.ci(@wc_path).revision
1715     assert_equal(rev, ctx.export(@repos_uri, tmp_base_path))
1716     assert_equal(src, File.open(tmp_path) {|f| f.read})
1717   end
1719   def test_ls
1720     log = "sample log"
1721     src = "source\n"
1722     file = "sample.txt"
1723     dir = "sample"
1724     dir_path = File.join(@wc_path, dir)
1725     path = File.join(@wc_path, file)
1727     ctx = make_context(log)
1729     ctx.mkdir(dir_path)
1730     File.open(path, "w") {|f| f.print(src)}
1731     ctx.add(path)
1732     rev = ctx.ci(@wc_path).revision
1734     dirents, locks = ctx.ls(@wc_path, rev)
1735     assert_equal([dir, file].sort, dirents.keys.sort)
1736     dir_dirent = dirents[dir]
1737     assert(dir_dirent.directory?)
1738     file_dirent = dirents[file]
1739     assert(file_dirent.file?)
1740   end
1742   def test_list
1743     log = "sample log"
1744     src = "source\n"
1745     file = "sample.txt"
1746     dir = "sample"
1747     prop_name = "sample-prop"
1748     prop_value = "sample value"
1749     dir_path = File.join(@wc_path, dir)
1750     path = File.join(@wc_path, file)
1752     ctx = make_context(log)
1754     ctx.mkdir(dir_path)
1755     File.open(path, "w") {|f| f.print(src)}
1756     ctx.add(path)
1757     ctx.prop_set(prop_name, prop_value, path)
1758     rev = ctx.ci(@wc_path).revision
1760     entries = []
1761     ctx.list(@wc_path, rev) do |path, dirent, lock, abs_path|
1762       entries << [path, dirent, lock, abs_path]
1763     end
1764     paths = entries.collect do |path, dirent, lock, abs_path|
1765       [path, abs_path]
1766     end
1767     assert_equal([["", "/"], [dir, "/"], [file, "/"]].sort, paths.sort)
1768     entries.each do |path, dirent, lock, abs_path|
1769       case path
1770       when dir, ""
1771         assert(dirent.directory?)
1772         assert_false(dirent.have_props?)
1773       when file
1774         assert(dirent.file?)
1775         assert_true(dirent.have_props?)
1776       else
1777         flunk
1778       end
1779     end
1780   end
1782   def test_list_with_depth
1783     setup_greek_tree
1785     log = "sample log"
1786     ctx = make_context(log)
1788     expected_lists_by_depth = {
1789       true => [:beta, :b, :lambda, :e, :f, :alpha],
1790       false => [:b, :lambda, :e, :f],
1791       'empty' => [:b],
1792       'files' => [:b, :lambda],
1793       'immediates' => [:b, :lambda, :e, :f],
1794       'infinity' => [:beta, :b, :lambda, :e, :f, :alpha],
1795     }
1797     recurse_and_depth_choices.each do |rd|
1798       paths = []
1799       ctx.list(@greek.path(:b), 'head' ,nil, rd) do |path, dirent, lock, abs_path|
1800         paths << (path.empty? ? abs_path : File.join(abs_path, path))
1801       end
1802       assert_equal(expected_lists_by_depth[rd].map{|s| "/#{@greek.resolve(s)}"}.sort,
1803                    paths.sort,
1804                    "depth '#{rd}")
1805     end
1806   end
1808   def test_switch
1809     log = "sample log"
1810     trunk_src = "trunk source\n"
1811     tag_src = "tag source\n"
1812     file = "sample.txt"
1813     file = "sample.txt"
1814     trunk_dir = "trunk"
1815     tag_dir = "tags"
1816     tag_name = "0.0.1"
1817     trunk_repos_uri = "#{@repos_uri}/#{trunk_dir}"
1818     tag_repos_uri = "#{@repos_uri}/#{tag_dir}/#{tag_name}"
1819     trunk_dir_path = File.join(@wc_path, trunk_dir)
1820     tag_dir_path = File.join(@wc_path, tag_dir)
1821     tag_name_dir_path = File.join(@wc_path, tag_dir, tag_name)
1822     trunk_path = File.join(trunk_dir_path, file)
1823     tag_path = File.join(tag_name_dir_path, file)
1824     path = File.join(@wc_path, file)
1826     ctx = make_context(log)
1828     ctx.mkdir(trunk_dir_path)
1829     File.open(trunk_path, "w") {|f| f.print(trunk_src)}
1830     ctx.add(trunk_path)
1831     trunk_rev = ctx.commit(@wc_path).revision
1833     ctx.mkdir(tag_dir_path, tag_name_dir_path)
1834     File.open(tag_path, "w") {|f| f.print(tag_src)}
1835     ctx.add(tag_path)
1836     tag_rev = ctx.commit(@wc_path).revision
1838     assert_equal(youngest_rev, ctx.switch(@wc_path, trunk_repos_uri))
1839     assert_equal(normalize_line_break(trunk_src), ctx.cat(path))
1841     assert_equal(youngest_rev, ctx.switch(@wc_path, tag_repos_uri))
1842     assert_equal(normalize_line_break(tag_src), ctx.cat(path))
1845     notify_info = []
1846     ctx.set_notify_func do |notify|
1847       notify_info << [notify.path, notify.action]
1848     end
1850     assert_equal(trunk_rev, ctx.switch(@wc_path, trunk_repos_uri, trunk_rev))
1851     assert_equal(normalize_line_break(trunk_src), ctx.cat(path))
1852     assert_equal([
1853                    [path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1854                    [@wc_path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1855                    [@wc_path, Svn::Wc::NOTIFY_UPDATE_COMPLETED],
1856                  ],
1857                  notify_info)
1859     notify_info.clear
1860     assert_equal(tag_rev, ctx.switch(@wc_path, tag_repos_uri, tag_rev))
1861     assert_equal(normalize_line_break(tag_src), ctx.cat(path))
1862     assert_equal([
1863                    [path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1864                    [@wc_path, Svn::Wc::NOTIFY_UPDATE_UPDATE],
1865                    [@wc_path, Svn::Wc::NOTIFY_UPDATE_COMPLETED],
1866                  ],
1867                  notify_info)
1868   end
1870   def test_authentication
1871     log = "sample log"
1872     src = "source\n"
1873     file = "sample.txt"
1874     path = File.join(@wc_path, file)
1875     svnserve_uri = "#{@repos_svnserve_uri}/#{file}"
1877     File.open(path, "w") {|f| f.print(src)}
1879     ctx = make_context(log)
1880     ctx.add(path)
1881     ctx.commit(@wc_path)
1883     ctx = Svn::Client::Context.new
1885     assert_raises(Svn::Error::AuthnNoProvider) do
1886       ctx.cat(svnserve_uri)
1887     end
1889     ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1890       cred.username = "wrong-#{@author}"
1891       cred.password = @password
1892       cred.may_save = false
1893     end
1894     assert_raises(Svn::Error::RaNotAuthorized) do
1895       ctx.cat(svnserve_uri)
1896     end
1898     ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1899       cred.username = @author
1900       cred.password = "wrong-#{@password}"
1901       cred.may_save = false
1902     end
1903     assert_raises(Svn::Error::RaNotAuthorized) do
1904       ctx.cat(svnserve_uri)
1905     end
1907     ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1908       cred.username = @author
1909       cred.password = @password
1910       cred.may_save = false
1911     end
1912     assert_equal(normalize_line_break(src), ctx.cat(svnserve_uri))
1913   end
1915   def assert_simple_provider(method)
1916     log = "sample log"
1917     src = "source\n"
1918     file = "sample.txt"
1919     path = File.join(@wc_path, file)
1920     svnserve_uri = "#{@repos_svnserve_uri}/#{file}"
1922     File.open(path, "w") {|f| f.print(src)}
1924     ctx = make_context(log)
1925     setup_auth_baton(ctx.auth_baton)
1926     ctx.add(path)
1927     ctx.commit(@wc_path)
1929     ctx = Svn::Client::Context.new
1930     setup_auth_baton(ctx.auth_baton)
1931     ctx.send(method)
1932     assert_raises(Svn::Error::RaNotAuthorized) do
1933       ctx.cat(svnserve_uri)
1934     end
1936     ctx = Svn::Client::Context.new
1937     setup_auth_baton(ctx.auth_baton)
1938     ctx.send(method)
1939     ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
1940       cred.username = @author
1941       cred.password = @password
1942     end
1943     assert_equal(normalize_line_break(src), ctx.cat(svnserve_uri))
1944   end
1946   def test_simple_provider
1947     assert_simple_provider(:add_simple_provider)
1948   end
1950   if Svn::Core.respond_to?(:auth_get_windows_simple_provider)
1951     def test_windows_simple_provider
1952       assert_simple_provider(:add_windows_simple_provider)
1953     end
1954   end
1956   if Svn::Core.respond_to?(:auth_get_keychain_simple_provider)
1957     def test_keychain_simple_provider
1958       assert_simple_provider(:add_keychain_simple_provider)
1959     end
1960   end
1962   def test_username_provider
1963     log = "sample log"
1964     new_log = "sample new log"
1965     src = "source\n"
1966     file = "sample.txt"
1967     path = File.join(@wc_path, file)
1968     repos_uri = "#{@repos_uri}/#{file}"
1970     File.open(path, "w") {|f| f.print(src)}
1972     ctx = make_context(log)
1973     ctx.add(path)
1974     info = ctx.commit(@wc_path)
1976     ctx = Svn::Client::Context.new
1977     setup_auth_baton(ctx.auth_baton)
1978     ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = @author
1979     ctx.add_username_provider
1980     assert_nothing_raised do
1981       ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
1982                       repos_uri, info.revision)
1983     end
1985     ctx = Svn::Client::Context.new
1986     setup_auth_baton(ctx.auth_baton)
1987     ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = "#{@author}-NG"
1988     ctx.add_username_provider
1989     assert_raise(Svn::Error::REPOS_HOOK_FAILURE) do
1990       ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
1991                       repos_uri, info.revision)
1992     end
1994     ctx = Svn::Client::Context.new
1995     setup_auth_baton(ctx.auth_baton)
1996     ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = nil
1997     ctx.add_username_prompt_provider(0) do |cred, realm, may_save|
1998     end
1999     assert_raise(Svn::Error::REPOS_HOOK_FAILURE) do
2000       ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
2001                       repos_uri, info.revision)
2002     end
2004     ctx = Svn::Client::Context.new
2005     setup_auth_baton(ctx.auth_baton)
2006     ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = nil
2007     ctx.add_username_prompt_provider(0) do |cred, realm, may_save|
2008       cred.username = @author
2009     end
2010     assert_nothing_raised do
2011       ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log,
2012                       repos_uri, info.revision)
2013     end
2014   end
2016   def test_add_providers
2017     ctx = Svn::Client::Context.new
2018     assert_nothing_raised do
2019       ctx.add_ssl_client_cert_file_provider
2020       ctx.add_ssl_client_cert_pw_file_provider
2021       ctx.add_ssl_server_trust_file_provider
2022       if Svn::Core.respond_to?(:auth_get_windows_ssl_server_trust_provider)
2023         ctx.add_windows_ssl_server_trust_provider
2024       end
2025     end
2026   end
2028   def test_commit_item
2029     assert_raise(NoMethodError) do
2030       Svn::Client::CommitItem.new
2031     end
2033     assert_raise(NoMethodError) do
2034       Svn::Client::CommitItem2.new
2035     end
2037     item = Svn::Client::CommitItem3.new
2038     assert_kind_of(Svn::Client::CommitItem3, item)
2040     url = "xxx"
2041     item.url = url
2042     assert_equal(url, item.dup.url)
2043   end
2045   def test_log_msg_func_commit_items
2046     log = "sample log"
2047     file = "file"
2048     file2 = "file2"
2049     src = "source"
2050     path = File.join(@wc_path, file)
2051     repos_uri2 = "#{@repos_uri}/#{file2}"
2053     File.open(path, "w") {|f| f.print(src)}
2055     ctx = make_context(log)
2056     items = nil
2057     ctx.set_log_msg_func do |items|
2058       [true, log]
2059     end
2061     ctx.add(path)
2062     ctx.prop_set(Svn::Core::PROP_MIME_TYPE, "text/plain", path)
2063     ctx.commit(@wc_path)
2064     assert_equal([[]], items.collect {|item| item.wcprop_changes})
2065     assert_equal([[]], items.collect {|item| item.incoming_prop_changes})
2066     assert_equal([nil], items.collect {|item| item.outgoing_prop_changes})
2068     items = nil
2069     ctx.cp(path, repos_uri2)
2070     assert_equal([nil], items.collect {|item| item.wcprop_changes})
2071     assert_equal([nil], items.collect {|item| item.incoming_prop_changes})
2072     assert_equal([nil], items.collect {|item| item.outgoing_prop_changes})
2073   end
2075   def test_log_msg_func_cancel
2076     log = "sample log"
2077     dir = "dir"
2078     dir_path = File.join(@wc_path, dir)
2080     ctx = make_context(log)
2081     ctx.set_log_msg_func do |items|
2082       raise Svn::Error::Cancelled
2083     end
2084     ctx.mkdir(dir_path)
2085     assert_raise(Svn::Error::Cancelled) do
2086       ctx.commit(@wc_path)
2087     end
2088   end
2090   def test_set_config
2091     log = "sample log"
2092     ctx = make_context(log)
2093     options = {
2094       "groups" => {"collabnet" => "svn.collab.net"},
2095       "collabnet" => {
2096         "http-proxy-host" => "proxy",
2097         "http-proxy-port" => "8080",
2098       },
2099     }
2100     servers_config_file = File.join(@config_path,
2101                                     Svn::Core::CONFIG_CATEGORY_SERVERS)
2102     File.open(servers_config_file, "w") do |file|
2103       options.each do |section, values|
2104         file.puts("[#{section}]")
2105         values.each do |key, value|
2106           file.puts("#{key} = #{value}")
2107         end
2108       end
2109     end
2110     config = Svn::Core::Config.config(@config_path)
2111     assert_nil(ctx.config)
2112     assert_equal(options, config[Svn::Core::CONFIG_CATEGORY_SERVERS].to_hash)
2113     ctx.config = config
2114     assert_equal(options,
2115                  ctx.config[Svn::Core::CONFIG_CATEGORY_SERVERS].to_hash)
2116   end
2118   def test_context_mimetypes_map
2119     context = Svn::Client::Context.new
2120     assert_nil(context.mimetypes_map)
2121     context.mimetypes_map = {"txt" => "text/plain"}
2122     assert_equal({"txt" => "text/plain"}, context.mimetypes_map)
2123   end
2125   def test_context_revprop_table
2126     context = Svn::Client::Context.new
2127     assert_nil(context.revprop_table)
2128     context.revprop_table = {"my-prop" => "XXX"}
2129     assert_equal({"my-prop" => "XXX"}, context.revprop_table)
2130   end
2132   def assert_changelists
2133     log = "sample log"
2134     file1 = "hello1.txt"
2135     file2 = "hello2.txt"
2136     src = "Hello"
2137     changelist1 = "XXX"
2138     changelist2 = "YYY"
2139     path1 = File.join(@wc_path, file1)
2140     path2 = File.join(@wc_path, file2)
2142     ctx = make_context(log)
2143     File.open(path1, "w") {|f| f.print(src)}
2144     File.open(path2, "w") {|f| f.print(src)}
2145     ctx.add(path1)
2146     ctx.add(path2)
2147     ctx.commit(@wc_path)
2149     assert_equal({}, yield(ctx, changelist1))
2150     assert_equal({nil=>[@wc_path,path1,path2]}, yield(ctx, nil))
2151     assert_equal({}, yield(ctx, []))
2152     assert_equal({}, yield(ctx, [changelist1]))
2153     assert_equal({}, yield(ctx, [changelist2]))
2154     ctx.add_to_changelist(changelist1, path1)
2155     assert_equal({changelist1=>[path1]}, yield(ctx, changelist1))
2156     assert_equal({changelist1=>[path1],nil=>[@wc_path,path2]}, yield(ctx, nil))
2157     assert_equal({}, yield(ctx, []))
2158     assert_equal({changelist1=>[path1]}, yield(ctx, [changelist1]))
2159     assert_equal({}, yield(ctx, [changelist2]))
2161     assert_equal({}, yield(ctx, changelist2))
2162     ctx.add_to_changelist(changelist2, [path1, path2])
2163     assert_equal({changelist2=>[path1, path2]}, yield(ctx, changelist2))
2164     assert_equal({}, yield(ctx, changelist1))
2166     ctx.add_to_changelist(changelist1, [path1, path2])
2167     assert_equal({changelist1=>[path1, path2]}, yield(ctx, changelist1))
2168     assert_equal({}, yield(ctx, changelist2))
2170     ctx.remove_from_changelists(changelist1, path1)
2171     assert_equal({changelist1=>[path2]}, yield(ctx, changelist1))
2172     ctx.remove_from_changelists(changelist1, [path2])
2173     assert_equal({}, yield(ctx, changelist1))
2175     ctx.add_to_changelist(changelist1, path1)
2176     ctx.add_to_changelist(changelist2, path2)
2177     assert_equal({changelist1=>[path1]}, yield(ctx, changelist1))
2178     assert_equal({changelist2=>[path2]}, yield(ctx, changelist2))
2180     assert_equal({changelist1=>[path1]}, yield(ctx, changelist1))
2181     assert_equal({changelist2=>[path2]}, yield(ctx, changelist2))
2182     assert_equal({changelist1=>[path1]}, yield(ctx, [changelist1]))
2183     assert_equal({changelist2=>[path2]}, yield(ctx, [changelist2]))
2184     assert_equal({changelist1=>[path1],changelist2=>[path2],nil=>[@wc_path]}, yield(ctx, nil))
2185     assert_equal({}, yield(ctx, []))
2186     assert_equal({changelist1=>[path1],changelist2=>[path2]},
2187                  yield(ctx, [changelist1,changelist2]))
2189     ctx.remove_from_changelists(nil, [path1, path2])
2190     assert_equal({}, yield(ctx, changelist1))
2191     assert_equal({}, yield(ctx, changelist2))
2192   end
2194   def test_changelists_get_without_block
2195     assert_changelists do |ctx, changelist_name|
2196       ctx.changelists(changelist_name, @wc_path)
2197     end
2198   end
2200   def test_changelists_get_with_block
2201     assert_changelists do |ctx, changelist_name|
2202       changelists = Hash.new{|h,k| h[k]=[]}
2203       ctx.changelists(changelist_name, @wc_path) do |path,cl_name|
2204         changelists[cl_name] << path
2205       end
2206       changelists
2207     end
2208   end