Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
cts
Commits
5de0eddd
Commit
5de0eddd
authored
11 years ago
by
Chiao Cheng
Committed by
Android Git Automerger
11 years ago
Browse files
Options
Download
Plain Diff
am
d8836bb1
: Cts test for DumpFileProvider.
* commit '
d8836bb1
': Cts test for DumpFileProvider.
parents
9365f2d8
d8836bb1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
0 deletions
+106
-0
tests/tests/provider/src/android/provider/cts/ContactsContract_DumpFileProviderTest.java
...d/provider/cts/ContactsContract_DumpFileProviderTest.java
+106
-0
No files found.
tests/tests/provider/src/android/provider/cts/ContactsContract_DumpFileProviderTest.java
0 → 100644
View file @
5de0eddd
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package
android.provider.cts
;
import
android.content.ContentResolver
;
import
android.net.Uri
;
import
android.test.AndroidTestCase
;
import
java.io.FileNotFoundException
;
public
class
ContactsContract_DumpFileProviderTest
extends
AndroidTestCase
{
private
static
final
String
URI_PREFIX
=
"content://com.android.contacts.dumpfile/"
;
private
static
final
String
[]
NOT_ALLOWED_FILES
=
{
"not_allowed.txt"
,
"../A-contacts-db.zip"
,
// ".." is not allowed.
"/A-contacts-db.zip"
,
// "/" is not allowed
"-contacts-db.zip"
,
// no name prefix
"asdf-contacts-db.zip"
};
private
static
final
String
[]
ALLOWED_FILES
=
{
"1234567890abcdefABCDEF-contacts-db.zip"
,
"a-contacts-db.zip"
,
"0-contacts-db.zip"
,
"A-contacts-db.zip"
,
"abcdefabcdefabcdefabcdef-contacts-db.zip"
};
private
ContentResolver
mResolver
;
@Override
protected
void
setUp
()
throws
Exception
{
super
.
setUp
();
mResolver
=
getContext
().
getContentResolver
();
}
public
void
testOpenFileDescriptor_throwsErrorWithIllegalFileName
()
{
for
(
String
fileName
:
NOT_ALLOWED_FILES
)
{
Uri
uri
=
Uri
.
parse
(
URI_PREFIX
+
fileName
);
assertOpenFileDescriptorThrowsError
(
uri
);
}
}
public
void
testOpenFileDescriptor_worksWithValidFileName
()
{
for
(
String
fileName
:
ALLOWED_FILES
)
{
final
Uri
uri
=
Uri
.
parse
(
URI_PREFIX
+
fileName
);
try
{
mResolver
.
openFileDescriptor
(
uri
,
"r"
);
}
catch
(
FileNotFoundException
e
)
{
}
}
}
public
void
testQuery_throwsErrorWithIllegalFileName
()
{
for
(
String
fileName
:
NOT_ALLOWED_FILES
)
{
final
Uri
uri
=
Uri
.
parse
(
URI_PREFIX
+
fileName
);
assertQueryThrowsError
(
uri
);
}
}
public
void
testQuery_worksWithValidFileName
()
{
for
(
String
fileName
:
ALLOWED_FILES
)
{
final
Uri
uri
=
Uri
.
parse
(
URI_PREFIX
+
fileName
);
mResolver
.
query
(
uri
,
null
,
null
,
null
,
null
);
}
}
private
void
assertQueryThrowsError
(
Uri
uri
)
{
try
{
mResolver
.
query
(
uri
,
null
,
null
,
null
,
null
);
}
catch
(
IllegalArgumentException
e
)
{
// pass
return
;
}
fail
(
"IllegalArgumentException expected but not thrown."
);
}
private
void
assertOpenFileDescriptorThrowsError
(
Uri
uri
)
{
try
{
mResolver
.
openFileDescriptor
(
uri
,
"r"
);
}
catch
(
IllegalArgumentException
e
)
{
// pass
return
;
}
catch
(
FileNotFoundException
e
)
{
}
fail
(
"IllegalArgumentException expected but not thrown."
);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment