1 /** 2 * Copyright (c) 2019, 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 #ifndef _TEST_METRICS_H_ 18 #define _TEST_METRICS_H_ 19 20 #include "BaseTestMetricsListener.h" 21 22 namespace android { 23 namespace net { 24 namespace metrics { 25 26 class TestOnDnsEvent : public BaseTestMetricsListener { 27 public: 28 // Both latencyMs and uid are not verified. No special reason. 29 struct TestResult { 30 int netId; 31 int eventType; 32 int returnCode; 33 int ipAddressesCount; 34 std::string hostname; 35 std::string ipAddress; // Check first address only. 36 }; 37 38 TestOnDnsEvent() = delete; TestOnDnsEvent(const std::vector<TestResult> & results)39 TestOnDnsEvent(const std::vector<TestResult>& results) : mResults(results){}; 40 41 // BaseTestMetricsListener::isVerified() override. isVerified()42 bool isVerified() override { return (getVerified() & EventFlag::onDnsEvent) != 0; } 43 44 // Override for testing verification. 45 android::binder::Status onDnsEvent(int32_t netId, int32_t eventType, int32_t returnCode, 46 int32_t /*latencyMs*/, const std::string& hostname, 47 const std::vector<std::string>& ipAddresses, 48 int32_t ipAddressesCount, int32_t /*uid*/) override; 49 50 private: 51 const std::vector<TestResult>& mResults; // Expected results for test verification. 52 }; 53 54 } // namespace metrics 55 } // namespace net 56 } // namespace android 57 58 #endif // _TEST_METRICS_H_ 59