1 /*
2 * Copyright (C) 2020 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 #include <OffloadControlTestV1_1.h>
18 #include <gtest/gtest.h>
19 #include <hidl/GtestPrinter.h>
20 #include <hidl/ServiceManagement.h>
21
22 using android::hardware::tetheroffload::control::V1_1::IOffloadControl;
23
24 const hidl_string TEST_IFACE("rmnet_data0");
25
26 // Check that calling setDataWarningAndLimit() without first having called initOffload() returns
27 // false.
TEST_P(OffloadControlTestV1_1_HalNotStarted,SetDataWarningAndLimitWithoutInitReturnsFalse)28 TEST_P(OffloadControlTestV1_1_HalNotStarted, SetDataWarningAndLimitWithoutInitReturnsFalse) {
29 const Return<void> ret = getControlV1_1()->setDataWarningAndLimit(TEST_IFACE, 5000ULL, 5000ULL,
30 ASSERT_FALSE_CALLBACK);
31 EXPECT_TRUE(ret.isOk());
32 }
33
34 /*
35 * Tests for IOffloadControl::setDataWarningAndLimit().
36 */
37
38 // Test that setDataWarningAndLimit() for an empty interface name fails.
TEST_P(OffloadControlTestV1_1_HalStarted,SetDataWarningAndLimitEmptyUpstreamIfaceFails)39 TEST_P(OffloadControlTestV1_1_HalStarted, SetDataWarningAndLimitEmptyUpstreamIfaceFails) {
40 const Return<void> ret = getControlV1_1()->setDataWarningAndLimit(
41 hidl_string(""), 12345ULL, 67890ULL, ASSERT_FALSE_CALLBACK);
42 EXPECT_TRUE(ret.isOk());
43 }
44
45 // TEST_IFACE is presumed to exist on the device and be up. No packets
46 // are ever actually caused to be forwarded.
TEST_P(OffloadControlTestV1_1_HalStarted,SetDataWarningAndLimitNonZeroOk)47 TEST_P(OffloadControlTestV1_1_HalStarted, SetDataWarningAndLimitNonZeroOk) {
48 const Return<void> ret = getControlV1_1()->setDataWarningAndLimit(TEST_IFACE, 4000ULL, 5000ULL,
49 ASSERT_TRUE_CALLBACK);
50 EXPECT_TRUE(ret.isOk());
51 }
52
53 // TEST_IFACE is presumed to exist on the device and be up. No packets
54 // are ever actually caused to be forwarded.
TEST_P(OffloadControlTestV1_1_HalStarted,SetDataWarningAndLimitZeroOk)55 TEST_P(OffloadControlTestV1_1_HalStarted, SetDataWarningAndLimitZeroOk) {
56 const Return<void> ret =
57 getControlV1_1()->setDataWarningAndLimit(TEST_IFACE, 0ULL, 0ULL, ASSERT_TRUE_CALLBACK);
58 EXPECT_TRUE(ret.isOk());
59 }
60
61 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OffloadControlTestV1_1_HalNotStarted);
62 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OffloadControlTestV1_1_HalStarted);
63
64 INSTANTIATE_TEST_CASE_P(
65 PerInstance, OffloadControlTestV1_1_HalNotStarted,
66 testing::Combine(testing::ValuesIn(android::hardware::getAllHalInstanceNames(
67 IOffloadConfig::descriptor)),
68 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
69 IOffloadControl::descriptor))),
70 android::hardware::PrintInstanceTupleNameToString<>);
71
72 INSTANTIATE_TEST_CASE_P(
73 PerInstance, OffloadControlTestV1_1_HalStarted,
74 testing::Combine(testing::ValuesIn(android::hardware::getAllHalInstanceNames(
75 IOffloadConfig::descriptor)),
76 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
77 IOffloadControl::descriptor))),
78 android::hardware::PrintInstanceTupleNameToString<>);
79