Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19ba4be2 authored by David Duarte's avatar David Duarte Committed by Gerrit Code Review
Browse files

Merge "Remove Bluetooth app robolectric tests" into main

parents 838b533e 2e07c253
Loading
Loading
Loading
Loading
+0 −24
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright 2017 The Android Open Source Project

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    coreApp="true"
    package="com.android.bluetooth.robotests">

  <application/>

</manifest>
 No newline at end of file
+0 −2
Original line number Original line Diff line number Diff line
manifest=packages/apps/Bluetooth/tests/robotests/AndroidManifest.xml
sdk=NEWEST_SDK
+0 −102
Original line number Original line Diff line number Diff line
/*
 * Copyright 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.opp;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;

import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;

import java.io.FileInputStream;
import java.io.IOException;

@RunWith(RobolectricTestRunner.class)
public class OppSendFileInfoTest {

    // Constants for test file size.
    private static final int TEST_FILE_SIZE = 10;
    private static final int MAXIMUM_FILE_SIZE = 0xFFFFFFFF;

    @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();

    @Mock private Context mContext;
    @Mock private ContentResolver mContentResolver;
    @Mock private FileInputStream mFileInputStream;

    /**
     * Test a BluetoothOppSendFileInfo generated from a local file (MIME type: text/plain,
     * size: #TEST_FILE_SIZE).
     * Check whether the BluetoothOppSendFileInfo matches the input.
     */
    @Test
    public void testFileOpen() throws IOException {
        Uri uri = Uri.parse("file:///android_asset/opp/OppTestFile.txt");
        doReturn(mContentResolver).when(mContext).getContentResolver();
        doReturn(mFileInputStream).when(mContentResolver).openInputStream(uri);
        doReturn(TEST_FILE_SIZE, -1).when(mFileInputStream).read(any(), eq(0), eq(4096));
        BluetoothOppSendFileInfo sendFileInfo = BluetoothOppSendFileInfo.generateFileInfo(
                mContext, uri, "text/plain", false);
        assertThat(sendFileInfo).isNotEqualTo(BluetoothOppSendFileInfo.SEND_FILE_INFO_ERROR);
        assertThat(sendFileInfo.mFileName).isEqualTo("OppTestFile.txt");
        assertThat(sendFileInfo.mMimetype).isEqualTo("text/plain");
        assertThat(sendFileInfo.mLength).isEqualTo(TEST_FILE_SIZE);
        assertThat(sendFileInfo.mInputStream).isEqualTo(mFileInputStream);
        assertThat(sendFileInfo.mStatus).isEqualTo(0);
    }

    /**
     * Test a BluetoothOppSendFileInfo generated from a web page, which is not supported.
     * Should return an error BluetoothOppSendFileInfo.
     */
    @Test
    public void testInvalidUriScheme() {
        Uri webpage = Uri.parse("http://www.android.com/");
        BluetoothOppSendFileInfo sendFileInfo = BluetoothOppSendFileInfo.generateFileInfo(
                mContext, webpage, "html", false);
        assertThat(sendFileInfo).isEqualTo(BluetoothOppSendFileInfo.SEND_FILE_INFO_ERROR);
    }

    /**
     * Test a BluetoothOppSendFileInfo generated from a big local file (MIME type: text/plain,
     * size: 8GB). It should return an error BluetoothOppSendFileInfo because the maximum size of
     * file supported is #MAXIMUM_FILE_SIZE (4GB).
     */
    @Test
    public void testBigFileOpen() throws IOException {
        Uri uri = Uri.parse("file:///android_asset/opp/OppTestFile.txt");
        doReturn(mContentResolver).when(mContext).getContentResolver();
        doReturn(mFileInputStream).when(mContentResolver).openInputStream(uri);
        doReturn(MAXIMUM_FILE_SIZE, MAXIMUM_FILE_SIZE, -1).when(mFileInputStream).read(any(),
                eq(0), eq(4096));
        BluetoothOppSendFileInfo sendFileInfo = BluetoothOppSendFileInfo.generateFileInfo(
                mContext, uri, "text/plain", false);
        assertThat(sendFileInfo).isEqualTo(BluetoothOppSendFileInfo.SEND_FILE_INFO_ERROR);
    }
}