OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "ppapi/tests/test_buffer.h" | 5 #include "ppapi/tests/test_buffer.h" |
6 | 6 |
7 #include "ppapi/c/dev/ppb_buffer_dev.h" | 7 #include "ppapi/c/dev/ppb_buffer_dev.h" |
8 #include "ppapi/cpp/dev/buffer_dev.h" | 8 #include "ppapi/cpp/dev/buffer_dev.h" |
9 #include "ppapi/cpp/graphics_2d.h" | 9 #include "ppapi/cpp/graphics_2d.h" |
10 #include "ppapi/cpp/instance.h" | 10 #include "ppapi/cpp/instance.h" |
11 #include "ppapi/cpp/module.h" | 11 #include "ppapi/cpp/module.h" |
12 #include "ppapi/tests/testing_instance.h" | 12 #include "ppapi/tests/testing_instance.h" |
13 | 13 |
14 REGISTER_TEST_CASE(Buffer); | 14 REGISTER_TEST_CASE(Buffer); |
15 | 15 |
16 bool TestBuffer::Init() { | 16 bool TestBuffer::Init() { |
17 buffer_interface_ = reinterpret_cast<PPB_Buffer_Dev const*>( | 17 buffer_interface_ = reinterpret_cast<PPB_Buffer_Dev const*>( |
18 pp::Module::Get()->GetBrowserInterface(PPB_BUFFER_DEV_INTERFACE)); | 18 pp::Module::Get()->GetBrowserInterface(PPB_BUFFER_DEV_INTERFACE)); |
19 return !!buffer_interface_; | 19 return !!buffer_interface_; |
20 } | 20 } |
21 | 21 |
22 void TestBuffer::RunTest() { | 22 void TestBuffer::RunTest() { |
23 instance_->LogTest("InvalidSize", TestInvalidSize()); | 23 instance_->LogTest("InvalidSize", TestInvalidSize()); |
24 instance_->LogTest("InitToZero", TestInitToZero()); | 24 instance_->LogTest("InitToZero", TestInitToZero()); |
25 instance_->LogTest("IsBuffer", TestIsBuffer()); | 25 instance_->LogTest("IsBuffer", TestIsBuffer()); |
26 instance_->LogTest("BasicLifecyle", TestBasicLifeCycle()); | |
26 } | 27 } |
27 | 28 |
28 std::string TestBuffer::TestInvalidSize() { | 29 std::string TestBuffer::TestInvalidSize() { |
29 pp::Buffer_Dev zero_size(instance_, 0); | 30 pp::Buffer_Dev zero_size(instance_, 0); |
30 if (!zero_size.is_null()) | 31 if (!zero_size.is_null()) |
31 return "Zero size accepted"; | 32 return "Zero size accepted"; |
32 | 33 |
33 PASS(); | 34 PASS(); |
34 } | 35 } |
35 | 36 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 // Make a valid buffer. | 69 // Make a valid buffer. |
69 pp::Buffer_Dev buffer(instance_, 100); | 70 pp::Buffer_Dev buffer(instance_, 100); |
70 if (buffer.is_null()) | 71 if (buffer.is_null()) |
71 return "Couldn't create buffer"; | 72 return "Couldn't create buffer"; |
72 if (!buffer_interface_->IsBuffer(buffer.pp_resource())) | 73 if (!buffer_interface_->IsBuffer(buffer.pp_resource())) |
73 return "Buffer should be identified as a buffer"; | 74 return "Buffer should be identified as a buffer"; |
74 | 75 |
75 PASS(); | 76 PASS(); |
76 } | 77 } |
77 | 78 |
79 std::string TestBuffer::TestBasicLifeCycle() { | |
80 enum { kBufferSize = 100 }; | |
81 | |
82 pp::Buffer_Dev *buffer = new pp::Buffer_Dev(instance_, kBufferSize); | |
83 if (buffer->is_null() || | |
84 !buffer_interface_->IsBuffer(buffer->pp_resource()) || | |
85 buffer->size() != kBufferSize) { | |
86 return "Error creating buffer (earlier test should have failed)"; | |
87 } | |
88 | |
89 // Test that the buffer got created & mapped. | |
90 if (buffer->data() == NULL) | |
91 return "Failed to Map() buffer"; | |
92 | |
93 // Test that the buffer is writeable. | |
94 char* data = reinterpret_cast<char*>(buffer->data()); | |
piman
2011/06/09 23:11:32
static_cast
Ami GONE FROM CHROMIUM
2011/06/09 23:35:28
Done.
| |
95 for (int i = 0; i < kBufferSize; ++i) | |
96 data[i] = 'X'; | |
97 | |
98 // Implicitly test that destroying the buffer doesn't encounter a fatal error | |
99 // in Unmap. | |
100 delete buffer; | |
101 | |
102 PASS(); | |
103 } | |
OLD | NEW |