1 /* 2 * Copyright (C) 2012 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 package com.android.cts.verifier.p2p.testcase; 17 18 import android.content.Context; 19 import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest; 20 import android.net.wifi.p2p.nsd.WifiP2pUpnpServiceRequest; 21 22 import com.android.cts.verifier.R; 23 24 /** 25 * Service discovery requester test case to check clearServiceRequests() works well. 26 */ 27 public class ServReqClearRequestTestCase extends ServReqTestCase { 28 29 public ServReqClearRequestTestCase(Context context) { 30 super(context); 31 } 32 33 @Override 34 protected boolean executeTest() throws InterruptedException { 35 36 notifyTestMsg(R.string.p2p_checking_serv_capab); 37 38 ActionListenerTest actionListener = new ActionListenerTest(); 39 40 /* 41 * create some service requests. 42 */ 43 WifiP2pUpnpServiceRequest upnpReq1 = 44 WifiP2pUpnpServiceRequest.newInstance(); 45 WifiP2pUpnpServiceRequest upnpReq2 = 46 WifiP2pUpnpServiceRequest.newInstance("ssdp:all"); 47 WifiP2pDnsSdServiceRequest bonjourReq1 = 48 WifiP2pDnsSdServiceRequest.newInstance(); 49 WifiP2pDnsSdServiceRequest bonjourReq2 = 50 WifiP2pDnsSdServiceRequest.newInstance("_ipp._tcp"); 51 52 /* 53 * add request 54 */ 55 mP2pMgr.addServiceRequest(mChannel, upnpReq1, actionListener); 56 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 57 mReason = mContext.getString(R.string.p2p_add_service_request_error); 58 return false; 59 } 60 mP2pMgr.addServiceRequest(mChannel, upnpReq2, actionListener); 61 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 62 mReason = mContext.getString(R.string.p2p_add_service_request_error); 63 return false; 64 } 65 mP2pMgr.addServiceRequest(mChannel, bonjourReq1, actionListener); 66 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 67 mReason = mContext.getString(R.string.p2p_add_service_request_error); 68 return false; 69 } 70 mP2pMgr.addServiceRequest(mChannel, bonjourReq2, actionListener); 71 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 72 mReason = mContext.getString(R.string.p2p_add_service_request_error); 73 return false; 74 } 75 76 /* 77 * clear requests 78 */ 79 mP2pMgr.clearServiceRequests(mChannel, actionListener); 80 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 81 mReason = mContext.getString(R.string.p2p_clear_service_requests_error); 82 return false; 83 } 84 85 /* 86 * search services, but NO_SERVICE_REQUESTS is returned. 87 */ 88 mP2pMgr.discoverServices(mChannel, actionListener); 89 if (!actionListener.check(ActionListenerTest.FAIL_NO_SERVICE, TIMEOUT)) { 90 mReason = mContext.getString(R.string.p2p_no_service_requests_error); 91 return false; 92 } 93 94 return true; 95 } 96 97 @Override 98 public String getTestName() { 99 return "Clear service requests test"; 100 } 101 } 102