indexing
	cluster:	"test_fsor"
	namespace:"candidate"
	pattern: "strategy"
	description: "Test strategy for  in the fso cluster."
	original_author: "Justin Finnerty"
	original_date: "August 2005"
	current_date: "$Date: 2005/09/05 02:35:01 $"
	current_author: "$Author: finnerty $"
	revision: "$Revision: 2.2 $"
   --  $Log: test_fso.ge,v $
   --  Revision 2.2  2005/09/05 02:35:01  finnerty
   --  Updated to conform to cursors/containers in the GOBO library and
   --  test programs compile with SE and VE.
   --
   --  Revision 2.1  2005/09/02 08:09:12  finnerty
   --  Renamed *.e to *.ge for gepp
   --
   --  Revision 2.0  2005/08/26 23:30:22  finnerty
   --  == alpha version ==
   --
   --  Revision 1.5  2005/08/12 06:56:25  finnerty
   --  Changes made to use the new factories for FSO_PROPERTIES.
   --
   --  Revision 1.4  2005/08/10 02:22:46  finnerty
   --  Provided exercise of both POSIX... and EIFFEL... variants of FSO_PROPERTIES
   --
   --  Revision 1.3  2005/08/09 13:48:51  finnerty
   --  Alpha of test class
   --
   --  Revision 1.2  2005/08/08 12:04:21  finnerty
   --  Added exercise method for UNIX_FSO_PROP.
   --
   --  Revision 1.1  2005/08/07 02:17:19  finnerty
   --  Unit test for FSO cluster
   --
class TEST_FSO
	-- Test classes in the fso cluster..

#ifdef SE
insert
#else
inherit
#endif
	UNIT_TEST
	ARGUMENTS
	KL_SHARED_STANDARD_FILES

creation {ANY}
	main

feature {}
	-- Test method
	main is
			-- Method to create stand-alone program to test classes in 
			-- FSO cluster

		local
			l_fso_prop: FSO_PROPERTIES
			l_factory: FACTORY_FOR_FSO
			l_fso: FILE_SYSTEM_OBJECT
#ifdef SE
			-- l_strategy: TEST_STRATEGY
#else
			l_strategy: TEST_STRATEGY
#endif
			l_index: INTEGER
			l_prop_factory: FACTORY_ARG[STRING,FSO_PROPERTIES]
		do
			-- Create a FSO_PROPERTIES object and report attributes
			!POSIX_FSO_PROP!l_prop_factory.make
			l_fso_prop := l_prop_factory.new ("test_fso.e")
			print_properties ("Using POSIX_FSO_PROP", "test_fso.e", l_fso_prop)
			
			-- Create a TEST_FSO object and use it to virtualise 
			-- directories specified on the command line or the "/etc" 
			-- directory. This implementation will change as the class 
			-- is developed.
			
			!!l_factory
#ifdef SE
			l_factory.set_strategy (agent notice)
#else
			!!l_strategy
			l_factory.set_strategy (l_strategy)
#endif
			from
				l_index := 1
			variant
				argument_count - l_index + 1
			until
				l_index > argument_count
			loop
				-- (Re)initialise the object
				std.output.put_string("--- DIRECTORY = ")
				std.output.put_string(argument(l_index))
				std.output.put_new_line
				-- and process
				l_fso := l_factory.virtualise_file_system(argument(l_index))
				print_tree(l_fso, "ENTIRE TREE")
				-- increment index
				l_index := l_index + 1
			end
			-- if no argumets look at /etc
			if argument_count < 1 then
				-- Initialise the object
				std.output.put_string("--- DIRECTORY = ")
				std.output.put_string(".")
				std.output.put_new_line
				-- and process
				l_fso := l_factory.virtualise_file_system(".")
				print_tree(l_fso, "--- ENTIRE TREE")
			end
		end

