phosphor-ipmi-flash: Code Health Cleanup
Removed the following warning.
- using decl '*' is unused
- 'push_back' is called inside a loop; consider pre-allocating the
container capacity before the loop
- function '*' defined in a header file; function
definitions in header files can lead to ODR violations
Change-Id: I44e4b0f8056a853fb45b690394be1a8ebec45b20
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/bmc/firmware-handler/firmware_handler.cpp b/bmc/firmware-handler/firmware_handler.cpp
index afcfc81..9268809 100644
--- a/bmc/firmware-handler/firmware_handler.cpp
+++ b/bmc/firmware-handler/firmware_handler.cpp
@@ -56,10 +56,10 @@
}
std::vector<std::string> blobs;
- for (const auto& item : firmwares)
- {
- blobs.push_back(item.blobName);
- }
+ blobs.reserve(firmwares.size());
+ std::for_each(
+ firmwares.begin(), firmwares.end(),
+ [&blobs](const auto& blob) { blobs.emplace_back(blob.blobName); });
if (0 == std::count(blobs.begin(), blobs.end(), hashBlobId))
{
diff --git a/bmc/firmware-handler/test/create_action_map.hpp b/bmc/firmware-handler/test/create_action_map.hpp
index 8238e2f..aa416e0 100644
--- a/bmc/firmware-handler/test/create_action_map.hpp
+++ b/bmc/firmware-handler/test/create_action_map.hpp
@@ -11,7 +11,7 @@
namespace ipmi_flash
{
-ActionMap CreateActionMap(const std::string& blobPath)
+static ActionMap CreateActionMap(const std::string& blobPath)
{
std::unique_ptr<ActionPack> actionPack = std::make_unique<ActionPack>();
actionPack->preparation = CreateTriggerMock();
@@ -22,5 +22,4 @@
map[blobPath] = std::move(actionPack);
return map;
}
-
} // namespace ipmi_flash
diff --git a/bmc/firmware-handler/test/meson.build b/bmc/firmware-handler/test/meson.build
index 38a8a1c..4ea436e 100644
--- a/bmc/firmware-handler/test/meson.build
+++ b/bmc/firmware-handler/test/meson.build
@@ -29,7 +29,8 @@
build_by_default: false,
implicit_include_directories: false,
include_directories: [root_inc, bmc_test_inc, firmware_inc],
- dependencies: [firmware_dep, gtest, gmock]))
+ dependencies:
+ [firmware_dep, image_mock_dep, triggerable_mock_dep, gtest, gmock]))
endforeach
file_handler_test = executable(
diff --git a/bmc/test/image_mock.cpp b/bmc/test/image_mock.cpp
new file mode 100644
index 0000000..b1de68b
--- /dev/null
+++ b/bmc/test/image_mock.cpp
@@ -0,0 +1,9 @@
+#include "image_mock.hpp"
+
+namespace ipmi_flash
+{
+std::unique_ptr<ImageHandlerMock> CreateImageMock()
+{
+ return std::make_unique<ImageHandlerMock>();
+}
+} // namespace ipmi_flash
diff --git a/bmc/test/image_mock.hpp b/bmc/test/image_mock.hpp
index 9999f58..8d84dbe 100644
--- a/bmc/test/image_mock.hpp
+++ b/bmc/test/image_mock.hpp
@@ -23,9 +23,6 @@
MOCK_METHOD(int, getSize, (), (override));
};
-std::unique_ptr<ImageHandlerMock> CreateImageMock()
-{
- return std::make_unique<ImageHandlerMock>();
-}
+std::unique_ptr<ImageHandlerMock> CreateImageMock();
} // namespace ipmi_flash
diff --git a/bmc/test/meson.build b/bmc/test/meson.build
index c579ec8..61d4767 100644
--- a/bmc/test/meson.build
+++ b/bmc/test/meson.build
@@ -1 +1,28 @@
bmc_test_inc = include_directories('.')
+
+image_mock_pre = declare_dependency(
+ include_directories: [root_inc, bmc_inc])
+
+image_mock_lib = static_library(
+ 'image_mock',
+ 'image_mock.cpp',
+ implicit_include_directories: false,
+ dependencies: image_mock_pre)
+
+image_mock_dep = declare_dependency(
+ link_with: image_mock_lib,
+ dependencies: image_mock_pre)
+
+
+triggerable_mock_pre = declare_dependency(
+ include_directories: [root_inc])
+
+triggerable_mock_lib = static_library(
+ 'triggerable_mock',
+ 'triggerable_mock.cpp',
+ implicit_include_directories: false,
+ dependencies: triggerable_mock_pre)
+
+triggerable_mock_dep = declare_dependency(
+ link_with: triggerable_mock_lib,
+ dependencies: triggerable_mock_pre)
diff --git a/bmc/test/triggerable_mock.cpp b/bmc/test/triggerable_mock.cpp
new file mode 100644
index 0000000..b599341
--- /dev/null
+++ b/bmc/test/triggerable_mock.cpp
@@ -0,0 +1,11 @@
+#include "triggerable_mock.hpp"
+
+#include <memory>
+
+namespace ipmi_flash
+{
+std::unique_ptr<TriggerableActionInterface> CreateTriggerMock()
+{
+ return std::make_unique<TriggerMock>();
+}
+} // namespace ipmi_flash
diff --git a/bmc/test/triggerable_mock.hpp b/bmc/test/triggerable_mock.hpp
index 0db90ee..4ae4463 100644
--- a/bmc/test/triggerable_mock.hpp
+++ b/bmc/test/triggerable_mock.hpp
@@ -22,9 +22,6 @@
using TriggerableActionInterface::cb;
};
-std::unique_ptr<TriggerableActionInterface> CreateTriggerMock()
-{
- return std::make_unique<TriggerMock>();
-}
+std::unique_ptr<TriggerableActionInterface> CreateTriggerMock();
} // namespace ipmi_flash
diff --git a/bmc/version-handler/test/version_mock.hpp b/bmc/version-handler/test/version_mock.hpp
index 4cae248..d8035a5 100644
--- a/bmc/version-handler/test/version_mock.hpp
+++ b/bmc/version-handler/test/version_mock.hpp
@@ -1,18 +1,18 @@
+#pragma once
#include "handler_config.hpp"
#include "image_mock.hpp"
#include "triggerable_mock.hpp"
#include "version_handler.hpp"
-#include <memory>
#include <string>
-#include <utility>
namespace ipmi_flash
{
-auto createMockVersionConfig(const std::string& id,
- ImageHandlerMock** im = nullptr,
- TriggerMock** tm = nullptr)
+static HandlerConfig<VersionBlobHandler::ActionPack>
+ createMockVersionConfig(const std::string& id,
+ ImageHandlerMock** im = nullptr,
+ TriggerMock** tm = nullptr)
{
HandlerConfig<VersionBlobHandler::ActionPack> ret;
ret.blobId = id;
@@ -34,15 +34,16 @@
template <typename C, typename Im = std::map<std::string, ImageHandlerMock*>,
typename Tm = std::map<std::string, TriggerMock*>>
-auto createMockVersionConfigs(const C& ids, Im* im = nullptr, Tm* tm = nullptr)
+static std::vector<HandlerConfig<VersionBlobHandler::ActionPack>>
+ createMockVersionConfigs(const C& ids, Im* im = nullptr, Tm* tm = nullptr)
{
std::vector<HandlerConfig<VersionBlobHandler::ActionPack>> ret;
- for (const auto& id : ids)
- {
- ret.push_back(
+ ret.reserve(ids.size());
+ std::for_each(ids.begin(), ids.end(), [im, tm, &ret](const auto& id) {
+ ret.emplace_back(
createMockVersionConfig(id, im == nullptr ? nullptr : &(*im)[id],
tm == nullptr ? nullptr : &(*tm)[id]));
- }
+ });
return ret;
}
diff --git a/tools/test/tools_updater_unittest.cpp b/tools/test/tools_updater_unittest.cpp
index 51a2848..cf6cf50 100644
--- a/tools/test/tools_updater_unittest.cpp
+++ b/tools/test/tools_updater_unittest.cpp
@@ -20,8 +20,6 @@
{
using ::testing::_;
-using ::testing::Eq;
-using ::testing::IsEmpty;
using ::testing::Return;
using ::testing::Throw;
using ::testing::TypedEq;