From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/test/test_texttable.cc | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/test/test_texttable.cc (limited to 'src/test/test_texttable.cc') 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 +#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), ""); +} -- cgit v1.2.3