Skip to content

Commit 8e52c4e

Browse files
committed
[eclipse-iceoryx#464] Try to fix gnu windows build
1 parent 4978834 commit 8e52c4e

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

iceoryx2-ffi/cxx/tests/src/log_tests.cpp

+16-18
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,37 @@
1010
//
1111
// SPDX-License-Identifier: Apache-2.0 OR MIT
1212

13-
#include <mutex>
14-
#include <string>
15-
#include <vector>
16-
17-
13+
#include "iox/string.hpp"
14+
#include "iox/vector.hpp"
1815
#include "iox2/log.hpp"
1916
#include "iox2/log_level.hpp"
2017

2118
#include "test.hpp"
2219

2320
namespace {
2421
using namespace iox2;
22+
constexpr uint64_t TEST_LOGGER_CAPACITY = 10;
23+
constexpr uint64_t STRING_CAPACITY = 64;
2524
class Entry {
2625
private:
2726
LogLevel m_log_level;
28-
std::string m_origin;
29-
std::string m_message;
27+
iox::string<STRING_CAPACITY> m_origin;
28+
iox::string<STRING_CAPACITY> m_message;
3029

3130
public:
3231
Entry(LogLevel log_level, const char* origin, const char* message)
3332
: m_log_level { log_level }
34-
, m_origin { origin }
35-
, m_message { message } {
33+
, m_origin { iox::TruncateToCapacity, origin }
34+
, m_message { iox::TruncateToCapacity, message } {
3635
}
3736

3837
auto is_equal(LogLevel log_level, const char* origin, const char* message) -> bool {
39-
return m_log_level == log_level && m_origin == origin && m_message == message;
38+
return m_log_level == log_level && m_origin == iox::string<STRING_CAPACITY>(iox::TruncateToCapacity, origin)
39+
&& m_message == iox::string<STRING_CAPACITY>(iox::TruncateToCapacity, message);
4040
}
4141
};
4242

43+
4344
class TestLogger : public Log {
4445
public:
4546
static auto set_global_logger() {
@@ -53,22 +54,19 @@ class TestLogger : public Log {
5354
}
5455

5556
void log(LogLevel log_level, const char* origin, const char* message) override {
56-
m_lock.lock();
57-
m_log_buffer.emplace_back(log_level, origin, message);
58-
m_lock.unlock();
57+
if (m_log_buffer.size() < TEST_LOGGER_CAPACITY) {
58+
m_log_buffer.emplace_back(log_level, origin, message);
59+
}
5960
}
6061

61-
auto get_log_buffer() -> std::vector<Entry> {
62-
m_lock.lock();
62+
auto get_log_buffer() -> iox::vector<Entry, TEST_LOGGER_CAPACITY> {
6363
auto buffer = m_log_buffer;
6464
m_log_buffer.clear();
65-
m_lock.unlock();
6665
return buffer;
6766
}
6867

6968
private:
70-
std::mutex m_lock;
71-
std::vector<Entry> m_log_buffer;
69+
iox::vector<Entry, TEST_LOGGER_CAPACITY> m_log_buffer;
7270
};
7371

7472
TEST(Log, custom_logger_works) {

0 commit comments

Comments
 (0)