• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 static mojo::test::TestSupport* g_test_support = NULL;
12 
13 extern "C" {
14 
MojoTestSupportLogPerfResult(const char * test_name,const char * sub_test_name,double value,const char * units)15 void MojoTestSupportLogPerfResult(const char* test_name,
16                                   const char* sub_test_name,
17                                   double value,
18                                   const char* units) {
19   if (g_test_support) {
20     g_test_support->LogPerfResult(test_name, sub_test_name, value, units);
21   } else {
22     if (sub_test_name) {
23       printf("[no test runner]\t%s/%s\t%g\t%s\n", test_name, sub_test_name,
24              value, units);
25     } else {
26       printf("[no test runner]\t%s\t%g\t%s\n", test_name, value, units);
27     }
28   }
29 }
30 
MojoTestSupportOpenSourceRootRelativeFile(const char * relative_path)31 FILE* MojoTestSupportOpenSourceRootRelativeFile(const char* relative_path) {
32   if (g_test_support)
33     return g_test_support->OpenSourceRootRelativeFile(relative_path);
34   printf("[no test runner]\n");
35   return NULL;
36 }
37 
MojoTestSupportEnumerateSourceRootRelativeDirectory(const char * relative_path)38 char** MojoTestSupportEnumerateSourceRootRelativeDirectory(
39     const char* relative_path) {
40   if (g_test_support)
41     return g_test_support->EnumerateSourceRootRelativeDirectory(relative_path);
42 
43   printf("[no test runner]\n");
44 
45   // Return empty list:
46   char** rv = static_cast<char**>(calloc(1, sizeof(char*)));
47   rv[0] = NULL;
48   return rv;
49 }
50 
51 }  // extern "C"
52 
53 namespace mojo {
54 namespace test {
55 
~TestSupport()56 TestSupport::~TestSupport() {
57 }
58 
59 // static
Init(TestSupport * test_support)60 void TestSupport::Init(TestSupport* test_support) {
61   assert(!g_test_support);
62   g_test_support = test_support;
63 }
64 
65 // static
Get()66 TestSupport* TestSupport::Get() {
67   return g_test_support;
68 }
69 
70 // static
Reset()71 void TestSupport::Reset() {
72   g_test_support = NULL;
73 }
74 
75 }  // namespace test
76 }  // namespace mojo
77