本文整理汇总了Java中android.test.suitebuilder.annotation.SmallTest类的典型用法代码示例。如果您正苦于以下问题:Java SmallTest类的具体用法?Java SmallTest怎么用?Java SmallTest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SmallTest类属于android.test.suitebuilder.annotation包,在下文中一共展示了SmallTest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWriteLessThanContentLength
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
@Feature({"Cronet"})
@CompareDefaultWithCronet
public void testWriteLessThanContentLength()
throws Exception {
URL url = new URL(NativeTestServer.getEchoBodyURL());
HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
// Set a content length that's 1 byte more.
connection.setFixedLengthStreamingMode(TestUtil.UPLOAD_DATA.length + 1);
OutputStream out = connection.getOutputStream();
out.write(TestUtil.UPLOAD_DATA);
try {
connection.getResponseCode();
fail();
} catch (ProtocolException e) {
// Expected.
}
connection.disconnect();
}
示例2: testFixedLengthStreamingModeWriteOneByte
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
@Feature({"Cronet"})
@CompareDefaultWithCronet
public void testFixedLengthStreamingModeWriteOneByte()
throws Exception {
URL url = new URL(NativeTestServer.getEchoBodyURL());
HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setFixedLengthStreamingMode(TestUtil.UPLOAD_DATA.length);
OutputStream out = connection.getOutputStream();
for (int i = 0; i < TestUtil.UPLOAD_DATA.length; i++) {
// Write one byte at a time.
out.write(TestUtil.UPLOAD_DATA[i]);
}
assertEquals(200, connection.getResponseCode());
assertEquals("OK", connection.getResponseMessage());
assertEquals(TestUtil.UPLOAD_DATA_STRING, TestUtil.getResponseAsString(connection));
connection.disconnect();
}
示例3: testPostOneMassiveWriteWriteOneByte
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
@Feature({"Cronet"})
@CompareDefaultWithCronet
public void testPostOneMassiveWriteWriteOneByte() throws Exception {
URL url = new URL(NativeTestServer.getEchoBodyURL());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setChunkedStreamingMode(0);
OutputStream out = connection.getOutputStream();
byte[] largeData = TestUtil.getLargeData();
for (int i = 0; i < largeData.length; i++) {
out.write(largeData[i]);
}
assertEquals(200, connection.getResponseCode());
assertEquals("OK", connection.getResponseMessage());
TestUtil.checkLargeData(TestUtil.getResponseAsString(connection));
connection.disconnect();
}
示例4: testInitTwoEnginesInSequence
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
@Feature({"Cronet"})
public void testInitTwoEnginesInSequence() throws Exception {
final CronetTestFramework testFramework = startCronetTestFrameworkAndSkipLibraryInit();
ConditionVariable runBlocker = new ConditionVariable(true);
RequestThread thread1 = new RequestThread(testFramework, mUrl, runBlocker);
RequestThread thread2 = new RequestThread(testFramework, mUrl404, runBlocker);
thread1.start();
thread1.join();
thread2.start();
thread2.join();
assertEquals(200, thread1.mCallback.mResponseInfo.getHttpStatusCode());
assertEquals(404, thread2.mCallback.mResponseInfo.getHttpStatusCode());
}
示例5: testAddWhileIteration
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
@Feature({"Android-AppBase"})
public void testAddWhileIteration() {
ObserverList<Observer> observerList = new ObserverList<Observer>();
Foo a = new Foo(1);
Foo b = new Foo(-1);
Foo c = new Foo(1);
FooAdder evil = new FooAdder(observerList, c);
observerList.addObserver(evil);
observerList.addObserver(a);
observerList.addObserver(b);
for (Observer obs : observerList) obs.observe(10);
assertTrue(observerList.hasObserver(c));
assertEquals(10, a.mTotal);
assertEquals(-10, b.mTotal);
assertEquals(0, c.mTotal);
}
示例6: testRecordBooleanHistogram
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
/**
* Tests recording of boolean histograms.
*/
@SmallTest
public void testRecordBooleanHistogram() {
String histogram = "HelloWorld.BooleanMetric";
HistogramDelta falseCount = new HistogramDelta(histogram, 0);
HistogramDelta trueCount = new HistogramDelta(histogram, 1);
assertEquals(0, trueCount.getDelta());
assertEquals(0, falseCount.getDelta());
RecordHistogram.recordBooleanHistogram(histogram, true);
assertEquals(1, trueCount.getDelta());
assertEquals(0, falseCount.getDelta());
RecordHistogram.recordBooleanHistogram(histogram, true);
assertEquals(2, trueCount.getDelta());
assertEquals(0, falseCount.getDelta());
RecordHistogram.recordBooleanHistogram(histogram, false);
assertEquals(2, trueCount.getDelta());
assertEquals(1, falseCount.getDelta());
}
示例7: testFinishAndRemoveTask
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
public void testFinishAndRemoveTask() throws InterruptedException {
MockActivity activity = new MockActivity();
ApiCompatibilityUtils.finishAndRemoveTask(activity);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
assertEquals(1, activity.mFinishAndRemoveTaskCallbackCount);
assertEquals(0, activity.mFinishCallbackCount);
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
long startTime = SystemClock.uptimeMillis();
while (activity.mFinishCallbackCount == 0
&& SystemClock.uptimeMillis() - startTime < WAIT_TIMEOUT_IN_MS) {
Thread.sleep(SLEEP_INTERVAL_IN_MS);
}
// MockActivity#finishAndRemoveTask() never sets isFinishing() to true for LOLLIPOP to
// simulate an exceptional case. In that case, MockActivity#finish() should be called
// after 3 tries.
assertEquals(3, activity.mFinishAndRemoveTaskCallbackCount);
assertEquals(1, activity.mFinishCallbackCount);
} else {
assertEquals(0, activity.mFinishAndRemoveTaskCallbackCount);
assertEquals(1, activity.mFinishCallbackCount);
}
assertTrue(activity.mIsFinishing);
}
示例8: testCanRecordEvent
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
@Feature({"Android-AppBase"})
public void testCanRecordEvent() {
EarlyTraceEvent.enable();
long myThreadId = Process.myTid();
long beforeMs = SystemClock.elapsedRealtime();
EarlyTraceEvent.begin(EVENT_NAME);
EarlyTraceEvent.end(EVENT_NAME);
long afterMs = SystemClock.elapsedRealtime();
assertEquals(1, EarlyTraceEvent.sCompletedEvents.size());
assertTrue(EarlyTraceEvent.sPendingEvents.isEmpty());
EarlyTraceEvent.Event event = EarlyTraceEvent.sCompletedEvents.get(0);
assertEquals(EVENT_NAME, event.mName);
assertEquals(myThreadId, event.mThreadId);
assertTrue(beforeMs <= event.mBeginTimeMs && event.mBeginTimeMs <= afterMs);
assertTrue(event.mBeginTimeMs <= event.mEndTimeMs);
assertTrue(beforeMs <= event.mEndTimeMs && event.mEndTimeMs <= afterMs);
}
示例9: testConnectBeforeWrite
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
@Feature({"Cronet"})
@CompareDefaultWithCronet
public void testConnectBeforeWrite() throws Exception {
URL url = new URL(NativeTestServer.getEchoBodyURL());
HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setFixedLengthStreamingMode(TestUtil.UPLOAD_DATA.length);
OutputStream out = connection.getOutputStream();
connection.connect();
out.write(TestUtil.UPLOAD_DATA);
assertEquals(200, connection.getResponseCode());
assertEquals("OK", connection.getResponseMessage());
assertEquals(TestUtil.UPLOAD_DATA_STRING, TestUtil.getResponseAsString(connection));
connection.disconnect();
}
示例10: testRedirectURLRequest
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
@Feature({"Cronet"})
public void testRedirectURLRequest() throws Exception {
createRequestAndWaitForComplete(
NativeTestServer.getRedirectURL(), false);
// ChromiumUrlRequest does not expose the url after redirect.
assertEquals(NativeTestServer.getRedirectURL(), mListener.mUrl);
assertEquals(200, mListener.mHttpStatusCode);
assertEquals("OK", mListener.mHttpStatusText);
// Expect that the request is redirected to success.txt.
assertEquals("this is a text file\n",
new String(mListener.mResponseAsBytes));
// Test that ChromiumUrlRequest caches information which is available
// after the native request adapter has been destroyed.
assertEquals(200, mRequest.getHttpStatusCode());
assertEquals("OK", mRequest.getHttpStatusText());
assertNull(mRequest.getException());
checkAfterAdapterDestroyed(mRequest);
}
示例11: testGetOutputStreamAfterConnectionMade
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
@Feature({"Cronet"})
@CompareDefaultWithCronet
public void testGetOutputStreamAfterConnectionMade() throws Exception {
URL url = new URL(NativeTestServer.getEchoBodyURL());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setChunkedStreamingMode(0);
assertEquals(200, connection.getResponseCode());
try {
connection.getOutputStream();
fail();
} catch (ProtocolException e) {
// Expected.
}
}
示例12: testSimpleGet
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
@Feature({"Cronet"})
@OnlyRunNativeCronet
public void testSimpleGet() throws Exception {
String url = Http2TestServer.getEchoMethodUrl();
TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCallback();
// Create stream.
BidirectionalStream stream = new BidirectionalStream
.Builder(url, callback, callback.getExecutor(),
mTestFramework.mCronetEngine)
.setHttpMethod("GET")
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
// Default method is 'GET'.
assertEquals("GET", callback.mResponseAsString);
UrlResponseInfo urlResponseInfo =
createUrlResponseInfo(new String[] {url}, "", 200, 27, ":status", "200");
assertResponseEquals(urlResponseInfo, callback.mResponseInfo);
checkResponseInfo(callback.mResponseInfo, Http2TestServer.getEchoMethodUrl(), 200, "");
}
示例13: testWriteAfterConnect
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
/**
* Tests write after connect. Strangely, the default implementation allows
* writing after being connected, so this test only runs against Cronet's
* implementation.
*/
@SmallTest
@Feature({"Cronet"})
@OnlyRunCronetHttpURLConnection
public void testWriteAfterConnect() throws Exception {
URL url = new URL(NativeTestServer.getEchoBodyURL());
HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
OutputStream out = connection.getOutputStream();
out.write(TestUtil.UPLOAD_DATA);
connection.connect();
try {
// Attemp to write some more.
out.write(TestUtil.UPLOAD_DATA);
fail();
} catch (IllegalStateException e) {
assertEquals("Cannot write after being connected.", e.getMessage());
}
}
示例14: testRewind
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
/**
* Tests that {@link CronetBufferedOutputStream} supports rewind in a
* POST preserving redirect.
* Use {@code OnlyRunCronetHttpURLConnection} as the default implementation
* does not pass this test.
*/
@SmallTest
@Feature({"Cronet"})
@OnlyRunCronetHttpURLConnection
public void testRewind() throws Exception {
URL url = new URL(NativeTestServer.getRedirectToEchoBody());
HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty(
"Content-Length", Integer.toString(TestUtil.UPLOAD_DATA.length));
OutputStream out = connection.getOutputStream();
out.write(TestUtil.UPLOAD_DATA);
assertEquals(TestUtil.UPLOAD_DATA_STRING, TestUtil.getResponseAsString(connection));
connection.disconnect();
}
示例15: testBadFileDescriptorProvider
import android.test.suitebuilder.annotation.SmallTest; //导入依赖的package包/类
@SmallTest
@Feature({"Cronet"})
public void testBadFileDescriptorProvider() throws Exception {
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder builder =
new UrlRequest.Builder(NativeTestServer.getRedirectToEchoBody(), callback,
callback.getExecutor(), mTestFramework.mCronetEngine);
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
try {
UploadDataProvider dataProvider = UploadDataProviders.create(pipe[0]);
builder.setUploadDataProvider(dataProvider, callback.getExecutor());
builder.addHeader("Content-Type", "useless/string");
builder.build().start();
callback.blockForDone();
assertTrue(callback.mError.getCause() instanceof IllegalArgumentException);
} finally {
pipe[1].close();
}
}