Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -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 | */ |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 16 | |
| 17 | #include "object.h" |
| 18 | #include "common_test.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame^] | 19 | #include "scoped_thread_state_change.h" |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 20 | #include "utils.h" |
| 21 | |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 22 | namespace art { |
| 23 | |
Elliott Hughes | 9058f2b | 2012-03-22 18:06:48 -0700 | [diff] [blame] | 24 | std::string PrettyArguments(const char* signature); |
| 25 | std::string PrettyReturnType(const char* signature); |
| 26 | |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 27 | class UtilsTest : public CommonTest { |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 30 | TEST_F(UtilsTest, PrettyDescriptor_ArrayReferences) { |
Elliott Hughes | 9058f2b | 2012-03-22 18:06:48 -0700 | [diff] [blame] | 31 | EXPECT_EQ("java.lang.Class[]", PrettyDescriptor("[Ljava/lang/Class;")); |
| 32 | EXPECT_EQ("java.lang.Class[][]", PrettyDescriptor("[[Ljava/lang/Class;")); |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 35 | TEST_F(UtilsTest, PrettyDescriptor_ScalarReferences) { |
Elliott Hughes | 9058f2b | 2012-03-22 18:06:48 -0700 | [diff] [blame] | 36 | EXPECT_EQ("java.lang.String", PrettyDescriptor("Ljava.lang.String;")); |
| 37 | EXPECT_EQ("java.lang.String", PrettyDescriptor("Ljava/lang/String;")); |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 40 | TEST_F(UtilsTest, PrettyDescriptor_PrimitiveArrays) { |
Elliott Hughes | 9058f2b | 2012-03-22 18:06:48 -0700 | [diff] [blame] | 41 | EXPECT_EQ("boolean[]", PrettyDescriptor("[Z")); |
| 42 | EXPECT_EQ("boolean[][]", PrettyDescriptor("[[Z")); |
| 43 | EXPECT_EQ("byte[]", PrettyDescriptor("[B")); |
| 44 | EXPECT_EQ("byte[][]", PrettyDescriptor("[[B")); |
| 45 | EXPECT_EQ("char[]", PrettyDescriptor("[C")); |
| 46 | EXPECT_EQ("char[][]", PrettyDescriptor("[[C")); |
| 47 | EXPECT_EQ("double[]", PrettyDescriptor("[D")); |
| 48 | EXPECT_EQ("double[][]", PrettyDescriptor("[[D")); |
| 49 | EXPECT_EQ("float[]", PrettyDescriptor("[F")); |
| 50 | EXPECT_EQ("float[][]", PrettyDescriptor("[[F")); |
| 51 | EXPECT_EQ("int[]", PrettyDescriptor("[I")); |
| 52 | EXPECT_EQ("int[][]", PrettyDescriptor("[[I")); |
| 53 | EXPECT_EQ("long[]", PrettyDescriptor("[J")); |
| 54 | EXPECT_EQ("long[][]", PrettyDescriptor("[[J")); |
| 55 | EXPECT_EQ("short[]", PrettyDescriptor("[S")); |
| 56 | EXPECT_EQ("short[][]", PrettyDescriptor("[[S")); |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Elliott Hughes | 5174fe6 | 2011-08-23 15:12:35 -0700 | [diff] [blame] | 59 | TEST_F(UtilsTest, PrettyDescriptor_PrimitiveScalars) { |
Elliott Hughes | 9058f2b | 2012-03-22 18:06:48 -0700 | [diff] [blame] | 60 | EXPECT_EQ("boolean", PrettyDescriptor("Z")); |
| 61 | EXPECT_EQ("byte", PrettyDescriptor("B")); |
| 62 | EXPECT_EQ("char", PrettyDescriptor("C")); |
| 63 | EXPECT_EQ("double", PrettyDescriptor("D")); |
| 64 | EXPECT_EQ("float", PrettyDescriptor("F")); |
| 65 | EXPECT_EQ("int", PrettyDescriptor("I")); |
| 66 | EXPECT_EQ("long", PrettyDescriptor("J")); |
| 67 | EXPECT_EQ("short", PrettyDescriptor("S")); |
| 68 | } |
| 69 | |
| 70 | TEST_F(UtilsTest, PrettyArguments) { |
| 71 | EXPECT_EQ("()", PrettyArguments("()V")); |
| 72 | EXPECT_EQ("(int)", PrettyArguments("(I)V")); |
| 73 | EXPECT_EQ("(int, int)", PrettyArguments("(II)V")); |
| 74 | EXPECT_EQ("(int, int, int[][])", PrettyArguments("(II[[I)V")); |
| 75 | EXPECT_EQ("(int, int, int[][], java.lang.Poop)", PrettyArguments("(II[[ILjava/lang/Poop;)V")); |
| 76 | EXPECT_EQ("(int, int, int[][], java.lang.Poop, java.lang.Poop[][])", PrettyArguments("(II[[ILjava/lang/Poop;[[Ljava/lang/Poop;)V")); |
| 77 | } |
| 78 | |
| 79 | TEST_F(UtilsTest, PrettyReturnType) { |
| 80 | EXPECT_EQ("void", PrettyReturnType("()V")); |
| 81 | EXPECT_EQ("int", PrettyReturnType("()I")); |
| 82 | EXPECT_EQ("int[][]", PrettyReturnType("()[[I")); |
| 83 | EXPECT_EQ("java.lang.Poop", PrettyReturnType("()Ljava/lang/Poop;")); |
| 84 | EXPECT_EQ("java.lang.Poop[][]", PrettyReturnType("()[[Ljava/lang/Poop;")); |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 87 | TEST_F(UtilsTest, PrettyTypeOf) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame^] | 88 | ScopedObjectAccess soa(Thread::Current()); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 89 | EXPECT_EQ("null", PrettyTypeOf(NULL)); |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 90 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 91 | SirtRef<String> s(String::AllocFromModifiedUtf8("")); |
| 92 | EXPECT_EQ("java.lang.String", PrettyTypeOf(s.get())); |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 93 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 94 | SirtRef<ShortArray> a(ShortArray::Alloc(2)); |
| 95 | EXPECT_EQ("short[]", PrettyTypeOf(a.get())); |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 96 | |
| 97 | Class* c = class_linker_->FindSystemClass("[Ljava/lang/String;"); |
| 98 | ASSERT_TRUE(c != NULL); |
| 99 | Object* o = ObjectArray<String>::Alloc(c, 0); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 100 | EXPECT_EQ("java.lang.String[]", PrettyTypeOf(o)); |
| 101 | EXPECT_EQ("java.lang.Class<java.lang.String[]>", PrettyTypeOf(o->GetClass())); |
| 102 | } |
| 103 | |
| 104 | TEST_F(UtilsTest, PrettyClass) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame^] | 105 | ScopedObjectAccess soa(Thread::Current()); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 106 | EXPECT_EQ("null", PrettyClass(NULL)); |
| 107 | Class* c = class_linker_->FindSystemClass("[Ljava/lang/String;"); |
| 108 | ASSERT_TRUE(c != NULL); |
| 109 | Object* o = ObjectArray<String>::Alloc(c, 0); |
| 110 | EXPECT_EQ("java.lang.Class<java.lang.String[]>", PrettyClass(o->GetClass())); |
| 111 | } |
| 112 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 113 | TEST_F(UtilsTest, PrettyClassAndClassLoader) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame^] | 114 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 115 | EXPECT_EQ("null", PrettyClassAndClassLoader(NULL)); |
| 116 | Class* c = class_linker_->FindSystemClass("[Ljava/lang/String;"); |
| 117 | ASSERT_TRUE(c != NULL); |
| 118 | Object* o = ObjectArray<String>::Alloc(c, 0); |
| 119 | EXPECT_EQ("java.lang.Class<java.lang.String[],null>", PrettyClassAndClassLoader(o->GetClass())); |
| 120 | } |
| 121 | |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 122 | TEST_F(UtilsTest, PrettyField) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame^] | 123 | ScopedObjectAccess soa(Thread::Current()); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 124 | EXPECT_EQ("null", PrettyField(NULL)); |
| 125 | |
| 126 | Class* java_lang_String = class_linker_->FindSystemClass("Ljava/lang/String;"); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 127 | |
| 128 | Field* f; |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 129 | f = java_lang_String->FindDeclaredInstanceField("count", "I"); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 130 | EXPECT_EQ("int java.lang.String.count", PrettyField(f)); |
| 131 | EXPECT_EQ("java.lang.String.count", PrettyField(f, false)); |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 132 | f = java_lang_String->FindDeclaredInstanceField("value", "[C"); |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 133 | EXPECT_EQ("char[] java.lang.String.value", PrettyField(f)); |
| 134 | EXPECT_EQ("java.lang.String.value", PrettyField(f, false)); |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 137 | TEST_F(UtilsTest, PrettySize) { |
| 138 | EXPECT_EQ("1GB", PrettySize(1 * GB)); |
| 139 | EXPECT_EQ("2GB", PrettySize(2 * GB)); |
| 140 | if (sizeof(size_t) > sizeof(uint32_t)) { |
| 141 | EXPECT_EQ("100GB", PrettySize(100 * GB)); |
| 142 | } |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 143 | EXPECT_EQ("1024KB", PrettySize(1 * MB)); |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 144 | EXPECT_EQ("10MB", PrettySize(10 * MB)); |
| 145 | EXPECT_EQ("100MB", PrettySize(100 * MB)); |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 146 | EXPECT_EQ("1024B", PrettySize(1 * KB)); |
Elliott Hughes | 409d273 | 2012-04-03 13:34:44 -0700 | [diff] [blame] | 147 | EXPECT_EQ("10KB", PrettySize(10 * KB)); |
| 148 | EXPECT_EQ("100KB", PrettySize(100 * KB)); |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 149 | EXPECT_EQ("0B", PrettySize(0)); |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 150 | EXPECT_EQ("1B", PrettySize(1)); |
| 151 | EXPECT_EQ("10B", PrettySize(10)); |
| 152 | EXPECT_EQ("100B", PrettySize(100)); |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 153 | EXPECT_EQ("512B", PrettySize(512)); |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | TEST_F(UtilsTest, PrettyDuration) { |
| 157 | const uint64_t one_sec = 1000000000; |
| 158 | const uint64_t one_ms = 1000000; |
| 159 | const uint64_t one_us = 1000; |
| 160 | |
| 161 | EXPECT_EQ("1s", PrettyDuration(1 * one_sec)); |
| 162 | EXPECT_EQ("10s", PrettyDuration(10 * one_sec)); |
| 163 | EXPECT_EQ("100s", PrettyDuration(100 * one_sec)); |
| 164 | EXPECT_EQ("1.001s", PrettyDuration(1 * one_sec + one_ms)); |
| 165 | EXPECT_EQ("1.000001s", PrettyDuration(1 * one_sec + one_us)); |
| 166 | EXPECT_EQ("1.000000001s", PrettyDuration(1 * one_sec + 1)); |
| 167 | |
| 168 | EXPECT_EQ("1ms", PrettyDuration(1 * one_ms)); |
| 169 | EXPECT_EQ("10ms", PrettyDuration(10 * one_ms)); |
| 170 | EXPECT_EQ("100ms", PrettyDuration(100 * one_ms)); |
| 171 | EXPECT_EQ("1.001ms", PrettyDuration(1 * one_ms + one_us)); |
| 172 | EXPECT_EQ("1.000001ms", PrettyDuration(1 * one_ms + 1)); |
| 173 | |
| 174 | EXPECT_EQ("1us", PrettyDuration(1 * one_us)); |
| 175 | EXPECT_EQ("10us", PrettyDuration(10 * one_us)); |
| 176 | EXPECT_EQ("100us", PrettyDuration(100 * one_us)); |
| 177 | EXPECT_EQ("1.001us", PrettyDuration(1 * one_us + 1)); |
| 178 | |
| 179 | EXPECT_EQ("1ns", PrettyDuration(1)); |
| 180 | EXPECT_EQ("10ns", PrettyDuration(10)); |
| 181 | EXPECT_EQ("100ns", PrettyDuration(100)); |
| 182 | } |
| 183 | |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 184 | TEST_F(UtilsTest, MangleForJni) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame^] | 185 | ScopedObjectAccess soa(Thread::Current()); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 186 | EXPECT_EQ("hello_00024world", MangleForJni("hello$world")); |
| 187 | EXPECT_EQ("hello_000a9world", MangleForJni("hello\xc2\xa9world")); |
| 188 | EXPECT_EQ("hello_1world", MangleForJni("hello_world")); |
| 189 | EXPECT_EQ("Ljava_lang_String_2", MangleForJni("Ljava/lang/String;")); |
| 190 | EXPECT_EQ("_3C", MangleForJni("[C")); |
| 191 | } |
| 192 | |
| 193 | TEST_F(UtilsTest, JniShortName_JniLongName) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame^] | 194 | ScopedObjectAccess soa(Thread::Current()); |
Elliott Hughes | 79082e3 | 2011-08-25 12:07:32 -0700 | [diff] [blame] | 195 | Class* c = class_linker_->FindSystemClass("Ljava/lang/String;"); |
| 196 | ASSERT_TRUE(c != NULL); |
| 197 | Method* m; |
| 198 | |
| 199 | m = c->FindVirtualMethod("charAt", "(I)C"); |
| 200 | ASSERT_TRUE(m != NULL); |
| 201 | EXPECT_EQ("Java_java_lang_String_charAt", JniShortName(m)); |
| 202 | EXPECT_EQ("Java_java_lang_String_charAt__I", JniLongName(m)); |
| 203 | |
| 204 | m = c->FindVirtualMethod("indexOf", "(Ljava/lang/String;I)I"); |
| 205 | ASSERT_TRUE(m != NULL); |
| 206 | EXPECT_EQ("Java_java_lang_String_indexOf", JniShortName(m)); |
| 207 | EXPECT_EQ("Java_java_lang_String_indexOf__Ljava_lang_String_2I", JniLongName(m)); |
| 208 | |
| 209 | m = c->FindDirectMethod("copyValueOf", "([CII)Ljava/lang/String;"); |
| 210 | ASSERT_TRUE(m != NULL); |
| 211 | EXPECT_EQ("Java_java_lang_String_copyValueOf", JniShortName(m)); |
| 212 | EXPECT_EQ("Java_java_lang_String_copyValueOf___3CII", JniLongName(m)); |
| 213 | } |
| 214 | |
Elliott Hughes | 3402380 | 2011-08-30 12:06:17 -0700 | [diff] [blame] | 215 | TEST_F(UtilsTest, Split) { |
| 216 | std::vector<std::string> actual; |
| 217 | std::vector<std::string> expected; |
| 218 | |
| 219 | expected.clear(); |
| 220 | |
| 221 | actual.clear(); |
| 222 | Split("", ':', actual); |
| 223 | EXPECT_EQ(expected, actual); |
| 224 | |
| 225 | actual.clear(); |
| 226 | Split(":", ':', actual); |
| 227 | EXPECT_EQ(expected, actual); |
| 228 | |
| 229 | expected.clear(); |
| 230 | expected.push_back("foo"); |
| 231 | |
| 232 | actual.clear(); |
| 233 | Split(":foo", ':', actual); |
| 234 | EXPECT_EQ(expected, actual); |
| 235 | |
| 236 | actual.clear(); |
| 237 | Split("foo:", ':', actual); |
| 238 | EXPECT_EQ(expected, actual); |
| 239 | |
| 240 | actual.clear(); |
| 241 | Split(":foo:", ':', actual); |
| 242 | EXPECT_EQ(expected, actual); |
| 243 | |
| 244 | expected.push_back("bar"); |
| 245 | |
| 246 | actual.clear(); |
| 247 | Split("foo:bar", ':', actual); |
| 248 | EXPECT_EQ(expected, actual); |
| 249 | |
| 250 | actual.clear(); |
| 251 | Split(":foo:bar", ':', actual); |
| 252 | EXPECT_EQ(expected, actual); |
| 253 | |
| 254 | actual.clear(); |
| 255 | Split("foo:bar:", ':', actual); |
| 256 | EXPECT_EQ(expected, actual); |
| 257 | |
| 258 | actual.clear(); |
| 259 | Split(":foo:bar:", ':', actual); |
| 260 | EXPECT_EQ(expected, actual); |
| 261 | |
| 262 | expected.push_back("baz"); |
| 263 | |
| 264 | actual.clear(); |
| 265 | Split("foo:bar:baz", ':', actual); |
| 266 | EXPECT_EQ(expected, actual); |
| 267 | |
| 268 | actual.clear(); |
| 269 | Split(":foo:bar:baz", ':', actual); |
| 270 | EXPECT_EQ(expected, actual); |
| 271 | |
| 272 | actual.clear(); |
| 273 | Split("foo:bar:baz:", ':', actual); |
| 274 | EXPECT_EQ(expected, actual); |
| 275 | |
| 276 | actual.clear(); |
| 277 | Split(":foo:bar:baz:", ':', actual); |
| 278 | EXPECT_EQ(expected, actual); |
| 279 | } |
| 280 | |
Elliott Hughes | 48436bb | 2012-02-07 15:23:28 -0800 | [diff] [blame] | 281 | TEST_F(UtilsTest, Join) { |
| 282 | std::vector<std::string> strings; |
| 283 | |
| 284 | strings.clear(); |
| 285 | EXPECT_EQ("", Join(strings, ':')); |
| 286 | |
| 287 | strings.clear(); |
| 288 | strings.push_back("foo"); |
| 289 | EXPECT_EQ("foo", Join(strings, ':')); |
| 290 | |
| 291 | strings.clear(); |
| 292 | strings.push_back(""); |
| 293 | strings.push_back("foo"); |
| 294 | EXPECT_EQ(":foo", Join(strings, ':')); |
| 295 | |
| 296 | strings.clear(); |
| 297 | strings.push_back("foo"); |
| 298 | strings.push_back(""); |
| 299 | EXPECT_EQ("foo:", Join(strings, ':')); |
| 300 | |
| 301 | strings.clear(); |
| 302 | strings.push_back(""); |
| 303 | strings.push_back("foo"); |
| 304 | strings.push_back(""); |
| 305 | EXPECT_EQ(":foo:", Join(strings, ':')); |
| 306 | |
| 307 | strings.clear(); |
| 308 | strings.push_back("foo"); |
| 309 | strings.push_back("bar"); |
| 310 | EXPECT_EQ("foo:bar", Join(strings, ':')); |
| 311 | |
| 312 | strings.clear(); |
| 313 | strings.push_back("foo"); |
| 314 | strings.push_back("bar"); |
| 315 | strings.push_back("baz"); |
| 316 | EXPECT_EQ("foo:bar:baz", Join(strings, ':')); |
| 317 | } |
| 318 | |
Brian Carlstrom | 7a967b3 | 2012-03-28 15:23:10 -0700 | [diff] [blame] | 319 | TEST_F(UtilsTest, StartsWith) { |
| 320 | EXPECT_FALSE(StartsWith("foo", "bar")); |
| 321 | EXPECT_TRUE(StartsWith("foo", "foo")); |
| 322 | EXPECT_TRUE(StartsWith("food", "foo")); |
| 323 | EXPECT_FALSE(StartsWith("fo", "foo")); |
| 324 | } |
| 325 | |
| 326 | TEST_F(UtilsTest, EndsWith) { |
| 327 | EXPECT_FALSE(EndsWith("foo", "bar")); |
| 328 | EXPECT_TRUE(EndsWith("foo", "foo")); |
| 329 | EXPECT_TRUE(EndsWith("foofoo", "foo")); |
| 330 | EXPECT_FALSE(EndsWith("oo", "foo")); |
| 331 | } |
| 332 | |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 333 | } // namespace art |