]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- extended testsuite 560/head
authorArvin Schnell <aschnell@suse.de>
Fri, 4 Sep 2020 07:38:31 +0000 (09:38 +0200)
committerArvin Schnell <aschnell@suse.de>
Fri, 4 Sep 2020 07:38:31 +0000 (09:38 +0200)
testsuite/Makefile.am
testsuite/csv-formatter.cc
testsuite/json-formatter.cc
testsuite/table-formatter.cc [new file with mode: 0644]

index f79ad66eb766083b638cae2670799a122eeb0298..e569d3bcf0708c2dd1aebce2491e44b94f930e55 100644 (file)
@@ -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
index 8415051612b559090794d7965b7229fe05b476e6..4f5f07be445e2dc7501c4066eb18d0c42ae501e9 100644 (file)
@@ -4,16 +4,15 @@
 
 #include <boost/test/unit_test.hpp>
 
-#include <vector>
-#include <string>
-
 #include "../client/utils/CsvFormatter.h"
 
+
 using namespace std;
 
+
 BOOST_AUTO_TEST_CASE(test1)
 {
-    vector<string> columns = { "column1", "column2", "column3" };;
+    vector<string> columns = { "column1", "column2", "column3" };
 
     vector<vector<string>> rows = {
        { "value;1", "value\n2", "value\"3" },
index 55fb726602650121a08accec3e39ca753eccbd29..7972944ae17f16e649bcdfad8391e5b626a39d71 100644 (file)
@@ -4,13 +4,12 @@
 
 #include <boost/test/unit_test.hpp>
 
-#include <vector>
-#include <string>
-
 #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 (file)
index 0000000..59a7cdc
--- /dev/null
@@ -0,0 +1,43 @@
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE snapper
+
+#include <boost/test/unit_test.hpp>
+
+#include "../client/utils/TableFormatter.h"
+
+
+using namespace std;
+
+
+BOOST_AUTO_TEST_CASE(test1)
+{
+    locale::global(locale("en_GB.UTF-8"));
+
+    vector<pair<string, TableAlign>> header = {
+       { "Number", TableAlign::RIGHT },
+       { "Name EN", TableAlign::LEFT },
+       { "Name DE", TableAlign::LEFT },
+       { "Square", TableAlign::RIGHT }
+    };
+
+    vector<vector<string>> 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);
+}