Skip to content

Commit

Permalink
factor file checking into test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
goatshriek committed Mar 17, 2024
1 parent 0e617c2 commit 1ea185a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 22 deletions.
12 changes: 11 additions & 1 deletion include/test/helper/rfc5424.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */

/*
* Copyright 2018-2023 Joel E. Anderson
* Copyright 2018-2024 Joel E. Anderson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -146,7 +146,17 @@
#define RFC_5424_PRIVAL_MAX 191

void TestRFC5424Compliance( const std::string &syslog_msg );

/**
* Tests each line of the given file for RFC 5424 compliance, and also tests
* that the number of messages equals the expected count.
*/
void
TestRFC5424File( const std::string &filename,
std::size_t expected_count );

void TestRFC5424StructuredData( const std::string &sd_elements );

void TestRFC5424Timestamp( const std::string &timestamp );

#endif /* __STUMPLESS_TEST_HELPER_RFC5424_HPP */
2 changes: 1 addition & 1 deletion src/target/chain.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ stumpless_add_target_to_chain( struct stumpless_target *chain,

VALIDATE_ARG_NOT_NULL( chain );
VALIDATE_ARG_NOT_NULL( target );

clear_error();

lock_target( chain );
Expand Down
5 changes: 2 additions & 3 deletions test/function/cpp/element.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0

/*
* Copyright 2020-2021 Joel E. Anderson
* Copyright 2020-2024 Joel E. Anderson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,6 @@
* limitations under the License.
*/

#include <cstddef>
#include <cstdlib>
#include <gtest/gtest.h>
#include <stumpless.hpp>
Expand Down Expand Up @@ -46,7 +45,7 @@ namespace {
};

TEST_F( CppElementTest, GetParamByIndex ) {
Param param = element_with_params->GetParam( ( size_t ) 0 );
Param param = element_with_params->GetParam( ( std::size_t ) 0 );
const char *param_name = param.GetName( );
EXPECT_STREQ( param_name, param_1_name );
free( ( void * ) param_name );
Expand Down
20 changes: 18 additions & 2 deletions test/helper/rfc5424.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0

/*
* Copyright 2018-2023 Joel E. Anderson
* Copyright 2018-2024 Joel E. Anderson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include <fstream>
#include <regex>
#include <string>
#include <gtest/gtest.h>
Expand Down Expand Up @@ -44,6 +45,21 @@ void TestRFC5424Compliance( const std::string &syslog_msg ) {
}
}

void
TestRFC5424File( const std::string &filename,
std::size_t expected_count ) {
std::ifstream log_file( filename );
std::string line;
std::size_t i = 0;

while( std::getline( log_file, line ) ) {
TestRFC5424Compliance( line.c_str() );
i++;
}

EXPECT_EQ( i, expected_count );
}

void TestRFC5424StructuredData( const std::string &structured_data ) {
enum sd_state {
INIT_STATE,
Expand Down Expand Up @@ -208,4 +224,4 @@ void TestRFC5424Timestamp( const std::string &timestamp ) {
default:
ADD_FAILURE() << "DATE-MONTH was not a value between 1 and 12";
}
}
}
14 changes: 2 additions & 12 deletions test/thread_safety/target/file.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0

/*
* Copyright 2020-2023 Joel E. Anderson
* Copyright 2020-2024 Joel E. Anderson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,9 +17,7 @@
*/

#include <cstddef>
#include <fstream>
#include <gtest/gtest.h>
#include <string>
#include <stumpless.h>
#include <thread>
#include "test/helper/assert.hpp"
Expand Down Expand Up @@ -59,15 +57,7 @@ namespace {
stumpless_free_all( );

// check for consistency in the log file
std::ifstream log_file( filename );
std::string line;
i = 0;
while( std::getline( log_file, line ) ) {
TestRFC5424Compliance( line.c_str() );
i++;
}
EXPECT_EQ( i, THREAD_COUNT * MESSAGE_COUNT );

TestRFC5424File( filename, THREAD_COUNT * MESSAGE_COUNT );
remove( filename );
}
}
1 change: 1 addition & 0 deletions tools/check_headers/c_standard_library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
"CRITICAL_SECTION":
- "private/windows_wrapper.h"
- "windows.h"
"size_t": "stddef.h"
"true": "stdbool.h"
3 changes: 0 additions & 3 deletions tools/check_headers/standard_library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@
"SIG_ERR": "signal.h"
"SIGINT": "signal.h"
"signal": "signal.h"
"size_t":
- "cstddef"
- "stddef.h"
"snprintf":
- "cstdio"
- "stdio.h"
Expand Down
1 change: 1 addition & 0 deletions tools/check_headers/stumpless_private.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
"TEST_LEVEL_DISABLED": "test/helper/level_disabled.hpp"
"TEST_LEVEL_ENABLED": "test/helper/level_enabled.hpp"
"TestRFC5424Compliance": "test/helper/rfc5424.hpp"
"TestRFC5424File": "test/helper/rfc5424.hpp"
"TestRFC5424Timestamp": "test/helper/rfc5424.hpp"
"TestSetDestinationOnOpenTarget": "test/helper/network.hpp"
"TestSetDestinationOnPausedTarget": "test/helper/network.hpp"
Expand Down

0 comments on commit 1ea185a

Please sign in to comment.