#=============================================================================================
# @TITLE			Backup history - check table
#
# @NUMBER			WDBM_FKT_02000
#
# @DESCRIPTION		Clicking the "Backup History" -link and checking the shown backup history
# @					table.
#
# @EXP_RESULT		The backup history table has shown up and the headline will be checked.
#
# @REQUIREMENTS		Test: WDBM_FKT_01000; WDBM_FKT_00100; WDBM_FKT_01010
#=============================================================================================

public function trim (in str) {
	if (substr(str, 1, 1) == " ") {

		str = trim(substr(str, 2));
	}
	if (substr(str, length(str)) == " ") {
		str = trim(substr(str, 1, length(str)-1));
	}
	return (str);
} 

static backup_tableitems_ok = 1;
static backup_tableitems_old [] = {"Label","Action","Beginning","Media Name","Log","Pages","Vol.","Next","From","To","Result"};
static backup_tableitems_new [] = {"Label","Action","Beginning","Medium","Log","Size (Pages)","Volumes","Next Log Page","From Page","To Page","Result"};
#=============================================================================================
# @STEP 1			Checking backup window.
#=============================================================================================
web_sync(100);
set_window (menu_window, 2);
web_link_click("Backup History");

set_window(work_window, 1);

if (new_interface == "1") {

	if (obj_exists("Information - CACHES - DB73",0) == 0) {	
		tl_step("Backup History","0","has shown up correctly");
	} else {
		tl_step("Backup History","1","has not shown up correctly");
	}
} else {

	if (obj_exists("1x1",0) == 0) {
	
		tl_step("Backup History","0","has shown up correctly");
	} else {
		tl_step("Backup History","1","has not shown up correctly");
	}
}
#=============================================================================================
# @STEP 2			Checking table content.
#=============================================================================================
set_window(work_window, 1);
if (new_interface == "1") {
	web_obj_get_text("Information - CACHES - DB73","#1","#1",cell_value_1,"","",1);
} else {
	tbl_get_cell_data("Database/Servername", "#1", "#1", cell_value_1);
}

if ((cell_value_1 == "Backup History - " & database && version == "7.3.00") ||
	(cell_value_1 == "Information - Backup History" && (version == "7.4.03" || version == "7.5.00" || version == "7.5.01" || version == "7.6.00"))) {

	tl_step("Table index - Backup history","0","correct");
	
	for (i=1;i<12;i++) {
		
		if (new_interface == "1") {
			web_obj_get_text("Database Users", "#1", "#"&i, cell_value_2, "", "", 1);
		} else {
			tbl_get_cell_data("1x1_2", "#1", "#"&i, cell_value_2);
		}
		
		if (new_interface == "1") {
			if (trim(cell_value_2) != backup_tableitems_new [i-1]) {
				backup_tableitems_ok = 0;
				break;
			}
		} else {
			if (trim(cell_value_2) != backup_tableitems_old [i-1]) {
				backup_tableitems_ok = 0;
				break;
			}
		}
	}
	if (backup_tableitems_ok == 0) {
		tl_step("headline of backup history table","1","incorrect");
	} else {
		tl_step("headline of backup history table","0","correct");
	}
#=============================================================================================
# @STEP 3			Checking the refresh button.
#=============================================================================================
    set_window(work_window,3);
    if (new_interface == "1") {
		web_image_click("1x1.gif", 7, 9);
	} else {
		web_image_click("refresh", 9, 4);
	}
	wait(5);
    set_window(work_window, 1);    
    
	if (new_interface == "1") {
		web_obj_get_text ("Information - CACHES - DB73", "#1", "#1", cell_value_3, "", "", 1);
	} else {
		tbl_get_cell_data ("Database/Servername", "#1", "#1", cell_value_3);
	}
    
    if ((cell_value_3 == "Backup History - " & database && version == "7.3.00") ||
		(cell_value_3 == "Information - Backup History" && (version == "7.4.03" || version == "7.5.00" || version == "7.5.01" || version == "7.6.00"))) {

    	tl_step("Table index after refresh - Backup history","0","correct");
    	
    	for (i=1;i<12;i++) {
			
			set_window(work_window, 1);
    		if (new_interface == "1") {
				web_obj_get_text("Database Users", "#1", "#"&i, cell_value_4, "", "", 1);
			} else {
				tbl_get_cell_data("1x1_2", "#1", "#"&i, cell_value_4);
			}
    		
    		if (new_interface == "1") {
				if (trim(cell_value_4) != backup_tableitems_new [i-1]) {
					backup_tableitems_ok = 0;
					break;
				}
			} else {
				if (trim(cell_value_4) != backup_tableitems_old [i-1]) {
					backup_tableitems_ok = 0;
					break;
				}
			}
    	}
    	if (backup_tableitems_ok == 0) {
    		tl_step("headline of backup history table after refresh","1","incorrect");
    	} else {
    		tl_step("headline of backup history table after refresh","0","correct");
    	}
    } else {
    	tl_step("Table index after refresh - Backup history","1","incorrect");
    }
} else {
	
	tl_step ("Information - Backup History", "1", "Header of table incorrect");
	
	if (cell_value_1 = "Error - " & database) {
	
		set_window(work_window, 1);
		if (new_interface == "1") {			
			web_obj_get_text("1x1", "#1", "#1", error_mes,"","",1);
		} else {
			tbl_get_cell_data("1x1_2", "#1", "#3", error_mes);
		}
		
		if (match(trim(error_mes),"backup history file not found") != 0 ||
			match(trim(error_mes),"-4 connection closed by comm. partner") != 0) {
			
			tl_step("Backup history","1","File could not be found");
		}
	} else {
    	tl_step("Table index - Backup history","1","incorrect");
    }
}
