Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply clang format and clang tidy to common #646

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
10e7c6e
Fix: apply clang format to common directory
TomasTurina Mar 5, 2025
0274998
fix: reorder common utils folder, remove target utils and create two …
TomasTurina Mar 5, 2025
85c619e
Feat: add workflow_dispatch to clang format GHA
TomasTurina Mar 5, 2025
4668dac
fix: apply clang tidy to byteArrayHelper
TomasTurina Mar 7, 2025
a63750c
fix: apply clang tidy to cmdHelper
TomasTurina Mar 10, 2025
4529b2a
fix: apply clang tidy to encodingHelper
TomasTurina Mar 10, 2025
e476a0e
fix: apply clang tidy to globHelper
TomasTurina Mar 10, 2025
103f821
fix: apply clang tidy to hashHelper
TomasTurina Mar 10, 2025
1532fdb
fix: apply clang tidy to linuxHelper
TomasTurina Mar 10, 2025
2999441
fix: apply clang format to jsonIO
TomasTurina Mar 10, 2025
350d611
fix: apply clang format to mapWrapper
TomasTurina Mar 10, 2025
d4a467f
fix: add missing comments to common functions
TomasTurina Mar 10, 2025
f5a4908
fix: apply clang tidy to networkHelper
TomasTurina Mar 11, 2025
9757f00
fix: apply clang format to pipelineHelper
TomasTurina Mar 11, 2025
20cc86f
fix: apply clang format to promiseHelper
TomasTurina Mar 11, 2025
7e760b3
fix: apply clang tidy to registryHelper
TomasTurina Mar 11, 2025
1d9f50a
fix: apply clang format to sqliteWrapper
TomasTurina Mar 11, 2025
81f996a
fix: apply clang tidy to stringHelper
TomasTurina Mar 11, 2025
bc7d725
fix: apply clang tidy to threadDispatcher
TomasTurina Mar 11, 2025
3991c34
fix: apply clang tidy to timeHelper
TomasTurina Mar 11, 2025
8cca600
fix: apply clang tidy to windowsHelper
TomasTurina Mar 11, 2025
05adcae
fix: fix comments format in some common libraries
TomasTurina Mar 12, 2025
13b8e6a
fix: fix sysInfoWin UT regex
TomasTurina Mar 12, 2025
329e323
fix: unify sqlite legacy wrappers
TomasTurina Mar 12, 2025
2d2c049
fix: merge promise_helper and thread_dispatcher
TomasTurina Mar 12, 2025
0cbda05
fix: remove glob_helper target from data provider
TomasTurina Mar 13, 2025
114f4fb
fix: remove some legacy LCOV flags from inventory code
TomasTurina Mar 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- opened
- synchronize
- reopened
workflow_dispatch:

jobs:
clang-format:
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ else()
add_subdirectory(common/file_helper)
add_subdirectory(common/logger)
add_subdirectory(common/pal)
add_subdirectory(common/utils)
endif()

add_subdirectory(modules)
Expand Down
2 changes: 1 addition & 1 deletion src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_subdirectory(cmdHelper)
add_subdirectory(config)
add_subdirectory(data_provider)
add_subdirectory(dbsync)
add_subdirectory(deleterHelper)
add_subdirectory(encodingHelper)
add_subdirectory(file_helper)
add_subdirectory(globHelper)
Expand All @@ -19,7 +20,6 @@ add_subdirectory(sqliteWrapper)
add_subdirectory(stringHelper)
add_subdirectory(threadDispatcher)
add_subdirectory(timeHelper)
add_subdirectory(utils)
add_subdirectory(windowsHelper)

if(BUILD_TESTS)
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/common/audit_op/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DisableFormat: true
SortIncludes: Never
2 changes: 2 additions & 0 deletions src/common/binaries_op/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DisableFormat: true
SortIncludes: Never
7 changes: 5 additions & 2 deletions src/common/byteArrayHelper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ project(byte_array_helper)
include(../../cmake/CommonSettings.cmake)
set_common_settings()

add_library(byte_array_helper INTERFACE)
add_library(byte_array_helper src/byteArrayHelper.cpp)

target_include_directories(byte_array_helper INTERFACE include)
target_include_directories(byte_array_helper PUBLIC include)

include(../../cmake/ConfigureTarget.cmake)
configure_target(byte_array_helper)

if(BUILD_TESTS)
enable_testing()
Expand Down
54 changes: 0 additions & 54 deletions src/common/byteArrayHelper/include/byteArrayHelper.h

This file was deleted.

17 changes: 17 additions & 0 deletions src/common/byteArrayHelper/include/byteArrayHelper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <cstdint>
#include <string>

namespace Utils
{
/// @brief Converts a byte array to an int32_t in big endian format
/// @param bytes the byte array to convert
/// @return the resulting int32_t
int32_t toInt32BE(const uint8_t* bytes);

/// @brief Converts a byte array to an int32_t in little endian format
/// @param bytes the byte array to convert
/// @return the resulting int32_t
int32_t toInt32LE(const uint8_t* bytes);
} // namespace Utils
28 changes: 28 additions & 0 deletions src/common/byteArrayHelper/src/byteArrayHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "byteArrayHelper.hpp"

