public function testImage() { $this->startCodeCoverage(); $image = new Image(); //no id, no matching checksum $image->Id = 0; if ($image->Exists()) { $this->fail('Exists() should return false when Id is 0'); return 1; } //id, no matching checksum $image->Id = 1; if ($image->Exists()) { $this->fail("Exists() should return false with no matching checksum\n"); } $pathToImage = dirname(__FILE__) . '/data/smile.gif'; $image->Filename = $pathToImage; $image->Extension = 'image/gif'; //dummy checksum so we don't break the test on pgSQL $image->Checksum = 100; //call save twice to cover different execution paths if (!$image->Save()) { $this->fail("Save() call #1 returned false when it should be true.\n"); return 1; } if (!$image->Save()) { $this->fail("Save() call #2 returned false when it should be true.\n"); return 1; } //exercise the TestImage class as well $testimage = new TestImage(); $testimage->Id = 1; $testimage->TestId = 1; if ($testimage->Exists()) { $this->fail("testimage shouldn't exist yet.\n"); return 1; } if (!$testimage->Insert()) { $this->fail("testimage::Insert() shouldn't have returned false.\n"); return 1; } if (!$testimage->Exists()) { $this->fail("testimage should exist at this point.\n"); return 1; } $this->pass('Passed'); $this->stopCodeCoverage(); return 0; }
if ($fileType == 'text/plain') { //出错,返回 json echo $request->getBody(); } else { $type = $request->getFileSuffix($fileType); //echo $this -> getParams(); //exit(); //返回 文件流 header("Content-type: " . $fileType); //类型 header("Accept-Ranges: bytes"); //告诉客户端浏览器返回的文件大小是按照字节进行计算的 header("Accept-Length: " . $request->getContentLength()); //文件大小 header("Content-Length: " . $request->getContentLength()); //文件大小 header('Content-Disposition: attachment; filename="' . time() . '.' . $type . '"'); //文件名 echo $request->getBody(); exit; } //echo( '内容: , '. $request -> getContentLength() ); //echo '<hr /><br /><br /><br />'; //echo '参数:<pre>'; //echo ($request -> getParams()); //echo '</pre>' ; } } // 测试 $test1 = new TestImage(); $test1->load();
public function Insert() { if ($this->Exists()) { return true; } include 'config/config.php'; $command = pdo_real_escape_string($this->Command); $name = pdo_real_escape_string($this->Name); $path = pdo_real_escape_string($this->Path); $details = pdo_real_escape_string($this->Details); $id = ''; $idvalue = ''; if ($this->Id) { $id = 'id,'; $idvalue = "'" . $this->Id . "',"; } if ($this->CompressedOutput) { if ($CDASH_DB_TYPE == 'pgsql') { $output = $this->Output; } else { $output = base64_decode($this->Output); } } elseif ($CDASH_USE_COMPRESSION) { $output = gzcompress($this->Output); if ($output === false) { $output = $this->Output; } else { if ($CDASH_DB_TYPE == 'pgsql') { if (strlen($this->Output) < 2000) { // compression doesn't help for small chunk $output = $this->Output; } $output = base64_encode($output); } } } else { $output = $this->Output; } // We check for mysql that the if ($CDASH_DB_TYPE == '' || $CDASH_DB_TYPE == 'mysql') { $query = pdo_query("SHOW VARIABLES LIKE 'max_allowed_packet'"); $query_array = pdo_fetch_array($query); $max = $query_array[1]; if (strlen($this->Output) > $max) { add_log('Output is bigger than max_allowed_packet', 'Test::Insert', LOG_ERR, $this->ProjectId); // We cannot truncate the output because it is compressed (too complicated) } } $pdo = get_link_identifier()->getPdo(); if ($this->Id) { $stmt = $pdo->prepare(' INSERT INTO test (id, projectid, crc32, name, path, command, details, output) VALUES (:id, :projectid, :crc32, :name, :path, :command, :details, :output)'); $stmt->bindParam(':id', $this->Id); $stmt->bindParam(':projectid', $this->ProjectId); $stmt->bindParam(':crc32', $this->Crc32); $stmt->bindParam(':name', $name); $stmt->bindParam(':path', $path); $stmt->bindParam(':command', $command); $stmt->bindParam(':details', $details); $stmt->bindParam(':output', $output, PDO::PARAM_LOB); $success = $stmt->execute(); } else { $stmt = $pdo->prepare(' INSERT INTO test (projectid, crc32, name, path, command, details, output) VALUES (:projectid, :crc32, :name, :path, :command, :details, :output)'); $stmt->bindParam(':projectid', $this->ProjectId); $stmt->bindParam(':crc32', $this->Crc32); $stmt->bindParam(':name', $name); $stmt->bindParam(':path', $path); $stmt->bindParam(':command', $command); $stmt->bindParam(':details', $details); $stmt->bindParam(':output', $output, PDO::PARAM_LOB); $success = $stmt->execute(); $this->Id = pdo_insert_id('test'); } if (!$success) { add_last_sql_error("Cannot insert test: {$name} into the database", $this->ProjectId); return false; } // Add the measurements foreach ($this->Measurements as $measurement) { $measurement->TestId = $this->Id; $measurement->Insert(); } // Add the images foreach ($this->Images as $image) { // Decode the data $imgStr = base64_decode($image->Data); $img = imagecreatefromstring($imgStr); ob_start(); switch ($image->Extension) { case 'image/jpg': imagejpeg($img); break; case 'image/jpeg': imagejpeg($img); break; case 'image/gif': imagegif($img); break; case 'image/png': imagepng($img); break; default: echo "Unknown image type: {$type}"; return; } $imageVariable = ob_get_contents(); ob_end_clean(); $image->Data = $imageVariable; $image->Checksum = crc32($imageVariable); $image->Save(); $testImage = new TestImage(); $testImage->Id = $image->Id; $testImage->TestId = $this->Id; $testImage->Role = $image->Name; $testImage->Insert(); } return true; }
function Insert() { if ($this->Exists()) { return true; } include "cdash/config.php"; $command = pdo_real_escape_string($this->Command); $name = pdo_real_escape_string($this->Name); $path = pdo_real_escape_string($this->Path); $details = pdo_real_escape_string($this->Details); $id = ""; $idvalue = ""; if ($this->Id) { $id = "id,"; $idvalue = "'" . $this->Id . "',"; } if ($this->CompressedOutput) { if ($CDASH_DB_TYPE == "pgsql") { $output = pg_escape_bytea($this->Output); } else { $output = base64_decode($this->Output); } } else { if ($CDASH_USE_COMPRESSION) { $output = gzcompress($this->Output); if ($output === false) { $output = $this->Output; } else { if ($CDASH_DB_TYPE == "pgsql") { if (strlen($this->Output) < 2000) { $output = $this->Output; } $output = pg_escape_bytea(base64_encode($output)); // hopefully does the escaping correctly } } } else { $output = $this->Output; } } // We check for mysql that the if ($CDASH_DB_TYPE == '' || $CDASH_DB_TYPE == 'mysql') { $query = pdo_query("SHOW VARIABLES LIKE 'max_allowed_packet'"); $query_array = pdo_fetch_array($query); $max = $query_array[1]; if (strlen($this->Output) > $max) { add_log("Output is bigger than max_allowed_packet", "Test::Insert", LOG_ERR, $this->ProjectId); // We cannot truncate the output because it is compressed (too complicated) } } $output = pdo_real_escape_string($output); $query = "INSERT INTO test (" . $id . "projectid,crc32,name,path,command,details,output)\n VALUES (" . $idvalue . "'{$this->ProjectId}','{$this->Crc32}','{$name}','{$path}','{$command}','{$details}','{$output}')"; if (!pdo_query($query)) { add_last_sql_error("Cannot insert test: " . $name . " into the database", $this->ProjectId); return false; } if (!$this->Id) { $this->Id = pdo_insert_id("test"); } // Add the measurements foreach ($this->Measurements as $measurement) { $measurement->TestId = $this->Id; $measurement->Insert(); } // Add the images foreach ($this->Images as $image) { // Decode the data $imgStr = base64_decode($image->Data); $img = imagecreatefromstring($imgStr); ob_start(); switch ($image->Extension) { case "image/jpg": imagejpeg($img); break; case "image/jpeg": imagejpeg($img); break; case "image/gif": imagegif($img); break; case "image/png": imagepng($img); break; default: echo "Unknown image type: {$type}"; return; } $imageVariable = addslashes(ob_get_contents()); ob_end_clean(); $image->Data = $imageVariable; $image->Checksum = crc32($imageVariable); $image->Save(); $testImage = new TestImage(); $testImage->Id = $image->Id; $testImage->TestId = $this->Id; $testImage->Role = $image->Name; $testImage->Insert(); } return true; }