1 /* 2 * Copyright (c) 2022-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <cstdlib> 17 #include <memory> 18 #include <string> 19 #include "gtest/gtest.h" 20 #define private public 21 #define protected public 22 #include "foundation/cpp_ext/algorithm_ext.h" 23 24 using namespace testing::ext; 25 26 namespace OHOS { 27 namespace Media { 28 namespace Test { 29 HWTEST(TestAnyOf, any_of_should_return_true_if_int_item_exists, TestSize.Level1) 30 { 31 std::vector<int> vec {1, 2, 3, 4}; __anon00c4d0c90102(int item) 32 ASSERT_EQ(true, CppExt::AnyOf(std::begin(vec), std::end(vec), [](int item) { return item == 3; })); 33 } 34 HWTEST(TestAnyOf, any_of_should_return_true_if_string_item_exists, TestSize.Level1) 35 { 36 std::vector<std::string> vec {"one", "two", "three"}; 37 ASSERT_EQ(true, CppExt::AnyOf(std::begin(vec), std::end(vec), __anon00c4d0c90202(const std::string& item) 38 [](const std::string& item) { return item == "two"; })); 39 } 40 41 HWTEST(TestAnyOf, any_of_should_return_false_if_item_not_exists, TestSize.Level1) 42 { 43 std::vector<int> vec {1, 2, 3, 4}; __anon00c4d0c90302(int item) 44 ASSERT_EQ(false, CppExt::AnyOf(std::begin(vec), std::end(vec), [](int item) { return item == 8; })); 45 } 46 } // namespace Test 47 } // namespace Media 48 } // namespace OHOS 49