| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/discardable_memory.h" | 5 #include "base/memory/discardable_memory.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 namespace base { | 8 namespace base { |
| 9 | 9 |
| 10 #if defined(OS_ANDROID) || defined(OS_MACOSX) | |
| 11 // Test Lock() and Unlock() functionalities. | 10 // Test Lock() and Unlock() functionalities. |
| 12 TEST(DiscardableMemoryTest, LockAndUnLock) { | 11 TEST(DiscardableMemoryTest, LockAndUnLock) { |
| 13 ASSERT_TRUE(DiscardableMemory::Supported()); | 12 ASSERT_TRUE(DiscardableMemory::Supported()); |
| 14 | 13 |
| 15 const size_t size = 1024; | 14 const size_t size = 1024; |
| 16 | 15 |
| 17 DiscardableMemory memory; | 16 DiscardableMemory memory; |
| 18 ASSERT_TRUE(memory.InitializeAndLock(size)); | 17 ASSERT_TRUE(memory.InitializeAndLock(size)); |
| 19 void* addr = memory.Memory(); | 18 void* addr = memory.Memory(); |
| 20 ASSERT_NE(static_cast<void*>(NULL), addr); | 19 ASSERT_NE(static_cast<void*>(NULL), addr); |
| 21 | 20 |
| 22 memory.Unlock(); | 21 memory.Unlock(); |
| 23 // The system should have no reason to purge discardable blocks in this brief | 22 // The system should have no reason to purge discardable blocks in this brief |
| 24 // interval, though technically speaking this might flake. | 23 // interval, though technically speaking this might flake. |
| 25 EXPECT_EQ(DISCARDABLE_MEMORY_SUCCESS, memory.Lock()); | 24 EXPECT_EQ(DISCARDABLE_MEMORY_SUCCESS, memory.Lock()); |
| 26 addr = memory.Memory(); | 25 addr = memory.Memory(); |
| 27 ASSERT_NE(static_cast<void*>(NULL), addr); | 26 ASSERT_NE(static_cast<void*>(NULL), addr); |
| 28 | 27 |
| 29 memory.Unlock(); | 28 memory.Unlock(); |
| 30 } | 29 } |
| 31 | 30 |
| 32 // Test delete a discardable memory while it is locked. | 31 // Test delete a discardable memory while it is locked. |
| 33 TEST(DiscardableMemoryTest, DeleteWhileLocked) { | 32 TEST(DiscardableMemoryTest, DeleteWhileLocked) { |
| 34 ASSERT_TRUE(DiscardableMemory::Supported()); | |
| 35 | |
| 36 const size_t size = 1024; | 33 const size_t size = 1024; |
| 37 | 34 |
| 38 DiscardableMemory memory; | 35 DiscardableMemory memory; |
| 39 ASSERT_TRUE(memory.InitializeAndLock(size)); | 36 ASSERT_TRUE(memory.InitializeAndLock(size)); |
| 40 } | 37 } |
| 41 | 38 |
| 42 #if defined(OS_MACOSX) | 39 #if !defined(OS_ANDROID) |
| 43 // Test forced purging. | 40 // Test forced purging. |
| 44 TEST(DiscardableMemoryTest, Purge) { | 41 TEST(DiscardableMemoryTest, Purge) { |
| 45 ASSERT_TRUE(DiscardableMemory::Supported()); | 42 ASSERT_TRUE(DiscardableMemory::Supported()); |
| 46 ASSERT_TRUE(DiscardableMemory::PurgeForTestingSupported()); | 43 ASSERT_TRUE(DiscardableMemory::PurgeForTestingSupported()); |
| 47 | 44 |
| 48 const size_t size = 1024; | 45 const size_t size = 1024; |
| 49 | 46 |
| 50 DiscardableMemory memory; | 47 DiscardableMemory memory; |
| 51 ASSERT_TRUE(memory.InitializeAndLock(size)); | 48 ASSERT_TRUE(memory.InitializeAndLock(size)); |
| 52 memory.Unlock(); | 49 memory.Unlock(); |
| 53 | 50 |
| 54 DiscardableMemory::PurgeForTesting(); | 51 DiscardableMemory::PurgeForTesting(); |
| 55 EXPECT_EQ(DISCARDABLE_MEMORY_PURGED, memory.Lock()); | 52 EXPECT_EQ(DISCARDABLE_MEMORY_PURGED, memory.Lock()); |
| 56 } | 53 } |
| 57 #endif // OS_MACOSX | 54 #endif // !OS_ANDROID |
| 58 | |
| 59 #endif // OS_* | |
| 60 | 55 |
| 61 } | 56 } |
| OLD | NEW |