UnitTest:JQM Unit TC helper has been added,TCs have been modified
[platform/framework/web/web-ui-fw.git] / tests / jqm-tchelper / log.php
1 <?php
2 error_reporting(E_ALL);
3 define ("BASE_PATH",".");
4 define ("FILES_DIR","logfiles");
5
6 class SevFile {
7
8         private $basePath = BASE_PATH;
9         private $filesDir = FILES_DIR;
10         private $fileName ;
11         private $filePath;
12         private $fileHandle;
13
14         public function __construct($fileName) {
15             $this->fileName = $fileName;
16             $this->filePath = $this->basePath . DIRECTORY_SEPARATOR . $this->filesDir . DIRECTORY_SEPARATOR;
17         }
18         public function createFile($writeMode) {
19             if($this->fileHandle = fopen($this->filePath . $this->fileName, $writeMode)) {
20                         return true;
21             }
22                 return false;
23         }
24
25         public function closeFile(){
26             fclose($this->fileHandle);
27         }
28
29         public function writeToFile($dataToInsert) {
30             self::createFile('w');
31             if(fwrite($this->fileHandle , $dataToInsert)) {
32                  return true;
33             }
34             self::closeFile();
35             return false;
36         }
37         public function appendToFile($dataToInsert){
38                 self::createFile('a');
39                 if(fwrite($this->fileHandle , $dataToInsert)) {
40                 return true;
41                 }
42                 self::closeFile();
43                 return false;
44         }
45
46         public function readFromFile($bytesToRead = 0){
47                 self::createFile('r');
48                 if($bytesToRead > 0) {
49                         if($result = fread($this->fileHandle , $bytesToRead)) {
50                                 return $result;
51                         }
52                 } else {
53                 if($result = fread($this->fileHandle , filesize($this->filePath . $this->fileName))) {
54                         return $result;
55                         }
56                 }
57                 self::closeFile();
58                 return false;
59         }
60 }
61
62 ?>
63
64 <?
65         if( $_POST["obj"] &&
66                 $_POST["currentTest"] )
67         {
68                 $obj = $_POST["obj"];
69                 $file = new SevFile("log.txt");
70                 $file->appendToFile( $_POST["currentTest"]."|". $obj["result"] ."|". $obj["actual"] ."|". $obj["expected"] ."|". $obj["message"] ."|". $obj["source"] ."\n" );
71                 $file->closeFile();
72                 echo  $_POST["currentTest"]."|". $obj["result"] ."|". $obj["actual"] ."|". $obj["expected"] ."|". $obj["message"] ."|". $obj["source"];
73         }else{
74                 echo "nofile";
75         }
76
77         if( $_REQUEST["reset"] )
78         {
79                 $file = new SevFile("log.txt");
80                 $file->writeToFile("");
81                 $file->closeFile();
82                 echo "reset";
83         }
84 ?>