# **********************************************************************
# Start of Test Script
# **********************************************************************

# **********************************************************************
# Test Main Menu items
# Items must first be in the GUI map
# **********************************************************************

TimesToRunTest = 1;

for ( i = 0; i < TimesToRunTest; i++ )
{
	Start_Time = get_time();

	# AUT1 = "D:\\Win98\\Notepad.exe";

	# Prefered method is to find Window Directory and use it.
	WindowsPath = getenv ( "winbootdir" );

	AUT1 = WindowsPath & "\\Notepad.exe";

	GUI_FileName = "C:\\WRScripts\\Notepad\\Notepad1\\Notepad.gui";

	GUI_close ( "<temporary>" );	# Clear temp buffer...
	GUI_close_all;		# Clear All Loaded GUI Map's...
	rc1 = GUI_load ( GUI_FileName );	# Load the GUI map to use...
	Log_Msg ( "GUI_load", 56, rc1 );

	rc1 = win_exists ( "AnyNotepadApp", -1 );
	if ( rc1 != 0 )
	{
		invoke_application ( AUT1, "", "C:\\", SW_SHOW );
	}

	rc1 = win_wait_info ( "AnyNotepadApp", "enabled", 1, 30 );

	rc1 = set_window ( "AnyNotepadApp", 15 );

	rc1 = win_activate ( "AnyNotepadApp" );

	rc1 = win_resize ( "AnyNotepadApp", 374, 380 );

	rc1 = win_move ( "AnyNotepadApp", -1, -1 );

	rc1 = set_window ( "AnyNotepadApp", 15 );

	rc1 = win_activate ( "AnyNotepadApp" );

	# used to clear any text entered into window...
	rc1 = menu_select_item ("File;New");
	if ( rc1 != 0 )
	{
		tl_step ( Error Message, FAIL, "[menu_select_item] Failed Return Code = " & rc1 );
	}

	# Wait's are bad, would take over 10 seconds otherwise (default timeout)
	wait (3);
	# value "-1" means don't wait at all
	rc1 = win_exists ( "Notepad", -1 );
	if ( rc1 == 0 )
	{
		tl_step ( "Status Message", PASS, "Selecting [File;New] so menu Items enabled/disabled are correct. " );
		rc1 = set_window ("Notepad", 5);
		rc1 = win_activate ("Notepad");
		rc1 = button_press ("No");
	}

	rc1 = set_window ( "AnyNotepadApp", 15 );
	rc1 = win_activate ( "AnyNotepadApp" );

# **********************************************************************
# This tests the Menu Items base on a Data Table
# using the Menu Item number and comparing the
# menu item found at that location
# **********************************************************************
	tl_step ( "Status Message", PASS, "Testing Menu Value's. ");

	table = "default.xls";
	# Make sure table is closed before opening it...
	ddt_close(table);
	wait(0,250);
	rc = ddt_open(table, DDT_MODE_READ);
	if (rc!= E_OK && rc != E_FILE_OPEN)
		pause("Cannot open table.");
	ddt_get_row_count(table,table_RowCount);
	for(table_Row = 1; table_Row <= table_RowCount; table_Row ++)
	{
		ddt_set_row(table,table_Row);
		Menu = ddt_val(table, "Menu" );
		MenuText = ddt_val(table, "MenuText" );
		Position = ddt_val(table, "Position" );
		rc1 = menu_get_info ( Menu & ";#" & Position & "", "label", value );
		if ( rc1 != 0 )
		{
			tl_step "Error Message", FAIL, "[menu_get_info] Failed! return code = " rc1 );
		}
		else
		{
			printf ( "Menu Name is\t: %s", value );
			printf ( "Name should be\t: %s\r\n", MenuText );
			# "compare_text" ignores space characters...
			rc1 = compare_text( MenuText, value );
			if ( rc1 != TRUE )
			{
				printf ( "Menu Name and Value retrieved don't match! \r\n" );
				tl_step ( "Error Message", FAIL, "Menu Value does NOT matches expected result! ");
				tl_step ( "Error Message", FAIL, "Got [" & value & "] should have been [" & MenuName & "] " );
			}
		}
	} # end for
	tl_step ( "Status Message", PASS, "Testing Menu Value's Done - " & table_Row & " Menu items checked. ");
	ddt_close(table);


# **********************************************************************
# This tests the Menu Items base on a GUI checklist
# This will also check if the menu item is
# enabled or disabled (grayed out)
# **********************************************************************
	rc1 = set_window ( "AnyNotepadApp", 15 );
	rc1 = win_activate ( "AnyNotepadApp" );

	# GUI checkpoint of Menu Items
	win_check_gui("AnyNotepadApp", "list1.ckl", "gui1", 1);
	# The above line of code replaces 35 lines of code above...
	# Plus it checks the state of the menu item enabled/disabled...

# **********************************************************************
# This computes the time it took to run the test script
# **********************************************************************

	End_Time = get_time();
	TotalTestTime = End_Time - Start_Time;
	Hours	= int(TotalTestTime / 3600);
	Minutes	= int((TotalTestTime - (Hours * 3600) ) / 60);
	Seconds	= int((TotalTestTime - (Hours * 3600) - (Minutes * 60)));

	printf ( "\r\nTotal Test Time %02d:%02d:%02d \r\n", Hours, Minutes, Seconds );
} # end while


