#=============================================================================================
# @TITLE					Check - Kernel Trace - Check table
#
# @NUMBER					WDBM_FKT_02044
#
# @DESCRIPTION		The for 'Server - Check' will be used and the shown table will be checked.
#
# @EXP_RESULT			The database1 verfiy will work.
#
# @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 mouth_array[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

static table_items_options_ok = 1;
static table_items_options [] = {
									{"Default","Includes Index, Lock, Long, Pages, Standard, Table"},
									{"Index","Interfaces according accesses to indexes"},
									{"Lock","Lock collisions and their elimination"},
									{"Long","Accesses to LONG columns"},
									{"Pages","I/O"},
									{"Standard","Beginning of all parts of the packet interface"},
									{"Table","Accesses to primary data"},
									{"Objects","Accesses to objects (includes add, get, alter, free)"},
									{"Objects add","Accesses to objects"},
									{"Objects get","Accesses to objects"},
									{"Objects alter","Accesses to objects"},
									{"Objects free","Accesses to objects"},
									{"Select","Complete message buffer of SELECT, GET, FETCH, SELECT ROW and UNION"},
									{"Insert","Complete message buffer of INSERT"},
									{"Update","Complete message buffer of UPDATE"},
									{"Delete","Complete message buffer of DELETE"},
									{"Order","Complete order packet"},
									{"Optimizer","Optimizer output"},
									{"Time","Elapsed time in kernel underneath of the message buffer"},
									{"Check","Additional checks on correct state of the regions"},
									{"Commands","All order packets (including internal packets)"}
								};

static table_items_protocol_ok = 1;
static table_items_protocol [] = 	{
										{"a","Order Interface (AK)"},
										{"b","Record Interface (BD)"},
										{"k","Show Message Block (KB)"},
										{"m","Message Block"}
#										{"e","No Entrypos Output"},
#										{"s","Strategy"},
#										{"t","Time"},
#										{"x","Switch Output (Slow Kernel)"}
									};
#=============================================================================================
# @STEP 1			Clicking the link for Check - Backup.
#=============================================================================================
set_window (menu_window, 3);
web_link_click("Kernel Trace");
#=============================================================================================
# @STEP 2			Checking the shown text and radiobuttons.
#=============================================================================================
set_window (work_window, 3);

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 == "Kernel Trace - " & database && version == "7.3.00") ||
	(cell_value_1 == "Check - Kernel Trace" && (version == "7.4.03" || version == "7.5.00" || version == "7.5.01" || version == "7.6.00"))) {
	
	for(n=2;n<23;n++) {	
		for(i=2;i<4;i++) {
		
			set_window (work_window, 3);
			
			if (version == "7.3.00" ) {
				tbl_get_cell_data("Owner","#"&n,"#"&i,cell_value_2);
			} else {
				
				if (new_interface == "1") {
					web_obj_get_text ("1x1_2", "#"&n, "#"&i+1, cell_value_2, "", "", 1);
				} else {
					tbl_get_cell_data ("Owner", "#"&n, "#"&i+1, cell_value_2);
				}
			}
			
			if (trim(cell_value_2) != table_items_options [n-2,i-2]) {
				table_items_options_ok = 0;
				break;
			}
		}
	}
	if (table_items_options_ok == 0) {
		tl_step("'Kernal Trace' table - options","1","Table content is incorrect");
	} else {
		tl_step("'Kernal Trace' table - options","0","Table content is correct");
	}
}
#=============================================================================================
# @STEP 3			Checking table content after 'Refresh'.
#=============================================================================================
set_window (work_window, 1);
if (new_interface == "1") {
	web_image_click("1x1.gif", 7, 9);
} else {
	web_image_click("refresh", 9, 4);
}
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 == "Kernel Trace - " & database && version == "7.3.00") ||
	(cell_value_3 == "Check - Kernel Trace" && (version == "7.4.03" || version == "7.5.00" || version == "7.5.01" || version == "7.6.00"))) {
	
	tl_step("After 'Refresh'","0","still the same table");
} else {
	tl_step("After 'Refresh'","1","is not the same table");
}
#=============================================================================================
# @STEP 4			Checking content of 'Protocol'.
#=============================================================================================
set_window (work_window, 3);
web_link_click("Protocol");
set_window (work_window, 0);

tbl_get_cell_data("Database/Servername","#1","#1",cell_value_2);

if (new_interface == "1") {
	web_obj_get_text ("Information - CACHES - DB73", "#1", "#1", cell_value_4, "", "", 1);
} else {
	tbl_get_cell_data ("Database/Servername", "#1", "#1", cell_value_4);
}