feature {NONE}
	-- FSO specific procedures
	frozen print_properties(a_title, a_path: STRING; a_fso_prop: FSO_PROPERTIES) is
			-- Print attributes
		do
			if a_fso_prop.exists then
				if a_title /= Void and not a_title.is_empty then
					std.output.put_string (a_title)
					std.output.put_new_line
				end
				std.output.put_string ("Stated file `")
				std.output.put_string (a_path)
				std.output.put_string ("'")
				std.output.put_new_line
				print_int("File size is: ", a_fso_prop.size)
				print_bool("Unknown type?: ", a_fso_prop.is_other)
				print_bool("Block device?: ", a_fso_prop.is_block_device)
				print_bool("Character device?: ", a_fso_prop.is_character_device)
				print_bool("Directory?: ", a_fso_prop.is_directory)
				print_bool("File?: ", a_fso_prop.is_file)
				print_bool("Pipe?: ", a_fso_prop.is_pipe)
				print_bool("Socket?: ", a_fso_prop.is_socket)
				print_bool("Symlink?: ", a_fso_prop.is_symlink)
				print_string("Access time is: ", a_fso_prop.time_access.out)
				print_string("Modification time is: ", a_fso_prop.time_modification.out)
				print_string("Change time is: ", a_fso_prop.time_change.out)
			end
		end

	frozen print_tree(a_node: FILE_SYSTEM_OBJECT; a_title: STRING) is
			-- Pretty print our tree with the give title. The title may 
			-- be void or empty. This only produces output in `debug' 
			-- mode.
		require
			a_node /= Void
		local
			l_tree_cursor: BILINEAR_CURSOR[FILE_SYSTEM_OBJECT]
			l_index: INTEGER
		do
			std.output.put_string(" --  ")
			if a_title /= Void and then not a_title.is_empty then
				std.output.put_string(a_title)
				std.output.put_string(": ")
			end
			std.output.put_string(a_node.path)
			std.output.put_new_line
			from
				l_tree_cursor := a_node.new_cursor
				l_index := 0
			until
				l_tree_cursor.off
			loop
				-- Print name
				print_entry (l_tree_cursor.item, l_tree_cursor.item.ancestor(a_node))
				-- Step cursor
				l_tree_cursor.forth
				l_index := l_index + 1
			end
			std.output.put_string("Total number of children is : ")
			std.output.put_integer(l_index)
			std.output.put_new_line
		end

	frozen print_entry(a_node: FILE_SYSTEM_OBJECT; a_depth: INTEGER) is
			-- Print a single entry. This only produces output in debug mode
		require
			a_node /= Void
			a_depth >= 0
		local
			l_index: INTEGER
		do
			from
				l_index := 0
			variant
				a_depth - l_index
			until
				l_index >= a_depth
			loop
				std.output.put_string(" | ")
				l_index := 1 + l_index
			end
			std.output.put_string(" |- ")
			std.output.put_string(a_node.name)
			std.output.put_new_line
		end

feature {NONE}
	-- General implementation procedures
	Width: INTEGER is 22

	frozen print_right(a_title: STRING; a_num: INTEGER) is
		local
			l_width: INTEGER
		do
			l_width := a_num - a_title.count
			if l_width > 0 then
				from
				variant
					l_width
				until
					l_width <= 0
				loop
					std.output.put_character (' ')
					l_width := l_width - 1
				end
			end
			std.output.put_string (a_title)
		end

	frozen print_int(a_title: STRING; a_num: INTEGER) is
		do
			print_right(a_title, Width)
			std.output.put_integer (a_num)
			std.output.put_new_line
		end

	frozen print_string(a_title, a_str: STRING;) is
		do
			print_right(a_title, Width)
			std.output.put_string (a_str)
			std.output.put_new_line
		end

	frozen print_bool(a_title: STRING; a_bit: BOOLEAN) is
		do
			print_right(a_title, Width)
			std.output.put_boolean (a_bit)
			std.output.put_new_line
		end

	notice (a_fso: FILE_SYSTEM_OBJECT) is
			-- overridden call to print some useful information
		do
			std.output.put_string(" |- Looking at: ")
			std.output.put_string(a_fso.name)
			std.output.put_character('%N')
		end

	
	--frozen print_dictionary(a_namesake_set: DICTIONARY[COLLECTION[FILE_SYSTEM_OBJECT],STRING]) is
		--	-- Pretty print the contents of the dictionary
		--require
		--	Ensure_dictionary: a_namesake_set /= Void
		--	Ensure_directory: not a_namesake_set.is_empty
		--local
		--	l_index: INTEGER
		--do
		--	std.output.put_string("---------------------------------------%N")
		--	std.output.put_string("Filename dictionary has [")
		--	std.output.put_integer(a_namesake_set.count)
		--	std.output.put_string("] entries%N")
		--	std.output.put_string("---------------------------------------%N")
		--	from
		--		l_index := a_namesake_set.lower
		--	variant
		--		a_namesake_set.count - l_index
		--	until
		--		l_index > a_namesake_set.upper
		--	loop
		--		-- Output the current file name
		--		format_line(a_namesake_set.key(l_index), a_namesake_set.item(l_index).count)
		--		l_index := l_index + 1
		--	end
		--end

	frozen format_line (a_string: STRING; a_count: INTEGER) is
			-- Format the count and file name for display.
		do
			-- Output the current file name
			std.output.put_string("[")
			std.output.put_integer(a_count)
			std.output.put_string("] files with name [")
			std.output.put_string(a_string)
			std.output.put_string("] exist.")
			std.output.put_character('%N')
		end
invariant
	-- Has_branch_pairs: branch_pairs /= Void

end -- class TEST_FSO
