tunit - Reference Guide  1.0.0
Modern c++17 unit testing framework on Windows, macOS, Linux, iOS and android.
line_info.h
Go to the documentation of this file.
1 #pragma once
4 #include <ostream>
5 #include <string>
6 
8 namespace tunit {
13  class line_info final {
14  public:
16  line_info() noexcept = default;
17 
21  line_info(const std::string& file_path, unsigned int line_number) noexcept : file_path_(file_path), line_number_(line_number) {}
22 
27  line_info(const std::string& member_name, const std::string& file_path, unsigned int line_number) noexcept : member_name_(member_name), file_path_(file_path), line_number_(line_number) {}
28 
31  static tunit::line_info empty() {return {};}
32 
34  line_info(const line_info& line_info) = default;
35  line_info& operator=(const line_info&) = default;
36  bool operator==(const line_info& li) const {return this->member_name_ == li.member_name_ && this->file_path_ == li.file_path_ && this->line_number_ == li.line_number_;}
37  bool operator!=(const line_info& li) const {return !this->operator==(li);}
39 
42  const std::string& member_name() const noexcept {return this->member_name_;}
43 
46  const std::string& file_path() const noexcept {return this->file_path_;}
47 
50  unsigned int line_number() const noexcept {return this->line_number_;}
51 
53  friend std::ostream& operator<<(std::ostream& os, const tunit::line_info line_info) noexcept {
54  if (line_info.file_path_ == "" && line_info.line_number_ == 0 && line_info.member_name_ == "")
55  return os << "{Empty}";
56  if (line_info.member_name_ == "")
57  return os << "{file_path=\"" << line_info.file_path_ << "\", line_number=" << line_info.line_number_<< "}";
58  return os << "{member_name=\"" << line_info.member_name_ << "\", file_path=\"" << line_info.file_path_ << "\", line_number=" << line_info.line_number_<< "}";
59  }
61 
62  private:
63  std::string member_name_;
64  std::string file_path_;
65  unsigned int line_number_ = 0;
66  };
67 }
68 
75 #define line_info_ \
76  tunit::line_info {__func__, __FILE__, __LINE__}
unsigned int line_number() const noexcept
Gets the line number.
Definition: line_info.h:50
line_info(const std::string &member_name, const std::string &file_path, unsigned int line_number) noexcept
Creates new instance of line info with member name specified, file path specified, and line number specified.
Definition: line_info.h:27
const std::string & member_name() const noexcept
Gets the member name.
Definition: line_info.h:42
static tunit::line_info empty()
Return an empty line info.
Definition: line_info.h:31
line_info information class is used to store current file, current line and current function informat...
Definition: line_info.h:13
line_info(const std::string &file_path, unsigned int line_number) noexcept
Creates new instance of line info with file path specified, and line number specified.
Definition: line_info.h:21
The tunit namespace contains a unit test library.
Definition: abort_error.h:8
const std::string & file_path() const noexcept
Gets the file path.
Definition: line_info.h:46
line_info() noexcept=default
Creates new instance of line info.