David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 "utils.h" |
| 18 | |
| 19 | #include "gtest/gtest.h" |
| 20 | |
| 21 | namespace art { |
| 22 | |
| 23 | class UtilsTest : public testing::Test {}; |
| 24 | |
| 25 | TEST_F(UtilsTest, PrettySize) { |
David Srbecky | de6c714 | 2019-01-09 11:27:40 +0000 | [diff] [blame] | 26 | EXPECT_EQ("1024MB", PrettySize(1 * GB)); |
| 27 | EXPECT_EQ("2048MB", PrettySize(2 * GB)); |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 28 | if (sizeof(size_t) > sizeof(uint32_t)) { |
| 29 | EXPECT_EQ("100GB", PrettySize(100 * GB)); |
| 30 | } |
| 31 | EXPECT_EQ("1024KB", PrettySize(1 * MB)); |
| 32 | EXPECT_EQ("10MB", PrettySize(10 * MB)); |
| 33 | EXPECT_EQ("100MB", PrettySize(100 * MB)); |
| 34 | EXPECT_EQ("1024B", PrettySize(1 * KB)); |
| 35 | EXPECT_EQ("10KB", PrettySize(10 * KB)); |
| 36 | EXPECT_EQ("100KB", PrettySize(100 * KB)); |
| 37 | EXPECT_EQ("0B", PrettySize(0)); |
| 38 | EXPECT_EQ("1B", PrettySize(1)); |
| 39 | EXPECT_EQ("10B", PrettySize(10)); |
| 40 | EXPECT_EQ("100B", PrettySize(100)); |
| 41 | EXPECT_EQ("512B", PrettySize(512)); |
| 42 | } |
| 43 | |
| 44 | TEST_F(UtilsTest, Split) { |
| 45 | std::vector<std::string> actual; |
| 46 | std::vector<std::string> expected; |
| 47 | |
| 48 | expected.clear(); |
| 49 | |
| 50 | actual.clear(); |
| 51 | Split("", ':', &actual); |
| 52 | EXPECT_EQ(expected, actual); |
| 53 | |
| 54 | actual.clear(); |
| 55 | Split(":", ':', &actual); |
| 56 | EXPECT_EQ(expected, actual); |
| 57 | |
| 58 | expected.clear(); |
| 59 | expected.push_back("foo"); |
| 60 | |
| 61 | actual.clear(); |
| 62 | Split(":foo", ':', &actual); |
| 63 | EXPECT_EQ(expected, actual); |
| 64 | |
| 65 | actual.clear(); |
| 66 | Split("foo:", ':', &actual); |
| 67 | EXPECT_EQ(expected, actual); |
| 68 | |
| 69 | actual.clear(); |
| 70 | Split(":foo:", ':', &actual); |
| 71 | EXPECT_EQ(expected, actual); |
| 72 | |
| 73 | expected.push_back("bar"); |
| 74 | |
| 75 | actual.clear(); |
| 76 | Split("foo:bar", ':', &actual); |
| 77 | EXPECT_EQ(expected, actual); |
| 78 | |
| 79 | actual.clear(); |
| 80 | Split(":foo:bar", ':', &actual); |
| 81 | EXPECT_EQ(expected, actual); |
| 82 | |
| 83 | actual.clear(); |
| 84 | Split("foo:bar:", ':', &actual); |
| 85 | EXPECT_EQ(expected, actual); |
| 86 | |
| 87 | actual.clear(); |
| 88 | Split(":foo:bar:", ':', &actual); |
| 89 | EXPECT_EQ(expected, actual); |
| 90 | |
| 91 | expected.push_back("baz"); |
| 92 | |
| 93 | actual.clear(); |
| 94 | Split("foo:bar:baz", ':', &actual); |
| 95 | EXPECT_EQ(expected, actual); |
| 96 | |
| 97 | actual.clear(); |
| 98 | Split(":foo:bar:baz", ':', &actual); |
| 99 | EXPECT_EQ(expected, actual); |
| 100 | |
| 101 | actual.clear(); |
| 102 | Split("foo:bar:baz:", ':', &actual); |
| 103 | EXPECT_EQ(expected, actual); |
| 104 | |
| 105 | actual.clear(); |
| 106 | Split(":foo:bar:baz:", ':', &actual); |
| 107 | EXPECT_EQ(expected, actual); |
| 108 | } |
| 109 | |
Wei Li | 8991ad0 | 2018-09-13 16:43:39 +0800 | [diff] [blame] | 110 | TEST_F(UtilsTest, GetProcessStatus) { |
David Srbecky | 883c134 | 2020-05-11 23:30:29 +0000 | [diff] [blame] | 111 | EXPECT_EQ("art_libartbase_", GetProcessStatus("Name")); |
Wei Li | 8991ad0 | 2018-09-13 16:43:39 +0800 | [diff] [blame] | 112 | EXPECT_EQ("R (running)", GetProcessStatus("State")); |
| 113 | EXPECT_EQ("<unknown>", GetProcessStatus("tate")); |
| 114 | EXPECT_EQ("<unknown>", GetProcessStatus("e")); |
| 115 | EXPECT_EQ("<unknown>", GetProcessStatus("Dummy")); |
| 116 | } |
| 117 | |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 118 | } // namespace art |