summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsmartcols/samples/Makemodule.am2
-rw-r--r--libsmartcols/samples/fromfile.c2
-rw-r--r--libsmartcols/samples/title.c19
-rw-r--r--tests/commands.sh1
-rw-r--r--tests/expected/libsmartcols/title12
-rwxr-xr-xtests/ts/libsmartcols/title28
6 files changed, 61 insertions, 3 deletions
diff --git a/libsmartcols/samples/Makemodule.am b/libsmartcols/samples/Makemodule.am
index b44d888b4..0a54abbbf 100644
--- a/libsmartcols/samples/Makemodule.am
+++ b/libsmartcols/samples/Makemodule.am
@@ -18,7 +18,7 @@ sample_scols_tree_CFLAGS = $(sample_scols_cflags)
endif
sample_scols_title_SOURCES = libsmartcols/samples/title.c
-sample_scols_title_LDADD = $(sample_scols_ldadd)
+sample_scols_title_LDADD = $(sample_scols_ldadd) libcommon.la
sample_scols_title_CFLAGS = $(sample_scols_cflags)
sample_scols_wrap_SOURCES = libsmartcols/samples/wrap.c
diff --git a/libsmartcols/samples/fromfile.c b/libsmartcols/samples/fromfile.c
index ec12267a6..aa283ded5 100644
--- a/libsmartcols/samples/fromfile.c
+++ b/libsmartcols/samples/fromfile.c
@@ -194,8 +194,6 @@ int main(int argc, char *argv[])
scols_table_set_termforce(tb, SCOLS_TERMFORCE_ALWAYS);
scols_table_set_termwidth(tb, strtou32_or_err(optarg, "failed to parse terminal width"));
break;
- default:
- err(EXIT_FAILURE, "%s [-r|--random]\n", program_invocation_short_name);
}
}
diff --git a/libsmartcols/samples/title.c b/libsmartcols/samples/title.c
index 08cc2c621..852316095 100644
--- a/libsmartcols/samples/title.c
+++ b/libsmartcols/samples/title.c
@@ -57,6 +57,13 @@ int main(int argc, char *argv[])
struct libscols_table *tb;
struct libscols_symbols *sy;
struct libscols_cell *title;
+ int c;
+
+ static const struct option longopts[] = {
+ { "maxout", 0, 0, 'm' },
+ { "width", 1, 0, 'w' },
+ { NULL, 0, 0, 0 },
+ };
setlocale(LC_ALL, ""); /* just to have enable UTF8 chars */
@@ -66,6 +73,18 @@ int main(int argc, char *argv[])
if (!tb)
err(EXIT_FAILURE, "failed to create output table");
+ while((c = getopt_long(argc, argv, "mw:", longopts, NULL)) != -1) {
+ switch(c) {
+ case 'm':
+ scols_table_enable_maxout(tb, TRUE);
+ break;
+ case 'w':
+ scols_table_set_termforce(tb, SCOLS_TERMFORCE_ALWAYS);
+ scols_table_set_termwidth(tb, strtou32_or_err(optarg, "failed to parse terminal width"));
+ break;
+ }
+ }
+
scols_table_enable_colors(tb, isatty(STDOUT_FILENO));
setup_columns(tb);
add_line(tb, "foo", "bla bla bla");
diff --git a/tests/commands.sh b/tests/commands.sh
index 102711c51..b20e6f587 100644
--- a/tests/commands.sh
+++ b/tests/commands.sh
@@ -17,6 +17,7 @@ TS_HELPER_LIBMOUNT_UPDATE="$top_builddir/test_mount_tab_update"
TS_HELPER_LIBMOUNT_UTILS="$top_builddir/test_mount_utils"
TS_HELPER_LIBMOUNT_DEBUG="$top_builddir/test_mount_debug"
TS_HELPER_LIBSMARTCOLS_FROMFILE="$top_builddir/sample-scols-fromfile"
+TS_HELPER_LIBSMARTCOLS_TITLE="$top_builddir/sample-scols-title"
TS_HELPER_PYLIBMOUNT_CONTEXT="$top_srcdir/libmount/python/test_mount_context.py"
TS_HELPER_PYLIBMOUNT_TAB="$top_srcdir/libmount/python/test_mount_tab.py"
TS_HELPER_PYLIBMOUNT_UPDATE="$top_srcdir/libmount/python/test_mount_tab_update.py"
diff --git a/tests/expected/libsmartcols/title b/tests/expected/libsmartcols/title
new file mode 100644
index 000000000..b5f4c1287
--- /dev/null
+++ b/tests/expected/libsmartcols/title
@@ -0,0 +1,12 @@
+ This is right title
+NAME DATA
+foo bla bla bla
+bar alb alb alb
+=======================This is center title (with padding)======================
+NAME DATA
+foo bla bla bla
+bar alb alb alb
+This is left title (with padding)-----------------------------------------------
+NAME DATA
+foo bla bla bla
+bar alb alb alb
diff --git a/tests/ts/libsmartcols/title b/tests/ts/libsmartcols/title
new file mode 100755
index 000000000..a9ba6a4fd
--- /dev/null
+++ b/tests/ts/libsmartcols/title
@@ -0,0 +1,28 @@
+#!/bin/bash
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="title"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+TESTPROG="$TS_HELPER_LIBSMARTCOLS_TITLE"
+ts_check_test_command "$TESTPROG"
+
+$TESTPROG --width 80 >> $TS_OUTPUT 2>&1
+
+ts_finalize