Search in sources :

Example 21 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project android_frameworks_base by crdroidandroid.

the class BitwiseStreamsTest method testThree.

@SmallTest
public void testThree() throws Exception {
    int offset = 4;
    byte[] inBuf = HexDump.hexStringToByteArray("00031040900112488ea794e0");
    BitwiseOutputStream outStream = new BitwiseOutputStream(30);
    outStream.skip(offset);
    for (int i = 0; i < inBuf.length; i++) outStream.write(8, inBuf[i]);
    BitwiseInputStream inStream = new BitwiseInputStream(outStream.toByteArray());
    inStream.skip(offset);
    byte[] inBufDup = new byte[inBuf.length];
    for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte) inStream.read(8);
    assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
}
Also used : BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream) BitwiseInputStream(com.android.internal.util.BitwiseInputStream) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 22 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project android_frameworks_base by crdroidandroid.

the class BitwiseStreamsTest method testFive.

@SmallTest
public void testFive() throws Exception {
    Random random = new Random();
    int iterations = 10000;
    int[] sizeArr = new int[iterations];
    int[] valueArr = new int[iterations];
    BitwiseOutputStream outStream = new BitwiseOutputStream(iterations * 4);
    for (int i = 0; i < iterations; i++) {
        int x = random.nextInt();
        int size = (x & 0x07) + 1;
        int value = x & (-1 >>> (32 - size));
        sizeArr[i] = size;
        valueArr[i] = value;
        outStream.write(size, value);
    }
    BitwiseInputStream inStream = new BitwiseInputStream(outStream.toByteArray());
    for (int i = 0; i < iterations; i++) {
        assertEquals(valueArr[i], inStream.read(sizeArr[i]));
    }
}
Also used : BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream) Random(java.util.Random) BitwiseInputStream(com.android.internal.util.BitwiseInputStream) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 23 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project android_frameworks_opt_telephony by LineageOS.

the class CdmaSmsCbTest method createBearerDataStream.

/**
 * Initialize a BitwiseOutputStream with the CDMA bearer data subparameters except for
 * user data. The caller will append the user data and add it to the parcel.
 * @param messageId the 16-bit message identifier
 * @param priority message priority
 * @param language message language code
 * @return the initialized BitwiseOutputStream
 */
private static BitwiseOutputStream createBearerDataStream(int messageId, int priority, int language) throws BitwiseOutputStream.AccessException {
    BitwiseOutputStream bos = new BitwiseOutputStream(10);
    bos.write(8, SUBPARAM_MESSAGE_IDENTIFIER);
    // length: 3 bytes
    bos.write(8, 3);
    bos.write(4, BearerData.MESSAGE_TYPE_DELIVER);
    bos.write(8, ((messageId >>> 8) & 0xff));
    bos.write(8, (messageId & 0xff));
    // no User Data Header
    bos.write(1, 0);
    // reserved
    bos.write(3, 0);
    if (priority != -1) {
        bos.write(8, SUBPARAM_PRIORITY_INDICATOR);
        // length: 1 byte
        bos.write(8, 1);
        bos.write(2, (priority & 0x03));
        // reserved
        bos.write(6, 0);
    }
    if (language != -1) {
        bos.write(8, SUBPARAM_LANGUAGE_INDICATOR);
        // length: 1 byte
        bos.write(8, 1);
        bos.write(8, (language & 0xff));
    }
    return bos;
}
Also used : BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream)

Example 24 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project android_frameworks_base by ParanoidAndroid.

the class BitwiseStreamsTest method testOne.

@SmallTest
public void testOne() throws Exception {
    int offset = 3;
    byte[] inBuf = HexDump.hexStringToByteArray("FFDD");
    BitwiseOutputStream outStream = new BitwiseOutputStream(30);
    outStream.skip(offset);
    for (int i = 0; i < inBuf.length; i++) outStream.write(8, inBuf[i]);
    byte[] outBuf = outStream.toByteArray();
    BitwiseInputStream inStream = new BitwiseInputStream(outBuf);
    byte[] inBufDup = new byte[inBuf.length];
    inStream.skip(offset);
    for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte) inStream.read(8);
    assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
}
Also used : BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream) BitwiseInputStream(com.android.internal.util.BitwiseInputStream) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 25 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project android_frameworks_base by ParanoidAndroid.

the class BitwiseStreamsTest method testTwo.

@SmallTest
public void testTwo() throws Exception {
    int offset = 3;
    byte[] inBuf = HexDump.hexStringToByteArray("11d4f29c0e9ad3c36e72584e064d9b53");
    BitwiseOutputStream outStream = new BitwiseOutputStream(30);
    outStream.skip(offset);
    for (int i = 0; i < inBuf.length; i++) outStream.write(8, inBuf[i]);
    BitwiseInputStream inStream = new BitwiseInputStream(outStream.toByteArray());
    inStream.skip(offset);
    byte[] inBufDup = new byte[inBuf.length];
    for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte) inStream.read(8);
    assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
}
Also used : BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream) BitwiseInputStream(com.android.internal.util.BitwiseInputStream) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

BitwiseOutputStream (com.android.internal.util.BitwiseOutputStream)50 SmallTest (android.test.suitebuilder.annotation.SmallTest)45 BitwiseInputStream (com.android.internal.util.BitwiseInputStream)42 Random (java.util.Random)13 CdmaSmsMessage (android.hardware.radio.V1_0.CdmaSmsMessage)5 FlakyTest (android.support.test.filters.FlakyTest)3 Test (org.junit.Test)3 CdmaSmsCbProgramData (android.telephony.cdma.CdmaSmsCbProgramData)2 SmsCbMessage (android.telephony.SmsCbMessage)1