Chromium Code Reviews| 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.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_ = reinterpret_cast<const PPB_Memory_Dev*>( | |
|
dmichael (off chromium)
2011/07/01 21:42:10
nit: static_cast
der Springer
2011/07/05 19:28:27
Done.
| |
| 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 const char* buffer = memory_dev_interface_->MemAlloc(kTestBufferSize); | |
|
dmichael (off chromium)
2011/07/01 21:42:10
why const?
der Springer
2011/07/05 19:28:27
Done.
| |
| 37 // Touch a couple of locations. Failure will crash the test. | |
| 38 buffer[0] = '1'; | |
| 39 buffer[kTestBufferSize - 1] = '1'; | |
| 40 memory_dev_interface_->MemFree(buffer); | |
| 41 } | |
| 42 | |
| 43 // Make sure nothing leaked. | |
| 44 ASSERT_TRUE(testing_interface_->GetLiveObjectsForInstance( | |
| 45 instance_->pp_instance()) == before_object); | |
| 46 | |
| 47 PASS(); | |
| 48 } | |
| 49 | |
| 50 std::string TestMemory::TestNullMemFree() { | |
| 51 // Failure crashes the test. | |
| 52 memory_dev_interface_->MemFree(NULL); | |
| 53 | |
| 54 PASS(); | |
| 55 } | |
| 56 | |
| OLD | NEW |