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 namespace OHOS {
25 namespace Media {
26 namespace Test {
TEST(TestAnyOf,any_of_should_return_true_if_int_item_exists)27 TEST(TestAnyOf, any_of_should_return_true_if_int_item_exists)
28 {
29 std::vector<int> vec {1, 2, 3, 4};
30 ASSERT_EQ(true, CppExt::AnyOf(std::begin(vec), std::end(vec), [](int item) { return item == 3; }));
31 }
TEST(TestAnyOf,any_of_should_return_true_if_string_item_exists)32 TEST(TestAnyOf, any_of_should_return_true_if_string_item_exists)
33 {
34 std::vector<std::string> vec {"one", "two", "three"};
35 ASSERT_EQ(true, CppExt::AnyOf(std::begin(vec), std::end(vec),
36 [](const std::string& item) { return item == "two"; }));
37 }
38
TEST(TestAnyOf,any_of_should_return_false_if_item_not_exists)39 TEST(TestAnyOf, any_of_should_return_false_if_item_not_exists)
40 {
41 std::vector<int> vec {1, 2, 3, 4};
42 ASSERT_EQ(false, CppExt::AnyOf(std::begin(vec), std::end(vec), [](int item) { return item == 8; }));
43 }
44 } // namespace Test
45 } // namespace Media
46 } // namespace OHOS
47