|
1 | 1 | package cn.leancloud.sms; |
2 | 2 |
|
3 | 3 | import cn.leancloud.Configure; |
| 4 | +import cn.leancloud.LCLogger; |
| 5 | +import cn.leancloud.core.LeanCloud; |
4 | 6 | import cn.leancloud.types.LCNull; |
5 | 7 | import io.reactivex.Observer; |
6 | 8 | import io.reactivex.disposables.Disposable; |
| 9 | +import io.reactivex.functions.Consumer; |
7 | 10 | import junit.framework.Test; |
8 | 11 | import junit.framework.TestCase; |
9 | 12 | import junit.framework.TestSuite; |
@@ -194,4 +197,60 @@ public void onComplete() { |
194 | 197 | } |
195 | 198 | }); |
196 | 199 | } |
| 200 | + |
| 201 | + public void testCaptcha() throws Exception { |
| 202 | + final CountDownLatch latch = new CountDownLatch(1); |
| 203 | + testSuccess = false; |
| 204 | + LCCaptchaOption option = new LCCaptchaOption(); |
| 205 | + option.setWidth(85); |
| 206 | + option.setHeight(40); |
| 207 | + LCCaptcha.requestCaptchaInBackground(option).subscribe(new Observer<LCCaptchaDigest>() { |
| 208 | + @Override |
| 209 | + public void onSubscribe(Disposable disposable) { |
| 210 | + |
| 211 | + } |
| 212 | + |
| 213 | + @Override |
| 214 | + public void onNext(LCCaptchaDigest lcCaptchaDigest) { |
| 215 | + System.out.println("Succeed to got digest: " + lcCaptchaDigest.getCaptchaUrl()); |
| 216 | + LCCaptcha.verifyCaptchaCodeInBackground("znca", lcCaptchaDigest).subscribe(new Observer<LCCaptchaValidateResult>() { |
| 217 | + @Override |
| 218 | + public void onSubscribe(Disposable disposable) { |
| 219 | + |
| 220 | + } |
| 221 | + |
| 222 | + @Override |
| 223 | + public void onNext(LCCaptchaValidateResult lcCaptchaValidateResult) { |
| 224 | + System.out.println("Succeed to got validateResult: " + lcCaptchaValidateResult); |
| 225 | + testSuccess = true; |
| 226 | + latch.countDown(); |
| 227 | + } |
| 228 | + |
| 229 | + @Override |
| 230 | + public void onError(Throwable throwable) { |
| 231 | + throwable.printStackTrace(); |
| 232 | + latch.countDown(); |
| 233 | + } |
| 234 | + |
| 235 | + @Override |
| 236 | + public void onComplete() { |
| 237 | + |
| 238 | + } |
| 239 | + }); |
| 240 | + } |
| 241 | + |
| 242 | + @Override |
| 243 | + public void onError(Throwable throwable) { |
| 244 | + throwable.printStackTrace(); |
| 245 | + latch.countDown(); |
| 246 | + } |
| 247 | + |
| 248 | + @Override |
| 249 | + public void onComplete() { |
| 250 | + |
| 251 | + } |
| 252 | + }); |
| 253 | + latch.await(); |
| 254 | + assertTrue(testSuccess); |
| 255 | + } |
197 | 256 | } |
0 commit comments