1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "mojo/public/tests/test_support_private.h"
6
7#include <assert.h>
8#include <stdio.h>
9#include <stdlib.h>
10
11static mojo::test::TestSupport* g_test_support = NULL;
12
13extern "C" {
14
15void MojoTestSupportLogPerfResult(const char* test_name,
16                                  double value,
17                                  const char* units) {
18  if (g_test_support)
19    g_test_support->LogPerfResult(test_name, value, units);
20  else
21    printf("[no test runner]\t%s\t%g\t%s\n", test_name, value, units);
22}
23
24FILE* MojoTestSupportOpenSourceRootRelativeFile(const char* relative_path) {
25  if (g_test_support)
26    return g_test_support->OpenSourceRootRelativeFile(relative_path);
27  printf("[no test runner]\n");
28  return NULL;
29}
30
31char** MojoTestSupportEnumerateSourceRootRelativeDirectory(
32    const char* relative_path) {
33  if (g_test_support)
34    return g_test_support->EnumerateSourceRootRelativeDirectory(relative_path);
35
36  printf("[no test runner]\n");
37
38  // Return empty list:
39  char** rv = static_cast<char**>(calloc(1, sizeof(char*)));
40  rv[0] = NULL;
41  return rv;
42}
43
44}  // extern "C"
45
46namespace mojo {
47namespace test {
48
49TestSupport::~TestSupport() {
50}
51
52// static
53void TestSupport::Init(TestSupport* test_support) {
54  assert(!g_test_support);
55  g_test_support = test_support;
56}
57
58// static
59TestSupport* TestSupport::Get() {
60  return g_test_support;
61}
62
63// static
64void TestSupport::Reset() {
65  g_test_support = NULL;
66}
67
68}  // namespace test
69}  // namespace mojo
70