blob: 8cff24e15f172e2f2f84759fc9223341ed675005 [file] [log] [blame]
[email protected]917e86a2011-06-30 21:42:371// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]de9bdd12010-11-04 00:36:222// 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]7358d572011-02-15 18:44:4011#include "ppapi/c/pp_instance.h"
[email protected]de9bdd12010-11-04 00:36:2212#include "ppapi/c/pp_stdint.h"
13#include "ppapi/cpp/completion_callback.h"
14
[email protected]3c149c62011-11-11 23:22:5215// Timeout to wait for some action to complete.
16extern const int kActionTimeoutMs;
17
[email protected]de9bdd12010-11-04 00:36:2218const PPB_Testing_Dev* GetTestingInterface();
19std::string ReportError(const char* method, int32_t error);
[email protected]3c149c62011-11-11 23:22:5220void PlatformSleep(int duration_ms);
[email protected]961e8972011-12-15 15:29:1921bool GetLocalHostPort(PP_Instance instance, std::string* host, uint16_t* port);
[email protected]de9bdd12010-11-04 00:36:2222
23class TestCompletionCallback {
24 public:
[email protected]7358d572011-02-15 18:44:4025 TestCompletionCallback(PP_Instance instance);
[email protected]917e86a2011-06-30 21:42:3726 TestCompletionCallback(PP_Instance instance, bool force_async);
[email protected]de9bdd12010-11-04 00:36:2227
[email protected]26d912d32011-05-02 17:28:1028 // Waits for the callback to be called and returns the
29 // result. Returns immediately if the callback was previously called
30 // and the result wasn't returned (i.e. each result value received
31 // by the callback is returned by WaitForResult() once and only
32 // once).
[email protected]de9bdd12010-11-04 00:36:2233 int32_t WaitForResult();
34
35 operator pp::CompletionCallback() const;
36
[email protected]64264ef2010-12-21 00:45:4337 unsigned run_count() const { return run_count_; }
38 void reset_run_count() { run_count_ = 0; }
39
[email protected]db567f2b2011-04-12 23:28:5940 int32_t result() const { return result_; }
41
[email protected]de9bdd12010-11-04 00:36:2242 private:
43 static void Handler(void* user_data, int32_t result);
44
[email protected]26d912d32011-05-02 17:28:1045 bool have_result_;
[email protected]de9bdd12010-11-04 00:36:2246 int32_t result_;
[email protected]917e86a2011-06-30 21:42:3747 bool force_async_;
[email protected]de9bdd12010-11-04 00:36:2248 bool post_quit_task_;
[email protected]64264ef2010-12-21 00:45:4349 unsigned run_count_;
[email protected]7358d572011-02-15 18:44:4050 PP_Instance instance_;
[email protected]de9bdd12010-11-04 00:36:2251};
52
[email protected]2059f3d2011-12-01 20:12:3753/*
54 * A set of macros to use for platform detection. These were largely copied
55 * from chromium's build_config.h.
56 */
57#if defined(__APPLE__)
58#define PPAPI_OS_MACOSX 1
59#elif defined(ANDROID)
60#define PPAPI_OS_ANDROID 1
61#elif defined(__native_client__)
62#define PPAPI_OS_NACL 1
63#elif defined(__linux__)
64#define PPAPI_OS_LINUX 1
65#elif defined(_WIN32)
66#define PPAPI_OS_WIN 1
67#elif defined(__FreeBSD__)
68#define PPAPI_OS_FREEBSD 1
69#elif defined(__OpenBSD__)
70#define PPAPI_OS_OPENBSD 1
71#elif defined(__sun)
72#define PPAPI_OS_SOLARIS 1
73#else
74#error Please add support for your platform in ppapi/c/pp_macros.h.
75#endif
76
77/* These are used to determine POSIX-like implementations vs Windows. */
78#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
79 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__)
80#define PPAPI_POSIX 1
81#endif
82
[email protected]de9bdd12010-11-04 00:36:2283#endif // PPAPI_TESTS_TEST_UTILS_H_