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 17 package com.android.cts.verifier.p2p.testcase; 18 19 20 import android.net.wifi.p2p.WifiP2pManager; 21 import android.net.wifi.p2p.WifiP2pManager.ActionListener; 22 import android.util.Log; 23 24 /** 25 * The utility class for testing android.net.wifi.p2p.WifiP2pManager.ActionListener 26 * callback function. 27 */ 28 public class ActionListenerTest extends ListenerTest implements ActionListener { 29 30 private static final String TAG = "ActionListenerTest"; 31 32 public static final Argument SUCCESS = new Argument(); 33 public static final Argument FAIL_NO_SERVICE = 34 new Argument(WifiP2pManager.NO_SERVICE_REQUESTS); 35 36 @Override 37 public void onFailure(int reason) { 38 Log.d(TAG, "onFailure() reason="+reason); 39 Argument arg = new Argument(reason); 40 receiveCallback(arg); 41 } 42 43 @Override 44 public void onSuccess() { 45 Log.d(TAG, "onSuccess()"); 46 Argument arg = new Argument(); 47 receiveCallback(arg); 48 } 49 50 /** 51 * The container of the argument of {@link #onFailure} or 52 * {@link #onSuccess}. 53 */ 54 static class Argument extends ListenerArgument { 55 56 boolean mIsSuccess; 57 58 int mResult; 59 60 /** 61 * For {@link #onSuccess} 62 */ 63 Argument() { 64 mIsSuccess = true; 65 mResult = 0; 66 } 67 68 /** 69 * For {@link #onFailure} 70 * @param result 71 */ 72 Argument(int result) { 73 mIsSuccess = false; 74 mResult = result; 75 } 76 77 @Override 78 public boolean equals(Object obj) { 79 if (obj == null || !(obj instanceof Argument)) { 80 return false; 81 } 82 Argument arg = (Argument)obj; 83 return (mIsSuccess == arg.mIsSuccess) && (mResult == arg.mResult); 84 } 85 86 @Override 87 public String toString() { 88 return "isSuccess=" + mIsSuccess + " result=" + mResult; 89 } 90 } 91 } 92