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" |
(...skipping 12 matching lines...) Expand all Loading... |
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 } | 26 } |
27 | 27 |
28 std::string TestBuffer::TestInvalidSize() { | 28 std::string TestBuffer::TestInvalidSize() { |
29 pp::Buffer_Dev zero_size(0); | 29 pp::Buffer_Dev zero_size(0); |
30 if (!zero_size.is_null()) | 30 if (!zero_size.is_null()) |
31 return "Zero size accepted"; | 31 return "Zero size accepted"; |
32 | 32 |
33 return ""; | 33 PASS(); |
34 } | 34 } |
35 | 35 |
36 std::string TestBuffer::TestInitToZero() { | 36 std::string TestBuffer::TestInitToZero() { |
37 pp::Buffer_Dev buffer(100); | 37 pp::Buffer_Dev buffer(100); |
38 if (buffer.is_null()) | 38 if (buffer.is_null()) |
39 return "Could not create buffer"; | 39 return "Could not create buffer"; |
40 | 40 |
41 if (buffer.size() != 100) | 41 if (buffer.size() != 100) |
42 return "Buffer size not as expected"; | 42 return "Buffer size not as expected"; |
43 | 43 |
44 // Now check that everything is 0. | 44 // Now check that everything is 0. |
45 unsigned char* bytes = static_cast<unsigned char *>(buffer.data()); | 45 unsigned char* bytes = static_cast<unsigned char *>(buffer.data()); |
46 for (uint32_t index = 0; index < buffer.size(); index++) { | 46 for (uint32_t index = 0; index < buffer.size(); index++) { |
47 if (bytes[index] != 0) | 47 if (bytes[index] != 0) |
48 return "Buffer isn't entirely zero"; | 48 return "Buffer isn't entirely zero"; |
49 } | 49 } |
50 | 50 |
51 return ""; | 51 PASS(); |
52 } | 52 } |
53 | 53 |
54 std::string TestBuffer::TestIsBuffer() { | 54 std::string TestBuffer::TestIsBuffer() { |
55 // Test that a NULL resource isn't a buffer. | 55 // Test that a NULL resource isn't a buffer. |
56 pp::Resource null_resource; | 56 pp::Resource null_resource; |
57 if (buffer_interface_->IsBuffer(null_resource.pp_resource())) | 57 if (buffer_interface_->IsBuffer(null_resource.pp_resource())) |
58 return "Null resource was reported as a valid buffer"; | 58 return "Null resource was reported as a valid buffer"; |
59 | 59 |
60 // Make another resource type and test it. | 60 // Make another resource type and test it. |
61 const int w = 16, h = 16; | 61 const int w = 16, h = 16; |
62 pp::Graphics2D device(pp::Size(w, h), true); | 62 pp::Graphics2D device(pp::Size(w, h), true); |
63 if (device.is_null()) | 63 if (device.is_null()) |
64 return "Couldn't create device context"; | 64 return "Couldn't create device context"; |
65 if (buffer_interface_->IsBuffer(device.pp_resource())) | 65 if (buffer_interface_->IsBuffer(device.pp_resource())) |
66 return "Device context was reported as a buffer"; | 66 return "Device context was reported as a buffer"; |
67 | 67 |
68 // Make a valid buffer. | 68 // Make a valid buffer. |
69 pp::Buffer_Dev buffer(100); | 69 pp::Buffer_Dev buffer(100); |
70 if (buffer.is_null()) | 70 if (buffer.is_null()) |
71 return "Couldn't create buffer"; | 71 return "Couldn't create buffer"; |
72 if (!buffer_interface_->IsBuffer(buffer.pp_resource())) | 72 if (!buffer_interface_->IsBuffer(buffer.pp_resource())) |
73 return "Buffer should be identified as a buffer"; | 73 return "Buffer should be identified as a buffer"; |
74 | 74 |
75 return ""; | 75 PASS(); |
76 } | 76 } |
77 | 77 |
OLD | NEW |