namespace Utils
{
/// @brief Bytes shift
enum BytesShift : uint8_t
{
THREE_BYTE = 24,
TWO_BYTE = 16,
ONE_BYTE = 8,
ZERO_BYTE = 0
};

// NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic)
int32_t toInt32BE(const uint8_t* bytes)
{
return static_cast<int32_t>(bytes[3]) << ZERO_BYTE | static_cast<int32_t>(bytes[2]) << ONE_BYTE |
static_cast<int32_t>(bytes[1]) << TWO_BYTE | static_cast<int32_t>(bytes[0]) << THREE_BYTE;
}

int32_t toInt32LE(const uint8_t* bytes)
{
return static_cast<int32_t>(bytes[0]) << ZERO_BYTE | static_cast<int32_t>(bytes[1]) << ONE_BYTE |
static_cast<int32_t>(bytes[2]) << TWO_BYTE | static_cast<int32_t>(bytes[3]) << THREE_BYTE;
}

// NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic)
} // namespace Utils
1 change: 0 additions & 1 deletion src/common/byteArrayHelper/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ add_executable(byte_array_helper_tests
${UTIL_CXX_UNITTEST_COMMON_SRC}
)

include(../../../cmake/ConfigureTarget.cmake)
configure_target(byte_array_helper_tests)

target_include_directories(byte_array_helper_tests PRIVATE
Expand Down
15 changes: 2 additions & 13 deletions src/common/byteArrayHelper/tests/byteArrayHelper_test.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
/*
* Wazuh shared modules utils
* Copyright (C) 2015, Wazuh Inc.
* March 16, 2021.
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
* License (version 2) as published by the FSF - Free Software
* Foundation.
*/

#include "byteArrayHelper_test.h"
#include "byteArrayHelper.h"
#include "byteArrayHelper_test.hpp"
#include "byteArrayHelper.hpp"

void ByteArrayHelperTest::SetUp() {};

Expand Down
26 changes: 0 additions & 26 deletions src/common/byteArrayHelper/tests/byteArrayHelper_test.h

This file was deleted.

13 changes: 13 additions & 0 deletions src/common/byteArrayHelper/tests/byteArrayHelper_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "gtest/gtest.h"

class ByteArrayHelperTest : public ::testing::Test
{
protected:
ByteArrayHelperTest() = default;
virtual ~ByteArrayHelperTest() = default;

void SetUp() override;
void TearDown() override;
};
9 changes: 6 additions & 3 deletions src/common/cmdHelper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ project(cmd_helper)
include(../../cmake/CommonSettings.cmake)
set_common_settings()

add_library(cmd_helper INTERFACE)
add_library(cmd_helper src/cmdHelper.cpp)

target_include_directories(cmd_helper INTERFACE include)
target_include_directories(cmd_helper PUBLIC include)

target_link_libraries(cmd_helper INTERFACE pal)
target_link_libraries(cmd_helper PRIVATE deleter_helper)

include(../../cmake/ConfigureTarget.cmake)
configure_target(cmd_helper)

if(BUILD_TESTS)
enable_testing()
Expand Down
64 changes: 0 additions & 64 deletions src/common/cmdHelper/include/cmdHelper.h

This file was deleted.

12 changes: 12 additions & 0 deletions src/common/cmdHelper/include/cmdHelper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <string>

namespace Utils
{
/// @brief Executes a command
/// @param cmd command
/// @param bufferSize buffer size in bytes
/// @return command output
std::string Exec(const std::string& cmd, const size_t bufferSize = 128);
} // namespace Utils
27 changes: 27 additions & 0 deletions src/common/cmdHelper/src/cmdHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "cmdHelper.hpp"

#include "fileSmartDeleter.hpp"
#include <cstdio>
#include <memory>
#include <string>
#include <vector>

namespace Utils
{
std::string Exec(const std::string& cmd, const size_t bufferSize)
{
const std::unique_ptr<FILE, FileSmartDeleter> file {popen(cmd.c_str(), "r")};
std::vector<char> buffer(bufferSize);
std::string result;

if (file)
{
while (fgets(buffer.data(), static_cast<int>(bufferSize), file.get()))
{
result += buffer.data();
}
}

return result;
}
} // namespace Utils
1 change: 0 additions & 1 deletion src/common/cmdHelper/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ add_executable(cmd_helper_tests
${UTIL_CXX_UNITTEST_COMMON_SRC}
)

include(../../../cmake/ConfigureTarget.cmake)
configure_target(cmd_helper_tests)

target_include_directories(cmd_helper_tests PRIVATE
Expand Down
19 changes: 4 additions & 15 deletions src/common/cmdHelper/tests/cmdHelper_test.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
/*
* Wazuh shared modules utils
* Copyright (C) 2015, Wazuh Inc.
* October 19, 2020.
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
* License (version 2) as published by the FSF - Free Software
* Foundation.
*/

#include "cmdHelper_test.h"
#include "cmdHelper.h"
#include "cmdHelper_test.hpp"
#include "cmdHelper.hpp"

void CmdUtilsTest::SetUp() {};

void CmdUtilsTest::TearDown() {};
#ifdef WIN32
TEST_F(CmdUtilsTest, CmdVersion)
{
const auto result{Utils::exec("ver")};
const auto result {Utils::Exec("ver")};
EXPECT_FALSE(result.empty());
}
#else
TEST_F(CmdUtilsTest, CmdUname)
{
const auto result{Utils::exec("uname")};
const auto result {Utils::Exec("uname")};
EXPECT_FALSE(result.empty());
}
#endif
Loading