Apply srsLTE formatting rules to srsLog. They were previously formatted with different rules when the project lived in the external rapo.

master
faluco 4 years ago committed by faluco
parent 873f375ecc
commit 1ccb62af3d

@ -41,7 +41,7 @@ struct metrics_container {
/// Returns the value of metric T.
template <typename T>
auto read() const -> const decltype(T::value)&
auto read() const -> const decltype(T::value) &
{
constexpr std::size_t index = detail::get_type_index_in_tuple<T, Ts...>();
return std::get<index>(metrics).value;
@ -124,18 +124,13 @@ struct metric {
static const char* units() { return Units::units(); }
/// Returns the formatting kind of the metric.
static metric_kind kind()
{
return metric_kind_selector<metric<Ty, Name, Units>>::kind;
}
static metric_kind kind() { return metric_kind_selector<metric<Ty, Name, Units> >::kind; }
};
/// Template specialization that tags metrics with arithmetic values (integers
/// and floating point) as numeric.
template <typename Ty, typename Name, typename Units>
struct metric_kind_selector<
metric<Ty, Name, Units>,
typename std::enable_if<std::is_arithmetic<Ty>::value>::type> {
struct metric_kind_selector<metric<Ty, Name, Units>, typename std::enable_if<std::is_arithmetic<Ty>::value>::type> {
static const metric_kind kind = metric_kind::numeric;
};
@ -168,8 +163,7 @@ namespace detail {
/// eg: using my_metric_t = srslog::build_metric_set_type<m1_t, set1_t, m2_t>;
/// NOTE: Adding duplicated types into the list is not allowed.
template <typename Name, typename... Ts>
using build_metric_set_type =
metric_set<Name, typename std::decay<Ts>::type...>;
using build_metric_set_type = metric_set<Name, typename std::decay<Ts>::type...>;
} // namespace detail
@ -200,9 +194,8 @@ using build_context_type = context<typename std::decay<Ts>::type...>;
static const char* name() { return _name_rep; } \
}; \
} \
using _type = srslog::metric<typename std::decay<_value_type>::type, \
metric_info::_type##__name_rep, \
metric_info::_type##__units>
using _type = srslog:: \
metric<typename std::decay<_value_type>::type, metric_info::_type##__name_rep, metric_info::_type##__units>
/// This macro defines a new metric set type using the following attributes:
/// a) name: encoded as a string.
@ -222,8 +215,7 @@ using build_context_type = context<typename std::decay<Ts>::type...>;
static const char* name() { return _name_rep; } \
}; \
} \
using _type = srslog::detail:: \
build_metric_set_type<metric_set_info::_type##__name_rep, __VA_ARGS__>
using _type = srslog::detail::build_metric_set_type<metric_set_info::_type##__name_rep, __VA_ARGS__>
/// This macro defines a list of metric sets of the same type:
/// a) name: encoded as a string.
@ -242,8 +234,7 @@ using build_context_type = context<typename std::decay<Ts>::type...>;
static const char* name() { return _name_rep; } \
}; \
} \
using _type = srslog::metric_list<list_info::_type##__name_rep, \
typename std::decay<_list_type>::type>
using _type = srslog::metric_list<list_info::_type##__name_rep, typename std::decay<_list_type>::type>
} // namespace srslog

