Weilin Xu | 67e83a3 | 2024-01-10 13:40:28 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2024 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 <broadcastradio-utils-aidl/UtilsV2.h> |
| 18 | #include <gtest/gtest.h> |
| 19 | |
| 20 | namespace aidl::android::hardware::broadcastradio { |
| 21 | |
| 22 | namespace { |
| 23 | struct IsValidMetadataV2TestCase { |
| 24 | std::string name; |
| 25 | Metadata metadata; |
| 26 | bool valid; |
| 27 | }; |
| 28 | |
| 29 | std::vector<IsValidMetadataV2TestCase> getIsValidMetadataV2TestCases() { |
| 30 | return std::vector<IsValidMetadataV2TestCase>({ |
| 31 | IsValidMetadataV2TestCase{.name = "valid_rds_pty", |
| 32 | .metadata = Metadata::make<Metadata::rdsPty>(1), |
| 33 | .valid = true}, |
| 34 | IsValidMetadataV2TestCase{.name = "negative_rds_pty", |
| 35 | .metadata = Metadata::make<Metadata::rdsPty>(-1), |
| 36 | .valid = false}, |
| 37 | IsValidMetadataV2TestCase{ |
| 38 | .name = "valid_hd_station_name_short", |
| 39 | .metadata = Metadata::make<Metadata::hdStationNameShort>("name_short"), |
| 40 | .valid = true}, |
| 41 | IsValidMetadataV2TestCase{ |
| 42 | .name = "too_long_hd_station_name_short", |
| 43 | .metadata = Metadata::make<Metadata::hdStationNameShort>("name_too_long"), |
| 44 | .valid = false}, |
| 45 | IsValidMetadataV2TestCase{ |
| 46 | .name = "valid_hd_subchannel_available", |
| 47 | .metadata = Metadata::make<Metadata::hdSubChannelsAvailable>(1), |
| 48 | .valid = true}, |
| 49 | IsValidMetadataV2TestCase{ |
| 50 | .name = "negative_subchannel_available", |
| 51 | .metadata = Metadata::make<Metadata::hdSubChannelsAvailable>(-1), |
| 52 | .valid = false}, |
| 53 | IsValidMetadataV2TestCase{ |
| 54 | .name = "large_subchannel_available", |
| 55 | .metadata = Metadata::make<Metadata::hdSubChannelsAvailable>(256), |
| 56 | .valid = false}, |
| 57 | }); |
| 58 | } |
| 59 | } // namespace |
| 60 | |
| 61 | class IsValidMetadataV2Test : public testing::TestWithParam<IsValidMetadataV2TestCase> {}; |
| 62 | |
| 63 | INSTANTIATE_TEST_SUITE_P(IsValidMetadataV2Tests, IsValidMetadataV2Test, |
| 64 | testing::ValuesIn(getIsValidMetadataV2TestCases()), |
| 65 | [](const testing::TestParamInfo<IsValidMetadataV2Test::ParamType>& info) { |
| 66 | return info.param.name; |
| 67 | }); |
| 68 | |
| 69 | TEST_P(IsValidMetadataV2Test, IsValidMetadataV2) { |
| 70 | IsValidMetadataV2TestCase testParam = GetParam(); |
| 71 | |
| 72 | ASSERT_EQ(utils::isValidMetadataV2(testParam.metadata), testParam.valid); |
| 73 | } |
| 74 | |
| 75 | } // namespace aidl::android::hardware::broadcastradio |