@@ -30,6 +30,19 @@ protected function setUp()
3030 protected function tearDown () {
3131 }
3232
33+ function generateRandomString ($ length = 10 ) {
34+ $ characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ' ;
35+ $ randomString = '' ;
36+ for ($ i = 0 ; $ i < $ length ; $ i ++) {
37+ $ randomString .= $ characters [rand (0 , strlen ($ characters ) - 1 )];
38+ }
39+ return $ randomString ;
40+ }
41+
42+ function generateRandomFile ($ size = 10 , $ filename = 'random-file ' ) {
43+ exec ("dd if=/dev/urandom of= " . $ filename . " bs=1 count= " . (string )$ size );
44+ }
45+
3346 /**********************************
3447 * TestBucket
3548 **********************************/
@@ -917,7 +930,7 @@ public function testUploadSmallObject() {
917930 */
918931 public function testPutObjectEmpty () {
919932 try {
920- $ this ->cosClient ->upload ($ this ->bucket , '你好.txt ' , '123 ' );
933+ $ this ->cosClient ->upload ($ this ->bucket , '你好.txt ' , '' );
921934 } catch (ServiceResponseException $ e ) {
922935 print $ e ;
923936 $ this ->assertFalse (TRUE );
@@ -986,7 +999,12 @@ public function testPutObjectMeta2K() {
986999 */
9871000 public function testUploadComplexObject () {
9881001 try {
989- $ this ->cosClient ->upload ($ this ->bucket , '→↓←→↖↗↙↘! \"#$%& \'()*+,-./0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[ \\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ' , 'Hello World ' );
1002+ $ key = '→↓←→↖↗↙↘! \"#$%& \'()*+,-./0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[ \\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ' ;
1003+ $ this ->cosClient ->upload ($ this ->bucket , $ key , 'Hello World ' );
1004+ $ this ->cosClient ->headObject (array (
1005+ 'Bucket ' => $ this ->bucket ,
1006+ 'Key ' => $ key
1007+ ));
9901008 } catch (ServiceResponseException $ e ) {
9911009 print $ e ;
9921010 $ this ->assertFalse (TRUE );
@@ -999,10 +1017,16 @@ public function testUploadComplexObject() {
9991017 */
10001018 public function testUploadLargeObject () {
10011019 try {
1020+ $ key = '你好.txt ' ;
1021+ $ body = $ this ->generateRandomString (3 *1024 *1024 +1023 );
1022+ $ md5 = base64_encode (md5 ($ body , true ));
10021023 $ this ->cosClient ->upload ($ bucket =$ this ->bucket ,
1003- $ key =' 你好.txt ' ,
1004- $ body =str_repeat ( ' a ' , 3 * 1024 * 1024 + 1 ) ,
1024+ $ key =$ key ,
1025+ $ body =$ body ,
10051026 $ options =['PartSize ' =>1024 * 1024 + 1 ]);
1027+ $ rt = $ this ->cosClient ->getObject (['Bucket ' =>$ this ->bucket , 'Key ' =>$ key ]);
1028+ $ download_md5 = base64_encode (md5 ($ rt ['Body ' ], true ));
1029+ $ this ->assertEquals ($ md5 , $ download_md5 );
10061030 } catch (ServiceResponseException $ e ) {
10071031 print $ e ;
10081032 $ this ->assertFalse (TRUE );
@@ -1154,16 +1178,24 @@ public function testCopySmallObject() {
11541178 */
11551179 public function testCopyLargeObject () {
11561180 try {
1181+ $ key = '你好.txt ' ;
1182+ $ dst_key = 'hi.txt ' ;
1183+ $ body = $ this ->generateRandomString (3 *1024 *1024 +1023 );
1184+ $ md5 = base64_encode (md5 ($ body , true ));
11571185 $ this ->cosClient ->upload ($ bucket =$ this ->bucket ,
1158- $ key =' 你好.txt ' ,
1159- $ body =str_repeat ( ' a ' , 3 * 1024 * 1024 + 1 ) ,
1186+ $ key =$ key ,
1187+ $ body =$ body ,
11601188 $ options =['PartSize ' =>1024 * 1024 + 1 ]);
11611189 $ this ->cosClient ->copy ($ bucket =$ this ->bucket ,
1162- $ key =' hi.txt ' ,
1190+ $ key =$ dst_key ,
11631191 $ copySource = ['Bucket ' =>$ this ->bucket ,
11641192 'Region ' =>$ this ->region ,
1165- 'Key ' =>' 你好.txt ' ],
1193+ 'Key ' =>$ key ],
11661194 $ options =['PartSize ' =>1024 * 1024 + 1 ]);
1195+
1196+ $ rt = $ this ->cosClient ->getObject (['Bucket ' =>$ this ->bucket , 'Key ' =>$ dst_key ]);
1197+ $ download_md5 = base64_encode (md5 ($ rt ['Body ' ], true ));
1198+ $ this ->assertEquals ($ md5 , $ download_md5 );
11671199 } catch (ServiceResponseException $ e ) {
11681200 print $ e ;
11691201 $ this ->assertFalse (TRUE );
0 commit comments