1 /* 2 * Copyright (C) 2008 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 17 package android.content.cts; 18 19 import android.content.IntentFilter; 20 import android.content.IntentFilter.AuthorityEntry; 21 import android.net.Uri; 22 import android.test.AndroidTestCase; 23 24 public class IntentFilter_AuthorityEntryTest extends AndroidTestCase { 25 26 private AuthorityEntry mAuthorityEntry; 27 private final String mHost = "testHost"; 28 private final String mWildHost = "*" + mHost; 29 private final int mPort = 80; 30 31 @Override 32 protected void setUp() throws Exception { 33 super.setUp(); 34 mAuthorityEntry = new AuthorityEntry(mHost, String.valueOf(mPort)); 35 } 36 37 public void testConstructor() { 38 mAuthorityEntry = new AuthorityEntry(mHost, String.valueOf(mPort)); 39 assertNotNull(mAuthorityEntry); 40 assertEquals(mHost, mAuthorityEntry.getHost()); 41 assertEquals(mPort, mAuthorityEntry.getPort()); 42 43 mAuthorityEntry = new AuthorityEntry(mWildHost, String.valueOf(mPort)); 44 assertNotNull(mAuthorityEntry); 45 assertEquals(mWildHost, mAuthorityEntry.getHost()); 46 assertEquals(Integer.valueOf(mPort).intValue(), mAuthorityEntry.getPort()); 47 } 48 49 public void testAuthorityEntryProperties() { 50 assertEquals(Integer.valueOf(mPort).intValue(), mAuthorityEntry.getPort()); 51 assertEquals(mHost, mAuthorityEntry.getHost()); 52 } 53 54 public void testMatch() { 55 Uri uri = Uri.parse("testUri"); 56 assertEquals(IntentFilter.NO_MATCH_DATA, mAuthorityEntry.match(uri)); 57 uri = Uri.parse("content://contacts/deleted_people"); 58 assertEquals(IntentFilter.NO_MATCH_DATA, mAuthorityEntry.match(uri)); 59 uri = Uri.parse("test"); 60 mAuthorityEntry = new IntentFilter.AuthorityEntry(mWildHost, String.valueOf(-1)); 61 assertEquals(IntentFilter.NO_MATCH_DATA, mAuthorityEntry.match(uri)); 62 uri = Uri.parse("http://" + mHost); 63 mAuthorityEntry = new IntentFilter.AuthorityEntry(mHost, String.valueOf(-1)); 64 assertEquals(IntentFilter.MATCH_CATEGORY_HOST, mAuthorityEntry.match(uri)); 65 66 uri = Uri.parse("http://" + mHost + ":90"); 67 mAuthorityEntry = new AuthorityEntry(mHost, String.valueOf(-1)); 68 assertEquals(IntentFilter.MATCH_CATEGORY_HOST, mAuthorityEntry.match(uri)); 69 70 uri = Uri.parse("http://" + mHost + ":80"); 71 mAuthorityEntry = new AuthorityEntry(mHost, String.valueOf(mPort)); 72 assertEquals(IntentFilter.MATCH_CATEGORY_PORT, mAuthorityEntry.match(uri)); 73 74 uri = Uri.parse("http://" + mHost + ":80"); 75 mAuthorityEntry = new AuthorityEntry(mHost, String.valueOf(-1)); 76 assertEquals(IntentFilter.MATCH_CATEGORY_HOST, mAuthorityEntry.match(uri)); 77 } 78 } 79