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