1 /*
2  * Copyright (C) 2019 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 "android-base/parsebool.h"
18 
19 #include <errno.h>
20 
21 #include <gtest/gtest.h>
22 #include <string_view>
23 
24 using android::base::ParseBool;
25 using android::base::ParseBoolResult;
26 
TEST(parsebool,true_)27 TEST(parsebool, true_) {
28   static const char* yes[] = {
29       "1", "on", "true", "y", "yes",
30   };
31   for (const char* s : yes) {
32     ASSERT_EQ(ParseBoolResult::kTrue, ParseBool(s));
33   }
34 }
35 
TEST(parsebool,false_)36 TEST(parsebool, false_) {
37   static const char* no[] = {
38       "0", "false", "n", "no", "off",
39   };
40   for (const char* s : no) {
41     ASSERT_EQ(ParseBoolResult::kFalse, ParseBool(s));
42   }
43 }
44 
TEST(parsebool,invalid)45 TEST(parsebool, invalid) {
46   ASSERT_EQ(ParseBoolResult::kError, ParseBool("blarg"));
47   ASSERT_EQ(ParseBoolResult::kError, ParseBool(""));
48 }
49