Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef PPAPI_TESTS_TEST_UTILS_H_ | 5 #ifndef PPAPI_TESTS_TEST_UTILS_H_ |
| 6 #define PPAPI_TESTS_TEST_UTILS_H_ | 6 #define PPAPI_TESTS_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "ppapi/c/dev/ppb_testing_dev.h" | 10 #include "ppapi/c/dev/ppb_testing_dev.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 bool waiting_; | 55 bool waiting_; |
| 56 bool signalled_; | 56 bool signalled_; |
| 57 // Disable copy and assign. | 57 // Disable copy and assign. |
| 58 NestedEvent(const NestedEvent&); | 58 NestedEvent(const NestedEvent&); |
| 59 NestedEvent& operator=(const NestedEvent&); | 59 NestedEvent& operator=(const NestedEvent&); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 enum CallbackType { PP_REQUIRED, PP_OPTIONAL, PP_BLOCKING }; | 62 enum CallbackType { PP_REQUIRED, PP_OPTIONAL, PP_BLOCKING }; |
| 63 class TestCompletionCallback { | 63 class TestCompletionCallback { |
| 64 public: | 64 public: |
| 65 class Delegate { | |
| 66 public: | |
| 67 virtual void OnCallback(void* user_data, int32_t result) = 0; | |
| 68 }; | |
| 65 explicit TestCompletionCallback(PP_Instance instance); | 69 explicit TestCompletionCallback(PP_Instance instance); |
| 66 // TODO(dmichael): Remove this constructor. | 70 // TODO(dmichael): Remove this constructor. |
| 67 TestCompletionCallback(PP_Instance instance, bool force_async); | 71 TestCompletionCallback(PP_Instance instance, bool force_async); |
| 68 | 72 |
| 69 TestCompletionCallback(PP_Instance instance, CallbackType callback_type); | 73 TestCompletionCallback(PP_Instance instance, CallbackType callback_type); |
| 70 | 74 |
| 75 void SetDelegate(Delegate* delegate) { delegate_ = delegate; } | |
|
dmichael (off chromium)
2012/06/25 15:50:51
Please add documentation for the method, including
Takashi Toyoshima
2012/06/26 09:19:10
Done.
| |
| 76 | |
| 71 // Waits for the callback to be called and returns the | 77 // Waits for the callback to be called and returns the |
| 72 // result. Returns immediately if the callback was previously called | 78 // result. Returns immediately if the callback was previously called |
| 73 // and the result wasn't returned (i.e. each result value received | 79 // and the result wasn't returned (i.e. each result value received |
| 74 // by the callback is returned by WaitForResult() once and only | 80 // by the callback is returned by WaitForResult() once and only |
| 75 // once). DEPRECATED: Please use the one below. | 81 // once). DEPRECATED: Please use the one below. |
| 76 // TODO(dmichael): Remove this one when all the tests are updated. | 82 // TODO(dmichael): Remove this one when all the tests are updated. |
| 77 int32_t WaitForResult(); | 83 int32_t WaitForResult(); |
| 78 | 84 |
| 79 // Wait for a result, given the return from the call which took this callback | 85 // Wait for a result, given the return from the call which took this callback |
| 80 // as a parameter. If |result| is PP_OK_COMPLETIONPENDING, WaitForResult will | 86 // as a parameter. If |result| is PP_OK_COMPLETIONPENDING, WaitForResult will |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 bool wait_for_result_called_; | 152 bool wait_for_result_called_; |
| 147 // Indicates whether we have already been invoked. | 153 // Indicates whether we have already been invoked. |
| 148 bool have_result_; | 154 bool have_result_; |
| 149 // The last result received (or PP_OK_COMPLETIONCALLBACK if none). | 155 // The last result received (or PP_OK_COMPLETIONCALLBACK if none). |
| 150 int32_t result_; | 156 int32_t result_; |
| 151 CallbackType callback_type_; | 157 CallbackType callback_type_; |
| 152 bool post_quit_task_; | 158 bool post_quit_task_; |
| 153 std::string errors_; | 159 std::string errors_; |
| 154 unsigned run_count_; | 160 unsigned run_count_; |
| 155 PP_Instance instance_; | 161 PP_Instance instance_; |
| 162 Delegate* delegate_; | |
| 156 }; | 163 }; |
| 157 | 164 |
| 158 // Verifies that the callback didn't record any errors. If the callback is run | 165 // Verifies that the callback didn't record any errors. If the callback is run |
| 159 // in an unexpected way (e.g., if it's invoked asynchronously when the call | 166 // in an unexpected way (e.g., if it's invoked asynchronously when the call |
| 160 // should have blocked), this returns an appropriate error string. | 167 // should have blocked), this returns an appropriate error string. |
| 161 #define CHECK_CALLBACK_BEHAVIOR(callback) \ | 168 #define CHECK_CALLBACK_BEHAVIOR(callback) \ |
| 162 do { \ | 169 do { \ |
| 163 if ((callback).failed()) \ | 170 if ((callback).failed()) \ |
| 164 return (callback).errors(); \ | 171 return (callback).errors(); \ |
| 165 } while (false) | 172 } while (false) |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 188 #error Please add support for your platform in ppapi/tests/test_utils.h | 195 #error Please add support for your platform in ppapi/tests/test_utils.h |
| 189 #endif | 196 #endif |
| 190 | 197 |
| 191 /* These are used to determine POSIX-like implementations vs Windows. */ | 198 /* These are used to determine POSIX-like implementations vs Windows. */ |
| 192 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ | 199 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ |
| 193 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__) | 200 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__) |
| 194 #define PPAPI_POSIX 1 | 201 #define PPAPI_POSIX 1 |
| 195 #endif | 202 #endif |
| 196 | 203 |
| 197 #endif // PPAPI_TESTS_TEST_UTILS_H_ | 204 #endif // PPAPI_TESTS_TEST_UTILS_H_ |
| OLD | NEW |