[email protected] | 917e86a | 2011-06-30 21:42:37 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | de9bdd1 | 2010-11-04 00:36:22 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef PPAPI_TESTS_TEST_UTILS_H_ | ||||
6 | #define PPAPI_TESTS_TEST_UTILS_H_ | ||||
7 | |||||
8 | #include <string> | ||||
9 | |||||
10 | #include "ppapi/c/dev/ppb_testing_dev.h" | ||||
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame] | 11 | #include "ppapi/c/pp_instance.h" |
[email protected] | de9bdd1 | 2010-11-04 00:36:22 | [diff] [blame] | 12 | #include "ppapi/c/pp_stdint.h" |
13 | #include "ppapi/cpp/completion_callback.h" | ||||
14 | |||||
[email protected] | 3c149c6 | 2011-11-11 23:22:52 | [diff] [blame^] | 15 | // Timeout to wait for some action to complete. |
16 | extern const int kActionTimeoutMs; | ||||
17 | |||||
[email protected] | de9bdd1 | 2010-11-04 00:36:22 | [diff] [blame] | 18 | const PPB_Testing_Dev* GetTestingInterface(); |
19 | std::string ReportError(const char* method, int32_t error); | ||||
[email protected] | 3c149c6 | 2011-11-11 23:22:52 | [diff] [blame^] | 20 | void PlatformSleep(int duration_ms); |
[email protected] | de9bdd1 | 2010-11-04 00:36:22 | [diff] [blame] | 21 | |
22 | class TestCompletionCallback { | ||||
23 | public: | ||||
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame] | 24 | TestCompletionCallback(PP_Instance instance); |
[email protected] | 917e86a | 2011-06-30 21:42:37 | [diff] [blame] | 25 | TestCompletionCallback(PP_Instance instance, bool force_async); |
[email protected] | de9bdd1 | 2010-11-04 00:36:22 | [diff] [blame] | 26 | |
[email protected] | 26d912d3 | 2011-05-02 17:28:10 | [diff] [blame] | 27 | // Waits for the callback to be called and returns the |
28 | // result. Returns immediately if the callback was previously called | ||||
29 | // and the result wasn't returned (i.e. each result value received | ||||
30 | // by the callback is returned by WaitForResult() once and only | ||||
31 | // once). | ||||
[email protected] | de9bdd1 | 2010-11-04 00:36:22 | [diff] [blame] | 32 | int32_t WaitForResult(); |
33 | |||||
34 | operator pp::CompletionCallback() const; | ||||
35 | |||||
[email protected] | 64264ef | 2010-12-21 00:45:43 | [diff] [blame] | 36 | unsigned run_count() const { return run_count_; } |
37 | void reset_run_count() { run_count_ = 0; } | ||||
38 | |||||
[email protected] | db567f2b | 2011-04-12 23:28:59 | [diff] [blame] | 39 | int32_t result() const { return result_; } |
40 | |||||
[email protected] | de9bdd1 | 2010-11-04 00:36:22 | [diff] [blame] | 41 | private: |
42 | static void Handler(void* user_data, int32_t result); | ||||
43 | |||||
[email protected] | 26d912d3 | 2011-05-02 17:28:10 | [diff] [blame] | 44 | bool have_result_; |
[email protected] | de9bdd1 | 2010-11-04 00:36:22 | [diff] [blame] | 45 | int32_t result_; |
[email protected] | 917e86a | 2011-06-30 21:42:37 | [diff] [blame] | 46 | bool force_async_; |
[email protected] | de9bdd1 | 2010-11-04 00:36:22 | [diff] [blame] | 47 | bool post_quit_task_; |
[email protected] | 64264ef | 2010-12-21 00:45:43 | [diff] [blame] | 48 | unsigned run_count_; |
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame] | 49 | PP_Instance instance_; |
[email protected] | de9bdd1 | 2010-11-04 00:36:22 | [diff] [blame] | 50 | }; |
51 | |||||
52 | #endif // PPAPI_TESTS_TEST_UTILS_H_ |