Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 17 | package com.android.mtp; |
| 18 | |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 19 | import android.database.Cursor; |
Daichi Hirono | 497b473 | 2016-03-14 14:46:37 +0900 | [diff] [blame] | 20 | import android.media.MediaFile; |
| 21 | import android.media.MediaFile.MediaFileType; |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 22 | import android.mtp.MtpConstants; |
| 23 | import android.mtp.MtpObjectInfo; |
Daichi Hirono | 3bb37e7 | 2016-02-29 15:30:56 +0900 | [diff] [blame] | 24 | import android.net.Uri; |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 25 | import android.provider.DocumentsContract; |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 26 | import android.provider.DocumentsContract.Document; |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 27 | import android.provider.DocumentsContract.Root; |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 28 | import android.test.AndroidTestCase; |
| 29 | import android.test.suitebuilder.annotation.SmallTest; |
| 30 | |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 31 | import java.io.FileNotFoundException; |
Daichi Hirono | 3bb37e7 | 2016-02-29 15:30:56 +0900 | [diff] [blame] | 32 | import java.util.Arrays; |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 33 | |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 34 | import static android.provider.DocumentsContract.Document.*; |
Daichi Hirono | 259ce80 | 2015-11-20 17:51:53 +0900 | [diff] [blame] | 35 | import static com.android.mtp.MtpDatabase.strings; |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 36 | import static com.android.mtp.MtpDatabaseConstants.*; |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 37 | import static com.android.mtp.TestUtil.OPERATIONS_SUPPORTED; |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 38 | |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 39 | @SmallTest |
| 40 | public class MtpDatabaseTest extends AndroidTestCase { |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 41 | private static final String[] COLUMN_NAMES = new String[] { |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 42 | DocumentsContract.Document.COLUMN_DOCUMENT_ID, |
Daichi Hirono | 18d70d5 | 2015-11-13 15:19:47 +0900 | [diff] [blame] | 43 | MtpDatabaseConstants.COLUMN_DEVICE_ID, |
| 44 | MtpDatabaseConstants.COLUMN_STORAGE_ID, |
| 45 | MtpDatabaseConstants.COLUMN_OBJECT_HANDLE, |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 46 | DocumentsContract.Document.COLUMN_MIME_TYPE, |
| 47 | DocumentsContract.Document.COLUMN_DISPLAY_NAME, |
| 48 | DocumentsContract.Document.COLUMN_SUMMARY, |
| 49 | DocumentsContract.Document.COLUMN_LAST_MODIFIED, |
| 50 | DocumentsContract.Document.COLUMN_ICON, |
| 51 | DocumentsContract.Document.COLUMN_FLAGS, |
Daichi Hirono | 4b54e03 | 2015-12-11 15:24:53 +0900 | [diff] [blame] | 52 | DocumentsContract.Document.COLUMN_SIZE, |
| 53 | MtpDatabaseConstants.COLUMN_DOCUMENT_TYPE |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 54 | }; |
| 55 | |
Daichi Hirono | 85a808b | 2015-10-27 17:22:13 +0900 | [diff] [blame] | 56 | private final TestResources resources = new TestResources(); |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 57 | MtpDatabase mDatabase; |
| 58 | |
| 59 | @Override |
| 60 | public void setUp() { |
Daichi Hirono | 47eb192 | 2015-11-16 13:01:31 +0900 | [diff] [blame] | 61 | mDatabase = new MtpDatabase(getContext(), MtpDatabaseConstants.FLAG_DATABASE_IN_MEMORY); |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public void tearDown() { |
| 66 | mDatabase.close(); |
| 67 | mDatabase = null; |
| 68 | } |
Daichi Hirono | 85a808b | 2015-10-27 17:22:13 +0900 | [diff] [blame] | 69 | |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 70 | private static int getInt(Cursor cursor, String columnName) { |
| 71 | return cursor.getInt(cursor.getColumnIndex(columnName)); |
| 72 | } |
| 73 | |
| 74 | private static boolean isNull(Cursor cursor, String columnName) { |
| 75 | return cursor.isNull(cursor.getColumnIndex(columnName)); |
| 76 | } |
| 77 | |
| 78 | private static String getString(Cursor cursor, String columnName) { |
| 79 | return cursor.getString(cursor.getColumnIndex(columnName)); |
| 80 | } |
| 81 | |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 82 | public void testPutSingleStorageDocuments() throws Exception { |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 83 | addTestDevice(); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 84 | |
| 85 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 86 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 87 | new MtpRoot(0, 1, "Storage", 1000, 2000, "") |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 88 | }); |
| 89 | mDatabase.getMapper().stopAddingDocuments("1"); |
| 90 | |
| 91 | { |
| 92 | final Cursor cursor = mDatabase.queryRootDocuments(COLUMN_NAMES); |
| 93 | assertEquals(1, cursor.getCount()); |
| 94 | |
| 95 | cursor.moveToNext(); |
| 96 | assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); |
| 97 | assertEquals(0, getInt(cursor, COLUMN_DEVICE_ID)); |
| 98 | assertEquals(1, getInt(cursor, COLUMN_STORAGE_ID)); |
| 99 | assertTrue(isNull(cursor, COLUMN_OBJECT_HANDLE)); |
Daichi Hirono | 8e87364 | 2016-02-07 15:17:16 +0900 | [diff] [blame] | 100 | assertEquals( |
| 101 | DocumentsContract.Document.MIME_TYPE_DIR, getString(cursor, COLUMN_MIME_TYPE)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 102 | assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 103 | assertTrue(isNull(cursor, COLUMN_SUMMARY)); |
| 104 | assertTrue(isNull(cursor, COLUMN_LAST_MODIFIED)); |
| 105 | assertEquals(R.drawable.ic_root_mtp, getInt(cursor, COLUMN_ICON)); |
Daichi Hirono | b3383fd | 2016-03-18 15:25:00 +0900 | [diff] [blame] | 106 | assertEquals(Document.FLAG_DIR_SUPPORTS_CREATE, getInt(cursor, COLUMN_FLAGS)); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 107 | assertEquals(1000, getInt(cursor, COLUMN_SIZE)); |
| 108 | assertEquals( |
Daichi Hirono | 8e87364 | 2016-02-07 15:17:16 +0900 | [diff] [blame] | 109 | MtpDatabaseConstants.DOCUMENT_TYPE_STORAGE, |
| 110 | getInt(cursor, COLUMN_DOCUMENT_TYPE)); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 111 | |
| 112 | cursor.close(); |
| 113 | } |
| 114 | |
| 115 | { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 116 | final Cursor cursor = mDatabase.queryRoots(resources, new String [] { |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 117 | Root.COLUMN_ROOT_ID, |
| 118 | Root.COLUMN_FLAGS, |
| 119 | Root.COLUMN_ICON, |
| 120 | Root.COLUMN_TITLE, |
| 121 | Root.COLUMN_SUMMARY, |
| 122 | Root.COLUMN_DOCUMENT_ID, |
| 123 | Root.COLUMN_AVAILABLE_BYTES, |
| 124 | Root.COLUMN_CAPACITY_BYTES |
| 125 | }); |
| 126 | assertEquals(1, cursor.getCount()); |
| 127 | |
| 128 | cursor.moveToNext(); |
Daichi Hirono | 6a5ea7e | 2016-02-02 16:35:03 +0900 | [diff] [blame] | 129 | assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID)); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 130 | assertEquals( |
Daichi Hirono | 83c679e7 | 2016-08-18 15:13:36 +0900 | [diff] [blame] | 131 | Root.FLAG_SUPPORTS_IS_CHILD | Root.FLAG_SUPPORTS_CREATE | Root.FLAG_LOCAL_ONLY, |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 132 | getInt(cursor, Root.COLUMN_FLAGS)); |
| 133 | assertEquals(R.drawable.ic_root_mtp, getInt(cursor, Root.COLUMN_ICON)); |
| 134 | assertEquals("Device Storage", getString(cursor, Root.COLUMN_TITLE)); |
| 135 | assertTrue(isNull(cursor, Root.COLUMN_SUMMARY)); |
Daichi Hirono | 6a5ea7e | 2016-02-02 16:35:03 +0900 | [diff] [blame] | 136 | assertEquals(1, getInt(cursor, Root.COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 137 | assertEquals(1000, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES)); |
| 138 | assertEquals(2000, getInt(cursor, Root.COLUMN_CAPACITY_BYTES)); |
| 139 | |
| 140 | cursor.close(); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | public void testPutStorageDocuments() throws Exception { |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 145 | addTestDevice(); |
| 146 | |
| 147 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 148 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 149 | new MtpRoot(0, 1, "Storage", 1000, 2000, ""), |
| 150 | new MtpRoot(0, 2, "Storage", 2000, 4000, ""), |
| 151 | new MtpRoot(0, 3, "/@#%&<>Storage", 3000, 6000,"") |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 152 | }); |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 153 | |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 154 | { |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 155 | final Cursor cursor = mDatabase.queryRootDocuments(COLUMN_NAMES); |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 156 | assertEquals(3, cursor.getCount()); |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 157 | |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 158 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 159 | assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 160 | assertEquals(0, getInt(cursor, COLUMN_DEVICE_ID)); |
| 161 | assertEquals(1, getInt(cursor, COLUMN_STORAGE_ID)); |
| 162 | assertTrue(isNull(cursor, COLUMN_OBJECT_HANDLE)); |
| 163 | assertEquals(DocumentsContract.Document.MIME_TYPE_DIR, getString(cursor, COLUMN_MIME_TYPE)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 164 | assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 165 | assertTrue(isNull(cursor, COLUMN_SUMMARY)); |
| 166 | assertTrue(isNull(cursor, COLUMN_LAST_MODIFIED)); |
| 167 | assertEquals(R.drawable.ic_root_mtp, getInt(cursor, COLUMN_ICON)); |
Daichi Hirono | b3383fd | 2016-03-18 15:25:00 +0900 | [diff] [blame] | 168 | assertEquals(Document.FLAG_DIR_SUPPORTS_CREATE, getInt(cursor, COLUMN_FLAGS)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 169 | assertEquals(1000, getInt(cursor, COLUMN_SIZE)); |
Daichi Hirono | 4b54e03 | 2015-12-11 15:24:53 +0900 | [diff] [blame] | 170 | assertEquals( |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 171 | MtpDatabaseConstants.DOCUMENT_TYPE_STORAGE, getInt(cursor, COLUMN_DOCUMENT_TYPE)); |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 172 | |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 173 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 174 | assertEquals(3, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 175 | assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 176 | |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 177 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 178 | assertEquals(4, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 179 | assertEquals("/@#%&<>Storage", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 88d2f78 | 2015-10-27 16:41:06 +0900 | [diff] [blame] | 180 | |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 181 | cursor.close(); |
| 182 | } |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 183 | } |
| 184 | |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 185 | private MtpObjectInfo createDocument(int objectHandle, String name, int format, int size) { |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 186 | final MtpObjectInfo.Builder builder = new MtpObjectInfo.Builder(); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 187 | builder.setObjectHandle(objectHandle); |
| 188 | builder.setName(name); |
| 189 | builder.setFormat(format); |
| 190 | builder.setCompressedSize(size); |
| 191 | return builder.build(); |
| 192 | } |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 193 | |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 194 | public void testPutChildDocuments() throws Exception { |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 195 | addTestDevice(); |
| 196 | addTestStorage("1"); |
| 197 | |
| 198 | mDatabase.getMapper().startAddingDocuments("2"); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 199 | mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 200 | createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024), |
| 201 | createDocument(101, "image.jpg", MtpConstants.FORMAT_EXIF_JPEG, 2 * 1024 * 1024), |
| 202 | createDocument(102, "music.mp3", MtpConstants.FORMAT_MP3, 3 * 1024 * 1024) |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 203 | }, new long[] { 1024L, 2L * 1024L * 1024L, 3L * 1024L * 1024L}); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 204 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 205 | final Cursor cursor = mDatabase.queryChildDocuments(COLUMN_NAMES, "2"); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 206 | assertEquals(3, cursor.getCount()); |
| 207 | |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 208 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 209 | assertEquals(3, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 210 | assertEquals(0, getInt(cursor, COLUMN_DEVICE_ID)); |
| 211 | assertEquals(0, getInt(cursor, COLUMN_STORAGE_ID)); |
| 212 | assertEquals(100, getInt(cursor, COLUMN_OBJECT_HANDLE)); |
| 213 | assertEquals("text/plain", getString(cursor, COLUMN_MIME_TYPE)); |
| 214 | assertEquals("note.txt", getString(cursor, COLUMN_DISPLAY_NAME)); |
| 215 | assertTrue(isNull(cursor, COLUMN_SUMMARY)); |
| 216 | assertTrue(isNull(cursor, COLUMN_LAST_MODIFIED)); |
| 217 | assertTrue(isNull(cursor, COLUMN_ICON)); |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 218 | assertEquals( |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 219 | COLUMN_FLAGS, |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 220 | DocumentsContract.Document.FLAG_SUPPORTS_DELETE | |
| 221 | DocumentsContract.Document.FLAG_SUPPORTS_WRITE, |
Daichi Hirono | 88d2f78 | 2015-10-27 16:41:06 +0900 | [diff] [blame] | 222 | cursor.getInt(9)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 223 | assertEquals(1024, getInt(cursor, COLUMN_SIZE)); |
Daichi Hirono | 4b54e03 | 2015-12-11 15:24:53 +0900 | [diff] [blame] | 224 | assertEquals( |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 225 | MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT, getInt(cursor, COLUMN_DOCUMENT_TYPE)); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 226 | |
| 227 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 228 | assertEquals(4, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 229 | assertEquals(0, getInt(cursor, COLUMN_DEVICE_ID)); |
| 230 | assertEquals(0, getInt(cursor, COLUMN_STORAGE_ID)); |
| 231 | assertEquals(101, getInt(cursor, COLUMN_OBJECT_HANDLE)); |
| 232 | assertEquals("image/jpeg", getString(cursor, COLUMN_MIME_TYPE)); |
| 233 | assertEquals("image.jpg", getString(cursor, COLUMN_DISPLAY_NAME)); |
| 234 | assertTrue(isNull(cursor, COLUMN_SUMMARY)); |
| 235 | assertTrue(isNull(cursor, COLUMN_LAST_MODIFIED)); |
| 236 | assertTrue(isNull(cursor, COLUMN_ICON)); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 237 | assertEquals( |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 238 | COLUMN_FLAGS, |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 239 | DocumentsContract.Document.FLAG_SUPPORTS_DELETE | |
| 240 | DocumentsContract.Document.FLAG_SUPPORTS_WRITE, |
| 241 | cursor.getInt(9)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 242 | assertEquals(2 * 1024 * 1024, getInt(cursor, COLUMN_SIZE)); |
Daichi Hirono | 4b54e03 | 2015-12-11 15:24:53 +0900 | [diff] [blame] | 243 | assertEquals( |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 244 | MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT, getInt(cursor, COLUMN_DOCUMENT_TYPE)); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 245 | |
| 246 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 247 | assertEquals(5, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 248 | assertEquals(0, getInt(cursor, COLUMN_DEVICE_ID)); |
| 249 | assertEquals(0, getInt(cursor, COLUMN_STORAGE_ID)); |
| 250 | assertEquals(102, getInt(cursor, COLUMN_OBJECT_HANDLE)); |
| 251 | assertEquals("audio/mpeg", getString(cursor, COLUMN_MIME_TYPE)); |
| 252 | assertEquals("music.mp3", getString(cursor, COLUMN_DISPLAY_NAME)); |
| 253 | assertTrue(isNull(cursor, COLUMN_SUMMARY)); |
| 254 | assertTrue(isNull(cursor, COLUMN_LAST_MODIFIED)); |
| 255 | assertTrue(isNull(cursor, COLUMN_ICON)); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 256 | assertEquals( |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 257 | COLUMN_FLAGS, |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 258 | DocumentsContract.Document.FLAG_SUPPORTS_DELETE | |
| 259 | DocumentsContract.Document.FLAG_SUPPORTS_WRITE, |
| 260 | cursor.getInt(9)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 261 | assertEquals(3 * 1024 * 1024, getInt(cursor, COLUMN_SIZE)); |
Daichi Hirono | 4b54e03 | 2015-12-11 15:24:53 +0900 | [diff] [blame] | 262 | assertEquals( |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 263 | MtpDatabaseConstants.DOCUMENT_TYPE_OBJECT, getInt(cursor, COLUMN_DOCUMENT_TYPE)); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 264 | |
| 265 | cursor.close(); |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 266 | } |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 267 | |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 268 | public void testPutChildDocuments_operationsSupported() throws Exception { |
| 269 | addTestDevice(); |
| 270 | addTestStorage("1"); |
| 271 | |
| 272 | // Put a document with empty supported operations. |
| 273 | mDatabase.getMapper().startAddingDocuments("2"); |
| 274 | mDatabase.getMapper().putChildDocuments(0, "2", new int[0], new MtpObjectInfo[] { |
| 275 | createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024) |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 276 | }, new long[] { 1024L }); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 277 | mDatabase.getMapper().stopAddingDocuments("2"); |
| 278 | |
| 279 | try (final Cursor cursor = |
| 280 | mDatabase.queryChildDocuments(strings(Document.COLUMN_FLAGS), "2")) { |
| 281 | assertEquals(1, cursor.getCount()); |
| 282 | cursor.moveToNext(); |
| 283 | assertEquals(0, cursor.getInt(0)); |
| 284 | } |
| 285 | |
| 286 | // Put a document with writable operations. |
| 287 | mDatabase.getMapper().startAddingDocuments("2"); |
| 288 | mDatabase.getMapper().putChildDocuments(0, "2", new int[] { |
| 289 | MtpConstants.OPERATION_SEND_OBJECT, |
| 290 | MtpConstants.OPERATION_SEND_OBJECT_INFO, |
| 291 | }, new MtpObjectInfo[] { |
| 292 | createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024) |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 293 | }, new long[] { 1024L }); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 294 | mDatabase.getMapper().stopAddingDocuments("2"); |
| 295 | |
| 296 | try (final Cursor cursor = |
| 297 | mDatabase.queryChildDocuments(strings(Document.COLUMN_FLAGS), "2")) { |
| 298 | assertEquals(1, cursor.getCount()); |
| 299 | cursor.moveToNext(); |
| 300 | assertEquals(Document.FLAG_SUPPORTS_WRITE, cursor.getInt(0)); |
| 301 | } |
| 302 | |
| 303 | // Put a document with deletable operations. |
| 304 | mDatabase.getMapper().startAddingDocuments("2"); |
| 305 | mDatabase.getMapper().putChildDocuments(0, "2", new int[] { |
| 306 | MtpConstants.OPERATION_DELETE_OBJECT |
| 307 | }, new MtpObjectInfo[] { |
| 308 | createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024) |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 309 | }, new long[] { 1024L }); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 310 | mDatabase.getMapper().stopAddingDocuments("2"); |
| 311 | |
| 312 | try (final Cursor cursor = |
| 313 | mDatabase.queryChildDocuments(strings(Document.COLUMN_FLAGS), "2")) { |
| 314 | assertEquals(1, cursor.getCount()); |
| 315 | cursor.moveToNext(); |
| 316 | assertEquals(Document.FLAG_SUPPORTS_DELETE, cursor.getInt(0)); |
| 317 | } |
| 318 | } |
| 319 | |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 320 | public void testRestoreIdForRootDocuments() throws Exception { |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 321 | final String[] columns = new String[] { |
| 322 | DocumentsContract.Document.COLUMN_DOCUMENT_ID, |
Daichi Hirono | 18d70d5 | 2015-11-13 15:19:47 +0900 | [diff] [blame] | 323 | MtpDatabaseConstants.COLUMN_STORAGE_ID, |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 324 | DocumentsContract.Document.COLUMN_DISPLAY_NAME |
| 325 | }; |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 326 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 327 | // Add device and two storages. |
| 328 | addTestDevice(); |
| 329 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 330 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 331 | new MtpRoot(0, 100, "Storage A", 1000, 0, ""), |
| 332 | new MtpRoot(0, 101, "Storage B", 1001, 0, "") |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 333 | }); |
| 334 | |
| 335 | { |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 336 | final Cursor cursor = mDatabase.queryRootDocuments(columns); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 337 | assertEquals(2, cursor.getCount()); |
| 338 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 339 | assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 340 | assertEquals(100, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 341 | assertEquals("Storage A", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 342 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 343 | assertEquals(3, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 344 | assertEquals(101, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 345 | assertEquals("Storage B", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 346 | cursor.close(); |
| 347 | } |
| 348 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 349 | // Clear mapping and add a device. |
Daichi Hirono | 259ce80 | 2015-11-20 17:51:53 +0900 | [diff] [blame] | 350 | mDatabase.getMapper().clearMapping(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 351 | addTestDevice(); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 352 | |
| 353 | { |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 354 | final Cursor cursor = mDatabase.queryRootDocuments(columns); |
Daichi Hirono | 8e87364 | 2016-02-07 15:17:16 +0900 | [diff] [blame] | 355 | assertEquals(0, cursor.getCount()); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 356 | cursor.close(); |
| 357 | } |
| 358 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 359 | // Add two storages, but one's name is different from previous one. |
| 360 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 361 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 362 | new MtpRoot(0, 200, "Storage A", 2000, 0, ""), |
| 363 | new MtpRoot(0, 202, "Storage C", 2002, 0, "") |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 364 | }); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 365 | mDatabase.getMapper().stopAddingDocuments("1"); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 366 | |
| 367 | { |
Daichi Hirono | 8e87364 | 2016-02-07 15:17:16 +0900 | [diff] [blame] | 368 | // After compeleting mapping, Storage A can be obtained with new storage ID. |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 369 | final Cursor cursor = mDatabase.queryRootDocuments(columns); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 370 | assertEquals(2, cursor.getCount()); |
| 371 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 372 | assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 373 | assertEquals(200, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 374 | assertEquals("Storage A", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 375 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 376 | assertEquals(4, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 377 | assertEquals(202, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 378 | assertEquals("Storage C", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 379 | cursor.close(); |
| 380 | } |
| 381 | } |
| 382 | |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 383 | public void testRestoreIdForChildDocuments() throws Exception { |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 384 | final String[] columns = new String[] { |
| 385 | DocumentsContract.Document.COLUMN_DOCUMENT_ID, |
Daichi Hirono | 18d70d5 | 2015-11-13 15:19:47 +0900 | [diff] [blame] | 386 | MtpDatabaseConstants.COLUMN_OBJECT_HANDLE, |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 387 | DocumentsContract.Document.COLUMN_DISPLAY_NAME |
| 388 | }; |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 389 | |
| 390 | addTestDevice(); |
| 391 | addTestStorage("1"); |
| 392 | |
| 393 | mDatabase.getMapper().startAddingDocuments("2"); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 394 | mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 395 | createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024), |
| 396 | createDocument(101, "image.jpg", MtpConstants.FORMAT_EXIF_JPEG, 2 * 1024 * 1024), |
| 397 | createDocument(102, "music.mp3", MtpConstants.FORMAT_MP3, 3 * 1024 * 1024) |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 398 | }, new long[] { 1024L, 2L * 1024L * 1024L, 3L * 1024L * 1024L}); |
Daichi Hirono | 259ce80 | 2015-11-20 17:51:53 +0900 | [diff] [blame] | 399 | mDatabase.getMapper().clearMapping(); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 400 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 401 | addTestDevice(); |
| 402 | addTestStorage("1"); |
| 403 | |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 404 | { |
Daichi Hirono | 8e87364 | 2016-02-07 15:17:16 +0900 | [diff] [blame] | 405 | // Don't return objects that lost MTP object handles. |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 406 | final Cursor cursor = mDatabase.queryChildDocuments(columns, "2"); |
Daichi Hirono | 8e87364 | 2016-02-07 15:17:16 +0900 | [diff] [blame] | 407 | assertEquals(0, cursor.getCount()); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 408 | cursor.close(); |
| 409 | } |
| 410 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 411 | mDatabase.getMapper().startAddingDocuments("2"); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 412 | mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 413 | createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024), |
| 414 | createDocument(203, "video.mp4", MtpConstants.FORMAT_MP4_CONTAINER, 1024), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 415 | }, new long[] { 1024L, 1024L }); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 416 | mDatabase.getMapper().stopAddingDocuments("2"); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 417 | |
| 418 | { |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 419 | final Cursor cursor = mDatabase.queryChildDocuments(columns, "2"); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 420 | assertEquals(2, cursor.getCount()); |
| 421 | |
| 422 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 423 | assertEquals(3, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 424 | assertEquals(200, getInt(cursor, COLUMN_OBJECT_HANDLE)); |
| 425 | assertEquals("note.txt", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 426 | |
| 427 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 428 | assertEquals(6, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 429 | assertEquals(203, getInt(cursor, COLUMN_OBJECT_HANDLE)); |
| 430 | assertEquals("video.mp4", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 431 | |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 432 | cursor.close(); |
| 433 | } |
| 434 | } |
| 435 | |
Daichi Hirono | b3fe72b | 2015-12-15 07:45:06 +0000 | [diff] [blame] | 436 | public void testRestoreIdForDifferentDevices() throws Exception { |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 437 | final String[] columns = new String[] { |
| 438 | DocumentsContract.Document.COLUMN_DOCUMENT_ID, |
Daichi Hirono | 18d70d5 | 2015-11-13 15:19:47 +0900 | [diff] [blame] | 439 | MtpDatabaseConstants.COLUMN_STORAGE_ID, |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 440 | DocumentsContract.Document.COLUMN_DISPLAY_NAME |
| 441 | }; |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 442 | final String[] rootColumns = new String[] { |
| 443 | Root.COLUMN_ROOT_ID, |
| 444 | Root.COLUMN_AVAILABLE_BYTES |
| 445 | }; |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 446 | mDatabase.getMapper().startAddingDocuments(null); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 447 | mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord( |
Daichi Hirono | ebd2405 | 2016-02-06 21:05:57 +0900 | [diff] [blame] | 448 | 0, "Device A", "Device key A", true, new MtpRoot[0], null, null)); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 449 | mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord( |
Daichi Hirono | ebd2405 | 2016-02-06 21:05:57 +0900 | [diff] [blame] | 450 | 1, "Device B", "Device key B", true, new MtpRoot[0], null, null)); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 451 | mDatabase.getMapper().stopAddingDocuments(null); |
| 452 | |
| 453 | mDatabase.getMapper().startAddingDocuments("1"); |
| 454 | mDatabase.getMapper().startAddingDocuments("2"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 455 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 456 | new MtpRoot(0, 100, "Storage", 0, 0, "") |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 457 | }); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 458 | mDatabase.getMapper().putStorageDocuments("2", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 459 | new MtpRoot(1, 100, "Storage", 0, 0, "") |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 460 | }); |
| 461 | |
| 462 | { |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 463 | final Cursor cursor = mDatabase.queryRootDocuments(columns); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 464 | assertEquals(2, cursor.getCount()); |
| 465 | cursor.moveToNext(); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 466 | assertEquals(3, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 467 | assertEquals(100, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 468 | assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 469 | cursor.moveToNext(); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 470 | assertEquals(4, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 471 | assertEquals(100, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 472 | assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 473 | cursor.close(); |
| 474 | } |
| 475 | |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 476 | { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 477 | final Cursor cursor = mDatabase.queryRoots(resources, rootColumns); |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 478 | assertEquals(2, cursor.getCount()); |
| 479 | cursor.moveToNext(); |
Daichi Hirono | 6a5ea7e | 2016-02-02 16:35:03 +0900 | [diff] [blame] | 480 | assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 481 | assertEquals(0, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES)); |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 482 | cursor.moveToNext(); |
Daichi Hirono | 6a5ea7e | 2016-02-02 16:35:03 +0900 | [diff] [blame] | 483 | assertEquals(2, getInt(cursor, Root.COLUMN_ROOT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 484 | assertEquals(0, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES)); |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 485 | cursor.close(); |
| 486 | } |
| 487 | |
Daichi Hirono | 259ce80 | 2015-11-20 17:51:53 +0900 | [diff] [blame] | 488 | mDatabase.getMapper().clearMapping(); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 489 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 490 | mDatabase.getMapper().startAddingDocuments(null); |
| 491 | mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord( |
Daichi Hirono | ebd2405 | 2016-02-06 21:05:57 +0900 | [diff] [blame] | 492 | 0, "Device A", "Device key A", true, new MtpRoot[0], null, null)); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 493 | mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord( |
Daichi Hirono | ebd2405 | 2016-02-06 21:05:57 +0900 | [diff] [blame] | 494 | 1, "Device B", "Device key B", true, new MtpRoot[0], null, null)); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 495 | mDatabase.getMapper().stopAddingDocuments(null); |
| 496 | |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 497 | mDatabase.getMapper().startAddingDocuments("1"); |
| 498 | mDatabase.getMapper().startAddingDocuments("2"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 499 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 500 | new MtpRoot(0, 200, "Storage", 2000, 0, "") |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 501 | }); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 502 | mDatabase.getMapper().putStorageDocuments("2", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 503 | new MtpRoot(1, 300, "Storage", 3000, 0, "") |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 504 | }); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 505 | mDatabase.getMapper().stopAddingDocuments("1"); |
| 506 | mDatabase.getMapper().stopAddingDocuments("2"); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 507 | |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 508 | { |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 509 | final Cursor cursor = mDatabase.queryRootDocuments(columns); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 510 | assertEquals(2, cursor.getCount()); |
| 511 | cursor.moveToNext(); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 512 | assertEquals(3, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 513 | assertEquals(200, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 514 | assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 515 | cursor.moveToNext(); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 516 | assertEquals(4, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 517 | assertEquals(300, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 518 | assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 519 | cursor.close(); |
| 520 | } |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 521 | |
| 522 | { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 523 | final Cursor cursor = mDatabase.queryRoots(resources, rootColumns); |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 524 | assertEquals(2, cursor.getCount()); |
| 525 | cursor.moveToNext(); |
Daichi Hirono | 6a5ea7e | 2016-02-02 16:35:03 +0900 | [diff] [blame] | 526 | assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 527 | assertEquals(2000, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES)); |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 528 | cursor.moveToNext(); |
Daichi Hirono | 6a5ea7e | 2016-02-02 16:35:03 +0900 | [diff] [blame] | 529 | assertEquals(2, getInt(cursor, Root.COLUMN_ROOT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 530 | assertEquals(3000, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES)); |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 531 | cursor.close(); |
| 532 | } |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 533 | } |
| 534 | |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 535 | public void testRestoreIdForDifferentParents() throws Exception { |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 536 | final String[] columns = new String[] { |
| 537 | DocumentsContract.Document.COLUMN_DOCUMENT_ID, |
Daichi Hirono | 18d70d5 | 2015-11-13 15:19:47 +0900 | [diff] [blame] | 538 | MtpDatabaseConstants.COLUMN_OBJECT_HANDLE |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 539 | }; |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 540 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 541 | // Add device, storage, and two directories. |
| 542 | addTestDevice(); |
| 543 | addTestStorage("1"); |
| 544 | mDatabase.getMapper().startAddingDocuments("2"); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 545 | mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 546 | createDocument(50, "A", MtpConstants.FORMAT_ASSOCIATION, 0), |
| 547 | createDocument(51, "B", MtpConstants.FORMAT_ASSOCIATION, 0), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 548 | }, new long[] { 0L, 0L }); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 549 | mDatabase.getMapper().stopAddingDocuments("2"); |
| 550 | |
| 551 | // Put note.txt in each directory. |
| 552 | mDatabase.getMapper().startAddingDocuments("3"); |
| 553 | mDatabase.getMapper().startAddingDocuments("4"); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 554 | mDatabase.getMapper().putChildDocuments(0, "3", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 555 | createDocument(100, "note.txt", MtpConstants.FORMAT_TEXT, 1024), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 556 | }, new long[] { 1024L }); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 557 | mDatabase.getMapper().putChildDocuments(0, "4", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 558 | createDocument(101, "note.txt", MtpConstants.FORMAT_TEXT, 1024), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 559 | }, new long[] { 1024L }); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 560 | |
| 561 | // Clear mapping. |
Daichi Hirono | 259ce80 | 2015-11-20 17:51:53 +0900 | [diff] [blame] | 562 | mDatabase.getMapper().clearMapping(); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 563 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 564 | // Add device, storage, and two directories again. |
| 565 | addTestDevice(); |
| 566 | addTestStorage("1"); |
| 567 | mDatabase.getMapper().startAddingDocuments("2"); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 568 | mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 569 | createDocument(50, "A", MtpConstants.FORMAT_ASSOCIATION, 0), |
| 570 | createDocument(51, "B", MtpConstants.FORMAT_ASSOCIATION, 0), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 571 | }, new long[] { 0L, 0L }); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 572 | mDatabase.getMapper().stopAddingDocuments("2"); |
| 573 | |
| 574 | // Add note.txt in each directory again. |
| 575 | mDatabase.getMapper().startAddingDocuments("3"); |
| 576 | mDatabase.getMapper().startAddingDocuments("4"); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 577 | mDatabase.getMapper().putChildDocuments(0, "3", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 578 | createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 579 | }, new long[] { 1024L }); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 580 | mDatabase.getMapper().putChildDocuments(0, "4", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 581 | createDocument(201, "note.txt", MtpConstants.FORMAT_TEXT, 1024), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 582 | }, new long[] { 1024L }); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 583 | mDatabase.getMapper().stopAddingDocuments("3"); |
| 584 | mDatabase.getMapper().stopAddingDocuments("4"); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 585 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 586 | // Check if the two note.txt are mapped correctly. |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 587 | { |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 588 | final Cursor cursor = mDatabase.queryChildDocuments(columns, "3"); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 589 | assertEquals(1, cursor.getCount()); |
| 590 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 591 | assertEquals(5, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 592 | assertEquals(200, getInt(cursor, COLUMN_OBJECT_HANDLE)); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 593 | cursor.close(); |
| 594 | } |
| 595 | { |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 596 | final Cursor cursor = mDatabase.queryChildDocuments(columns, "4"); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 597 | assertEquals(1, cursor.getCount()); |
| 598 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 599 | assertEquals(6, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9fca541 | 2016-02-07 13:20:22 +0900 | [diff] [blame] | 600 | assertEquals(201, getInt(cursor, COLUMN_OBJECT_HANDLE)); |
Daichi Hirono | a8a3722e | 2015-10-26 16:39:54 +0900 | [diff] [blame] | 601 | cursor.close(); |
| 602 | } |
| 603 | } |
| 604 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 605 | public void testClearMtpIdentifierBeforeResolveRootDocuments() throws Exception { |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 606 | final String[] columns = new String[] { |
| 607 | DocumentsContract.Document.COLUMN_DOCUMENT_ID, |
Daichi Hirono | 18d70d5 | 2015-11-13 15:19:47 +0900 | [diff] [blame] | 608 | MtpDatabaseConstants.COLUMN_STORAGE_ID, |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 609 | DocumentsContract.Document.COLUMN_DISPLAY_NAME |
| 610 | }; |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 611 | final String[] rootColumns = new String[] { |
| 612 | Root.COLUMN_ROOT_ID, |
| 613 | Root.COLUMN_AVAILABLE_BYTES |
| 614 | }; |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 615 | |
Daichi Hirono | 8e87364 | 2016-02-07 15:17:16 +0900 | [diff] [blame] | 616 | addTestDevice(); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 617 | |
| 618 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 619 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 620 | new MtpRoot(0, 100, "Storage", 0, 0, ""), |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 621 | }); |
Daichi Hirono | 259ce80 | 2015-11-20 17:51:53 +0900 | [diff] [blame] | 622 | mDatabase.getMapper().clearMapping(); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 623 | |
Daichi Hirono | ebd2405 | 2016-02-06 21:05:57 +0900 | [diff] [blame] | 624 | addTestDevice(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 625 | |
| 626 | try (final Cursor cursor = mDatabase.queryRoots(resources, rootColumns)) { |
| 627 | assertEquals(1, cursor.getCount()); |
| 628 | cursor.moveToNext(); |
| 629 | assertEquals("1", getString(cursor, Root.COLUMN_ROOT_ID)); |
| 630 | } |
| 631 | |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 632 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 633 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 634 | new MtpRoot(0, 200, "Storage", 2000, 0, ""), |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 635 | }); |
Daichi Hirono | 259ce80 | 2015-11-20 17:51:53 +0900 | [diff] [blame] | 636 | mDatabase.getMapper().clearMapping(); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 637 | |
Daichi Hirono | ebd2405 | 2016-02-06 21:05:57 +0900 | [diff] [blame] | 638 | addTestDevice(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 639 | |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 640 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 641 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 642 | new MtpRoot(0, 300, "Storage", 3000, 0, ""), |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 643 | }); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 644 | mDatabase.getMapper().stopAddingDocuments("1"); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 645 | |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 646 | { |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 647 | final Cursor cursor = mDatabase.queryRootDocuments(columns); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 648 | assertEquals(1, cursor.getCount()); |
| 649 | cursor.moveToNext(); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 650 | assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 651 | assertEquals(300, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 652 | assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 653 | cursor.close(); |
| 654 | } |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 655 | { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 656 | final Cursor cursor = mDatabase.queryRoots(resources, rootColumns); |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 657 | assertEquals(1, cursor.getCount()); |
| 658 | cursor.moveToNext(); |
Daichi Hirono | 6a5ea7e | 2016-02-02 16:35:03 +0900 | [diff] [blame] | 659 | assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 660 | assertEquals(3000, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES)); |
Daichi Hirono | 0378da4 | 2015-11-05 11:56:12 +0900 | [diff] [blame] | 661 | cursor.close(); |
| 662 | } |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | public void testPutSameNameRootsAfterClearing() throws Exception { |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 666 | final String[] columns = new String[] { |
| 667 | DocumentsContract.Document.COLUMN_DOCUMENT_ID, |
Daichi Hirono | 18d70d5 | 2015-11-13 15:19:47 +0900 | [diff] [blame] | 668 | MtpDatabaseConstants.COLUMN_STORAGE_ID, |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 669 | DocumentsContract.Document.COLUMN_DISPLAY_NAME |
| 670 | }; |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 671 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 672 | // Add a device and a storage. |
| 673 | addTestDevice(); |
| 674 | addTestStorage("1"); |
| 675 | |
| 676 | // Disconnect devices. |
Daichi Hirono | 259ce80 | 2015-11-20 17:51:53 +0900 | [diff] [blame] | 677 | mDatabase.getMapper().clearMapping(); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 678 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 679 | // Add a device and two storages that has same name. |
| 680 | addTestDevice(); |
| 681 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 682 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 683 | new MtpRoot(0, 200, "Storage", 2000, 0, ""), |
| 684 | new MtpRoot(0, 201, "Storage", 2001, 0, ""), |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 685 | }); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 686 | mDatabase.getMapper().stopAddingDocuments("1"); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 687 | |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 688 | { |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 689 | final Cursor cursor = mDatabase.queryRootDocuments(columns); |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 690 | assertEquals(2, cursor.getCount()); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 691 | |
| 692 | // First storage reuse document ID of previous storage. |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 693 | cursor.moveToNext(); |
Daichi Hirono | 9fca541 | 2016-02-07 13:20:22 +0900 | [diff] [blame] | 694 | // One reuses exisitng document ID 1. |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 695 | assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 696 | assertEquals(200, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 697 | assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 698 | |
| 699 | // Second one has new document ID. |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 700 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 701 | assertEquals(3, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 702 | assertEquals(201, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 703 | assertEquals("Storage", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 704 | |
Daichi Hirono | 6de8a0e | 2015-10-27 16:18:17 +0900 | [diff] [blame] | 705 | cursor.close(); |
| 706 | } |
| 707 | } |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 708 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 709 | public void testReplaceExistingRoots() throws Exception { |
Daichi Hirono | 8e87364 | 2016-02-07 15:17:16 +0900 | [diff] [blame] | 710 | addTestDevice(); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 711 | |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 712 | // The client code should be able to replace existing rows with new information. |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 713 | // Add one. |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 714 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 715 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 716 | new MtpRoot(0, 100, "Storage A", 0, 0, ""), |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 717 | }); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 718 | mDatabase.getMapper().stopAddingDocuments("1"); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 719 | // Replace it. |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 720 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 721 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 722 | new MtpRoot(0, 100, "Storage B", 1000, 1000, ""), |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 723 | }); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 724 | mDatabase.getMapper().stopAddingDocuments("1"); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 725 | { |
| 726 | final String[] columns = new String[] { |
| 727 | DocumentsContract.Document.COLUMN_DOCUMENT_ID, |
Daichi Hirono | 18d70d5 | 2015-11-13 15:19:47 +0900 | [diff] [blame] | 728 | MtpDatabaseConstants.COLUMN_STORAGE_ID, |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 729 | DocumentsContract.Document.COLUMN_DISPLAY_NAME |
| 730 | }; |
Daichi Hirono | 4604b74 | 2015-11-12 12:12:48 +0900 | [diff] [blame] | 731 | final Cursor cursor = mDatabase.queryRootDocuments(columns); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 732 | assertEquals(1, cursor.getCount()); |
| 733 | cursor.moveToNext(); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 734 | assertEquals(2, getInt(cursor, COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 735 | assertEquals(100, getInt(cursor, COLUMN_STORAGE_ID)); |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 736 | assertEquals("Storage B", getString(cursor, COLUMN_DISPLAY_NAME)); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 737 | cursor.close(); |
| 738 | } |
| 739 | { |
| 740 | final String[] columns = new String[] { |
| 741 | Root.COLUMN_ROOT_ID, |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 742 | Root.COLUMN_TITLE, |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 743 | Root.COLUMN_AVAILABLE_BYTES |
| 744 | }; |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 745 | final Cursor cursor = mDatabase.queryRoots(resources, columns); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 746 | assertEquals(1, cursor.getCount()); |
| 747 | cursor.moveToNext(); |
Daichi Hirono | 6a5ea7e | 2016-02-02 16:35:03 +0900 | [diff] [blame] | 748 | assertEquals(1, getInt(cursor, Root.COLUMN_ROOT_ID)); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 749 | assertEquals("Device Storage B", getString(cursor, Root.COLUMN_TITLE)); |
Daichi Hirono | 9984ebd | 2015-12-15 16:02:27 +0900 | [diff] [blame] | 750 | assertEquals(1000, getInt(cursor, Root.COLUMN_AVAILABLE_BYTES)); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 751 | cursor.close(); |
| 752 | } |
| 753 | } |
| 754 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 755 | public void testFailToReplaceExisitingUnmappedRoots() throws Exception { |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 756 | // The client code should not be able to replace rows before resolving 'unmapped' rows. |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 757 | // Add one. |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 758 | addTestDevice(); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 759 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 760 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 761 | new MtpRoot(0, 100, "Storage A", 0, 0, ""), |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 762 | }); |
Daichi Hirono | 259ce80 | 2015-11-20 17:51:53 +0900 | [diff] [blame] | 763 | mDatabase.getMapper().clearMapping(); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 764 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 765 | addTestDevice(); |
| 766 | try (final Cursor oldCursor = |
| 767 | mDatabase.queryRoots(resources, strings(Root.COLUMN_ROOT_ID))) { |
| 768 | assertEquals(1, oldCursor.getCount()); |
| 769 | oldCursor.moveToNext(); |
| 770 | assertEquals("1", getString(oldCursor, Root.COLUMN_ROOT_ID)); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 771 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 772 | // Add one. |
| 773 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 774 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 775 | new MtpRoot(0, 101, "Storage B", 1000, 1000, ""), |
| 776 | }); |
| 777 | // Add one more before resolving unmapped documents. |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 778 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 779 | new MtpRoot(0, 102, "Storage B", 1000, 1000, ""), |
| 780 | }); |
| 781 | mDatabase.getMapper().stopAddingDocuments("1"); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 782 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 783 | // Because the roots shares the same name, the roots should have new IDs. |
| 784 | try (final Cursor newCursor = mDatabase.queryChildDocuments( |
| 785 | strings(Document.COLUMN_DOCUMENT_ID), "1")) { |
| 786 | assertEquals(2, newCursor.getCount()); |
| 787 | newCursor.moveToNext(); |
| 788 | assertFalse(oldCursor.getString(0).equals(newCursor.getString(0))); |
| 789 | newCursor.moveToNext(); |
| 790 | assertFalse(oldCursor.getString(0).equals(newCursor.getString(0))); |
| 791 | } |
| 792 | } |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 793 | } |
| 794 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 795 | public void testQueryDocuments() throws Exception { |
| 796 | addTestDevice(); |
| 797 | addTestStorage("1"); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 798 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 799 | final Cursor cursor = mDatabase.queryDocument("2", strings(Document.COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 800 | assertEquals(1, cursor.getCount()); |
| 801 | cursor.moveToNext(); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 802 | assertEquals("Storage", getString(cursor, Document.COLUMN_DISPLAY_NAME)); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 803 | cursor.close(); |
| 804 | } |
| 805 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 806 | public void testQueryRoots() throws Exception { |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 807 | // Add device document. |
Daichi Hirono | 8e87364 | 2016-02-07 15:17:16 +0900 | [diff] [blame] | 808 | addTestDevice(); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 809 | |
| 810 | // It the device does not have storages, it shows a device root. |
| 811 | { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 812 | final Cursor cursor = mDatabase.queryRoots(resources, strings(Root.COLUMN_TITLE)); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 813 | assertEquals(1, cursor.getCount()); |
| 814 | cursor.moveToNext(); |
| 815 | assertEquals("Device", cursor.getString(0)); |
| 816 | cursor.close(); |
| 817 | } |
| 818 | |
| 819 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 820 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 821 | new MtpRoot(0, 100, "Storage A", 0, 0, "") |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 822 | }); |
| 823 | mDatabase.getMapper().stopAddingDocuments("1"); |
| 824 | |
| 825 | // It the device has single storage, it shows a storage root. |
| 826 | { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 827 | final Cursor cursor = mDatabase.queryRoots(resources, strings(Root.COLUMN_TITLE)); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 828 | assertEquals(1, cursor.getCount()); |
| 829 | cursor.moveToNext(); |
| 830 | assertEquals("Device Storage A", cursor.getString(0)); |
| 831 | cursor.close(); |
| 832 | } |
| 833 | |
| 834 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 835 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 836 | new MtpRoot(0, 100, "Storage A", 0, 0, ""), |
| 837 | new MtpRoot(0, 101, "Storage B", 0, 0, "") |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 838 | }); |
| 839 | mDatabase.getMapper().stopAddingDocuments("1"); |
| 840 | |
| 841 | // It the device has multiple storages, it shows a device root. |
| 842 | { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 843 | final Cursor cursor = mDatabase.queryRoots(resources, strings(Root.COLUMN_TITLE)); |
Daichi Hirono | 81d4853 | 2015-12-16 15:03:19 +0900 | [diff] [blame] | 844 | assertEquals(1, cursor.getCount()); |
| 845 | cursor.moveToNext(); |
| 846 | assertEquals("Device", cursor.getString(0)); |
| 847 | cursor.close(); |
| 848 | } |
| 849 | } |
| 850 | |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 851 | public void testGetParentId() throws FileNotFoundException { |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 852 | addTestDevice(); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 853 | |
Daichi Hirono | 7a375c4 | 2015-12-14 17:14:29 +0900 | [diff] [blame] | 854 | mDatabase.getMapper().startAddingDocuments("1"); |
Daichi Hirono | 0f32537 | 2016-02-21 15:50:30 +0900 | [diff] [blame] | 855 | mDatabase.getMapper().putStorageDocuments("1", OPERATIONS_SUPPORTED, new MtpRoot[] { |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 856 | new MtpRoot(0, 100, "Storage A", 0, 0, ""), |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 857 | }); |
Daichi Hirono | 7a375c4 | 2015-12-14 17:14:29 +0900 | [diff] [blame] | 858 | mDatabase.getMapper().stopAddingDocuments("1"); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 859 | |
Daichi Hirono | 7a375c4 | 2015-12-14 17:14:29 +0900 | [diff] [blame] | 860 | mDatabase.getMapper().startAddingDocuments("2"); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 861 | mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
| 862 | createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 863 | }, new long[] { 1024L }); |
Daichi Hirono | 7a375c4 | 2015-12-14 17:14:29 +0900 | [diff] [blame] | 864 | mDatabase.getMapper().stopAddingDocuments("2"); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 865 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 866 | assertEquals("2", mDatabase.getParentIdentifier("3").mDocumentId); |
| 867 | } |
| 868 | |
| 869 | public void testDeleteDocument() throws Exception { |
| 870 | addTestDevice(); |
| 871 | addTestStorage("1"); |
| 872 | |
| 873 | mDatabase.getMapper().startAddingDocuments("2"); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 874 | mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
| 875 | createDocument(200, "dir", MtpConstants.FORMAT_ASSOCIATION, 1024), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 876 | }, new long[] { 1024L }); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 877 | mDatabase.getMapper().stopAddingDocuments("2"); |
| 878 | |
| 879 | mDatabase.getMapper().startAddingDocuments("3"); |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 880 | mDatabase.getMapper().putChildDocuments(0, "3", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
| 881 | createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 882 | }, new long[] { 1024L }); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 883 | mDatabase.getMapper().stopAddingDocuments("3"); |
| 884 | |
| 885 | mDatabase.deleteDocument("3"); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 886 | |
| 887 | { |
| 888 | // Do not query deleted documents. |
| 889 | final Cursor cursor = |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 890 | mDatabase.queryChildDocuments(strings(Document.COLUMN_DOCUMENT_ID), "2"); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 891 | assertEquals(0, cursor.getCount()); |
| 892 | cursor.close(); |
| 893 | } |
| 894 | |
| 895 | { |
| 896 | // Child document should be deleted also. |
| 897 | final Cursor cursor = |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 898 | mDatabase.queryDocument("4", strings(Document.COLUMN_DOCUMENT_ID)); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 899 | assertEquals(0, cursor.getCount()); |
| 900 | cursor.close(); |
| 901 | } |
| 902 | } |
| 903 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 904 | public void testPutNewDocument() throws Exception { |
| 905 | addTestDevice(); |
| 906 | addTestStorage("1"); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 907 | |
| 908 | assertEquals( |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 909 | "3", |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 910 | mDatabase.putNewDocument( |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 911 | 0, "2", OPERATIONS_SUPPORTED, |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 912 | createDocument(200, "note.txt", MtpConstants.FORMAT_TEXT, 1024), |
| 913 | 1024L)); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 914 | |
| 915 | { |
| 916 | final Cursor cursor = |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 917 | mDatabase.queryChildDocuments(strings(Document.COLUMN_DOCUMENT_ID), "2"); |
Daichi Hirono | 49f920f | 2015-11-19 10:19:52 +0900 | [diff] [blame] | 918 | assertEquals(1, cursor.getCount()); |
| 919 | cursor.moveToNext(); |
| 920 | assertEquals("3", cursor.getString(0)); |
| 921 | cursor.close(); |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 922 | } |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 923 | |
| 924 | // The new document should not be mapped with existing invalidated document. |
| 925 | mDatabase.getMapper().clearMapping(); |
Daichi Hirono | 8e87364 | 2016-02-07 15:17:16 +0900 | [diff] [blame] | 926 | addTestDevice(); |
| 927 | addTestStorage("1"); |
| 928 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 929 | mDatabase.getMapper().startAddingDocuments("2"); |
| 930 | mDatabase.putNewDocument( |
Daichi Hirono | 61ba923 | 2016-02-26 12:58:39 +0900 | [diff] [blame] | 931 | 0, "2", OPERATIONS_SUPPORTED, |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 932 | createDocument(201, "note.txt", MtpConstants.FORMAT_TEXT, 1024), |
| 933 | 1024L); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 934 | mDatabase.getMapper().stopAddingDocuments("2"); |
| 935 | |
| 936 | { |
| 937 | final Cursor cursor = |
| 938 | mDatabase.queryChildDocuments(strings(Document.COLUMN_DOCUMENT_ID), "2"); |
| 939 | assertEquals(1, cursor.getCount()); |
| 940 | cursor.moveToNext(); |
| 941 | assertEquals("4", cursor.getString(0)); |
| 942 | cursor.close(); |
| 943 | } |
Daichi Hirono | cfcb0c0 | 2015-11-10 12:52:59 +0900 | [diff] [blame] | 944 | } |
Daichi Hirono | 20754c5 | 2015-12-15 18:52:26 +0900 | [diff] [blame] | 945 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 946 | public void testGetDocumentIdForDevice() throws Exception { |
| 947 | addTestDevice(); |
| 948 | assertEquals("1", mDatabase.getDocumentIdForDevice(0)); |
Daichi Hirono | 20754c5 | 2015-12-15 18:52:26 +0900 | [diff] [blame] | 949 | } |
Daichi Hirono | 83983d7 | 2016-01-29 17:37:36 +0900 | [diff] [blame] | 950 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 951 | public void testGetClosedDevice() throws Exception { |
Daichi Hirono | 83983d7 | 2016-01-29 17:37:36 +0900 | [diff] [blame] | 952 | mDatabase.getMapper().startAddingDocuments(null); |
| 953 | mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord( |
Daichi Hirono | ebd2405 | 2016-02-06 21:05:57 +0900 | [diff] [blame] | 954 | 0, "Device", null /* deviceKey */, /* opened is */ false, new MtpRoot[0], null, |
| 955 | null)); |
Daichi Hirono | 83983d7 | 2016-01-29 17:37:36 +0900 | [diff] [blame] | 956 | mDatabase.getMapper().stopAddingDocuments(null); |
| 957 | |
| 958 | final String[] columns = new String [] { |
| 959 | DocumentsContract.Root.COLUMN_ROOT_ID, |
| 960 | DocumentsContract.Root.COLUMN_TITLE, |
| 961 | DocumentsContract.Root.COLUMN_AVAILABLE_BYTES |
| 962 | }; |
Daichi Hirono | f83ccbd | 2016-02-04 16:58:55 +0900 | [diff] [blame] | 963 | try (final Cursor cursor = mDatabase.queryRoots(resources, columns)) { |
Daichi Hirono | 83983d7 | 2016-01-29 17:37:36 +0900 | [diff] [blame] | 964 | assertEquals(1, cursor.getCount()); |
| 965 | assertTrue(cursor.moveToNext()); |
| 966 | assertEquals(1, cursor.getLong(0)); |
| 967 | assertEquals("Device", cursor.getString(1)); |
| 968 | assertTrue(cursor.isNull(2)); |
| 969 | } |
| 970 | } |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 971 | |
Daichi Hirono | ebd2405 | 2016-02-06 21:05:57 +0900 | [diff] [blame] | 972 | public void testMappingWithoutKey() throws FileNotFoundException { |
| 973 | mDatabase.getMapper().startAddingDocuments(null); |
| 974 | mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord( |
| 975 | 0, "Device", null /* device key */, /* opened is */ true, new MtpRoot[0], null, |
| 976 | null)); |
| 977 | mDatabase.getMapper().stopAddingDocuments(null); |
| 978 | |
| 979 | mDatabase.getMapper().startAddingDocuments(null); |
| 980 | mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord( |
| 981 | 0, "Device", null /* device key */, /* opened is */ true, new MtpRoot[0], null, |
| 982 | null)); |
| 983 | mDatabase.getMapper().stopAddingDocuments(null); |
| 984 | |
| 985 | try (final Cursor cursor = |
| 986 | mDatabase.queryRoots(resources, strings(DocumentsContract.Root.COLUMN_ROOT_ID))) { |
| 987 | assertEquals(1, cursor.getCount()); |
| 988 | assertTrue(cursor.moveToNext()); |
| 989 | assertEquals(1, cursor.getLong(0)); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | public void testMappingFailsWithoutKey() throws FileNotFoundException { |
| 994 | mDatabase.getMapper().startAddingDocuments(null); |
| 995 | mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord( |
| 996 | 0, "Device", null /* device key */, /* opened is */ true, new MtpRoot[0], null, |
| 997 | null)); |
| 998 | mDatabase.getMapper().stopAddingDocuments(null); |
| 999 | |
| 1000 | // MTP identifier is cleared here. Mapping no longer works without device key. |
| 1001 | mDatabase.getMapper().startAddingDocuments(null); |
| 1002 | mDatabase.getMapper().stopAddingDocuments(null); |
| 1003 | |
| 1004 | mDatabase.getMapper().startAddingDocuments(null); |
| 1005 | mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord( |
| 1006 | 0, "Device", null /* device key */, /* opened is */ true, new MtpRoot[0], null, |
| 1007 | null)); |
| 1008 | mDatabase.getMapper().stopAddingDocuments(null); |
| 1009 | |
| 1010 | try (final Cursor cursor = |
| 1011 | mDatabase.queryRoots(resources, strings(DocumentsContract.Root.COLUMN_ROOT_ID))) { |
| 1012 | assertEquals(1, cursor.getCount()); |
| 1013 | assertTrue(cursor.moveToNext()); |
| 1014 | assertEquals(2, cursor.getLong(0)); |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | public void testUpdateDocumentWithoutChange() throws FileNotFoundException { |
| 1019 | mDatabase.getMapper().startAddingDocuments(null); |
| 1020 | assertTrue(mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord( |
| 1021 | 0, "Device", "device_key", /* opened is */ true, new MtpRoot[0], null, |
| 1022 | null))); |
| 1023 | assertFalse(mDatabase.getMapper().stopAddingDocuments(null)); |
| 1024 | |
| 1025 | mDatabase.getMapper().startAddingDocuments(null); |
| 1026 | assertFalse(mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord( |
| 1027 | 0, "Device", "device_key", /* opened is */ true, new MtpRoot[0], null, |
| 1028 | null))); |
| 1029 | assertFalse(mDatabase.getMapper().stopAddingDocuments(null)); |
| 1030 | } |
| 1031 | |
Daichi Hirono | 3bb37e7 | 2016-02-29 15:30:56 +0900 | [diff] [blame] | 1032 | public void testSetBootCount() { |
| 1033 | assertEquals(0, mDatabase.getLastBootCount()); |
| 1034 | mDatabase.setLastBootCount(10); |
| 1035 | assertEquals(10, mDatabase.getLastBootCount()); |
| 1036 | try { |
| 1037 | mDatabase.setLastBootCount(-1); |
| 1038 | fail(); |
| 1039 | } catch (IllegalArgumentException e) {} |
| 1040 | } |
| 1041 | |
| 1042 | public void testCleanDatabase() throws FileNotFoundException { |
| 1043 | // Add tree. |
| 1044 | addTestDevice(); |
| 1045 | addTestStorage("1"); |
| 1046 | mDatabase.getMapper().startAddingDocuments("2"); |
| 1047 | mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
| 1048 | createDocument(100, "apple.txt", MtpConstants.FORMAT_TEXT, 1024), |
| 1049 | createDocument(101, "orange.txt", MtpConstants.FORMAT_TEXT, 1024), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 1050 | }, new long[] { 1024L, 1024L }); |
Daichi Hirono | 3bb37e7 | 2016-02-29 15:30:56 +0900 | [diff] [blame] | 1051 | mDatabase.getMapper().stopAddingDocuments("2"); |
| 1052 | |
| 1053 | // Disconnect the device. |
| 1054 | mDatabase.getMapper().startAddingDocuments(null); |
| 1055 | mDatabase.getMapper().stopAddingDocuments(null); |
| 1056 | |
| 1057 | // Clean database. |
| 1058 | mDatabase.cleanDatabase(new Uri[] { |
| 1059 | DocumentsContract.buildDocumentUri(MtpDocumentsProvider.AUTHORITY, "3") |
| 1060 | }); |
| 1061 | |
| 1062 | // Add tree again. |
| 1063 | addTestDevice(); |
| 1064 | addTestStorage("1"); |
| 1065 | mDatabase.getMapper().startAddingDocuments("2"); |
| 1066 | mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
| 1067 | createDocument(100, "apple.txt", MtpConstants.FORMAT_TEXT, 1024), |
| 1068 | createDocument(101, "orange.txt", MtpConstants.FORMAT_TEXT, 1024), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 1069 | }, new long[] { 1024L, 1024L }); |
Daichi Hirono | 3bb37e7 | 2016-02-29 15:30:56 +0900 | [diff] [blame] | 1070 | mDatabase.getMapper().stopAddingDocuments("2"); |
| 1071 | |
| 1072 | try (final Cursor cursor = mDatabase.queryChildDocuments( |
| 1073 | strings(COLUMN_DOCUMENT_ID, Document.COLUMN_DISPLAY_NAME), "2")) { |
| 1074 | assertEquals(2, cursor.getCount()); |
| 1075 | |
| 1076 | // Persistent uri uses the same ID. |
| 1077 | cursor.moveToNext(); |
| 1078 | assertEquals("3", cursor.getString(0)); |
| 1079 | assertEquals("apple.txt", cursor.getString(1)); |
| 1080 | |
| 1081 | // Others does not. |
| 1082 | cursor.moveToNext(); |
| 1083 | assertEquals("5", cursor.getString(0)); |
| 1084 | assertEquals("orange.txt", cursor.getString(1)); |
| 1085 | } |
| 1086 | } |
| 1087 | |
Daichi Hirono | 497b473 | 2016-03-14 14:46:37 +0900 | [diff] [blame] | 1088 | public void testFormatCodeForMpeg() throws FileNotFoundException { |
| 1089 | addTestDevice(); |
| 1090 | addTestStorage("1"); |
| 1091 | mDatabase.getMapper().startAddingDocuments("2"); |
| 1092 | mDatabase.getMapper().putChildDocuments(0, "2", OPERATIONS_SUPPORTED, new MtpObjectInfo[] { |
| 1093 | createDocument(100, "audio.m4a", MtpConstants.FORMAT_MPEG, 1000), |
| 1094 | createDocument(101, "video.m4v", MtpConstants.FORMAT_MPEG, 1000), |
| 1095 | createDocument(102, "unknown.mp4", MtpConstants.FORMAT_MPEG, 1000), |
| 1096 | createDocument(103, "inconsistent.txt", MtpConstants.FORMAT_MPEG, 1000), |
| 1097 | createDocument(104, "noext", MtpConstants.FORMAT_UNDEFINED, 1000), |
Daichi Hirono | 64111e0 | 2016-03-24 21:07:38 +0900 | [diff] [blame] | 1098 | }, new long[] { 1000L, 1000L, 1000L, 1000L, 1000L }); |
Daichi Hirono | 497b473 | 2016-03-14 14:46:37 +0900 | [diff] [blame] | 1099 | mDatabase.getMapper().stopAddingDocuments("2"); |
| 1100 | try (final Cursor cursor = mDatabase.queryChildDocuments( |
| 1101 | strings(COLUMN_DISPLAY_NAME, COLUMN_MIME_TYPE), |
| 1102 | "2")) { |
| 1103 | assertEquals(5, cursor.getCount()); |
| 1104 | cursor.moveToNext(); |
| 1105 | assertEquals("audio.m4a", cursor.getString(0)); |
| 1106 | assertEquals("audio/mp4", cursor.getString(1)); |
| 1107 | cursor.moveToNext(); |
| 1108 | assertEquals("video.m4v", cursor.getString(0)); |
| 1109 | assertEquals("video/mp4", cursor.getString(1)); |
| 1110 | cursor.moveToNext(); |
| 1111 | // Assume that the file is video as we don't have any hints to find out if the file is |
| 1112 | // video or audio. |
| 1113 | assertEquals("unknown.mp4", cursor.getString(0)); |
| 1114 | assertEquals("video/mp4", cursor.getString(1)); |
| 1115 | // Don't return mime type that is inconsistent with format code. |
| 1116 | cursor.moveToNext(); |
| 1117 | assertEquals("inconsistent.txt", cursor.getString(0)); |
Daichi Hirono | daa61d4 | 2016-08-10 14:59:18 +0900 | [diff] [blame] | 1118 | assertEquals("video/mpeg", cursor.getString(1)); |
Daichi Hirono | 497b473 | 2016-03-14 14:46:37 +0900 | [diff] [blame] | 1119 | cursor.moveToNext(); |
| 1120 | assertEquals("noext", cursor.getString(0)); |
| 1121 | assertEquals("application/octet-stream", cursor.getString(1)); |
| 1122 | } |
| 1123 | } |
| 1124 | |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 1125 | private void addTestDevice() throws FileNotFoundException { |
Daichi Hirono | f578fa2 | 2016-02-19 18:05:42 +0900 | [diff] [blame] | 1126 | TestUtil.addTestDevice(mDatabase); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | private void addTestStorage(String parentId) throws FileNotFoundException { |
Daichi Hirono | f578fa2 | 2016-02-19 18:05:42 +0900 | [diff] [blame] | 1130 | TestUtil.addTestStorage(mDatabase, parentId); |
Daichi Hirono | 619afda | 2016-02-07 14:23:43 +0900 | [diff] [blame] | 1131 | } |
Daichi Hirono | 9678f60 | 2015-10-22 12:35:05 +0900 | [diff] [blame] | 1132 | } |