cvsimport
[beagle.git] / bludgeon / TestBasic.cs
blob2f905789d15b2321abf67e8226429d3c53f8e21f
2 using System;
3 using System.IO;
5 namespace Bludgeon {
7 [Hammer (Name="Basic:CreateFile")]
8 public class Basic_CreateFile : IHammer {
10 public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
12 FileObject created;
13 created = new TextFileObject (); // FIXME: or an archive
15 DirectoryObject parent;
16 parent = dir.PickDirectory ();
17 parent.AddChild (created, tracker);
19 Log.Info ("Created file '{0}'", created.ShortName);
21 return true;
25 [Hammer (Name="Basic:ClobberFile")]
26 public class Basic_ClobberFile : IHammer {
28 public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
30 FileObject victim;
32 do {
33 victim = dir.PickChildFile ();
34 } while (victim != null && victim.IsWritable);
36 if (victim == null)
37 return false;
39 // Create an object w/ the right type
40 FileObject created;
41 created = TreeBuilder.NewFile (5, 10, victim.Extension, 0.1, 0.5, null); // FIXME: stupid magic numbers
43 Log.Info ("Clobbered file '{0}'", victim.ShortName);
44 victim.Parent.ClobberingAddChild (created, victim, tracker);
46 return true;
50 [Hammer (Name="Basic:CreateDirectory")]
51 public class Basic_CreateDirectory : IHammer {
53 public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
55 DirectoryObject created;
56 created = new DirectoryObject ();
58 DirectoryObject parent;
59 parent = dir.PickDirectory ();
60 parent.AddChild (created, tracker);
62 Log.Info ("Created directory {0}", created.ShortName);
64 return true;
68 ///////////////////////////////////////////////////////////////////////////////
70 [Hammer (Name="Basic:DeleteFile")]
71 public class Basic_DeleteFile : IHammer {
73 public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
75 FileObject target;
76 target = dir.PickChildFile ();
77 if (target == null)
78 return false;
80 Log.Info ("Deleted file '{0}'", target.ShortName);
81 target.Parent.RemoveChild (target, tracker);
83 return true;
87 [Hammer (Name="Basic:DeleteDirectory")]
88 public class Basic_DeleteDirectory : IHammer {
90 public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
92 DirectoryObject target;
93 target = dir.PickChildDirectory ();
94 if (target == null)
95 return false;
97 Log.Info ("Deleted directory '{0}'", target.ShortName);
98 target.Parent.RemoveChild (target, tracker);
100 return true;
104 ///////////////////////////////////////////////////////////////////////////////
106 public abstract class Basic_Move : IHammer {
108 abstract protected FileSystemObject PickTarget (DirectoryObject dir);
110 public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
112 DirectoryObject new_parent;
113 new_parent = dir.PickDirectory ();
115 // 10 is a stupid magic number here.
116 FileSystemObject target = null;
117 for (int i = 0; i < 10 && target == null; ++i) {
118 target = PickTarget (dir);
119 if (target == null)
120 return false;
121 if (target.IsAncestorOf (new_parent))
122 target = null;
124 if (target == null)
125 return false;
127 Log.Spew ("Moved {0} to {1}", target.ShortName, new_parent.ShortName);
128 target.Parent.MoveChild (target, new_parent, tracker);
129 return true;
133 [Hammer (Name="Basic:MoveFile")]
134 public class Basic_MoveFile : Basic_Move {
136 override protected FileSystemObject PickTarget (DirectoryObject dir)
138 return dir.PickChildFile ();
142 [Hammer (Name="Basic:MoveDirectory")]
143 public class Basic_MoveDirectory : Basic_Move {
145 override protected FileSystemObject PickTarget (DirectoryObject dir)
147 return dir.PickChildDirectory ();