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