Skip to content

Commit c245124

Browse files
committed
Insert threaded tests
Insert example for simple, configuration change and threads
1 parent cf08ae2 commit c245124

File tree

14 files changed

+938
-40
lines changed

14 files changed

+938
-40
lines changed

examples/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030

3131
project(examples)
3232

33-
add_subdirectory(logger)
33+
add_subdirectory(configuration)
34+
add_subdirectory(simple)
35+
add_subdirectory(threads)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Copyright (c) 2021 Florian Becker <[email protected]> (VX APPS).
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# 1. Redistributions of source code must retain the above copyright notice, this
9+
# list of conditions and the following disclaimer.
10+
#
11+
# 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# this list of conditions and the following disclaimer in the documentation
13+
# and/or other materials provided with the distribution.
14+
#
15+
# 3. Neither the name of the copyright holder nor the names of its
16+
# contributors may be used to endorse or promote products derived from
17+
# this software without specific prior written permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
#
30+
31+
project(configuration)
32+
33+
add_executable(${PROJECT_NAME}
34+
main.cpp
35+
)
36+
37+
target_link_libraries(${PROJECT_NAME} PRIVATE modern.cpp.logger)
38+
39+
# Strip binary for release builds
40+
if(CMAKE_BUILD_TYPE STREQUAL Release)
41+
if(CMAKE_STRIP)
42+
if(APPLE)
43+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} -S ${PROJECT_NAME} COMMENT "Striping symbols..." USES_TERMINAL)
44+
else()
45+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-all ${PROJECT_NAME} COMMENT "Striping symbols..." USES_TERMINAL)
46+
endif()
47+
endif()
48+
endif()
49+
50+
install(TARGETS ${PROJECT_NAME} COMPONENT ${PROJECT_NAME} RUNTIME DESTINATION bin)

examples/configuration/main.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 2021 Florian Becker <[email protected]> (VX APPS).
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
*
15+
* 3. Neither the name of the copyright holder nor the names of its
16+
* contributors may be used to endorse or promote products derived from
17+
* this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
/* stl header */
32+
#include <filesystem>
33+
#include <iostream>
34+
#include <map>
35+
#include <string>
36+
37+
/* modern.cpp.logger */
38+
#include <LoggerFactory.h>
39+
40+
/**
41+
* @brief Filename of temporary log file.
42+
*/
43+
constexpr auto filename = "example.log";
44+
45+
/**
46+
* @brief Log message itself.
47+
*/
48+
constexpr auto logMessage = "This is a log message";
49+
50+
/**
51+
* @brief Function for log some messages.
52+
*/
53+
static void logSomeMessages() {
54+
55+
LogFatal( logMessage );
56+
LogError( logMessage );
57+
LogWarning( logMessage );
58+
LogInfo( logMessage );
59+
LogDebug( logMessage );
60+
LogVerbose( logMessage );
61+
}
62+
63+
int main() {
64+
65+
/* configure logging, if you dont it defaults to standard out logging with colors */
66+
std::cout << "Log to std::cout" << std::endl;
67+
ConfigureLogger( { { "type", "std" }, { "color", "true" } } );
68+
69+
/* Log some messages */
70+
logSomeMessages();
71+
72+
/* create tmp file */
73+
std::filesystem::path tmpPath = std::filesystem::temp_directory_path();
74+
tmpPath /= filename;
75+
std::string tmpFile = tmpPath.string();
76+
std::cout << "Create tmp file: " << tmpFile << std::endl;
77+
78+
/* configure logging, if you dont it defaults to standard out logging with colors */
79+
std::cout << "Log to file" << std::endl;
80+
ConfigureLogger( { { "type", "file" }, { "filename", tmpFile }, { "reopen_interval", "1" } } );
81+
82+
/* Log some messages */
83+
logSomeMessages();
84+
85+
/* remove tmp file */
86+
bool removed = std::filesystem::remove( tmpFile );
87+
if ( !removed ) {
88+
89+
std::cout << "Tmp file cannot be removed: " << tmpFile << std::endl;
90+
return EXIT_FAILURE;
91+
}
92+
std::cout << "Tmp file was removed: " << tmpFile << std::endl;
93+
return EXIT_SUCCESS;
94+
95+
return EXIT_SUCCESS;
96+
}

examples/simple/CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Copyright (c) 2021 Florian Becker <[email protected]> (VX APPS).
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# 1. Redistributions of source code must retain the above copyright notice, this
9+
# list of conditions and the following disclaimer.
10+
#
11+
# 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# this list of conditions and the following disclaimer in the documentation
13+
# and/or other materials provided with the distribution.
14+
#
15+
# 3. Neither the name of the copyright holder nor the names of its
16+
# contributors may be used to endorse or promote products derived from
17+
# this software without specific prior written permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
#
30+
31+
project(simple)
32+
33+
add_executable(${PROJECT_NAME}
34+
main.cpp
35+
)
36+
37+
target_link_libraries(${PROJECT_NAME} PRIVATE modern.cpp.logger)
38+
39+
# Strip binary for release builds
40+
if(CMAKE_BUILD_TYPE STREQUAL Release)
41+
if(CMAKE_STRIP)
42+
if(APPLE)
43+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} -S ${PROJECT_NAME} COMMENT "Striping symbols..." USES_TERMINAL)
44+
else()
45+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-all ${PROJECT_NAME} COMMENT "Striping symbols..." USES_TERMINAL)
46+
endif()
47+
endif()
48+
endif()
49+
50+
install(TARGETS ${PROJECT_NAME} COMPONENT ${PROJECT_NAME} RUNTIME DESTINATION bin)

