Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/media/libcubeb/gtest/common.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright © 2013 Sebastien Alaiwan
3
 *
4
 * This program is made available under an ISC-style license.  See the
5
 * accompanying file LICENSE for details.
6
 */
7
#if !defined(TEST_COMMON)
8
#define TEST_COMMON
9
10
#if defined( _WIN32)
11
#ifndef WIN32_LEAN_AND_MEAN
12
#define WIN32_LEAN_AND_MEAN
13
#endif
14
#include <objbase.h>
15
#include <windows.h>
16
#else
17
#include <unistd.h>
18
#endif
19
20
#include <cstdarg>
21
#include "cubeb/cubeb.h"
22
#include "cubeb_mixer.h"
23
24
template<typename T, size_t N>
25
constexpr size_t
26
ARRAY_LENGTH(T(&)[N])
27
0
{
28
0
  return N;
29
0
}
Unexecuted instantiation: unsigned long ARRAY_LENGTH<float, 512ul>(float (&) [512ul])
Unexecuted instantiation: unsigned long ARRAY_LENGTH<cubeb*, 4ul>(cubeb* (&) [4ul])
Unexecuted instantiation: unsigned long ARRAY_LENGTH<int, 4ul>(int (&) [4ul])
Unexecuted instantiation: unsigned long ARRAY_LENGTH<cubeb_stream*, 8ul>(cubeb_stream* (&) [8ul])
Unexecuted instantiation: unsigned long ARRAY_LENGTH<cubeb*, 2ul>(cubeb* (&) [2ul])
30
31
void delay(unsigned int ms)
32
0
{
33
#if defined(_WIN32)
34
  Sleep(ms);
35
#else
36
  sleep(ms / 1000);
37
0
  usleep(ms % 1000 * 1000);
38
0
#endif
39
0
}
40
41
#if !defined(M_PI)
42
#define M_PI 3.14159265358979323846
43
#endif
44
45
typedef struct {
46
  char const * name;
47
  unsigned int const channels;
48
  uint32_t const layout;
49
} layout_info;
50
51
int has_available_input_device(cubeb * ctx)
52
0
{
53
0
  cubeb_device_collection devices;
54
0
  int input_device_available = 0;
55
0
  int r;
56
0
  /* Bail out early if the host does not have input devices. */
57
0
  r = cubeb_enumerate_devices(ctx, CUBEB_DEVICE_TYPE_INPUT, &devices);
58
0
  if (r != CUBEB_OK) {
59
0
    fprintf(stderr, "error enumerating devices.");
60
0
    return 0;
61
0
  }
62
0
63
0
  if (devices.count == 0) {
64
0
    fprintf(stderr, "no input device available, skipping test.\n");
65
0
    cubeb_device_collection_destroy(ctx, &devices);
66
0
    return 0;
67
0
  }
68
0
69
0
  for (uint32_t i = 0; i < devices.count; i++) {
70
0
    input_device_available |= (devices.device[i].state ==
71
0
                               CUBEB_DEVICE_STATE_ENABLED);
72
0
  }
73
0
74
0
  if (!input_device_available) {
75
0
    fprintf(stderr, "there are input devices, but they are not "
76
0
        "available, skipping\n");
77
0
  }
78
0
79
0
  cubeb_device_collection_destroy(ctx, &devices);
80
0
  return !!input_device_available;
81
0
}
82
83
void print_log(const char * msg, ...)
84
0
{
85
0
  va_list args;
86
0
  va_start(args, msg);
87
0
  vprintf(msg, args);
88
0
  va_end(args);
89
0
}
90
91
/** Initialize cubeb with backend override.
92
 *  Create call cubeb_init passing value for CUBEB_BACKEND env var as
93
 *  override. */
94
int common_init(cubeb ** ctx, char const * ctx_name)
95
0
{
96
0
  int r;
97
0
  char const * backend;
98
0
  char const * ctx_backend;
99
0
100
0
  backend = getenv("CUBEB_BACKEND");
101
0
  r = cubeb_init(ctx, ctx_name, backend);
102
0
  if (r == CUBEB_OK && backend) {
103
0
    ctx_backend = cubeb_get_backend_id(*ctx);
104
0
    if (strcmp(backend, ctx_backend) != 0) {
105
0
      fprintf(stderr, "Requested backend `%s', got `%s'\n",
106
0
              backend, ctx_backend);
107
0
    }
108
0
  }
109
0
110
0
  return r;
111
0
}
112
113
#if defined( _WIN32)
114
class TestEnvironment : public ::testing::Environment {
115
public:
116
  void SetUp() override {
117
    hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
118
  }
119
120
  void TearDown() override {
121
    if (SUCCEEDED(hr)) {
122
      CoUninitialize();
123
    }
124
  }
125
126
private:
127
  HRESULT hr;
128
};
129
130
::testing::Environment* const foo_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment);
131
#endif
132
133
#endif /* TEST_COMMON */