@ -30,12 +30,11 @@ struct flush_backend_cmd {
/// This structure packs all the required data required to create a log entry in
/// the backend.
//:TODO: replace this object using a real command pattern when we have a raw
//: TODO: replace this object using a real command pattern when we have a raw
// memory queue for passing entries.
struct log_entry {
sink* s;
std::function<void(log_entry_metadata&& metadata, fmt::memory_buffer& buffer)>
format_func;
std::function<void(log_entry_metadata&& metadata, fmt::memory_buffer& buffer)> format_func;
log_entry_metadata metadata;
std::unique_ptr<flush_backend_cmd> flush_cmd;
};

@ -24,7 +24,7 @@ using small_str_buffer = fmt::basic_memory_buffer<char, 64>;
namespace detail {
/// This structure gives the user a way to log generic information as a context.
//:TODO: legacy struct, will get replaced by the new context framework.
//: TODO: legacy struct, will get replaced by the new context framework.
struct log_context {
/// Generic context value.
uint32_t value;

@ -30,7 +30,7 @@ struct in_place_type_t {
template <typename T>
struct is_in_place_type_t : std::false_type {};
template <typename T>
struct is_in_place_type_t<in_place_type_t<T>> : std::true_type {};
struct is_in_place_type_t<in_place_type_t<T> > : std::true_type {};
/// This is a very minimalist and non compliant implementation of std::any which
/// is included in C++17.
@ -39,7 +39,7 @@ struct is_in_place_type_t<in_place_type_t<T>> : std::true_type {};
class any
{
public:
//:TODO: Clang 3.8 does not compile when default constructing a const object
//: TODO: Clang 3.8 does not compile when default constructing a const object
// due to DR253. Declare the defaulted constructor out of the class.
any();
@ -54,15 +54,12 @@ public:
/// b) is move constructible.
/// c) is not an specialization of in_place_type_t.
/// Otherwise the rest of special member functions are considered.
template <
typename T,
typename std::enable_if<
!std::is_same<typename std::decay<T>::type, any>{} &&
template <typename T,
typename std::enable_if<!std::is_same<typename std::decay<T>::type, any>{} &&
std::is_move_constructible<typename std::decay<T>::type>{} &&
!is_in_place_type_t<typename std::decay<T>::type>{},
int>::type = 0>
explicit any(T&& t) :
storage(new storage_impl<typename std::decay<T>::type>(std::forward<T>(t)))
explicit any(T&& t) : storage(new storage_impl<typename std::decay<T>::type>(std::forward<T>(t)))
{}
/// Constructs an object of type decayed T directly into the internal storage
@ -73,12 +70,9 @@ public:
/// Otherwise the rest of special member functions are considered.
template <typename T,
typename... Args,
typename std::enable_if<
std::is_constructible<typename std::decay<T>::type, Args...>{},
int>::type = 0>
typename std::enable_if<std::is_constructible<typename std::decay<T>::type, Args...>{}, int>::type = 0>
explicit any(in_place_type_t<T>, Args&&... args) :
storage(new storage_impl<typename std::decay<T>::type>(
std::forward<Args>(args)...))
storage(new storage_impl<typename std::decay<T>::type>(std::forward<Args>(args)...))
{}
any(any&& other) : storage(std::move(other.storage)) {}
@ -140,7 +134,7 @@ private:
std::unique_ptr<type_interface> storage;
};
//:TODO: declared out of line, see TODO above.
//: TODO: declared out of line, see TODO above.
inline any::any() = default;
/// Constructs an any object containing an object of type T, passing the
@ -160,8 +154,7 @@ inline T* any_cast(any* operand)
if (!operand || !operand->storage)
return nullptr;
using U =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
using U = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
if (operand->storage->type() != &any::type_tag<U>::tag)
return nullptr;
@ -177,8 +170,7 @@ inline const T* any_cast(const any* operand)
if (!operand || !operand->storage)
return nullptr;
using U =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
using U = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
if (operand->storage->type() != &any::type_tag<U>::tag)
return nullptr;

@ -27,13 +27,9 @@ class memory_buffer
const size_t length;
public:
memory_buffer(const char* buffer, size_t length) :
buffer(buffer), length(length)
{}
memory_buffer(const char* buffer, size_t length) : buffer(buffer), length(length) {}
explicit memory_buffer(const std::string& s) :
buffer(s.data()), length(s.size())
{}
explicit memory_buffer(const std::string& s) : buffer(s.data()), length(s.size()) {}
/// Returns a pointer to the start of the memory block.
const char* data() const { return buffer; }

@ -19,7 +19,7 @@ namespace srslog {
namespace detail {
//:TODO: these are temp helpers that will be replaced by std utils.
//: TODO: these are temp helpers that will be replaced by std utils.
/// Abstraction of a pthread mutex.
class mutex
@ -118,10 +118,7 @@ public:
/// Blocks the calling thread on this condition variable up to the specified
/// timeout. Returns true on timeout expiration, otherwise false.
bool wait(timespec ts)
{
return (::pthread_cond_timedwait(&cond_var, m.raw(), &ts) == ETIMEDOUT);
}
bool wait(timespec ts) { return (::pthread_cond_timedwait(&cond_var, m.raw(), &ts) == ETIMEDOUT); }
/// Builds an absolute time timespec structure adding the specified time out
/// in ms.
@ -152,11 +149,7 @@ class cond_var_scoped_lock
condition_variable& cond_var;
public:
explicit cond_var_scoped_lock(condition_variable& cond_var) :
cond_var(cond_var)
{
cond_var.lock();
}
explicit cond_var_scoped_lock(condition_variable& cond_var) : cond_var(cond_var) { cond_var.lock(); }
cond_var_scoped_lock(const cond_var_scoped_lock&) = delete;
cond_var_scoped_lock& operator=(const cond_var_scoped_lock&) = delete;

@ -28,8 +28,7 @@ template <std::size_t...>
struct index_sequence {};
template <std::size_t N, std::size_t... Next>
struct index_sequence_helper
: public index_sequence_helper<N - 1U, N - 1U, Next...> {};
struct index_sequence_helper : public index_sequence_helper<N - 1U, N - 1U, Next...> {};
template <std::size_t... Next>
struct index_sequence_helper<0U, Next...> {
@ -47,20 +46,19 @@ template <typename T, typename Tuple>
struct tuple_index;
template <typename T, typename... Ts>
struct tuple_index<T, std::tuple<T, Ts...>> {
struct tuple_index<T, std::tuple<T, Ts...> > {
static constexpr std::size_t value = 0;
};
template <typename T, typename U, typename... Ts>
struct tuple_index<T, std::tuple<U, Ts...>> {
static constexpr std::size_t value =
1 + tuple_index<T, std::tuple<Ts...>>::value;
struct tuple_index<T, std::tuple<U, Ts...> > {
static constexpr std::size_t value = 1 + tuple_index<T, std::tuple<Ts...> >::value;
};
template <typename T, typename... Ts>
constexpr std::size_t get_type_index_in_tuple()
{
return tuple_index<T, std::tuple<Ts...>>::value;
return tuple_index<T, std::tuple<Ts...> >::value;
}
} // namespace detail

@ -21,7 +21,7 @@ namespace srslog {
namespace detail {
//:TODO: this is a temp work queue.
//: TODO: this is a temp work queue.
/// Thread safe generic data type work queue.
template <typename T, size_t capacity = SRSLOG_QUEUE_CAPACITY>

@ -39,8 +39,7 @@ log_channel& fetch_log_channel(const std::string& id);
/// Returns an instance of a log_channel with the specified id that writes to
/// the specified sink.
/// NOTE: Any '#' characters in the id will get removed.
log_channel&
fetch_log_channel(const std::string& id, sink& s, log_channel_config config);
log_channel& fetch_log_channel(const std::string& id, sink& s, log_channel_config config);
/// Creates a new log channel instance with the specified id string and sink,
/// then registers it in the log channel repository so that it can be later
@ -80,16 +79,13 @@ inline T* find_logger(const std::string& id)
/// specified id string. All logger channels will write into the default sink.
/// The context value of the logger can be printed on each log entry by setting
/// to true the should_print_context argument.
basic_logger& fetch_basic_logger(const std::string& id,
bool should_print_context = true);
basic_logger& fetch_basic_logger(const std::string& id, bool should_print_context = true);
/// Returns an instance of a basic logger (see basic_logger type) with the
/// specified id string. All logger channels will write into the specified sink.
/// The context value of the logger can be printed on each log entry by setting
/// to true the should_print_context argument.
basic_logger& fetch_basic_logger(const std::string& id,
sink& s,
bool should_print_context = true);
basic_logger& fetch_basic_logger(const std::string& id, sink& s, bool should_print_context = true);
/// Returns a logger instance with the specified id string, type and channel
/// references.
@ -98,7 +94,7 @@ template <typename T, typename... Args>
inline T& fetch_logger(const std::string& id, Args&&... args)
{
static_assert(detail::is_logger<T>::value, "T should be a logger type");
if (auto *logger = find_logger<T>(id)) {
if (auto* logger = find_logger<T>(id)) {
return *logger;
}
auto logger = detail::make_any<T>(id, std::forward<Args>(args)...);
@ -115,9 +111,7 @@ inline T& fetch_logger(const std::string& id, Args&&... args)
/// the specified sink. Returns a pointer to the newly created logger, otherwise
/// when a logger is already registered with the same id it returns nullptr.
/// NOTE: Deprecated, use fetch_basic_logger instead.
basic_logger* create_basic_logger(const std::string& id,
sink& s,
bool should_print_context = true);
basic_logger* create_basic_logger(const std::string& id, sink& s, bool should_print_context = true);
/// Creates a new logger instance with the specified id string, type and channel
/// references, registering it into the logger repository so that it can be
@ -172,15 +166,13 @@ sink* find_sink(const std::string& id);
/// Returns an instance of a sink that writes to the stdout stream. You may use
/// different ids if you need to create multiple stdout sinks with different
/// formatters.
sink& fetch_stdout_sink(
const std::string& id = "stdout",
sink& fetch_stdout_sink(const std::string& id = "stdout",
std::unique_ptr<log_formatter> f = get_default_log_formatter());
/// Returns an instance of a sink that writes to the stderr stream. You may use
/// different ids if you need to create multiple stderr sinks with different
/// formatters.
sink& fetch_stderr_sink(
const std::string& id = "stderr",
sink& fetch_stderr_sink(const std::string& id = "stderr",
std::unique_ptr<log_formatter> f = get_default_log_formatter());
/// Returns an instance of a sink that writes into a file in the specified path.
@ -188,8 +180,7 @@ sink& fetch_stderr_sink(
/// new file each time the current file exceeds this value. The units of
/// max_size are bytes.
/// NOTE: Any '#' characters in the path will get removed.
sink& fetch_file_sink(
const std::string& path,
sink& fetch_file_sink(const std::string& path,
size_t max_size = 0,
std::unique_ptr<log_formatter> f = get_default_log_formatter());

@ -66,8 +66,7 @@ srslog_log_channel* srslog_find_log_channel(const char* id);
/**
* Controls whether the specified channel accepts incoming log entries.
*/
void srslog_set_log_channel_enabled(srslog_log_channel* channel,
srslog_bool enabled);
void srslog_set_log_channel_enabled(srslog_log_channel* channel, srslog_bool enabled);
/**
* Returns 1 if the specified channel is accepting incoming log entries,

@ -39,7 +39,7 @@ void srslog::event_trace_init()
static constexpr char default_file_name[] = "event_trace.log";
// Create the default event trace channel.
//:TODO: handle name reservation.
//: TODO: handle name reservation.
sink* s = create_file_sink(default_file_name);
assert(s && "Default event file sink is reserved");
tracer = create_log_channel("event_trace_channel", *s);

@ -24,9 +24,7 @@ namespace srslog {
class file_sink : public sink
{
public:
file_sink(std::string name,
size_t max_size,
std::unique_ptr<log_formatter> f) :
file_sink(std::string name, size_t max_size, std::unique_ptr<log_formatter> f) :
sink(std::move(f)),
max_size((max_size == 0) ? 0 : std::max<size_t>(max_size, 4 * 1024)),
base_filename(std::move(name))
@ -72,8 +70,7 @@ private:
/// Creates a new file and increments the file index counter.
detail::error_string create_file()
{
return handler.create(
file_utils::build_filename_with_index(base_filename, file_index++));
return handler.create(file_utils::build_filename_with_index(base_filename, file_index++));
}
/// Handles the file rotation feature when it is activated.

@ -31,8 +31,7 @@ inline std::string format_error(const std::string& error, int error_code)
}
/// Splits the specified path into a filename and its extension (if present).
inline std::pair<std::string, std::string>
split_filename_extension(const std::string& filename)
inline std::pair<std::string, std::string> split_filename_extension(const std::string& filename)
{
// Search for the last dot.
auto dot_pos = filename.find_last_of('.');
@ -41,8 +40,7 @@ split_filename_extension(const std::string& filename)
// a) No dot found: my_file
// b) Dot found at the beginning: .my_file
// c) Dot found at the end: my_file.
if (dot_pos == std::string::npos || dot_pos == 0 ||
dot_pos == filename.size() - 1) {
if (dot_pos == std::string::npos || dot_pos == 0 || dot_pos == filename.size() - 1) {
return {filename, ""};
}
@ -61,8 +59,7 @@ split_filename_extension(const std::string& filename)
}
/// Builds a file name formatting the input base name and file index.
inline std::string build_filename_with_index(const std::string& basename,
size_t index)
inline std::string build_filename_with_index(const std::string& basename, size_t index)
{
if (index == 0) {
return basename;
@ -101,19 +98,15 @@ public:
return {};
}
return format_error(
fmt::format("Unable to create log file \"{}\"", new_path), errno);
return format_error(fmt::format("Unable to create log file \"{}\"", new_path), errno);
}
/// Writes the provided memory buffer into an open file, otherwise does
/// nothing.
detail::error_string write(detail::memory_buffer buffer)
{
if (handle &&
std::fwrite(buffer.data(), sizeof(char), buffer.size(), handle) !=
buffer.size()) {
auto err_str = format_error(
fmt::format("Unable to write log file \"{}\"", path), errno);
if (handle && std::fwrite(buffer.data(), sizeof(char), buffer.size(), handle) != buffer.size()) {
auto err_str = format_error(fmt::format("Unable to write log file \"{}\"", path), errno);
close();
return err_str;
}
@ -125,9 +118,7 @@ public:
detail::error_string flush()
{
if (handle && ::fflush(handle) == EOF) {
auto err_str = format_error(
fmt::format("Error encountered while flushing log file \"{}\"", path),
errno);
auto err_str = format_error(fmt::format("Error encountered while flushing log file \"{}\"", path), errno);
close();
return err_str;
}

@ -25,8 +25,7 @@ class stream_sink : public sink
{
public:
stream_sink(sink_stream_type s, std::unique_ptr<log_formatter> f) :
sink(std::move(f)),
handle((s == sink_stream_type::stdout) ? stdout : stderr)
sink(std::move(f)), handle((s == sink_stream_type::stdout) ? stdout : stderr)
{}
stream_sink(const stream_sink& other) = delete;

@ -155,7 +155,7 @@ sink& srslog::fetch_file_sink(const std::string& path, size_t max_size, std::uni
return *s;
}
//:TODO: GCC5 or lower versions emits an error if we use the new() expression
//: TODO: GCC5 or lower versions emits an error if we use the new() expression
// directly, use redundant piecewise_construct instead.
auto& s = srslog_instance::get().get_sink_repo().emplace(
std::piecewise_construct,
@ -362,7 +362,7 @@ sink* srslog::create_stderr_sink(const std::string& name)
sink* srslog::create_file_sink(const std::string& path, size_t max_size)
{
//:TODO: GCC5 or lower versions emits an error if we use the new() expression
//: TODO: GCC5 or lower versions emits an error if we use the new() expression
// directly, use redundant piecewise_construct instead.
return srslog_instance::get()
.get_sink_repo()

@ -56,8 +56,7 @@ srslog_log_channel* srslog_find_log_channel(const char* id)
return c_cast<srslog_log_channel>(find_log_channel(id));
}
void srslog_set_log_channel_enabled(srslog_log_channel* channel,
srslog_bool enabled)
void srslog_set_log_channel_enabled(srslog_log_channel* channel, srslog_bool enabled)
{
assert(channel && "Expected a valid channel");
c_cast<log_channel>(channel)->set_enabled(enabled);

@ -27,18 +27,16 @@ class srslog_instance
srslog_instance()
{
// stdout and stderr sinks are always present.
auto& stdout_sink = sink_repo.emplace(
std::piecewise_construct,
auto& stdout_sink =
sink_repo.emplace(std::piecewise_construct,
std::forward_as_tuple("stdout"),
std::forward_as_tuple(new stream_sink(
sink_stream_type::stdout,
std::forward_as_tuple(new stream_sink(sink_stream_type::stdout,
std::unique_ptr<log_formatter>(new text_formatter))));
default_sink = stdout_sink.get();
sink_repo.emplace(std::piecewise_construct,
std::forward_as_tuple("stderr"),
std::forward_as_tuple(new stream_sink(
sink_stream_type::stderr,
std::forward_as_tuple(new stream_sink(sink_stream_type::stderr,
std::unique_ptr<log_formatter>(new text_formatter))));
// Initialize the default formatter pointer with a text formatter.
@ -70,7 +68,7 @@ public:
const channel_repo_type& get_channel_repo() const { return channel_repo; }
/// Sink repository accessor.
using sink_repo_type = object_repository<std::string, std::unique_ptr<sink>>;
using sink_repo_type = object_repository<std::string, std::unique_ptr<sink> >;
sink_repo_type& get_sink_repo() { return sink_repo; }
const sink_repo_type& get_sink_repo() const { return sink_repo; }
@ -79,10 +77,7 @@ public:
const detail::log_backend& get_backend() const { return backend; }
/// Installs the specified error handler into the backend.
void set_error_handler(error_handler callback)
{
backend.set_error_handler(std::move(callback));
}
void set_error_handler(error_handler callback) { backend.set_error_handler(std::move(callback)); }
/// Set the specified sink as the default one.
void set_default_sink(sink& s) { default_sink = &s; }

@ -22,10 +22,7 @@ static constexpr char log_filename[] = "file_sink_test.log";
static bool when_data_is_written_to_file_then_contents_are_valid()
{
file_test_utils::scoped_file_deleter deleter(log_filename);
file_sink file(
log_filename,
0,
std::unique_ptr<log_formatter>(new test_dummies::log_formatter_dummy));
file_sink file(log_filename, 0, std::unique_ptr<log_formatter>(new test_dummies::log_formatter_dummy));
std::vector<std::string> entries;
for (unsigned i = 0; i != 10; ++i) {
@ -37,8 +34,7 @@ static bool when_data_is_written_to_file_then_contents_are_valid()
file.flush();
ASSERT_EQ(file_test_utils::file_exists(log_filename), true);
ASSERT_EQ(file_test_utils::compare_file_contents(log_filename, entries),
true);
ASSERT_EQ(file_test_utils::compare_file_contents(log_filename, entries), true);
return true;
}
@ -49,10 +45,7 @@ class file_sink_subclass : public file_sink
{
public:
file_sink_subclass(std::string name, size_t max_size) :
file_sink(
std::move(name),
max_size,
std::unique_ptr<log_formatter>(new test_dummies::log_formatter_dummy))
file_sink(std::move(name), max_size, std::unique_ptr<log_formatter>(new test_dummies::log_formatter_dummy))
{}
uint32_t get_num_of_files() const { return get_file_index(); }
@ -60,14 +53,10 @@ public:
static bool when_data_written_exceeds_size_threshold_then_new_file_is_created()
{
std::string filename0 =
file_utils::build_filename_with_index(log_filename, 0);
std::string filename1 =
file_utils::build_filename_with_index(log_filename, 1);
std::string filename2 =
file_utils::build_filename_with_index(log_filename, 2);
file_test_utils::scoped_file_deleter deleter = {
filename0, filename1, filename2};
std::string filename0 = file_utils::build_filename_with_index(log_filename, 0);
std::string filename1 = file_utils::build_filename_with_index(log_filename, 1);
std::string filename2 = file_utils::build_filename_with_index(log_filename, 2);
file_test_utils::scoped_file_deleter deleter = {filename0, filename1, filename2};
file_sink_subclass file(log_filename, 5001);
@ -112,8 +101,7 @@ static bool when_data_written_exceeds_size_threshold_then_new_file_is_created()
int main()
{
TEST_FUNCTION(when_data_is_written_to_file_then_contents_are_valid);
TEST_FUNCTION(
when_data_written_exceeds_size_threshold_then_new_file_is_created);
TEST_FUNCTION(when_data_written_exceeds_size_threshold_then_new_file_is_created);
return 0;
}

@ -47,8 +47,7 @@ inline bool file_exists(const std::string& path)
/// Reads the contents of the file specified in path and returns true if they
/// match with the data in entries, otherwise returns false.
inline bool compare_file_contents(const std::string& path,
const std::vector<std::string>& entries)
inline bool compare_file_contents(const std::string& path, const std::vector<std::string>& entries)
{
std::ifstream file(path, std::ios::binary);
if (!file.is_open()) {

@ -21,9 +21,7 @@ static constexpr char log_filename2[] = "file_utils_test2.log";
static bool filename_extension_split_test()
{
auto checker = [](const std::string& base,
const std::string& file,
const std::string& ext) {
auto checker = [](const std::string& base, const std::string& file, const std::string& ext) {
auto result = file_utils::split_filename_extension(base);
return (result.first == file && result.second == ext);
};
@ -48,10 +46,8 @@ static bool filename_with_index_build_test()
ASSERT_EQ(file_utils::build_filename_with_index("filename", 0), "filename");
ASSERT_EQ(file_utils::build_filename_with_index("filename", 1), "filename.1");
ASSERT_EQ(file_utils::build_filename_with_index("filename.txt", 0),
"filename.txt");
ASSERT_EQ(file_utils::build_filename_with_index("filename.txt", 1),
"filename.1.txt");
ASSERT_EQ(file_utils::build_filename_with_index("filename.txt", 0), "filename.txt");
ASSERT_EQ(file_utils::build_filename_with_index("filename.txt", 1), "filename.1.txt");
return true;
}
@ -82,8 +78,7 @@ static bool when_created_method_is_called_then_file_is_created()
return true;
}
static bool
when_created_method_is_called_twice_then_file_is_closed_and_created()
static bool when_created_method_is_called_twice_then_file_is_closed_and_created()
{
file_test_utils::scoped_file_deleter deleter = {log_filename, log_filename2};
file_utils::file f;
@ -137,8 +132,7 @@ static bool when_data_is_written_to_file_then_contents_are_valid()
err_str = f.flush();
ASSERT_EQ(err_str.get_error().empty(), true);
ASSERT_EQ(file_test_utils::compare_file_contents(log_filename, {"test\n"}),
true);
ASSERT_EQ(file_test_utils::compare_file_contents(log_filename, {"test\n"}), true);
return true;
}
@ -166,8 +160,7 @@ int main()
TEST_FUNCTION(filename_with_index_build_test);
TEST_FUNCTION(when_default_constructing_file_then_no_file_is_created);
TEST_FUNCTION(when_created_method_is_called_then_file_is_created);
TEST_FUNCTION(
when_created_method_is_called_twice_then_file_is_closed_and_created);
TEST_FUNCTION(when_created_method_is_called_twice_then_file_is_closed_and_created);
TEST_FUNCTION(when_write_method_is_called_with_no_file_then_nothing_happens);
TEST_FUNCTION(when_flush_method_is_called_with_no_file_then_nothing_happens);
TEST_FUNCTION(when_data_is_written_to_file_then_contents_are_valid);

@ -19,11 +19,9 @@ using namespace srslog;
static constexpr char test_id1[] = "Test1";
static constexpr char test_id2[] = "Test2";
//:TODO: older compilers may not have defined this C++11 trait.
#if (defined(__clang__) && (__clang_major__ >= 5)) || \
(defined(__GNUG__) && (__GNUC__ >= 5))
static_assert(std::is_trivially_copyable<detail::memory_buffer>::value,
"Expected to be trivially copyable");
//: TODO: older compilers may not have defined this C++11 trait.
#if (defined(__clang__) && (__clang_major__ >= 5)) || (defined(__GNUG__) && (__GNUC__ >= 5))
static_assert(std::is_trivially_copyable<detail::memory_buffer>::value, "Expected to be trivially copyable");
#endif
static bool when_srslog_is_created_then_stdout_and_stderr_sinks_exist()
@ -82,8 +80,7 @@ static bool when_non_existent_id_is_passed_then_nothing_is_found()
return true;
}
static bool
when_id_with_sharps_is_passed_then_channel_is_fetched_with_clean_id()
static bool when_id_with_sharps_is_passed_then_channel_is_fetched_with_clean_id()
{
log_channel& channel1 = fetch_log_channel("a1#a");
log_channel& channel2 = fetch_log_channel("a2#a", fetch_stdout_sink(), {});
@ -116,8 +113,7 @@ static bool when_fetching_logger_then_logger_instance_is_returned()
log_channel& info = fetch_log_channel("logger.info");
log_channel& debug = fetch_log_channel("logger.debug");
auto& logger =
fetch_logger<basic_logger>(logger_id, error, warning, info, debug);
auto& logger = fetch_logger<basic_logger>(logger_id, error, warning, info, debug);
ASSERT_EQ(logger.id(), logger_id);
@ -127,8 +123,7 @@ static bool when_fetching_logger_then_logger_instance_is_returned()
static bool when_fetching_basic_logger_then_basic_logger_instance_is_returned()
{
basic_logger& logger1 = fetch_basic_logger(basic_logger_id1);
basic_logger& logger2 =
fetch_basic_logger(basic_logger_id2, fetch_stdout_sink());
basic_logger& logger2 = fetch_basic_logger(basic_logger_id2, fetch_stdout_sink());
ASSERT_EQ(logger1.id(), basic_logger_id1);
ASSERT_EQ(logger2.id(), basic_logger_id2);
@ -205,8 +200,7 @@ static bool when_invalid_id_is_passed_then_no_sink_is_found()
return true;
}
static bool
when_setting_stderr_as_default_then_get_default_returns_stderr_sink()
static bool when_setting_stderr_as_default_then_get_default_returns_stderr_sink()
{
set_default_sink(fetch_stderr_sink());
sink& default_sink = get_default_sink();
@ -216,8 +210,7 @@ when_setting_stderr_as_default_then_get_default_returns_stderr_sink()
return true;
}
static bool
when_creating_non_default_stdout_and_stderr_sinks_then_they_are_created()
static bool when_creating_non_default_stdout_and_stderr_sinks_then_they_are_created()
{
auto& out1 = fetch_stdout_sink("stdout1");
auto& err1 = fetch_stderr_sink("stderr1");
@ -260,11 +253,9 @@ static bool when_setting_custom_sink_twice_then_insertion_fails()
return true;
}
static bool
when_default_formatter_is_installed_then_getter_returns_same_formatter()
static bool when_default_formatter_is_installed_then_getter_returns_same_formatter()
{
auto f =
std::unique_ptr<log_formatter>(new test_dummies::log_formatter_dummy);
auto f = std::unique_ptr<log_formatter>(new test_dummies::log_formatter_dummy);
set_default_log_formatter(std::move(f));
// Dummy formatter does not implement the clone method, thus the unique
@ -278,35 +269,27 @@ when_default_formatter_is_installed_then_getter_returns_same_formatter()
int main()
{
TEST_FUNCTION(when_srslog_is_created_then_stdout_and_stderr_sinks_exist);
TEST_FUNCTION(
when_no_installed_default_formatter_then_a_formatter_is_returned);
TEST_FUNCTION(when_no_installed_default_formatter_then_a_formatter_is_returned);
TEST_FUNCTION(when_no_installed_default_sink_then_stdout_sink_is_used);
TEST_FUNCTION(when_fetching_channel_then_channel_instance_is_returned);
TEST_FUNCTION(when_valid_id_is_passed_then_channel_is_found);
TEST_FUNCTION(when_non_existent_id_is_passed_then_nothing_is_found);
TEST_FUNCTION(
when_id_with_sharps_is_passed_then_channel_is_fetched_with_clean_id);
TEST_FUNCTION(when_id_with_sharps_is_passed_then_channel_is_fetched_with_clean_id);
TEST_FUNCTION(when_channel_already_exists_then_fetch_returns_channel);
TEST_FUNCTION(when_fetching_logger_then_logger_instance_is_returned);
TEST_FUNCTION(
when_fetching_basic_logger_then_basic_logger_instance_is_returned);
TEST_FUNCTION(when_fetching_basic_logger_then_basic_logger_instance_is_returned);
TEST_FUNCTION(when_valid_id_and_type_is_passed_then_logger_is_found);
TEST_FUNCTION(when_basic_logger_already_exists_then_fetch_returns_logger);
TEST_FUNCTION(
when_invalid_id_with_valid_type_is_passed_then_no_logger_is_found);
TEST_FUNCTION(when_invalid_id_with_valid_type_is_passed_then_no_logger_is_found);
TEST_FUNCTION(when_invalid_id_and_type_is_passed_then_no_logger_is_found);
TEST_FUNCTION(
when_valid_id_with_invalid_type_is_passed_then_no_logger_is_found);
TEST_FUNCTION(when_valid_id_with_invalid_type_is_passed_then_no_logger_is_found);
TEST_FUNCTION(when_file_sink_is_fetched_then_sink_instance_is_returned);
TEST_FUNCTION(when_invalid_id_is_passed_then_no_sink_is_found);
TEST_FUNCTION(
when_setting_stderr_as_default_then_get_default_returns_stderr_sink);
TEST_FUNCTION(
when_creating_non_default_stdout_and_stderr_sinks_then_they_are_created);
TEST_FUNCTION(when_setting_stderr_as_default_then_get_default_returns_stderr_sink);
TEST_FUNCTION(when_creating_non_default_stdout_and_stderr_sinks_then_they_are_created);
TEST_FUNCTION(when_setting_custom_sink_first_time_then_insertion_succeeds);
TEST_FUNCTION(when_setting_custom_sink_twice_then_insertion_fails);
TEST_FUNCTION(
when_default_formatter_is_installed_then_getter_returns_same_formatter);
TEST_FUNCTION(when_default_formatter_is_installed_then_getter_returns_same_formatter);
return 0;
}

Loading…
Cancel
Save