-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaemon_test.cc
65 lines (51 loc) · 1.83 KB
/
daemon_test.cc
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
// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include <optional>
#include <utility>
#include <base/files/file_path.h>
#include <base/values.h>
#include <brillo/dbus/mock_dbus_method_response.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "runtime_probe/daemon.h"
#include "runtime_probe/proto_bindings/runtime_probe.pb.h"
#include "runtime_probe/system/context_mock_impl.h"
namespace runtime_probe {
namespace {
using ::brillo::dbus_utils::MockDBusMethodResponse;
using ::testing::NiceMock;
using ::testing::Return;
class DaemonTest : public ::testing::Test {
protected:
Daemon daemon_;
org::chromium::RuntimeProbeInterface* const dbus_adaptor_{&daemon_};
private:
ContextMockImpl mock_context_;
};
TEST_F(DaemonTest, ProbeCategories_LoadDefaultFailed) {
ProbeRequest request;
request.set_probe_default_category(true);
std::optional<ProbeResult> reply;
auto response =
std::make_unique<MockDBusMethodResponse<ProbeResult>>(nullptr);
response->save_return_args(&reply);
dbus_adaptor_->ProbeCategories(std::move(response), request);
EXPECT_TRUE(reply);
EXPECT_EQ(reply->error(), RUNTIME_PROBE_ERROR_PROBE_CONFIG_INVALID);
}
TEST_F(DaemonTest, ProbeSsfcComponents_LoadDefaultFailed) {
ProbeSsfcComponentsRequest request;
std::optional<ProbeSsfcComponentsResponse> reply;
auto response =
std::make_unique<MockDBusMethodResponse<ProbeSsfcComponentsResponse>>(
nullptr);
response->save_return_args(&reply);
dbus_adaptor_->ProbeSsfcComponents(std::move(response), request);
EXPECT_TRUE(reply);
EXPECT_EQ(reply->error(), RUNTIME_PROBE_ERROR_PROBE_CONFIG_INVALID);
}
// TODO(kevinptt): Add more test cases for D-Bus methods.
} // namespace
} // namespace runtime_probe