From d994e601d20be292369099448c5b6bffc8319362 Mon Sep 17 00:00:00 2001 From: Andreas Peters Date: Wed, 15 Oct 2014 11:30:35 +0200 Subject: [PATCH] common: Formatter: cosmetic re-indent Signed-off-by: Andreas Peters --- src/common/Formatter.cc | 256 ++++++++++---------- src/common/Formatter.h | 322 +++++++++++++------------ src/test/common/test_tableformatter.cc | 161 +++++++------ 3 files changed, 372 insertions(+), 367 deletions(-) diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index a438ad778e9..93714c51630 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -59,35 +59,31 @@ FormatterAttrs::FormatterAttrs(const char *attr, ...) va_end(ap); } -Formatter::Formatter() -{ -} +Formatter::Formatter() { } -Formatter::~Formatter() -{ -} +Formatter::~Formatter() { } Formatter * new_formatter(const std::string &type) { - std::string mytype = type; - if (mytype == "") - mytype = "json-pretty"; + std::string mytype = type; + if (mytype == "") + mytype = "json-pretty"; - if (mytype == "json") - return new JSONFormatter(false); - else if (mytype == "json-pretty") - return new JSONFormatter(true); - else if (mytype == "xml") - return new XMLFormatter(false); - else if (mytype == "xml-pretty") - return new XMLFormatter(true); - else if (mytype == "table") - return new TableFormatter(); - else if (mytype == "table-kv") - return new TableFormatter(true); - else - return (Formatter *)NULL; + if (mytype == "json") + return new JSONFormatter(false); + else if (mytype == "json-pretty") + return new JSONFormatter(true); + else if (mytype == "xml") + return new XMLFormatter(false); + else if (mytype == "xml-pretty") + return new XMLFormatter(true); + else if (mytype == "table") + return new TableFormatter(); + else if (mytype == "table-kv") + return new TableFormatter(true); + else + return (Formatter *) NULL; } void Formatter::dump_format(const char *name, const char *fmt, ...) @@ -98,7 +94,7 @@ void Formatter::dump_format(const char *name, const char *fmt, ...) va_end(ap); } -void Formatter:: dump_format_ns(const char *name, const char *ns, const char *fmt, ...) +void Formatter::dump_format_ns(const char *name, const char *ns, const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -107,7 +103,6 @@ void Formatter:: dump_format_ns(const char *name, const char *ns, const char *fm } - void Formatter::dump_format_unquoted(const char *name, const char *fmt, ...) { va_list ap; @@ -117,8 +112,9 @@ void Formatter::dump_format_unquoted(const char *name, const char *fmt, ...) } // ----------------------- + JSONFormatter::JSONFormatter(bool p) - : m_pretty(p), m_is_pending_string(false) +: m_pretty(p), m_is_pending_string(false) { reset(); } @@ -145,14 +141,14 @@ void JSONFormatter::print_comma(json_formatter_stack_entry_d& entry) if (entry.size) { if (m_pretty) { m_ss << ",\n"; - for (unsigned i=1; i < m_stack.size(); i++) - m_ss << " "; + for (unsigned i = 1; i < m_stack.size(); i++) + m_ss << " "; } else { m_ss << ","; } } else if (entry.is_array && m_pretty) { m_ss << "\n"; - for (unsigned i=1; i < m_stack.size(); i++) + for (unsigned i = 1; i < m_stack.size(); i++) m_ss << " "; } if (m_pretty && entry.is_array) @@ -178,9 +174,9 @@ void JSONFormatter::print_name(const char *name) if (!entry.is_array) { if (m_pretty) { if (entry.size) - m_ss << " "; + m_ss << " "; else - m_ss << " "; + m_ss << " "; } m_ss << "\"" << name << "\""; if (m_pretty) @@ -307,7 +303,7 @@ const char *XMLFormatter::XML_1_DTD = ""; XMLFormatter::XMLFormatter(bool pretty) - : m_pretty(pretty) +: m_pretty(pretty) { reset(); } @@ -436,7 +432,7 @@ void XMLFormatter::dump_format_va(const char* name, const char *ns, bool quoted, std::string e(name); print_spaces(); if (ns) { - m_ss << "<" << e << " xmlns=\"" << ns << "\">" << buf << ""; + m_ss << "<" << e << " xmlns=\"" << ns << "\">" << buf << ""; } else { m_ss << "<" << e << ">" << escape_xml_str(buf) << ""; } @@ -479,8 +475,7 @@ void XMLFormatter::open_section_in_ns(const char *name, const char *ns, const Fo if (ns) { m_ss << "<" << name << attrs_str << " xmlns=\"" << ns << "\">"; - } - else { + } else { m_ss << "<" << name << attrs_str << ">"; } if (m_pretty) @@ -492,7 +487,7 @@ void XMLFormatter::finish_pending_string() { if (!m_pending_string_name.empty()) { m_ss << escape_xml_str(m_pending_string.str().c_str()) - << ""; + << ""; m_pending_string_name.clear(); m_pending_string.str(std::string()); if (m_pretty) { @@ -532,110 +527,110 @@ void TableFormatter::flush(std::ostream& os) std::set need_header_set; // auto-sizing columns - for (size_t i=0; i< m_vec.size(); i++) { - for (size_t j=0; j< m_vec[i].size(); j++) { + for (size_t i = 0; i < m_vec.size(); i++) { + for (size_t j = 0; j < m_vec[i].size(); j++) { column_size.resize(m_vec[i].size()); column_name.resize(m_vec[i].size()); - if (i>0) { - if (m_vec[i-1][j] != m_vec[i][j]) { - // changing row labels require to show the header - need_header_set.insert(i); - column_name[i] = m_vec[i][j].first; - } + if (i > 0) { + if (m_vec[i - 1][j] != m_vec[i][j]) { + // changing row labels require to show the header + need_header_set.insert(i); + column_name[i] = m_vec[i][j].first; + } } else { - column_name[i] = m_vec[i][j].first; + column_name[i] = m_vec[i][j].first; } - if (m_vec[i][j].second.length()> column_size[j]) - column_size[j]=m_vec[i][j].second.length(); - if (m_vec[i][j].first.length()> column_size[j]) - column_size[j]=m_vec[i][j].first.length(); + if (m_vec[i][j].second.length() > column_size[j]) + column_size[j] = m_vec[i][j].second.length(); + if (m_vec[i][j].first.length() > column_size[j]) + column_size[j] = m_vec[i][j].first.length(); } } - - bool need_header=false; - if ( (column_size.size() == m_column_size.size() ) ) { - for (size_t i=0; i > attrs; -struct FormatterAttrs { - std::list< std::pair > attrs; - - FormatterAttrs(const char *attr, ...); -}; - -class Formatter { - public: - Formatter(); - virtual ~Formatter(); - - virtual void flush(std::ostream& os) = 0; - void flush(bufferlist &bl) { - std::stringstream os; - flush(os); - bl.append(os.str()); - } - virtual void reset() = 0; - - virtual void open_array_section(const char *name) = 0; - virtual void open_array_section_in_ns(const char *name, const char *ns) = 0; - virtual void open_object_section(const char *name) = 0; - virtual void open_object_section_in_ns(const char *name, const char *ns) = 0; - virtual void close_section() = 0; - virtual void dump_unsigned(const char *name, uint64_t u) = 0; - virtual void dump_int(const char *name, int64_t s) = 0; - virtual void dump_float(const char *name, double d) = 0; - virtual void dump_string(const char *name, std::string s) = 0; - virtual void dump_bool(const char *name, bool b) { - dump_format_unquoted(name, "%s", (b ? "true" : "false")); - } - virtual std::ostream& dump_stream(const char *name) = 0; - virtual void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) = 0; - virtual void dump_format(const char *name, const char *fmt, ...); - virtual void dump_format_ns(const char *name, const char *ns, const char *fmt, ...); - virtual void dump_format_unquoted(const char *name, const char *fmt, ...); - virtual int get_len() const = 0; - virtual void write_raw_data(const char *data) = 0; - - /* with attrs */ - virtual void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs) { - open_array_section(name); - } - virtual void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs) { - open_object_section(name); - } - virtual void dump_string_with_attrs(const char *name, std::string s, const FormatterAttrs& attrs) { - dump_string(name, s); - } -}; - -Formatter *new_formatter(const std::string &type); - -class JSONFormatter : public Formatter { - public: - JSONFormatter(bool p=false); - - void flush(std::ostream& os); - void reset(); - virtual void open_array_section(const char *name); - void open_array_section_in_ns(const char *name, const char *ns); - void open_object_section(const char *name); - void open_object_section_in_ns(const char *name, const char *ns); - void close_section(); - void dump_unsigned(const char *name, uint64_t u); - void dump_int(const char *name, int64_t u); - void dump_float(const char *name, double d); - void dump_string(const char *name, std::string s); - std::ostream& dump_stream(const char *name); - void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); - int get_len() const; - void write_raw_data(const char *data); - - private: - struct json_formatter_stack_entry_d { - int size; - bool is_array; - json_formatter_stack_entry_d() : size(0), is_array(false) {} + FormatterAttrs(const char *attr, ...); }; - bool m_pretty; - void open_section(const char *name, bool is_array); - void print_quoted_string(const char *s); - void print_name(const char *name); - void print_comma(json_formatter_stack_entry_d& entry); - void finish_pending_string(); + class Formatter { + public: + Formatter(); + virtual ~Formatter(); - std::stringstream m_ss, m_pending_string; - std::list m_stack; - bool m_is_pending_string; -}; + virtual void flush(std::ostream& os) = 0; + void flush(bufferlist &bl) + { + std::stringstream os; + flush(os); + bl.append(os.str()); + } + virtual void reset() = 0; -class XMLFormatter : public Formatter { - public: - static const char *XML_1_DTD; - XMLFormatter(bool pretty = false); + virtual void open_array_section(const char *name) = 0; + virtual void open_array_section_in_ns(const char *name, const char *ns) = 0; + virtual void open_object_section(const char *name) = 0; + virtual void open_object_section_in_ns(const char *name, const char *ns) = 0; + virtual void close_section() = 0; + virtual void dump_unsigned(const char *name, uint64_t u) = 0; + virtual void dump_int(const char *name, int64_t s) = 0; + virtual void dump_float(const char *name, double d) = 0; + virtual void dump_string(const char *name, std::string s) = 0; + virtual void dump_bool(const char *name, bool b) + { + dump_format_unquoted(name, "%s", (b ? "true" : "false")); + } + virtual std::ostream& dump_stream(const char *name) = 0; + virtual void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) = 0; + virtual void dump_format(const char *name, const char *fmt, ...); + virtual void dump_format_ns(const char *name, const char *ns, const char *fmt, ...); + virtual void dump_format_unquoted(const char *name, const char *fmt, ...); + virtual int get_len() const = 0; + virtual void write_raw_data(const char *data) = 0; + /* with attrs */ + virtual void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs) + { + open_array_section(name); + } + virtual void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs) + { + open_object_section(name); + } + virtual void dump_string_with_attrs(const char *name, std::string s, const FormatterAttrs& attrs) + { + dump_string(name, s); + } + }; - void flush(std::ostream& os); - void reset(); - void open_array_section(const char *name); - void open_array_section_in_ns(const char *name, const char *ns); - void open_object_section(const char *name); - void open_object_section_in_ns(const char *name, const char *ns); - void close_section(); - void dump_unsigned(const char *name, uint64_t u); - void dump_int(const char *name, int64_t u); - void dump_float(const char *name, double d); - void dump_string(const char *name, std::string s); - std::ostream& dump_stream(const char *name); - void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); - int get_len() const; - void write_raw_data(const char *data); + Formatter *new_formatter(const std::string &type); - /* with attrs */ - void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); - void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); - void dump_string_with_attrs(const char *name, std::string s, const FormatterAttrs& attrs); - private: - void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); - void finish_pending_string(); - void print_spaces(); - static std::string escape_xml_str(const char *str); - void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); + class JSONFormatter : public Formatter { + public: + JSONFormatter(bool p = false); - std::stringstream m_ss, m_pending_string; - std::deque m_sections; - bool m_pretty; - std::string m_pending_string_name; -}; + void flush(std::ostream& os); + void reset(); + virtual void open_array_section(const char *name); + void open_array_section_in_ns(const char *name, const char *ns); + void open_object_section(const char *name); + void open_object_section_in_ns(const char *name, const char *ns); + void close_section(); + void dump_unsigned(const char *name, uint64_t u); + void dump_int(const char *name, int64_t u); + void dump_float(const char *name, double d); + void dump_string(const char *name, std::string s); + std::ostream& dump_stream(const char *name); + void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); + int get_len() const; + void write_raw_data(const char *data); -class TableFormatter : public Formatter { - public: - TableFormatter(bool keyval=false); + private: - void flush(std::ostream& os); - void reset(); - virtual void open_array_section(const char *name); - void open_array_section_in_ns(const char *name, const char *ns); - void open_object_section(const char *name); - void open_object_section_in_ns(const char *name, const char *ns); + struct json_formatter_stack_entry_d { + int size; + bool is_array; + json_formatter_stack_entry_d() : size(0), is_array(false) { } + }; - void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); - void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); + bool m_pretty; + void open_section(const char *name, bool is_array); + void print_quoted_string(const char *s); + void print_name(const char *name); + void print_comma(json_formatter_stack_entry_d& entry); + void finish_pending_string(); - void close_section(); - void dump_unsigned(const char *name, uint64_t u); - void dump_int(const char *name, int64_t u); - void dump_float(const char *name, double d); - void dump_string(const char *name, std::string s); - void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); - void dump_string_with_attrs(const char *name, std::string s, const FormatterAttrs& attrs); - std::ostream& dump_stream(const char *name); + std::stringstream m_ss, m_pending_string; + std::list m_stack; + bool m_is_pending_string; + }; - int get_len() const; - void write_raw_data(const char *data); - void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); + class XMLFormatter : public Formatter { + public: + static const char *XML_1_DTD; + XMLFormatter(bool pretty = false); - private: - void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); - std::vector< std::vector > > m_vec; - std::stringstream m_ss; - size_t m_vec_index(const char* name); - std::string get_section_name(const char* name); - void finish_pending_string(); - std::string m_pending_name; - bool m_keyval; + void flush(std::ostream& os); + void reset(); + void open_array_section(const char *name); + void open_array_section_in_ns(const char *name, const char *ns); + void open_object_section(const char *name); + void open_object_section_in_ns(const char *name, const char *ns); + void close_section(); + void dump_unsigned(const char *name, uint64_t u); + void dump_int(const char *name, int64_t u); + void dump_float(const char *name, double d); + void dump_string(const char *name, std::string s); + std::ostream& dump_stream(const char *name); + void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); + int get_len() const; + void write_raw_data(const char *data); - int m_section_open; - std::vector< std::string > m_section; - std::map m_section_cnt; - std::vector m_column_size; - std::vector< std::string > m_column_name; -}; + /* with attrs */ + void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); + void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); + void dump_string_with_attrs(const char *name, std::string s, const FormatterAttrs& attrs); + private: + void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); + void finish_pending_string(); + void print_spaces(); + static std::string escape_xml_str(const char *str); + void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); + + std::stringstream m_ss, m_pending_string; + std::deque m_sections; + bool m_pretty; + std::string m_pending_string_name; + }; + + class TableFormatter : public Formatter { + public: + TableFormatter(bool keyval = false); + + void flush(std::ostream& os); + void reset(); + virtual void open_array_section(const char *name); + void open_array_section_in_ns(const char *name, const char *ns); + void open_object_section(const char *name); + void open_object_section_in_ns(const char *name, const char *ns); + + void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); + void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); + + void close_section(); + void dump_unsigned(const char *name, uint64_t u); + void dump_int(const char *name, int64_t u); + void dump_float(const char *name, double d); + void dump_string(const char *name, std::string s); + void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); + void dump_string_with_attrs(const char *name, std::string s, const FormatterAttrs& attrs); + std::ostream& dump_stream(const char *name); + + int get_len() const; + void write_raw_data(const char *data); + void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); + + private: + void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); + std::vector< std::vector > > m_vec; + std::stringstream m_ss; + size_t m_vec_index(const char* name); + std::string get_section_name(const char* name); + void finish_pending_string(); + std::string m_pending_name; + bool m_keyval; + + int m_section_open; + std::vector< std::string > m_section; + std::map m_section_cnt; + std::vector m_column_size; + std::vector< std::string > m_column_name; + }; } diff --git a/src/test/common/test_tableformatter.cc b/src/test/common/test_tableformatter.cc index 4c2abbadc5e..cf00bbc8ed4 100644 --- a/src/test/common/test_tableformatter.cc +++ b/src/test/common/test_tableformatter.cc @@ -5,12 +5,13 @@ #include #include -TEST(tableformatter, singleline) { +TEST(tableformatter, singleline) +{ std::stringstream sout; TableFormatter formatter; - formatter.dump_int("integer",10); - formatter.dump_float("float",10.0); - formatter.dump_string("string","string"); + formatter.dump_int("integer", 10); + formatter.dump_float("float", 10.0); + formatter.dump_string("string", "string"); formatter.flush(sout); std::string cmp = "" @@ -19,40 +20,42 @@ TEST(tableformatter, singleline) { "+----------+--------+---------+\n" "| 10 | 10 | string |\n" "+----------+--------+---------+\n"; - EXPECT_EQ(cmp,sout.str()); + EXPECT_EQ(cmp, sout.str()); } -TEST(tableformatter, multiline) { +TEST(tableformatter, multiline) +{ std::stringstream sout; TableFormatter formatter; - formatter.dump_int("integer",10); - formatter.dump_float("float",10.0); - formatter.dump_string("string","string"); - formatter.dump_int("integer",20); - formatter.dump_float("float",20.0); - formatter.dump_string("string","string"); + formatter.dump_int("integer", 10); + formatter.dump_float("float", 10.0); + formatter.dump_string("string", "string"); + formatter.dump_int("integer", 20); + formatter.dump_float("float", 20.0); + formatter.dump_string("string", "string"); std::string cmp = "" - "+----------+--------+---------+\n" - "| integer | float | string |\n" - "+----------+--------+---------+\n" - "| 10 | 10 | string |\n" - "| 20 | 20 | string |\n" - "+----------+--------+---------+\n"; + "+----------+--------+---------+\n" + "| integer | float | string |\n" + "+----------+--------+---------+\n" + "| 10 | 10 | string |\n" + "| 20 | 20 | string |\n" + "+----------+--------+---------+\n"; formatter.flush(sout); - EXPECT_EQ(cmp,sout.str()); + EXPECT_EQ(cmp, sout.str()); } -TEST(tableformatter, multiflush) { +TEST(tableformatter, multiflush) +{ std::stringstream sout1; std::stringstream sout2; TableFormatter formatter; - formatter.dump_int("integer",10); - formatter.dump_float("float",10.0); - formatter.dump_string("string","string"); + formatter.dump_int("integer", 10); + formatter.dump_float("float", 10.0); + formatter.dump_string("string", "string"); formatter.flush(sout1); - + std::string cmp = "" "+----------+--------+---------+\n" "| integer | float | string |\n" @@ -60,32 +63,33 @@ TEST(tableformatter, multiflush) { "| 10 | 10 | string |\n" "+----------+--------+---------+\n"; - EXPECT_EQ(cmp,sout1.str()); + EXPECT_EQ(cmp, sout1.str()); - formatter.dump_int("integer",20); - formatter.dump_float("float",20.0); - formatter.dump_string("string","string"); + formatter.dump_int("integer", 20); + formatter.dump_float("float", 20.0); + formatter.dump_string("string", "string"); formatter.flush(sout2); cmp = "" "| 20 | 20 | string |\n" "+----------+--------+---------+\n"; - EXPECT_EQ(cmp,sout2.str()); + EXPECT_EQ(cmp, sout2.str()); } -TEST(tableformatter, multireset) { +TEST(tableformatter, multireset) +{ std::stringstream sout; TableFormatter formatter; - formatter.dump_int("integer",10); - formatter.dump_float("float",10.0); - formatter.dump_string("string","string"); + formatter.dump_int("integer", 10); + formatter.dump_float("float", 10.0); + formatter.dump_string("string", "string"); formatter.flush(sout); formatter.reset(); - formatter.dump_int("integer",20); - formatter.dump_float("float",20.0); - formatter.dump_string("string","string"); + formatter.dump_int("integer", 20); + formatter.dump_float("float", 20.0); + formatter.dump_string("string", "string"); formatter.flush(sout); std::string cmp = "" @@ -100,19 +104,20 @@ TEST(tableformatter, multireset) { "| 20 | 20 | string |\n" "+----------+--------+---------+\n"; - EXPECT_EQ(cmp,sout.str()); + EXPECT_EQ(cmp, sout.str()); } -TEST(tableformatter, changingheaderlength) { +TEST(tableformatter, changingheaderlength) +{ std::stringstream sout; TableFormatter formatter; - formatter.dump_int("integer",10); - formatter.dump_float("float",10.0); - formatter.dump_string("string","string"); + formatter.dump_int("integer", 10); + formatter.dump_float("float", 10.0); + formatter.dump_string("string", "string"); formatter.flush(sout); - formatter.dump_int("integer",20); - formatter.dump_float("float",20.0); - formatter.dump_string("string","stringstring"); + formatter.dump_int("integer", 20); + formatter.dump_float("float", 20.0); + formatter.dump_string("string", "stringstring"); formatter.flush(sout); std::string cmp = "" @@ -127,19 +132,20 @@ TEST(tableformatter, changingheaderlength) { "| 20 | 20 | stringstring |\n" "+----------+--------+---------------+\n"; - EXPECT_EQ(cmp,sout.str()); + EXPECT_EQ(cmp, sout.str()); } -TEST(tableformatter, changingheader) { +TEST(tableformatter, changingheader) +{ std::stringstream sout; TableFormatter formatter; - formatter.dump_int("integer",10); - formatter.dump_float("float",10.0); - formatter.dump_string("string","string"); + formatter.dump_int("integer", 10); + formatter.dump_float("float", 10.0); + formatter.dump_string("string", "string"); formatter.flush(sout); - formatter.dump_int("longinteger",20); - formatter.dump_float("double",20.0); - formatter.dump_string("char*","stringstring"); + formatter.dump_int("longinteger", 20); + formatter.dump_float("double", 20.0); + formatter.dump_string("char*", "stringstring"); formatter.flush(sout); std::string cmp = "" @@ -154,20 +160,21 @@ TEST(tableformatter, changingheader) { "| 20 | 20 | stringstring |\n" "+--------------+---------+---------------+\n"; - EXPECT_EQ(cmp,sout.str()); + EXPECT_EQ(cmp, sout.str()); } -TEST(tableformatter, extendingheader) { +TEST(tableformatter, extendingheader) +{ std::stringstream sout; TableFormatter formatter; - formatter.dump_int("integer",10); - formatter.dump_float("float",10.0); - formatter.dump_string("string","string"); + formatter.dump_int("integer", 10); + formatter.dump_float("float", 10.0); + formatter.dump_string("string", "string"); formatter.flush(sout); - formatter.dump_int("integer",20); - formatter.dump_float("float",20.0); - formatter.dump_string("string","string"); - formatter.dump_string("char*","abcde"); + formatter.dump_int("integer", 20); + formatter.dump_float("float", 20.0); + formatter.dump_string("string", "string"); + formatter.dump_string("char*", "abcde"); formatter.flush(sout); std::string cmp = "" @@ -182,10 +189,11 @@ TEST(tableformatter, extendingheader) { "| 20 | 20 | string | abcde |\n" "+----------+--------+---------+--------+\n"; - EXPECT_EQ(cmp,sout.str()); + EXPECT_EQ(cmp, sout.str()); } -TEST(tableformatter, stream) { +TEST(tableformatter, stream) +{ std::stringstream sout; TableFormatter* formatter = (TableFormatter*) new_formatter("table"); formatter->dump_stream("integer") << 10; @@ -201,29 +209,30 @@ TEST(tableformatter, stream) { "| 10 | 10 | string |\n" "+----------+--------+---------+\n"; - EXPECT_EQ(cmp,sout.str()); + EXPECT_EQ(cmp, sout.str()); } -TEST(tableformatter, multiline_keyval) { +TEST(tableformatter, multiline_keyval) +{ std::stringstream sout; TableFormatter* formatter = (TableFormatter*) new_formatter("table-kv"); - formatter->dump_int("integer",10); - formatter->dump_float("float",10.0); - formatter->dump_string("string","string"); - formatter->dump_int("integer",20); - formatter->dump_float("float",20.0); - formatter->dump_string("string","string"); + formatter->dump_int("integer", 10); + formatter->dump_float("float", 10.0); + formatter->dump_string("string", "string"); + formatter->dump_int("integer", 20); + formatter->dump_float("float", 20.0); + formatter->dump_string("string", "string"); formatter->flush(sout); delete formatter; std::string cmp = "" - "key::integer=\"10\" key::float=\"10\" key::string=\"string\" \n" - "key::integer=\"20\" key::float=\"20\" key::string=\"string\" \n"; - - EXPECT_EQ(cmp,sout.str()); + "key::integer=\"10\" key::float=\"10\" key::string=\"string\" \n" + "key::integer=\"20\" key::float=\"20\" key::string=\"string\" \n"; + + EXPECT_EQ(cmp, sout.str()); } -/* +/* * Local Variables: * compile-command: "cd ../.. ; make -j4 && * make unittest_tableformatter &&