Flutter Engine
The Flutter Engine
Test.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "tests/Test.h"
9
11#include "src/base/SkTime.h"
13
14#include <cstdlib>
15#include <cstring>
16
17static DEFINE_string2(tmpDir, t, nullptr, "Temp directory to use.");
18
20
21bool skiatest::Reporter::allowExtendedTest() const { return false; }
22
23bool skiatest::Reporter::verbose() const { return false; }
24
25
27 SkString fullMessage = f.message;
28 if (!fContextStack.empty()) {
29 fullMessage.append(" [");
30 for (int i = 0; i < fContextStack.size(); ++i) {
31 if (i > 0) {
32 fullMessage.append(", ");
33 }
34 fullMessage.append(fContextStack[i]);
35 }
36 fullMessage.append("]");
37 }
38 this->reportFailed(skiatest::Failure(f.fileName, f.lineNo, f.condition, fullMessage));
39}
40
42 SkString result = SkStringPrintf("%s:%d\t", this->fileName, this->lineNo);
43 if (!this->message.isEmpty()) {
44 result.append(this->message);
45 if (strlen(this->condition) > 0) {
46 result.append(": ");
47 }
48 }
49 result.append(this->condition);
50 return result;
51}
52
54 if (!FLAGS_tmpDir.isEmpty()) {
55 return SkString(FLAGS_tmpDir[0]);
56 }
57#ifdef SK_BUILD_FOR_ANDROID
58 const char* environmentVariable = "TMPDIR";
59 const char* defaultValue = "/data/local/tmp";
60#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
61 const char* environmentVariable = "TMPDIR";
62 const char* defaultValue = "/tmp";
63#elif defined(SK_BUILD_FOR_WIN)
64 const char* environmentVariable = "TEMP";
65 const char* defaultValue = nullptr;
66#else
67 const char* environmentVariable = nullptr;
68 const char* defaultValue = nullptr;
69#endif
70 const char* tmpdir = environmentVariable ? getenv(environmentVariable) : nullptr;
71 return SkString(tmpdir ? tmpdir : defaultValue);
72}
73
75
77 return SkTime::GetNSecs() - fStartNanos;
78}
79
80double skiatest::Timer::elapsedMs() const { return this->elapsedNs() * 1e-6; }
81
83 const double elapsedMs = this->elapsedMs();
84 SkASSERT(SK_MSecMax >= elapsedMs);
85 return static_cast<SkMSec>(elapsedMs);
86}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static constexpr SkMSec SK_MSecMax
Definition: SkTypes.h:188
uint32_t SkMSec
Definition: SkTypes.h:184
static DEFINE_string2(tmpDir, t, nullptr, "Temp directory to use.")
void append(const char text[])
Definition: SkString.h:203
void reportFailedWithContext(const skiatest::Failure &)
Definition: Test.cpp:26
virtual void bumpTestCount()
Definition: Test.cpp:19
virtual bool verbose() const
Definition: Test.cpp:23
virtual bool allowExtendedTest() const
Definition: Test.cpp:21
SkMSec elapsedMsInt() const
Definition: Test.cpp:82
double elapsedNs() const
Definition: Test.cpp:76
double elapsedMs() const
Definition: Test.cpp:80
GAsyncResult * result
Win32Message message
double GetNSecs()
Definition: SkTime.cpp:17
SkString GetTmpDir()
Definition: Test.cpp:53
SkString toString() const
Definition: Test.cpp:41