OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ppapi/tests/test_memory.h" |
| 6 |
| 7 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 8 #include "ppapi/c/dev/ppb_memory_dev.h" |
| 9 #include "ppapi/cpp/instance.h" |
| 10 #include "ppapi/cpp/module.h" |
| 11 #include "ppapi/tests/testing_instance.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 size_t kTestBufferSize = 1000; |
| 16 |
| 17 } // namespace |
| 18 |
| 19 REGISTER_TEST_CASE(Memory); |
| 20 |
| 21 bool TestMemory::Init() { |
| 22 memory_dev_interface_ = static_cast<const PPB_Memory_Dev*>( |
| 23 pp::Module::Get()->GetBrowserInterface(PPB_MEMORY_DEV_INTERFACE)); |
| 24 return memory_dev_interface_ && InitTestingInterface(); |
| 25 } |
| 26 |
| 27 void TestMemory::RunTest() { |
| 28 RUN_TEST(MemAlloc); |
| 29 RUN_TEST(NullMemFree); |
| 30 } |
| 31 |
| 32 std::string TestMemory::TestMemAlloc() { |
| 33 uint32_t before_object = testing_interface_->GetLiveObjectsForInstance( |
| 34 instance_->pp_instance()); |
| 35 { |
| 36 char* buffer = static_cast<char*>( |
| 37 memory_dev_interface_->MemAlloc(kTestBufferSize)); |
| 38 // Touch a couple of locations. Failure will crash the test. |
| 39 buffer[0] = '1'; |
| 40 buffer[kTestBufferSize - 1] = '1'; |
| 41 memory_dev_interface_->MemFree(buffer); |
| 42 } |
| 43 |
| 44 // Make sure nothing leaked. |
| 45 ASSERT_TRUE(testing_interface_->GetLiveObjectsForInstance( |
| 46 instance_->pp_instance()) == before_object); |
| 47 |
| 48 PASS(); |
| 49 } |
| 50 |
| 51 std::string TestMemory::TestNullMemFree() { |
| 52 // Failure crashes the test. |
| 53 memory_dev_interface_->MemFree(NULL); |
| 54 |
| 55 PASS(); |
| 56 } |
| 57 |
OLD | NEW |