@@ -63,6 +63,36 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
6363 Assert .assertNotNull (resp );
6464 }
6565
66+ @ SmallTest
67+ public void test0Data () throws Throwable {
68+ final String expectKey = "你好;\" \r \n \r \n \r \n " ;
69+ Map <String , String > params = new HashMap <String , String >();
70+ params .put ("x:foo" , "fooval" );
71+ final UploadOptions opt = new UploadOptions (params , null , true , null , null );
72+
73+ uploadManager .put ("" .getBytes (), expectKey , TestConfig .token , new UpCompletionHandler () {
74+ public void complete (String k , ResponseInfo rinfo , JSONObject response ) {
75+ Log .i ("qiniutest" , k + rinfo );
76+ key = k ;
77+ info = rinfo ;
78+ resp = response ;
79+ signal .countDown ();
80+ }
81+ }, opt );
82+
83+ try {
84+ signal .await (10 , TimeUnit .SECONDS ); // wait for callback
85+ Assert .assertNotNull ("timeout" , info );
86+ } catch (InterruptedException e ) {
87+ e .printStackTrace ();
88+ }
89+ Assert .assertEquals (info .toString (), ResponseInfo .ZeroSizeFile , info .statusCode );
90+ Assert .assertEquals (info .toString (), expectKey , key );
91+ Assert .assertFalse (info .toString (), info .isOK ());
92+ Assert .assertEquals (info .toString (), "" , info .reqId );
93+ Assert .assertNull (resp );
94+ }
95+
6696 @ SmallTest
6797 public void testNoKey () throws Throwable {
6898 final String expectKey = null ;
@@ -159,7 +189,7 @@ public void testNoToken() throws Throwable {
159189 final String expectKey = "你好" ;
160190 runTestOnUiThread (new Runnable () { // THIS IS THE KEY TO SUCCESS
161191 public void run () {
162- uploadManager .put (new byte [0 ], expectKey , null , new UpCompletionHandler () {
192+ uploadManager .put (new byte [1 ], expectKey , null , new UpCompletionHandler () {
163193 public void complete (String k , ResponseInfo rinfo , JSONObject response ) {
164194 Log .i ("qiniutest" , k + rinfo );
165195 key = k ;
@@ -187,7 +217,7 @@ public void testEmptyToken() throws Throwable {
187217 final String expectKey = "你好" ;
188218 runTestOnUiThread (new Runnable () { // THIS IS THE KEY TO SUCCESS
189219 public void run () {
190- uploadManager .put (new byte [0 ], expectKey , "" , new UpCompletionHandler () {
220+ uploadManager .put (new byte [1 ], expectKey , "" , new UpCompletionHandler () {
191221 public void complete (String k , ResponseInfo rinfo , JSONObject response ) {
192222 Log .i ("qiniutest" , k + rinfo );
193223 key = k ;
@@ -242,6 +272,38 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
242272 TempFile .remove (f );
243273 }
244274
275+ @ MediumTest
276+ public void test0File () throws Throwable {
277+ final String expectKey = "世/界" ;
278+ final File f = TempFile .createFile (0 );
279+ Map <String , String > params = new HashMap <String , String >();
280+ params .put ("x:foo" , "fooval" );
281+ final UploadOptions opt = new UploadOptions (params , null , true , null , null );
282+ uploadManager .put (f , expectKey , TestConfig .token , new UpCompletionHandler () {
283+ public void complete (String k , ResponseInfo rinfo , JSONObject response ) {
284+ Log .i ("qiniutest" , k + rinfo );
285+ key = k ;
286+ info = rinfo ;
287+ resp = response ;
288+ signal .countDown ();
289+ }
290+ }, opt );
291+
292+ try {
293+ signal .await (10 , TimeUnit .SECONDS ); // wait for callback
294+ Assert .assertNotNull ("timeout" , info );
295+ } catch (InterruptedException e ) {
296+ e .printStackTrace ();
297+ }
298+ Assert .assertEquals (f .toString (), 0 , f .length ());
299+ Assert .assertEquals (info .toString (), ResponseInfo .ZeroSizeFile , info .statusCode );
300+ Assert .assertEquals (info .toString (), expectKey , key );
301+ Assert .assertFalse (info .toString (), info .isOK ());
302+ Assert .assertEquals (info .toString (), "" , info .reqId );
303+ Assert .assertNull (resp );
304+ TempFile .remove (f );
305+ }
306+
245307 @ SmallTest
246308 public void testNoComplete () {
247309 Exception error = null ;
0 commit comments