Fix compiler warning due to missing function prototype.
[svn.git] / subversion / bindings / swig / ruby / test / test_wc.rb
blobe936c11d2417d9e0126cbc1b4b7b2be1943cdc3d
1 require "my-assertions"
2 require "util"
4 require "svn/core"
5 require "svn/wc"
6 require "svn/repos"
7 require "svn/ra"
9 class SvnWcTest < Test::Unit::TestCase
10   include SvnTestUtil
12   def setup
13     setup_basic
14   end
16   def teardown
17     teardown_basic
18   end
20   def test_version
21     assert_equal(Svn::Core.subr_version, Svn::Wc.version)
22   end
24   def test_status
25     file1 = "a"
26     file1_path = File.join(@wc_path, file1)
28     Svn::Wc::AdmAccess.open(nil, @wc_path, false, 0) do |adm|
29       status = adm.status(file1_path)
30       assert_equal(Svn::Wc::STATUS_NONE, status.text_status)
31       assert_nil(status.entry)
32     end
34     non_exist_child_path = File.join(@wc_path, "NOT-EXIST")
35     assert_nothing_raised do
36       Svn::Wc::AdmAccess.probe_open(nil, non_exist_child_path, false, 0){}
37     end
39     FileUtils.touch(file1_path)
40     Svn::Wc::AdmAccess.open(nil, @wc_path, false, 0) do |adm|
41       status = adm.status(file1_path)
42       assert_equal(Svn::Wc::STATUS_UNVERSIONED, status.text_status)
43       assert_nil(status.entry)
44     end
46     log = "sample log"
47     ctx = make_context(log)
48     ctx.add(file1_path)
49     Svn::Wc::AdmAccess.open(nil, @wc_path, false, 0) do |adm|
50       status = adm.status(file1_path)
51       assert_equal(Svn::Wc::STATUS_ADDED, status.text_status)
52     end
54     commit_info = ctx.commit(@wc_path)
56     Svn::Wc::AdmAccess.open(nil, @wc_path, false, 0) do |adm|
57       status = adm.status(file1_path)
58       assert_equal(Svn::Wc::STATUS_NORMAL, status.text_status)
59       assert_equal(commit_info.revision, status.entry.revision)
60     end
61   end
63   def test_wc
64     assert_not_equal(0, Svn::Wc.check_wc(@wc_path))
65     assert(Svn::Wc.normal_prop?("name"))
66     assert(Svn::Wc.wc_prop?("#{Svn::Core::PROP_WC_PREFIX}name"))
67     assert(Svn::Wc.entry_prop?("#{Svn::Core::PROP_ENTRY_PREFIX}name"))
68   end
70   def test_adm_access
71     log = "sample log"
72     source = "sample source"
73     dir = "dir"
74     file = "file"
75     prop_name = "name"
76     prop_value = "value"
77     dir_path = File.join(@wc_path, dir)
78     path = File.join(dir_path, file)
79     ctx = make_context(log)
81     ctx.mkdir(dir_path)
82     File.open(path, "w") {|f| f.print(source)}
83     ctx.add(path)
84     rev = ctx.ci(@wc_path).revision
86     result = Svn::Wc::AdmAccess.open_anchor(path, true, 5)
87     anchor_access, target_access, target = result
89     assert_equal(file, target)
90     assert_equal(dir_path, anchor_access.path)
91     assert_equal(dir_path, target_access.path)
93     assert(anchor_access.locked?)
94     assert(target_access.locked?)
96     assert(!target_access.has_binary_prop?(path))
97     assert(!target_access.text_modified?(path))
98     assert(!target_access.props_modified?(path))
100     File.open(path, "w") {|f| f.print(source * 2)}
101     target_access.set_prop(prop_name, prop_value, path)
102     assert_equal(prop_value, target_access.prop(prop_name, path))
103     assert_equal({prop_name => prop_value},
104                  target_access.prop_list(path))
105     assert(target_access.text_modified?(path))
106     assert(target_access.props_modified?(path))
108     target_access.set_prop("name", nil, path)
109     assert(!target_access.props_modified?(path))
111     target_access.revert(path)
112     assert(!target_access.text_modified?(path))
113     assert(!target_access.props_modified?(path))
115     anchor_access.close
116     target_access.close
118     access = Svn::Wc::AdmAccess.probe_open(nil, path, false, 5)
119     assert(!Svn::Wc.default_ignores({}).empty?)
120     assert_equal(Svn::Wc.default_ignores({}), access.ignores({}))
121     assert(access.wc_root?(@wc_path))
123     access = Svn::Wc::AdmAccess.probe_open(nil, @wc_path, false, 5)
124     assert_equal(@wc_path, access.path)
125     assert_equal(dir_path, access.retrieve(dir_path).path)
126     assert_equal(dir_path, access.probe_retrieve(dir_path).path)
127     assert_equal(dir_path, access.probe_try(dir_path, false, 5).path)
129     Svn::Wc::AdmAccess.probe_open(nil, @wc_path, false, 5) do |access|
130       assert(!access.locked?)
131     end
133     Svn::Wc::AdmAccess.probe_open(nil, @wc_path, true, 5) do |access|
134       assert(access.locked?)
135     end
136   end
138   def test_traversal_info
139     info = Svn::Wc::TraversalInfo.new
140     assert_equal([{}, {}], info.edited_externals)
141   end
143   def assert_externals_description
144     dir = "dir"
145     url = "http://svn.example.com/trunk"
146     description = "#{dir} #{url}"
147     items = yield([@wc_path, description])
148     assert_equal([[dir, url]],
149                  items.collect {|item| [item.target_dir, item.url]})
150     assert_kind_of(Svn::Wc::ExternalItem2, items.first)
151   end
153   def test_externals_description
154     assert_externals_description do |args|
155       Svn::Wc::ExternalsDescription.parse(*args)
156     end
157   end
159   def test_externals_description_for_backward_compatibility
160     assert_externals_description do |args|
161       Svn::Wc.parse_externals_description(*args)
162     end
163   end
165   def test_notify
166     path = @wc_path
167     action = Svn::Wc::NOTIFY_SKIP
168     notify = Svn::Wc::Notify.new(path, action)
169     assert_equal(path, notify.path)
170     assert_equal(action, notify.action)
172     notify2 = notify.dup
173     assert_equal(path, notify2.path)
174     assert_equal(action, notify2.action)
175   end
177   def test_entry
178     log = "sample log"
179     source1 = "source"
180     source2 = "SOURCE"
181     source3 = "SHOYU"
182     file = "file"
183     path = File.join(@wc_path, file)
184     ctx = make_context(log)
186     File.open(path, "w") {|f| f.print(source1)}
187     ctx.add(path)
188     rev1 = ctx.ci(@wc_path).revision
190     Svn::Wc::AdmAccess.open(nil, @wc_path, false, 5) do |access|
191       show = true
192       entry = Svn::Wc::Entry.new(path, access, show)
193       assert_equal(file, entry.name)
194       assert_equal(file, entry.dup.name)
196       entries = access.read_entries
197       assert_equal(["", file].sort, entries.keys.sort)
198       entry = entries[file]
199       assert_equal(file, entry.name)
201       assert(!entry.conflicted?(@wc_path))
202     end
204     File.open(path, "w") {|f| f.print(source2)}
205     rev2 = ctx.ci(@wc_path).revision
207     ctx.up(@wc_path, rev1)
208     File.open(path, "w") {|f| f.print(source3)}
209     ctx.up(@wc_path, rev2)
211     Svn::Wc::AdmAccess.open(nil, @wc_path, true, 5) do |access|
212       entry = access.read_entries[file]
213       assert(entry.conflicted?(@wc_path))
214       assert(entry.text_conflicted?(@wc_path))
215       assert(!entry.prop_conflicted?(@wc_path))
217       access.resolved_conflict(path)
218       assert(!entry.conflicted?(@wc_path))
220       access.process_committed(@wc_path, rev2 + 1)
221     end
222   end
224   def test_committed_queue
225     log = "sample log"
226     source1 = "source"
227     source2 = "SOURCE"
228     file1 = "file1"
229     file2 = "file2"
230     path1 = File.join(@wc_path, file1)
231     path2 = File.join(@wc_path, file2)
232     ctx = make_context(log)
234     File.open(path1, "w") {|f| f.print(source1)}
235     File.open(path2, "w") {|f| f.print(source2)}
236     ctx.add(path1)
237     ctx.add(path2)
238     rev1 = ctx.ci(@wc_path).revision
239     next_rev = rev1 + 1
241     Svn::Wc::AdmAccess.open(nil, @wc_path, true, 5) do |access|
242       queue = Svn::Wc::CommittedQueue.new
243       queue.push(access, path1, true, {"my-prop" => "value"})
244       queue.process(access, next_rev)
245     end
247     Svn::Wc::AdmAccess.open(nil, @wc_path, true, 5) do |access|
248       queue = Svn::Wc::CommittedQueue.new
249       queue.push(access, path1, true, [Svn::Core::Prop.new("my-prop", "value")])
250       queue.process(access, next_rev)
251     end
252   end
254   def test_ancestry
255     file1 = "file1"
256     file2 = "file2"
257     path1 = File.join(@wc_path, file1)
258     path2 = File.join(@wc_path, file2)
259     log = "sample log"
260     ctx = make_context(log)
262     FileUtils.touch(path1)
263     ctx.add(path1)
264     rev1 = ctx.ci(@wc_path).revision
266     ctx.cp(path1, path2)
267     rev2 = ctx.ci(@wc_path).revision
269     Svn::Wc::AdmAccess.open(nil, @wc_path, false, 5) do |access|
270       assert_equal(["#{@repos_uri}/#{file2}", rev2],
271                    access.ancestry(path2))
272       result = []
273       callbacks = Proc.new do |path, entry|
274         result << [path, entry]
275       end
276       def callbacks.found_entry(path, entry)
277         call(path, entry)
278       end
279       access.walk_entries(@wc_path, callbacks)
280       assert_equal([@wc_path, path1, path2].sort,
281                    result.collect{|path, entry| path}.sort)
282       entry = result.assoc(path2)[1]
283       assert_equal(file2, entry.name)
285       callbacks = Proc.new do |path, entry|
286         raise Svn::Error::Cancelled
287       end
288       def callbacks.found_entry(path, entry)
289         call(path, entry)
290       end
291       assert_raises(Svn::Error::Cancelled) do
292         access.walk_entries(@wc_path, callbacks)
293       end
295       def callbacks.ignored_errors=(value)
296         @ignored_errors = value
297       end
298       def callbacks.handle_error(path, err)
299         @ignored_errors << [path, err] if err
300       end
301       ignored_errors = []
302       callbacks.ignored_errors = ignored_errors
303       access.walk_entries(@wc_path, callbacks)
304       assert_equal([
305                     [@wc_path, Svn::Error::Cancelled],
306                     [path1, Svn::Error::Cancelled],
307                     [path2, Svn::Error::Cancelled],
308                    ],
309                    ignored_errors.collect {|path, err| [path, err.class]})
310     end
312     Svn::Wc::AdmAccess.open(nil, @wc_path, true, 5) do |access|
313       assert_raises(Svn::Error::WcPathFound) do
314         access.mark_missing_deleted(path1)
315       end
316       FileUtils.rm(path1)
317       access.mark_missing_deleted(path1)
318       access.maybe_set_repos_root(path2, @repos_uri)
319     end
320   end
322   def test_adm_ensure
323     adm_dir = Dir.glob(File.join(@wc_path, "{.,_}svn")).first
324     assert(File.exists?(adm_dir))
325     FileUtils.rm_rf(adm_dir)
326     assert(!File.exists?(adm_dir))
327     Svn::Wc.ensure_adm(@wc_path, nil, @repos_uri, nil, 0)
328     assert(File.exists?(adm_dir))
329   end
331   def test_merge
332     left = <<-EOL
339     right = <<-EOR
346     merge_target = <<-EOM
353     expect = <<-EOE
361     left_label = "left"
362     right_label = "right"
363     merge_target_label = "merge_target"
365     left_file = "left"
366     right_file = "right"
367     merge_target_file = "merge_target"
368     left_path = File.join(@wc_path, left_file)
369     right_path = File.join(@wc_path, right_file)
370     merge_target_path = File.join(@wc_path, merge_target_file)
372     log = "sample log"
373     ctx = make_context(log)
375     File.open(left_path, "w") {|f| f.print(left)}
376     File.open(right_path, "w") {|f| f.print(right)}
377     File.open(merge_target_path, "w") {|f| f.print(merge_target)}
378     ctx.add(left_path)
379     ctx.add(right_path)
380     ctx.add(merge_target_path)
382     ctx.ci(@wc_path)
384     Svn::Wc::AdmAccess.open(nil, @wc_path, true, 5) do |access|
385       assert_equal(Svn::Wc::MERGE_MERGED,
386                    access.merge(left_path, right_path, merge_target_path,
387                                 left_label, right_label, merge_target_label))
388       assert_equal(expect, File.read(merge_target_path))
389     end
390   end
392   def test_status
393     source = "source"
394     file1 = "file1"
395     file2 = "file2"
396     file3 = "file3"
397     file4 = "file4"
398     file5 = "file5"
399     path1 = File.join(@wc_path, file1)
400     path2 = File.join(@wc_path, file2)
401     path3 = File.join(@wc_path, file3)
402     path4 = File.join(@wc_path, file4)
403     path5 = File.join(@wc_path, file5)
404     log = "sample log"
405     ctx = make_context(log)
407     File.open(path1, "w") {|f| f.print(source)}
408     ctx.add(path1)
409     rev1 = ctx.ci(@wc_path).revision
411     ctx.cp(path1, path2)
412     rev2 = ctx.ci(@wc_path).revision
414     FileUtils.rm(path1)
416     Svn::Wc::AdmAccess.open(nil, @wc_path, false, 5) do |access|
417       status = access.status(path1)
418       assert_equal(Svn::Wc::STATUS_MISSING, status.text_status)
419       assert_equal(Svn::Wc::STATUS_MISSING, status.dup.text_status)
420     end
422     ctx.revert(path1)
424     Svn::Wc::AdmAccess.open(nil, @wc_path, true, 5) do |access|
425       access.copy(path1, file3)
426       assert(File.exist?(path3))
427       access.delete(path1)
428       assert(!File.exist?(path1))
429       FileUtils.touch(path4)
430       access.add(path4)
431       assert(File.exist?(path4))
432       access.add_repos_file2(path5, path2, {})
433       assert_equal(source, File.open(path5) {|f| f.read})
435       status = access.status(path2)
436       assert_equal(Svn::Wc::STATUS_MISSING, status.text_status)
437       access.remove_from_revision_control(file2)
438       status = access.status(path2)
439       assert_equal(Svn::Wc::STATUS_NONE, status.text_status)
440     end
441   end
443   def test_delete
444     source = "source"
445     file = "file"
446     path = File.join(@wc_path, file)
447     log = "sample log"
448     ctx = make_context(log)
450     File.open(path, "w") {|f| f.print(source)}
451     ctx.add(path)
452     ctx.ci(@wc_path).revision
454     assert(File.exists?(path))
455     Svn::Wc::AdmAccess.open(nil, @wc_path, true, 5) do |access|
456       access.delete(path)
457     end
458     assert(!File.exists?(path))
460     ctx.revert(path)
462     assert(File.exists?(path))
463     Svn::Wc::AdmAccess.open(nil, @wc_path, true, 5) do |access|
464       access.delete(path, nil, nil, true)
465     end
466     assert(File.exists?(path))
467   end
469   def test_locked
470     assert(!Svn::Wc.locked?(@wc_path))
471     Svn::Wc::AdmAccess.open(nil, @wc_path, true, -1) do |access|
472       assert(Svn::Wc.locked?(@wc_path))
473     end
474     assert(!Svn::Wc.locked?(@wc_path))
475     Svn::Wc::AdmAccess.open(nil, @wc_path, false, -1) do |access|
476       assert(!Svn::Wc.locked?(@wc_path))
477     end
478     assert(!Svn::Wc.locked?(@wc_path))
479   end
481   def assert_translated_eol(method_name)
482     src_file = "src"
483     crlf_file = "crlf"
484     cr_file = "cr"
485     lf_file = "lf"
486     src_path = File.join(@wc_path, src_file)
487     crlf_path = File.join(@wc_path, crlf_file)
488     cr_path = File.join(@wc_path, cr_file)
489     lf_path = File.join(@wc_path, lf_file)
491     source = "a\n"
492     crlf_source = source.gsub(/\n/, "\r\n")
493     cr_source = source.gsub(/\n/, "\r")
494     lf_source = source.gsub(/\n/, "\n")
496     File.open(crlf_path, "w") {}
497     File.open(cr_path, "w") {}
498     File.open(lf_path, "w") {}
500     log = "log"
501     ctx = make_context(log)
502     ctx.add(crlf_path)
503     ctx.add(cr_path)
504     ctx.add(lf_path)
505     ctx.prop_set("svn:eol-style", "CRLF", crlf_path)
506     ctx.prop_set("svn:eol-style", "CR", cr_path)
507     ctx.prop_set("svn:eol-style", "LF", lf_path)
508     ctx.ci(crlf_path)
509     ctx.ci(cr_path)
510     ctx.ci(lf_path)
512     Svn::Wc::AdmAccess.open(nil, @wc_path, true, 5) do |access|
513       _wrap_assertion do
514         File.open(src_path, "wb") {|f| f.print(source)}
515         args = [method_name, src_path, crlf_path, Svn::Wc::TRANSLATE_FROM_NF]
516         result = yield(access.send(*args), source)
517         result ||= File.open(src_path, "rb") {|f| f.read}
518         assert_equal(crlf_source, result)
520         File.open(src_path, "wb") {|f| f.print(source)}
521         args = [method_name, src_path, cr_path, Svn::Wc::TRANSLATE_FROM_NF]
522         result = yield(access.send(*args), source)
523         result ||= File.open(src_path, "rb") {|f| f.read}
524         assert_equal(cr_source, result)
526         File.open(src_path, "wb") {|f| f.print(source)}
527         args = [method_name, src_path, lf_path, Svn::Wc::TRANSLATE_FROM_NF]
528         result = yield(access.send(*args), source)
529         result ||= File.open(src_path, "rb") {|f| f.read}
530         assert_equal(lf_source, result)
531       end
532     end
533   end
535   def test_translated_file_eol
536     assert_translated_eol(:translated_file) do |name, source|
537       File.open(name, "rb") {|f| f.read}
538     end
539   end
541   def test_translated_file2_eol
542     assert_translated_eol(:translated_file2) do |file, source|
543       file.read
544     end
545   end
547   def test_translated_stream_eol
548     assert_translated_eol(:translated_stream) do |stream, source|
549       if source
550         stream.write(source)
551         stream.close
552         nil
553       else
554         stream.read
555       end
556     end
557   end
559   def assert_translated_keyword(method_name)
560     src_file = "$Revision$"
561     revision_file = "revision_file"
562     src_path = File.join(@wc_path, src_file)
563     revision_path = File.join(@wc_path, revision_file)
565     source = "$Revision$\n"
566     revision_source = source.gsub(/\$Revision\$/, "$Revision: 1 $")
568     File.open(revision_path, "w") {}
570     log = "log"
571     ctx = make_context(log)
572     ctx.add(revision_path)
573     ctx.prop_set("svn:keywords", "Revision", revision_path)
574     ctx.ci(revision_path)
576     Svn::Wc::AdmAccess.open(nil, @wc_path, true, 5) do |access|
577       File.open(src_path, "wb") {|f| f.print(source)}
578       args = [method_name, src_path, revision_path, Svn::Wc::TRANSLATE_FROM_NF]
579       result = yield(access.send(*args), source)
580       result ||= File.open(src_path, "rb") {|f| f.read}
581       assert_equal(revision_source, result)
583       File.open(src_path, "wb") {|f| f.print(source)}
584       args = [method_name, src_path, revision_path, Svn::Wc::TRANSLATE_TO_NF]
585       assert_equal(source, yield(access.send(*args)))
586     end
587   end
589   def test_translated_file_keyword
590     assert_translated_keyword(:translated_file) do |name, source|
591       File.open(name, "rb") {|f| f.read}
592     end
593   end
595   def test_translated_file2_keyword
596     assert_translated_keyword(:translated_file2) do |file, source|
597       file.read
598     end
599   end
601   def test_translated_stream_keyword
602     assert_translated_keyword(:translated_stream) do |stream, source|
603       if source
604         stream.write(source)
605         stream.close
606         nil
607       else
608         stream.read
609       end
610     end
611   end
613   def test_revision_status
614     log = "log"
615     file = "file"
616     path = File.join(@wc_path, file)
618     File.open(path, "w") {|f| f.print("a")}
619     ctx = make_context(log)
620     ctx.add(path)
621     ctx.ci(path)
623     File.open(path, "w") {|f| f.print("b")}
624     ctx.ci(path)
626     File.open(path, "w") {|f| f.print("c")}
627     rev = ctx.ci(path).revision
629     status = Svn::Wc::RevisionStatus.new(path, nil, true)
630     assert_equal(rev, status.min_rev)
631     assert_equal(rev, status.max_rev)
632   end
634   def test_external_item_new
635     assert_raises(NoMethodError) do
636       Svn::Wc::ExternalItem.new
637     end
639     item = Svn::Wc::ExternalItem2.new
640     assert_kind_of(Svn::Wc::ExternalItem2, item)
641   end
643   def test_external_item_dup
644     item = Svn::Wc::ExternalItem2.new
645     assert_kind_of(Svn::Wc::ExternalItem2, item)
647     item.target_dir = "xxx"
648     duped_item = item.dup
649     assert_equal(item.target_dir, duped_item.target_dir)
650   end
652   def test_committed_queue_new
653     queue = Svn::Wc::CommittedQueue.new
654     assert_kind_of(Svn::Wc::CommittedQueue, queue)
655   end
657   def assert_diff_callbacks(method_name)
658     log = "sample log"
659     file1 = "hello.txt"
660     file2 = "hello2.txt"
661     src = "Hello"
662     dir = "dir"
663     dir_path = File.join(@wc_path, dir)
664     path1 = File.join(dir_path, file1)
665     path2 = File.join(dir_path, file2)
666     prop_name = "my-prop"
667     prop_value = "value"
669     ctx = make_context(log)
670     config = {}
671     callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
672     session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
674     FileUtils.mkdir(dir_path)
675     File.open(path1, "w") {|f| f.print(src)}
676     ctx.add(dir_path)
677     rev1 = ctx.commit(@wc_path).revision
679     File.open(path1, "w") {|f| f.print(src * 2)}
680     File.open(path2, "w") {|f| f.print(src)}
681     ctx.add(path2)
682     ctx.prop_set(prop_name, prop_value, path1)
684     Svn::Wc::AdmAccess.open(nil, @wc_path, true, 5) do |adm|
685       callbacks = Object.new
686       def callbacks.result
687         @result
688       end
689       def callbacks.result=(result)
690         @result = result
691       end
692       def callbacks.file_added(access, path, tmpfile1, tmpfile2, rev1,
693                                rev2, mimetype1, mimetype2,
694                                prop_changes, original_props)
695         @result << [:file_added, path, prop_changes]
696         [Svn::Wc::NOTIFY_STATE_UNCHANGED, Svn::Wc::NOTIFY_STATE_UNCHANGED]
697       end
698       def callbacks.file_changed(access, path, tmpfile1, tmpfile2, rev1,
699                                  rev2, mimetype1, mimetype2,
700                                  prop_changes, original_props)
701         @result << [:file_changed, path, prop_changes]
702         [Svn::Wc::NOTIFY_STATE_UNCHANGED, Svn::Wc::NOTIFY_STATE_UNCHANGED]
703       end
704       def callbacks.dir_props_changed(access, path, prop_changes, original_props)
705         @result << [:dir_props_changed, path, prop_changes]
706         Svn::Wc::NOTIFY_STATE_UNCHANGED
707       end
708       callbacks.result = []
709       editor = adm.__send__(method_name, dir, callbacks)
710       reporter = session.diff(rev1, "", @repos_uri, editor)
711       adm.crawl_revisions(dir_path, reporter)
713       args = {
714         :dir_changed_prop_names => [
715                                     "svn:entry:committed-date",
716                                     "svn:entry:uuid",
717                                     "svn:entry:last-author",
718                                     "svn:entry:committed-rev"
719                                    ],
720         :file_changed_prop_name => prop_name,
721         :file_changed_prop_value => prop_value,
722       }
723       dir_changed_props, file_changed_props, empty_changed_props = yield(args)
724       assert_equal([
725                     [:dir_props_changed, @wc_path, dir_changed_props],
726                     [:file_changed, path1, file_changed_props],
727                     [:file_added, path2, empty_changed_props],
728                    ],
729                    callbacks.result)
730     end
731   end
733   def test_diff_callbacks_for_backward_compatibility
734     assert_diff_callbacks(:diff_editor) do |args|
735       dir_changed_props = args[:dir_changed_prop_names].collect do |name|
736         Svn::Core::Prop.new(name, nil)
737       end
738       prop_name = args[:file_changed_prop_name]
739       prop_value = args[:file_changed_prop_value]
740       file_changed_props = [Svn::Core::Prop.new(prop_name, prop_value)]
741       empty_changed_props = []
742       [dir_changed_props, file_changed_props, empty_changed_props]
743     end
744   end
746   def test_diff_callbacks
747     assert_diff_callbacks(:diff_editor2) do |args|
748       dir_changed_props = {}
749       args[:dir_changed_prop_names].each do |name|
750         dir_changed_props[name] = nil
751       end
752       prop_name = args[:file_changed_prop_name]
753       prop_value = args[:file_changed_prop_value]
754       file_changed_props = {prop_name => prop_value}
755       empty_changed_props = {}
756       [dir_changed_props, file_changed_props, empty_changed_props]
757     end
758   end
760   def test_update_editor
761     log = "sample log"
762     file1 = "hello.txt"
763     file2 = "hello2.txt"
764     src = "Hello"
765     dir = "dir"
766     dir_path = File.join(@wc_path, dir)
767     path1 = File.join(dir_path, file1)
768     path2 = File.join(dir_path, file2)
770     ctx = make_context(log)
771     config = {}
772     callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
773     session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
775     FileUtils.mkdir(dir_path)
776     File.open(path1, "w") {|f| f.print(src)}
777     ctx.add(dir_path)
778     rev1 = ctx.commit(@wc_path).revision
780     File.open(path1, "w") {|f| f.print(src * 2)}
781     File.open(path2, "w") {|f| f.print(src)}
782     ctx.add(path2)
783     rev2 = ctx.commit(@wc_path).revision
785     assert(File.exists?(path2))
786     assert_equal(0, ctx.up(@wc_path, 0))
787     assert(!File.exists?(path2))
788     Svn::Wc::AdmAccess.open(nil, @wc_path) do |access|
789       editor = access.update_editor(@wc_path, 0)
790       assert_equal(0, editor.target_revision)
792       reporter = session.update2(rev2, "", editor)
793       access.crawl_revisions(@wc_path, reporter)
794       assert_equal(rev2, editor.target_revision)
795     end
796   end
798   def test_update_editor_options
799     log = "sample log"
800     file1 = "hello.txt"
801     file2 = "hello2.txt"
802     src = "Hello"
803     dir = "dir"
804     dir_path = File.join(@wc_path, dir)
805     path1 = File.join(dir_path, file1)
806     path2 = File.join(dir_path, file2)
808     ctx = make_context(log)
809     config = {}
810     callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
811     session = Svn::Ra::Session.open(@repos_uri)
813     FileUtils.mkdir(dir_path)
814     File.open(path1, "w") {|f| f.print(src)}
815     ctx.add(dir_path)
816     rev1 = ctx.commit(@wc_path).revision
818     File.open(path1, "w") {|f| f.print(src * 2)}
819     File.open(path2, "w") {|f| f.print(src)}
820     ctx.add(path2)
821     rev2 = ctx.commit(@wc_path).revision
823     assert(File.exists?(path2))
824     assert_equal(0, ctx.up(@wc_path, 0))
825     assert(!File.exists?(path2))
826     notification_count = 0
827     Svn::Wc::AdmAccess.open(nil, @wc_path) do |access|
828       notify_func = Proc.new {|n| notification_count += 1}
829       assert_raises(ArgumentError) do
830         access.update_editor2(:target_revision => 0,
831                               :target => @wc_path,
832                               :notify_fun => notify_func)
833       end
834       editor = access.update_editor(@wc_path, 0, true, nil, false, nil,
835                                     notify_func)
836       assert_equal(0, editor.target_revision)
838       reporter = session.update2(rev2, "", editor)
839       access.crawl_revisions(@wc_path, reporter)
840       assert_equal(rev2, editor.target_revision)
841     end
842     assert_equal(4, notification_count, "wrong number of notifications")
843   end
845   def test_update_editor2_conflict_func
846     log = "sample log"
847     source1 = "source"
848     source2 = "SOURCE"
849     source3 = "SHOYU"
850     file = "file"
851     path = File.join(@wc_path, file)
852     ctx = make_context(log)
854     File.open(path, "w") {|f| f.print(source1)}
855     ctx.add(path)
856     rev1 = ctx.ci(@wc_path).revision
858     File.open(path, "w") {|f| f.print(source2)}
859     rev2 = ctx.ci(@wc_path).revision
861     ctx.up(@wc_path, rev1)
862     File.open(path, "w") {|f| f.print(source3)}
864     session = Svn::Ra::Session.open(@repos_uri)
866     conflicted_paths = {}
868     Svn::Wc::AdmAccess.open(nil, @wc_path) do |access|
869       editor = access.update_editor2(
870           :target => @wc_path,
871           :conflict_func => lambda{|n|
872             conflicted_paths[n.path]=true
873             Svn::Wc::CONFLICT_CHOOSE_MERGED
874           },
875           :target_revision => 0
876       )
878       assert_equal(0, editor.target_revision)
880       reporter = session.update2(rev2, "", editor)
881       access.crawl_revisions(@wc_path, reporter)
882       assert_equal(rev2, editor.target_revision)
883     end
885     assert_equal([path], conflicted_paths.keys);
886   end
888   def test_switch_editor
889     log = "sample log"
890     file1 = "hello.txt"
891     file2 = "hello2.txt"
892     src = "Hello"
893     dir1 = "dir1"
894     dir2 = "dir2"
895     dir1_path = File.join(@wc_path, dir1)
896     dir2_path = File.join(@wc_path, dir2)
897     dir1_uri = "#{@repos_uri}/#{dir1}"
898     dir2_uri = "#{@repos_uri}/#{dir2}"
899     path1 = File.join(dir1_path, file1)
900     path2 = File.join(dir2_path, file2)
902     ctx = make_context(log)
903     config = {}
904     callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
905     session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
907     FileUtils.mkdir(dir1_path)
908     File.open(path1, "w") {|f| f.print(src)}
909     ctx.add(dir1_path)
910     rev1 = ctx.commit(@wc_path).revision
912     FileUtils.mkdir(dir2_path)
913     File.open(path2, "w") {|f| f.print(src)}
914     ctx.add(dir2_path)
915     rev2 = ctx.commit(@wc_path).revision
917     assert(File.exists?(path1))
918     assert_equal(rev2, ctx.switch(@wc_path, dir2_uri))
919     assert(File.exists?(File.join(@wc_path, file2)))
920     Svn::Wc::AdmAccess.open_anchor(@wc_path) do |access, dir_access, target|
921       editor = dir_access.switch_editor(@wc_path, dir1_uri, rev2)
922       assert_equal(rev2, editor.target_revision)
924       reporter = session.switch2(rev1, dir1, dir1_uri, editor)
925       dir_access.crawl_revisions(@wc_path, reporter)
926       assert_equal(rev1, editor.target_revision)
927     end
928   end
930   def test_relocate
931     log = "sample log"
932     file1 = "hello.txt"
933     file2 = "hello2.txt"
934     src = "Hello"
935     dir1 = "dir1"
936     dir2 = "dir2"
937     dir1_path = File.join(@wc_path, dir1)
938     dir2_path = File.join(@wc_path, dir2)
939     dir1_uri = "#{@repos_uri}/#{dir1}"
940     dir2_uri = "#{@repos_uri}/#{dir2}"
941     path1 = File.join(dir1_path, file1)
942     path2 = File.join(dir2_path, file2)
944     ctx = make_context(log)
945     config = {}
946     callbacks = Svn::Ra::Callbacks.new(ctx.auth_baton)
947     session = Svn::Ra::Session.open(@repos_uri, config, callbacks)
949     FileUtils.mkdir(dir1_path)
950     File.open(path1, "w") {|f| f.print(src)}
951     ctx.add(dir1_path)
952     rev1 = ctx.commit(@wc_path).revision
954     FileUtils.mkdir(dir2_path)
955     File.open(path2, "w") {|f| f.print(src)}
956     ctx.add(dir2_path)
957     rev2 = ctx.commit(@wc_path).revision
959     Svn::Wc::AdmAccess.probe_open(nil, @wc_path) do |access|
960       assert(@repos_uri, access.entry(@wc_path).url)
961       values = []
962       access.relocate(@wc_path, @repos_uri, dir2_uri) do |uuid, url, root_url|
963         values << [uuid, url, root_url]
964       end
965       assert_equal([
966                     [@fs.uuid, dir2_uri, nil],
967                     [@fs.uuid, dir2_uri, dir2_uri],
968                     [nil, "#{dir2_uri}/#{dir1}", dir2_uri],
969                     [nil, "#{dir2_uri}/#{dir1}/#{file1}", dir2_uri],
970                     [nil, "#{dir2_uri}/#{dir2}", dir2_uri],
971                     [nil, "#{dir2_uri}/#{dir2}/#{file2}", dir2_uri],
972                    ],
973                    values)
974       assert(dir2_uri, access.entry(@wc_path).url)
975     end
976   end
978   def test_ignore?
979     assert(!Svn::Wc.ignore?("xxx.c", []))
980     assert(Svn::Wc.ignore?("xxx.c", ["*.c"]))
981     assert(!Svn::Wc.ignore?("xxx.c", ["XXX.c"]))
982     assert(Svn::Wc.ignore?("xxx.c", ["xxx.c"]))
983     assert(!Svn::Wc.ignore?("xxx.c", ["*.H", "*.C"]))
984     assert(Svn::Wc.ignore?("xxx.C", ["*.H", "*.C"]))
985   end
987   def test_changelist
988     log = "sample log"
989     file = "hello.txt"
990     src = "Hello"
991     path = File.join(@wc_path, file)
993     ctx = make_context(log)
994     File.open(path, "w") {|f| f.print(src)}
995     ctx.add(path)
996     rev1 = ctx.commit(@wc_path).revision
998     Svn::Wc::AdmAccess.open(nil, @wc_path) do |access|
999       assert_nil(access.entry(@wc_path).changelist)
1000     end
1002     notifies = []
1003     notify_collector = Proc.new {|notify| notifies << notify }
1004     Svn::Wc::AdmAccess.open(nil, @wc_path) do |access|
1005       access.set_changelist(path, "123", nil, notify_collector)
1006     end
1007     assert_equal([[path, nil]],
1008                  notifies.collect {|notify| [notify.path, notify.err]})
1010     notifies = []
1011     Svn::Wc::AdmAccess.open(nil, @wc_path) do |access|
1012       access.set_changelist(path, "456", nil, notify_collector)
1013     end
1014     assert_equal([[path, Svn::Error::WcChangelistMove],
1015                   [path, NilClass]],
1016                  notifies.collect {|notify| [notify.path, notify.err.class]})
1018     notifies = []
1020     assert_raises(Svn::Error::ClientIsDirectory) do
1021       Svn::Wc::AdmAccess.open(nil, @wc_path) do |access|
1022         access.set_changelist(@wc_path, "789", nil, notify_collector)
1023       end
1024     end
1025   end