if ((cell_value_4 == "Kernel Trace - " & database && version == "7.3.00") ||
	(cell_value_4 == "Check - Kernel Trace" && (version == "7.4.03" || version == "7.5.00" || version == "7.5.01" || version == "7.6.00"))) {
	
	for(n=2;n<6;n++) {
		for(i=2;i<4;i++) {
		
			set_window (work_window, 0);
			
			if (version == "7.3.00" ) {
				tbl_get_cell_data ("Owner", "#"&n, "#"&i, cell_value_5);
			} else {
				
				if (new_interface == "1") {
					web_obj_get_text ("1x1_2", "#"&n, "#"&i, cell_value_5, "", "", 1);
				} else {
					tbl_get_cell_data ("Owner", "#"&n, "#"&i, cell_value_5);
				}
			}
			
			if (trim(cell_value_5) != table_items_protocol [n-2,i-2]) {
				table_items_protocol_ok = 0;
				break;
			}
		}
	}
	if (table_items_protocol_ok == 0) {
		tl_step("'Kernal Trace' table - protocol","1","Table content is incorrect");
	} else {
		tl_step("'Kernal Trace' table - protocol","0","Table content is correct");
	}
}
#=============================================================================================
# @STEP 5			Creating new kernal trace file.
#=============================================================================================
time_sec = get_time(); #Get current time

set_window (work_window, 4);
web_link_click("Options");
set_window (work_window, 1);

button_set("Option",ON);
button_set("Option_1",ON);
web_link_click("Selected Items On");

wait(3);

set_window (work_window, 2);
web_link_click("Protocol");
set_window (work_window, 2);
button_set("Option_2",ON);
button_set("Option_3",ON);
button_set("Option_4",ON);
#button_set("Option_5",ON);
web_link_click("Make Protocol");
set_window (work_window, 6);
web_link_click("Flush");

set_window (work_window, 6);
if (obj_exists ("Information - CACHES - DB73", 0) == 0) {
	web_obj_get_text ("Information - CACHES - DB73", "#1", "#1", text, "", "", 1);
	
	if (match (text, "Error") != 0) {	
		tl_step("kernel trace - flush", "1", "did not work");
	}
}
#=============================================================================================
# @STEP 6			Checking whether file was created - create time check.
#=============================================================================================
set_window (menu_window, 4);

if (version == "7.3.00") {
	web_link_click("Files");
}
if (version == "7.4.03" ||
	version == "7.5.00" ||
	version == "7.5.01" ||
	version == "7.6.00") {
	web_link_click("Diagnosis Files");
}

wait(10);
set_window (work_window, 1);
web_link_click("Kernel Trace Protocol");
wait(5);

if (obj_exists("Kernel Trace Protocol",0) == 0) {
	set_window (work_window, 1);
	web_link_click("Kernel Trace Protocol");
	wait(5);
}

set_window(work_window, 1);
if (new_interface == "1") {
	tbl_get_cell_data ("Information - CACHES - DB73", "#1", "#2", cell_value_6);
} else {
	tbl_get_cell_data ("1x1", "#1", "#2", cell_value_6);
}
time = time_str(time_sec);
	
split(time,array," ");
	
mouth = array[2];
time_current  = array[4];
	
for (i=1;i<=12;i++) {
	if (mouth == mouth_array[i-1]) {
		if (i<10) {
			mouth_new = "0" & (i);
			break;
		} else {
			mouth_new = (i);
			break;
		}
	}
}
date = array[5] & "-" & mouth_new & "-" & array[3];

split (cell_value_6, array_1, " ");

time_dbm = array_1[5];

split (time_current, array_2, ":");
split (time_dbm, array_3, ":");

if (cell_value_6 != "") {

	if (match(cell_value_6,date) != 0 &&
		array_3[1] >= array_2[1] &&
		array_3[2] >= array_2[2]) {
		
		tl_step("Kernel trace","0","correct");
	} else {
		tl_step("Kernel trace","1","incorrect");
	}
}else {
	
	if (array_2[1] >= array_3[1] &&
		array_2[2] >= array_3[2]) {
		
		tl_step("Kernel trace","0","correct");
	} else {
		tl_step("Kernel trace","1","incorrect");
	}
}
#=============================================================================================
# @STEP 7			Switching Kernel trace to off.
#=============================================================================================
set_window (menu_window, 3);
web_link_click("Kernel Trace");
set_window (work_window, 1);
web_link_click("All Items Off");
