Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | // Author: cshapiro@google.com (Carl Shapiro) |
| 3 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 4 | #include "class_linker.h" |
| 5 | #include "common_test.h" |
| 6 | #include "dex_file.h" |
| 7 | #include "heap.h" |
| 8 | #include "object.h" |
| 9 | #include "scoped_ptr.h" |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 10 | |
| 11 | #include <stdio.h> |
| 12 | #include "gtest/gtest.h" |
| 13 | |
| 14 | namespace art { |
| 15 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 16 | class ObjectTest : public RuntimeTest {}; |
| 17 | |
| 18 | TEST_F(ObjectTest, IsInSamePackage) { |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 19 | // Matches |
| 20 | EXPECT_TRUE(Class::IsInSamePackage("Ljava/lang/Object;", |
| 21 | "Ljava/lang/Class")); |
| 22 | EXPECT_TRUE(Class::IsInSamePackage("LFoo;", |
| 23 | "LBar;")); |
| 24 | |
| 25 | // Mismatches |
| 26 | EXPECT_FALSE(Class::IsInSamePackage("Ljava/lang/Object;", |
| 27 | "Ljava/io/File;")); |
| 28 | EXPECT_FALSE(Class::IsInSamePackage("Ljava/lang/Object;", |
| 29 | "Ljava/lang/reflect/Method;")); |
| 30 | } |
| 31 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 32 | TEST_F(ObjectTest, AllocObjectArray) { |
| 33 | ObjectArray* oa = class_linker_->AllocObjectArray(2); |
| 34 | EXPECT_EQ(2U, oa->GetLength()); |
| 35 | EXPECT_TRUE(oa->Get(0) == NULL); |
| 36 | EXPECT_TRUE(oa->Get(1) == NULL); |
| 37 | oa->Set(0, oa); |
| 38 | EXPECT_TRUE(oa->Get(0) == oa); |
| 39 | EXPECT_TRUE(oa->Get(1) == NULL); |
| 40 | oa->Set(1, oa); |
| 41 | EXPECT_TRUE(oa->Get(0) == oa); |
| 42 | EXPECT_TRUE(oa->Get(1) == oa); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 45 | } // namespace art |