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 21 import com.android.cts.verifier.R; 22 23 /** 24 * Service discovery requester test case to search bonjour IPP PTR service 25 * on channel1 and search AFP TXT service on channel2. 26 */ 27 public class ServReqMultiClientTestCase02 extends ServReqTestCase { 28 ServReqMultiClientTestCase02(Context context)29 public ServReqMultiClientTestCase02(Context context) { 30 super(context); 31 } 32 33 @Override executeTest()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 bonjour IPP PTR request and AFP TXT request. 42 */ 43 WifiP2pDnsSdServiceRequest bonjourIppPtrReq = 44 WifiP2pDnsSdServiceRequest.newInstance("_ipp._tcp"); 45 WifiP2pDnsSdServiceRequest bonjourAfpTxtReq = 46 WifiP2pDnsSdServiceRequest.newInstance("Example", "_afpovertcp._tcp"); 47 48 /* 49 * add bonjour IPP PTR request to channel1. 50 */ 51 mP2pMgr.addServiceRequest(mChannel, bonjourIppPtrReq, actionListener); 52 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 53 mReason = mContext.getString(R.string.p2p_add_service_request_error); 54 return false; 55 } 56 57 /* 58 * add bonjour AFP TXT request to channel2. 59 */ 60 mP2pMgr.addServiceRequest(mSubChannel, bonjourAfpTxtReq, actionListener); 61 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 62 mReason = mContext.getString(R.string.p2p_add_service_request_error); 63 return false; 64 } 65 66 /* 67 * initialize test listener 68 */ 69 UPnPServiceResponseListenerTest upnpCh1Listener = 70 new UPnPServiceResponseListenerTest(mTargetAddress); 71 DnsSdResponseListenerTest dnsCh1Listener = 72 new DnsSdResponseListenerTest(mTargetAddress); 73 DnsSdTxtRecordListenerTest txtCh1Listener = 74 new DnsSdTxtRecordListenerTest(mTargetAddress); 75 UPnPServiceResponseListenerTest upnpCh2Listener = 76 new UPnPServiceResponseListenerTest(mTargetAddress); 77 DnsSdResponseListenerTest dnsCh2Listener = 78 new DnsSdResponseListenerTest(mTargetAddress); 79 DnsSdTxtRecordListenerTest txtCh2Listener = 80 new DnsSdTxtRecordListenerTest(mTargetAddress); 81 82 /* 83 * set service response listener callback. 84 */ 85 mP2pMgr.setUpnpServiceResponseListener(mChannel, upnpCh1Listener); 86 mP2pMgr.setDnsSdResponseListeners(mChannel, dnsCh1Listener, txtCh1Listener); 87 mP2pMgr.setUpnpServiceResponseListener(mSubChannel, upnpCh2Listener); 88 mP2pMgr.setDnsSdResponseListeners(mSubChannel, dnsCh2Listener, txtCh2Listener); 89 90 /* 91 * discover services 92 */ 93 mP2pMgr.discoverServices(mChannel, actionListener); 94 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 95 mReason = mContext.getString(R.string.p2p_discover_services_error); 96 return false; 97 } 98 99 /* 100 * channel1 receive only Bonjour IPP PTR. 101 */ 102 Timeout t = new Timeout(TIMEOUT); 103 if (!dnsCh1Listener.check(DnsSdResponseListenerTest.IPP_DNS_PTR, 104 t.getRemainTime())) { 105 mReason = getListenerError(dnsCh1Listener); 106 return false; 107 } 108 if (!txtCh1Listener.check(DnsSdTxtRecordListenerTest.NO_DNS_TXT, 109 t.getRemainTime())) { 110 mReason = getListenerError(txtCh1Listener); 111 return false; 112 } 113 if (!upnpCh1Listener.check( 114 UPnPServiceResponseListenerTest.NO_UPNP_SERVICES, 115 t.getRemainTime())) { 116 mReason = getListenerError(upnpCh1Listener); 117 return false; 118 } 119 120 /* 121 * channel2 receive only Bonjour AFP TXT. 122 */ 123 if (!dnsCh2Listener.check(DnsSdResponseListenerTest.NO_DNS_PTR, 124 t.getRemainTime())) { 125 mReason = getListenerError(dnsCh2Listener); 126 return false; 127 } 128 if (!txtCh2Listener.check(DnsSdTxtRecordListenerTest.AFP_DNS_TXT, 129 t.getRemainTime())) { 130 mReason = getListenerError(txtCh2Listener); 131 return false; 132 } 133 if (!upnpCh2Listener.check( 134 UPnPServiceResponseListenerTest.NO_UPNP_SERVICES, 135 t.getRemainTime())) { 136 mReason = getListenerError(upnpCh2Listener); 137 return false; 138 } 139 140 return true; 141 } 142 143 @Override getTestName()144 public String getTestName() { 145 return "Multiple clients test 02"; 146 } 147 } 148