summaryrefslogtreecommitdiffstats
path: root/tests/LargeAssetTest
diff options
context:
space:
mode:
Diffstat (limited to 'tests/LargeAssetTest')
-rw-r--r--tests/LargeAssetTest/Android.mk11
-rw-r--r--tests/LargeAssetTest/AndroidManifest.xml28
-rw-r--r--tests/LargeAssetTest/assets/million-intsbin0 -> 4000000 bytes
-rw-r--r--tests/LargeAssetTest/res/layout/lat.xml52
-rw-r--r--tests/LargeAssetTest/res/values/strings.xml23
-rw-r--r--tests/LargeAssetTest/src/com/android/largeassettest/LargeAssetTest.java104
6 files changed, 218 insertions, 0 deletions
diff --git a/tests/LargeAssetTest/Android.mk b/tests/LargeAssetTest/Android.mk
new file mode 100644
index 0000000..cb7f01b
--- /dev/null
+++ b/tests/LargeAssetTest/Android.mk
@@ -0,0 +1,11 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := LargeAssetTest
+LOCAL_CERTIFICATE := platform
+
+include $(BUILD_PACKAGE)
diff --git a/tests/LargeAssetTest/AndroidManifest.xml b/tests/LargeAssetTest/AndroidManifest.xml
new file mode 100644
index 0000000..c86118e
--- /dev/null
+++ b/tests/LargeAssetTest/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<!-- Copyright (C) 2010 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"
+ package="com.android.largeassettest">
+
+ <application>
+ <activity android:name="LargeAssetTest" android:label="Large Asset Test">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/tests/LargeAssetTest/assets/million-ints b/tests/LargeAssetTest/assets/million-ints
new file mode 100644
index 0000000..0607de1
--- /dev/null
+++ b/tests/LargeAssetTest/assets/million-ints
Binary files differ
diff --git a/tests/LargeAssetTest/res/layout/lat.xml b/tests/LargeAssetTest/res/layout/lat.xml
new file mode 100644
index 0000000..eda7b82
--- /dev/null
+++ b/tests/LargeAssetTest/res/layout/lat.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ >
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="25dp"
+ android:textColor="#ffffffff"
+ android:text="@string/prompt"
+ />
+
+ <TextView android:id="@+id/result"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_marginTop="25dp"
+ android:textSize="24sp"
+ android:textColor="#ffffffff"
+ />
+
+ <Button android:id="@+id/validate"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/button_text" />
+
+ <TextView
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:layout_weight="1"
+ />
+</LinearLayout>
+
+
diff --git a/tests/LargeAssetTest/res/values/strings.xml b/tests/LargeAssetTest/res/values/strings.xml
new file mode 100644
index 0000000..54478fa
--- /dev/null
+++ b/tests/LargeAssetTest/res/values/strings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 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.
+-->
+
+<resources>
+
+ <string name="prompt">Click the button below to read and validate the large binary asset.</string>
+ <string name="button_text">Validate the asset</string>
+
+</resources>
+
diff --git a/tests/LargeAssetTest/src/com/android/largeassettest/LargeAssetTest.java b/tests/LargeAssetTest/src/com/android/largeassettest/LargeAssetTest.java
new file mode 100644
index 0000000..e3a9cf4
--- /dev/null
+++ b/tests/LargeAssetTest/src/com/android/largeassettest/LargeAssetTest.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2006 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.largeassettest;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.res.AssetManager;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * Skeleton to test large-asset handling. The asset in question is one million
+ * four-byte integers, in ascending numeric order.
+ */
+public class LargeAssetTest extends Activity {
+ Button mValidateButton;
+ TextView mResultText;
+ Validator mValidateThread;
+
+ @Override
+ protected void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ setContentView(R.layout.lat);
+
+ mResultText = (TextView) findViewById(R.id.result);
+ mValidateButton = (Button) findViewById(R.id.validate);
+
+ mValidateButton.setOnClickListener(mClickListener);
+ }
+
+ View.OnClickListener mClickListener = new View.OnClickListener() {
+ public void onClick(View v) {
+ mValidateButton.setEnabled(false);
+ mValidateThread = new Validator();
+ mValidateThread.execute(LargeAssetTest.this.getAssets());
+ }
+ };
+
+ /**
+ * Validation happens in a separate thread
+ */
+ class Validator extends AsyncTask<AssetManager, Integer, Boolean> {
+ static final String TAG = "Validator";
+
+ @Override
+ protected Boolean doInBackground(AssetManager... params) {
+ AssetManager am = params[0];
+ try {
+ InputStream is = am.open("million-ints", AssetManager.ACCESS_STREAMING);
+ byte[] buf = new byte[4];
+
+ for (int i = 0; i < 1000000; i++) {
+ int num = is.read(buf, 0, 4);
+ if (num != 4) {
+ Log.e(TAG, "Wanted 4 bytes but read " + num);
+ return false;
+ }
+ // the byte array is stored in the asset in little-endian order
+ int value = (buf[3] << 24) + ((buf[2] & 0xFF) << 16)
+ + ((buf[1] & 0xFF) << 8) + (buf[0] & 0xFF);
+ if (value != i) {
+ Log.e(TAG, "Mismatch: index " + i + " : value " + value);
+ return false;
+ }
+ }
+
+ is.close();
+ } catch (IOException e) {
+ Log.w(TAG, "Couldn't open asset", e);
+ return false;
+ }
+ Log.i(TAG, "Finished, reporting valid");
+ return true;
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ CharSequence text = (result) ? "Valid!" : "NOT VALID";
+ mResultText.setText(text);
+ mValidateButton.setEnabled(true);
+ }
+ }
+}