Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
74skiatest::Timer::Timer() : fStartNanos(SkTime::GetNSecs()) {}
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 DEFINE_string2(name, shortName, defaultValue, helpString)
#define SkASSERT(cond)
Definition SkAssert.h:116
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
static constexpr SkMSec SK_MSecMax
Definition SkTypes.h:188
uint32_t SkMSec
Definition SkTypes.h:184
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