<?php error_reporting(E_ALL | E_STRICT); ini_set("track_errors", "On"); $INC = "../inc"; require_once($INC . "/init.inc.php"); require_once($INC . "/util.inc.php"); require_once($INC . "/log.inc.php"); rg_log_set_file("util.log"); $rg_scripts = "."; $rg_theme = "util"; $id = rg_id(16); if (strlen($id) != 16) { echo "Cannot generate an id!\n"; exit(1); } @mkdir("util.tmp", 0700, TRUE); file_put_contents("util.tmp/file1", "aaa"); file_put_contents("util.tmp/file2", "bbb"); $r = rg_rmdir("util.tmp"); if ($r !== TRUE) { echo "Cannot delete dir (" . rg_util_error() . ")!\n"; exit(1); } $r = rg_exec("/xxxx"); if ($r['ok'] == 1) { echo "util.php: running non existing command does not return 0!\n"; print_r($r); exit(1); } $r = rg_exec("ls"); if ($r['ok'] != 1) { echo "util.php: cannot run a command!\n"; print_r($r); exit(1); } $r = rg_exec("./util_exit_code.sh 5"); if ($r['code'] != 5) { echo "util.php: error code seems to not be propageted!\n"; print_r($r); exit(1); } // test rg_template_table($dir, $data, $more) with no data $r = rg_template_table("t1", array(), array("a" => "A")); $e = "XAX"; if (strcmp($r, $e) != 0) { echo "util.php: nodata.html is not working (r=$r e=$e)!\n"; exit(1); } // test rg_template_table($dir, $data, $more) with data $data = array(array("a" => "A", "b" => "B"), array("a" => "A2", "b" => "B2")); $r = rg_template_table("t2", $data, array("c" => "C")); $e = "HEADCABCA2B2CFOOTC"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template_table is not working (r=$r e=$e)!\n"; exit(1); } // test rg_template with conditional formating (false) $data = array("X" => "0", "A" => "Avalue", "B" => "Bvalue"); $r = rg_template("t3/c1", $data); $e = "XXBvalueYY"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } // test rg_template with conditional formating (true) $data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); $r = rg_template("t3/c1", $data); $e = "XXAvalueYY"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } // test rg_template with conditional formating (multiline) $data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); $r = rg_template("t3/c1", $data); $e = "XXAvalueYY"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } // test rg_template with conditional formating (nested 1) $data = array("X" => "1", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", "R" => "Rvalue", "T" => "Tvalue"); $r = rg_template("t3/c3", $data); $e = "XXRvalueZZYY"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } // test rg_template with conditional formating (nested 2) $data = array("X" => "1", "Y" => "0", "A" => "Avalue", "B" => "Bvalue", "R" => "Rvalue", "T" => "Tvalue"); $r = rg_template("t3/c3", $data); $e = "XXTvalueZZYY"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } rg_log("test rg_template with conditional formating (nested 3)"); $data = array("X" => "0", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", "R" => "Rvalue", "T" => "Tvalue"); $r = rg_template("t3/c3", $data); $e = "XXBvalueYY"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } rg_log("test rg_template with conditional formating (nested nested 1)"); $data = array("X" => "1", "Y" => "1", "Z" => "1"); $r = rg_template("t3/c4", $data); $r = preg_replace('/\s/', '', $r); $e = "XXTRUE_LEVEL_2YY"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } rg_log("test rg_template with conditional formating (nested nested 2)"); $data = array("X" => "1", "Y" => "0", "Z" => "1"); $r = rg_template("t3/c4", $data); $r = preg_replace('/\s/', '', $r); $e = "XXFALSE_LEVEL_1YY"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } rg_log("test rg_template with conditional formating (nested nested 2)"); $data = array("X" => "0", "Y" => "1", "Z" => "1"); $r = rg_template("t3/c4", $data); $r = preg_replace('/\s/', '', $r); $e = "XXFALSE_LEVEL_0YY"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } rg_log("test rg_template with conditional formating (nested nested 3)"); $data = array("X" => "0", "Y" => "0", "Z" => "0"); $r = rg_template("t3/c5", $data); $r = preg_replace('/\s/', '', $r); $e = "XX-X0Y0Z0-YY"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } rg_log("test rg_template with conditional formating (nested nested 4)"); $data = array("X" => "0", "Y" => "1", "Z" => "0"); $r = rg_template("t3/c5", $data); $r = preg_replace('/\s/', '', $r); $e = "XX-X0Y1Z0-YY"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } rg_log("test rg_template with conditional formating (empty)"); $data = array(); $r = rg_template("t3/c6", $data); $r = preg_replace('/\s/', '', $r); $e = "A"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } rg_log("test rg_template with conditional formating (!empty)"); $data = array("AAA" => ""); $r = rg_template("t3/c7", $data); $r = preg_replace('/\s/', '', $r); $e = "B"; if (strcmp($r, $e) != 0) { echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; exit(1); } // test rg_copy_tree $r = rg_copy_tree("tree1", "tree1.copy", 0755); if ($r !== TRUE) { echo "rg_copy_tree malfunction!\n"; exit(1); } if (!file_exists("tree1.copy/a/f2")) { echo "rg_copy_tree malfunction (f2)!\n"; exit(1); } echo "util: OK!\n"; ?>