examples/simple/main.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2021 Florian Becker <[email protected]> (VX APPS).
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
*
15+
* 3. Neither the name of the copyright holder nor the names of its
16+
* contributors may be used to endorse or promote products derived from
17+
* this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
/* stl header */
32+
#include <map>
33+
#include <string>
34+
35+
/* modern.cpp.logger */
36+
#include <LoggerFactory.h>
37+
38+
/**
39+
* @brief Log message itself.
40+
*/
41+
constexpr auto logMessage = "This is a log message";
42+
43+
int main() {
44+
45+
/* configure logging, if you dont it defaults to standard out logging with colors */
46+
ConfigureLogger( { { "type", "std" }, { "color", "true" } } );
47+
48+
/* Log some messages */
49+
LogFatal( logMessage );
50+
LogError( logMessage );
51+
LogWarning( logMessage );
52+
LogInfo( logMessage );
53+
LogDebug( logMessage );
54+
LogVerbose( logMessage );
55+
56+
return EXIT_SUCCESS;
57+
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2020 Florian Becker <[email protected]> (VX APPS).
2+
# Copyright (c) 2021 Florian Becker <[email protected]> (VX APPS).
33
# All rights reserved.
44
#
55
# Redistribution and use in source and binary forms, with or without
@@ -28,9 +28,7 @@
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
#
3030

31-
project(logger)
32-
33-
#include_directories(${3RDPARTY_DIR})
31+
project(threads)
3432

3533
add_executable(${PROJECT_NAME}
3634
main.cpp
Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020 Florian Becker <[email protected]> (VX APPS).
2+
* Copyright (c) 2021 Florian Becker <[email protected]> (VX APPS).
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -31,22 +31,18 @@
3131
/* stl header */
3232
#include <algorithm>
3333
#include <filesystem>
34+
#include <iostream>
3435
#include <string>
3536
#include <thread>
3637
#include <vector>
3738

3839
/* modern.cpp.logger */
39-
//#include <FileLogger.h>
4040
#include <LoggerFactory.h>
41-
//#include <Logger.h>
42-
//#include <StdLogger.h>
43-
//#include <XmlFileLogger.h>
44-
#include <iostream>
4541

4642
/**
4743
* @brief Filename of temporary log file.
4844
*/
49-
constexpr auto filename = "thread-test.log";
45+
constexpr auto filename = "thread-example.log";
5046

5147
/**
5248
* @brief Count of log messages per thread.
@@ -80,7 +76,7 @@ static void work() {
8076

8177
int main() {
8278

83-
std::cout << std::filesystem::temp_directory_path() << std::endl;
79+
/* create tmp file */
8480
std::filesystem::path tmpPath = std::filesystem::temp_directory_path();
8581
tmpPath /= filename;
8682
std::string tmpFile = tmpPath.string();
@@ -105,38 +101,13 @@ int main() {
105101
}
106102
threads.clear();
107103

108-
// = { { "type", "file" }, { "filename", "test2.log" }, { "reopen_interval", "1" } };
109-
110-
/* Log to /dev/null */
111-
/* std::unordered_map<std::string, std::string> configuration;
112-
Logger logger( configuration );
113-
logger.log( logMessage, Severity::Fatal ); */
114-
115-
/* Log to stdout */
116-
// std::unordered_map<std::string, std::string> configuration = { { "color", "" } };
117-
// StdLogger logger( configuration );
118-
// logger.log( logMessage, Severity::Fatal );
119-
120-
/* Log to file */
121-
/* std::unordered_map<std::string, std::string> configuration = { { "color", "" }, {"filename", "logger.log"} };
122-
FileLogger logger( configuration );
123-
logger.log( logMessage, Severity::Fatal ); */
124-
125-
/* Log to file */
126-
// std::unordered_map<std::string, std::string> configuration = { { "color", "" }, {"filename", "logger.xml"} };
127-
// XmlFileLogger logger( configuration );
128-
// logger.log( logMessage, Severity::Fatal );
129-
130-
/* Log with logging factory */
131-
LogFatal( logMessage );
132-
104+
/* remove tmp file */
133105
bool removed = std::filesystem::remove( tmpFile );
134106
if ( !removed ) {
135107

136108
std::cout << "Tmp file cannot be removed: " << tmpFile << std::endl;
137109
return EXIT_FAILURE;
138110
}
139111
std::cout << "Tmp file was removed: " << tmpFile << std::endl;
140-
141112
return EXIT_SUCCESS;
142113
}

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@
3131
project(tests)
3232

3333
add_subdirectory(simple)
34+
add_subdirectory(threads)

tests/simple/SimpleXmlLogger.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ namespace vx {
117117
}
118118

119119
std::size_t count = TestHelper::countNewLines( tmpFile );
120-
std::cout << count << std::endl;
121120

122121
bool removed = std::filesystem::remove( tmpFile );
123122
if ( !removed ) {

0 commit comments

Comments
 (0)