1 /******************************************************************************
2  *
3  *  Copyright 2019 The Android Open Source Project
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #include "common/init_flags.h"
20 
21 #include <gtest/gtest.h>
22 
23 using bluetooth::common::InitFlags;
24 
TEST(InitFlagsTest,test_enable_debug_logging_for_all)25 TEST(InitFlagsTest, test_enable_debug_logging_for_all) {
26   const char* input[] = {"INIT_logging_debug_enabled_for_all=true", nullptr};
27   InitFlags::Load(input);
28   ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("foo"));
29   ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("bar"));
30   ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForAll());
31 }
32 
TEST(InitFlagsTest,test_enable_debug_logging_for_tags)33 TEST(InitFlagsTest, test_enable_debug_logging_for_tags) {
34   const char* input[] = {"INIT_logging_debug_enabled_for_tags=foo,bar,hello", nullptr};
35   InitFlags::Load(input);
36   ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("foo"));
37   ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("bar"));
38   ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("hello"));
39   ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("Foo"));
40   ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForAll());
41 }
42 
TEST(InitFlagsTest,test_disable_debug_logging_for_tags)43 TEST(InitFlagsTest, test_disable_debug_logging_for_tags) {
44   const char* input[] = {"INIT_logging_debug_disabled_for_tags=foo,bar,hello", nullptr};
45   InitFlags::Load(input);
46   ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("foo"));
47   ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("bar"));
48   ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("hello"));
49   ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("Foo"));
50   ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForAll());
51 }
52 
TEST(InitFlagsTest,test_debug_logging_multiple_flags)53 TEST(InitFlagsTest, test_debug_logging_multiple_flags) {
54   const char* input[] = {"INIT_logging_debug_enabled_for_tags=foo,hello",
55                          "INIT_logging_debug_disabled_for_tags=foo,bar",
56                          "INIT_logging_debug_enabled_for_all=false",
57                          nullptr};
58   InitFlags::Load(input);
59   ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("foo"));
60   ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("bar"));
61   ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("hello"));
62   ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("Foo"));
63   ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForAll());
64 }
65