From: Arvin Schnell Date: Fri, 4 Sep 2020 07:38:31 +0000 (+0200) Subject: - extended testsuite X-Git-Tag: v0.8.14~24^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=85e7771f5f6bf27d5a9d44d0a56119e42fcdff3e;p=thirdparty%2Fsnapper.git - extended testsuite --- diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index f79ad66e..e569d3bc 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -6,9 +6,10 @@ AM_CPPFLAGS = -I$(top_srcdir) $(DBUS_CFLAGS) LDADD = ../snapper/libsnapper.la ../dbus/libdbus.la -lboost_unit_test_framework -check_PROGRAMS = sysconfig-get1.test dirname1.test basename1.test \ - equal-date.test dbus-escape.test cmp-lt.test humanstring.test table.test \ - csv-formatter.test json-formatter.test getopts.test lvm-utils.test +check_PROGRAMS = sysconfig-get1.test dirname1.test basename1.test \ + equal-date.test dbus-escape.test cmp-lt.test humanstring.test \ + table.test table-formatter.test csv-formatter.test json-formatter.test \ + getopts.test lvm-utils.test if ENABLE_BTRFS_QUOTA check_PROGRAMS += qgroup1.test @@ -26,6 +27,8 @@ humanstring_test_LDADD = -lboost_unit_test_framework ../client/utils/libutils.la table_test_LDADD = -lboost_unit_test_framework ../client/utils/libutils.la +table_formatter_test_LDADD = -lboost_unit_test_framework ../client/utils/libutils.la + csv_formatter_test_LDADD = -lboost_unit_test_framework ../client/utils/libutils.la json_formatter_test_LDADD = -lboost_unit_test_framework ../client/utils/libutils.la diff --git a/testsuite/csv-formatter.cc b/testsuite/csv-formatter.cc index 84150516..4f5f07be 100644 --- a/testsuite/csv-formatter.cc +++ b/testsuite/csv-formatter.cc @@ -4,16 +4,15 @@ #include -#include -#include - #include "../client/utils/CsvFormatter.h" + using namespace std; + BOOST_AUTO_TEST_CASE(test1) { - vector columns = { "column1", "column2", "column3" };; + vector columns = { "column1", "column2", "column3" }; vector> rows = { { "value;1", "value\n2", "value\"3" }, diff --git a/testsuite/json-formatter.cc b/testsuite/json-formatter.cc index 55fb7266..7972944a 100644 --- a/testsuite/json-formatter.cc +++ b/testsuite/json-formatter.cc @@ -4,13 +4,12 @@ #include -#include -#include - #include "../client/utils/JsonFormatter.h" + using namespace std; + BOOST_AUTO_TEST_CASE(test1_escape_values) { snapper::cli::JsonFormatter::Data data = { @@ -38,6 +37,9 @@ BOOST_AUTO_TEST_CASE(test1_escape_values) " \"key4\": \"\\\"value9\\\"\"\n" "}"; + // TODO it is inconsistent that here a final newline is missing while the other + // formatters add it + snapper::cli::JsonFormatter formatter(data); BOOST_CHECK_EQUAL(formatter.str(), expected_result); diff --git a/testsuite/table-formatter.cc b/testsuite/table-formatter.cc new file mode 100644 index 00000000..59a7cdc8 --- /dev/null +++ b/testsuite/table-formatter.cc @@ -0,0 +1,43 @@ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE snapper + +#include + +#include "../client/utils/TableFormatter.h" + + +using namespace std; + + +BOOST_AUTO_TEST_CASE(test1) +{ + locale::global(locale("en_GB.UTF-8")); + + vector> header = { + { "Number", TableAlign::RIGHT }, + { "Name EN", TableAlign::LEFT }, + { "Name DE", TableAlign::LEFT }, + { "Square", TableAlign::RIGHT } + }; + + vector> rows = { + { "0", "zero", "Null", "0" }, + { "1", "one", "Eins", "1"} , + { "5", "five", "Fünf", "25" }, + { "12", "twelve", "Zwölf", "144" } + }; + + snapper::cli::TableFormatter formatter(header, rows, Ascii); + + string result = { + "Number | Name EN | Name DE | Square\n" + "-------+---------+---------+-------\n" + " 0 | zero | Null | 0\n" + " 1 | one | Eins | 1\n" + " 5 | five | Fünf | 25\n" + " 12 | twelve | Zwölf | 144\n" + }; + + BOOST_CHECK_EQUAL(formatter.str(), result); +}