summaryrefslogtreecommitdiffstats
path: root/src/test/test_texttable.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/test/test_texttable.cc
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test_texttable.cc')
-rw-r--r--src/test/test_texttable.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/test/test_texttable.cc b/src/test/test_texttable.cc
new file mode 100644
index 00000000..0d439d16
--- /dev/null
+++ b/src/test/test_texttable.cc
@@ -0,0 +1,78 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2012 Inktank Storage, Inc.
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#include "common/TextTable.h"
+#include <iostream>
+#include "gtest/gtest.h"
+#include "include/coredumpctl.h"
+
+TEST(TextTable, Alignment) {
+ TextTable t;
+
+ // test alignment
+ // 3 5-character columns
+ t.define_column("HEAD1", TextTable::LEFT, TextTable::LEFT);
+ t.define_column("HEAD2", TextTable::LEFT, TextTable::CENTER);
+ t.define_column("HEAD3", TextTable::LEFT, TextTable::RIGHT);
+
+ t << "1" << 2 << 3 << TextTable::endrow;
+ std::ostringstream oss;
+ oss << t;
+ ASSERT_STREQ("HEAD1 HEAD2 HEAD3 \n1 2 3 \n", oss.str().c_str());
+}
+
+TEST(TextTable, WidenAndClearShrink) {
+ TextTable t;
+
+ t.define_column("1", TextTable::LEFT, TextTable::LEFT);
+
+ // default column size is 1, widen to 5
+ t << "wider";
+
+ // validate wide output
+ std::ostringstream oss;
+ oss << t;
+ ASSERT_STREQ("1 \nwider \n", oss.str().c_str());
+ oss.str("");
+
+ // reset, validate single-char width output
+ t.clear();
+ t << "s";
+ oss << t;
+ ASSERT_STREQ("1 \ns \n", oss.str().c_str());
+}
+
+TEST(TextTable, Indent) {
+ TextTable t;
+
+ t.define_column("1", TextTable::LEFT, TextTable::LEFT);
+ t.set_indent(10);
+ t << "s";
+ std::ostringstream oss;
+ oss << t;
+ ASSERT_STREQ(" 1 \n s \n", oss.str().c_str());
+}
+
+
+TEST(TextTable, TooManyItems) {
+ TextTable t;
+
+ t.define_column("1", TextTable::LEFT, TextTable::LEFT);
+ t.define_column("2", TextTable::LEFT, TextTable::LEFT);
+ t.define_column("3", TextTable::LEFT, TextTable::LEFT);
+
+ // expect assertion failure on this, which throws FailedAssertion
+ PrCtl unset_dumpable;
+ ASSERT_DEATH((t << "1" << "2" << "3" << "4" << TextTable::endrow), "");
+}