2006-02-27 Gabor Kelemen <kelemeng@gnome.hu>
[beagle.git] / bludgeon / TestMove.cs
blob96c93be2843ae92c006a2ec6878eca5a91d5077c
2 using System;
3 using System.IO;
5 namespace Bludgeon {
7 public abstract class Move_Tour : IHammer {
9 abstract protected FileModel PickTarget ();
11 public void HammerOnce ()
13 FileModel tourist;
14 tourist = PickTarget ();
16 Log.Spew ("Touring {0} {1}",
17 tourist.Type, tourist.ShortName);
19 int count = 10;
20 while (count > 0) {
22 FileModel new_parent;
23 new_parent = FileModel.PickAnyDirectory ();
25 string new_name;
26 new_name = Token.GetRandom ();
28 if (tourist.MoveTo (new_parent, new_name)) {
29 Log.Spew ("{0}: Toured to {1}", count, tourist.ShortName);
30 --count;
36 [Hammer (Name="Move:TourFile")]
37 public class Move_TourFile : Move_Tour {
39 override protected FileModel PickTarget ()
41 return FileModel.PickFile ();
45 [Hammer (Name="Move:TourDirectory")]
46 public class Move_TourDirectory : Move_Tour {
48 override protected FileModel PickTarget ()
50 return FileModel.PickNonRootDirectory ();
54 /////////////////////////////////////////////////////////////////////
56 public abstract class Move_ShortLived : IHammer {
58 abstract protected FileModel Create ();
60 public void HammerOnce ()
62 FileModel short_lived;
63 short_lived = Create ();
64 Log.Spew ("Created {0} {1}", short_lived.Type, short_lived.ShortName);
66 int count = 10;
67 // tour the file
68 while (count > 0) {
69 FileModel new_parent;
70 new_parent = FileModel.PickAnyDirectory ();
72 string new_name;
73 new_name = Token.GetRandom ();
75 if (short_lived.MoveTo (new_parent, new_name)) {
76 Log.Spew ("Moved to {0}", short_lived.ShortName);
77 --count;
81 short_lived.Delete ();
82 Log.Spew ("Deleted {0}", short_lived.ShortName);
86 [Hammer (Name="Move:ShortLivedFile")]
87 public class Move_ShortLivedFile : Move_ShortLived {
89 override protected FileModel Create ()
91 FileModel parent, child;
92 do {
93 parent = FileModel.PickAnyDirectory ();
94 child = parent.NewFile ();
95 } while (child == null);
96 return child;
100 [Hammer (Name="Move:ShortLivedDirectory")]
101 public class Move_ShortLivedDirectory : Move_ShortLived {
103 override protected FileModel Create ()
105 FileModel parent, child;
106 do {
107 parent = FileModel.PickAnyDirectory ();
108 child = parent.NewDirectory ();
109 } while (child == null);
110 return child;