當前位置: 首頁>>代碼示例>>Java>>正文


Java SmallTest類代碼示例

本文整理匯總了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();
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:23,代碼來源:CronetFixedModeOutputStreamTest.java

示例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();
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:22,代碼來源:CronetFixedModeOutputStreamTest.java

示例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();
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:20,代碼來源:CronetChunkedOutputStreamTest.java

示例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());
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:17,代碼來源:CronetUrlRequestContextTest.java

示例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);
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:21,代碼來源:ObserverListTest.java

示例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());
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:24,代碼來源:RecordHistogramTest.java

示例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);
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:27,代碼來源:ApiCompatibilityUtilsTest.java

示例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);
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:20,代碼來源:EarlyTraceEventTest.java

示例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();
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:19,代碼來源:CronetFixedModeOutputStreamTest.java

示例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);
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:20,代碼來源:ChromiumUrlRequestTest.java

示例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.
    }
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:18,代碼來源:CronetChunkedOutputStreamTest.java

示例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, "");
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:24,代碼來源:BidirectionalStreamTest.java

示例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());
    }
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:26,代碼來源:CronetBufferedOutputStreamTest.java

示例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();
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:23,代碼來源:CronetBufferedOutputStreamTest.java

示例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();
    }
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:21,代碼來源:UploadDataProvidersTest.java


注:本文中的android.test.suitebuilder.annotation.SmallTest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。