1/* 2 * Copyright (C) 2017 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 "property_type.h" 18 19#include <gtest/gtest.h> 20 21namespace android { 22namespace init { 23 24TEST(property_type, CheckType_string) { 25 EXPECT_TRUE(CheckType("string", "")); 26 EXPECT_TRUE(CheckType("string", "-234")); 27 EXPECT_TRUE(CheckType("string", "234")); 28 EXPECT_TRUE(CheckType("string", "true")); 29 EXPECT_TRUE(CheckType("string", "false")); 30 EXPECT_TRUE(CheckType("string", "45645634563456345634563456")); 31 EXPECT_TRUE(CheckType("string", "some other string")); 32} 33 34TEST(property_type, CheckType_int) { 35 EXPECT_FALSE(CheckType("int", "")); 36 EXPECT_FALSE(CheckType("int", "abc")); 37 EXPECT_FALSE(CheckType("int", "-abc")); 38 EXPECT_TRUE(CheckType("int", "0")); 39 EXPECT_TRUE(CheckType("int", std::to_string(std::numeric_limits<int64_t>::min()))); 40 EXPECT_TRUE(CheckType("int", std::to_string(std::numeric_limits<int64_t>::max()))); 41 EXPECT_TRUE(CheckType("int", "123")); 42 EXPECT_TRUE(CheckType("int", "-123")); 43} 44 45TEST(property_type, CheckType_uint) { 46 EXPECT_FALSE(CheckType("uint", "")); 47 EXPECT_FALSE(CheckType("uint", "abc")); 48 EXPECT_FALSE(CheckType("uint", "-abc")); 49 EXPECT_TRUE(CheckType("uint", "0")); 50 EXPECT_TRUE(CheckType("uint", std::to_string(std::numeric_limits<uint64_t>::max()))); 51 EXPECT_TRUE(CheckType("uint", "123")); 52 EXPECT_FALSE(CheckType("uint", "-123")); 53} 54 55TEST(property_type, CheckType_double) { 56 EXPECT_FALSE(CheckType("double", "")); 57 EXPECT_FALSE(CheckType("double", "abc")); 58 EXPECT_FALSE(CheckType("double", "-abc")); 59 EXPECT_TRUE(CheckType("double", "0.0")); 60 EXPECT_TRUE(CheckType("double", std::to_string(std::numeric_limits<double>::min()))); 61 EXPECT_TRUE(CheckType("double", std::to_string(std::numeric_limits<double>::max()))); 62 EXPECT_TRUE(CheckType("double", "123.1")); 63 EXPECT_TRUE(CheckType("double", "-123.1")); 64} 65 66TEST(property_type, CheckType_size) { 67 EXPECT_FALSE(CheckType("size", "")); 68 EXPECT_FALSE(CheckType("size", "ab")); 69 EXPECT_FALSE(CheckType("size", "abcd")); 70 EXPECT_FALSE(CheckType("size", "0")); 71 72 EXPECT_TRUE(CheckType("size", "512g")); 73 EXPECT_TRUE(CheckType("size", "512k")); 74 EXPECT_TRUE(CheckType("size", "512m")); 75 76 EXPECT_FALSE(CheckType("size", "512gggg")); 77 EXPECT_FALSE(CheckType("size", "512mgk")); 78 EXPECT_FALSE(CheckType("size", "g")); 79 EXPECT_FALSE(CheckType("size", "m")); 80} 81 82TEST(property_type, CheckType_enum) { 83 EXPECT_FALSE(CheckType("enum abc", "")); 84 EXPECT_FALSE(CheckType("enum abc", "ab")); 85 EXPECT_FALSE(CheckType("enum abc", "abcd")); 86 EXPECT_FALSE(CheckType("enum 123 456 789", "0")); 87 88 EXPECT_TRUE(CheckType("enum abc", "abc")); 89 EXPECT_TRUE(CheckType("enum 123 456 789", "123")); 90 EXPECT_TRUE(CheckType("enum 123 456 789", "456")); 91 EXPECT_TRUE(CheckType("enum 123 456 789", "789")); 92} 93 94} // namespace init 95} // namespace android 96