1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2012 Inktank Storage, Inc.
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "common/TextTable.h"
17 #include "gtest/gtest.h"
18 #include "include/coredumpctl.h"
20 TEST(TextTable, Alignment) {
24 // 3 5-character columns
25 t.define_column("HEAD1", TextTable::LEFT, TextTable::LEFT);
26 t.define_column("HEAD2", TextTable::LEFT, TextTable::CENTER);
27 t.define_column("HEAD3", TextTable::LEFT, TextTable::RIGHT);
29 t << "1" << 2 << 3 << TextTable::endrow;
30 std::ostringstream oss;
32 ASSERT_STREQ("HEAD1 HEAD2 HEAD3 \n1 2 3 \n", oss.str().c_str());
35 TEST(TextTable, WidenAndClearShrink) {
38 t.define_column("1", TextTable::LEFT, TextTable::LEFT);
40 // default column size is 1, widen to 5
43 // validate wide output
44 std::ostringstream oss;
46 ASSERT_STREQ("1 \nwider \n", oss.str().c_str());
49 // reset, validate single-char width output
53 ASSERT_STREQ("1 \ns \n", oss.str().c_str());
56 TEST(TextTable, Indent) {
59 t.define_column("1", TextTable::LEFT, TextTable::LEFT);
62 std::ostringstream oss;
64 ASSERT_STREQ(" 1 \n s \n", oss.str().c_str());
68 TEST(TextTable, TooManyItems) {
71 t.define_column("1", TextTable::LEFT, TextTable::LEFT);
72 t.define_column("2", TextTable::LEFT, TextTable::LEFT);
73 t.define_column("3", TextTable::LEFT, TextTable::LEFT);
75 // expect assertion failure on this, which throws FailedAssertion
77 ASSERT_DEATH((t << "1" << "2" << "3" << "4" << TextTable::endrow), "");