-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathperformance_test.cc
More file actions
89 lines (72 loc) · 2.74 KB
/
Copy pathperformance_test.cc
File metadata and controls
89 lines (72 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2021 Google LLC
#if defined(FIREBASE_ANDROID_FOR_DESKTOP)
#define __ANDROID__
#include <jni.h>
#include "testing/run_all_tests.h"
#endif // defined(FIREBASE_ANDROID_FOR_DESKTOP)
#include "app/src/include/firebase/app.h"
#include "app/tests/include/firebase/app_for_testing.h"
#include "performance/src/include/firebase/performance.h"
#include "performance/src/include/firebase/performance/http_metric.h"
#include "performance/src/include/firebase/performance/trace.h"
#include "performance/src/performance_common.h"
#ifdef __ANDROID__
#include "app/src/util_android.h"
#endif // __ANDROID__
#if defined(FIREBASE_ANDROID_FOR_DESKTOP)
#undef __ANDROID__
#endif // defined(FIREBASE_ANDROID_FOR_DESKTOP)
#include "absl/memory/memory.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "testing/config.h"
#include "testing/reporter.h"
namespace firebase {
namespace performance {
class PerformanceTest : public ::testing::Test {
protected:
void SetUp() override {
firebase::testing::cppsdk::ConfigSet("{}");
reporter_.reset();
firebase_app_.reset(testing::CreateApp());
AddExpectationAndroid("FirebasePerformance.getInstance", {});
performance::Initialize(*firebase_app_);
}
void TearDown() override {
firebase::testing::cppsdk::ConfigReset();
Terminate();
firebase_app_.reset();
EXPECT_THAT(reporter_.getFakeReports(),
::testing::Eq(reporter_.getExpectations()));
}
void AddExpectationAndroid(const char* fake,
std::initializer_list<std::string> args) {
reporter_.addExpectation(fake, "", firebase::testing::cppsdk::kAndroid,
args);
}
void AddExpectationApple(const char* fake,
std::initializer_list<std::string> args) {
reporter_.addExpectation(fake, "", firebase::testing::cppsdk::kIos, args);
}
std::unique_ptr<App> firebase_app_;
firebase::testing::cppsdk::Reporter reporter_;
};
TEST_F(PerformanceTest, TestDestroyDefaultApp) {
EXPECT_TRUE(internal::IsInitialized());
firebase_app_.reset();
EXPECT_FALSE(internal::IsInitialized());
}
TEST_F(PerformanceTest, TestSetPerformanceCollectionEnabled) {
AddExpectationApple("-[FIRPerformance setDataCollectionEnabled:]", {"YES"});
AddExpectationAndroid("FirebasePerformance.setPerformanceCollectionEnabled",
{"true"});
SetPerformanceCollectionEnabled(true);
}
TEST_F(PerformanceTest, TestSetPerformanceCollectionDisabled) {
AddExpectationApple("-[FIRPerformance setDataCollectionEnabled:]", {"NO"});
AddExpectationAndroid("FirebasePerformance.setPerformanceCollectionEnabled",
{"false"});
SetPerformanceCollectionEnabled(false);
}
} // namespace performance
} // namespace firebase