blob: 72588b4dc8fb869e9eef49778397c0f38e106ea5 [file] [log] [blame]
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "power_manager/powerd/system/thermal/thermal_device_factory.h"
#include <set>
#include <string>
#include <vector>
#include <base/check.h>
#include <base/files/file_path.h>
#include <base/files/file_util.h>
#include <base/files/scoped_temp_dir.h>
#include <gtest/gtest.h>
namespace power_manager {
namespace system {
TEST(ThermalDeviceFactory, CreateThermalDevices) {
base::ScopedTempDir scoped_temp_dir;
CHECK(scoped_temp_dir.CreateUniqueTempDir());
base::FilePath temp_dir = scoped_temp_dir.GetPath();
std::string dirs[] = {"cooling_device1", "cooling_device2", "thermal_zone1",
"thermal_zone2"};
for (const auto& dir : dirs) {
base::FilePath device_dir = temp_dir.Append(dir);
CHECK(base::CreateDirectory(device_dir));
}
std::vector<std::unique_ptr<ThermalDeviceInterface>> res =
ThermalDeviceFactory::CreateThermalDevices(temp_dir.value().c_str());
EXPECT_EQ(2, res.size());
std::set<base::FilePath> expected_paths = {
temp_dir.Append("cooling_device1"), temp_dir.Append("cooling_device2")};
std::set<base::FilePath> actual_paths = {
static_cast<ThermalDevice*>(res[0].get())->get_device_path_for_testing(),
static_cast<ThermalDevice*>(res[1].get())->get_device_path_for_testing()};
EXPECT_EQ(expected_paths, actual_paths);
}
} // namespace system
} // namespace power_manager