]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/test_texttable.cc
update sources to 12.2.7
[ceph.git] / ceph / src / test / test_texttable.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2012 Inktank Storage, Inc.
7 *
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.
12 *
13 */
14
15 #include "common/TextTable.h"
16 #include <iostream>
17 #include "gtest/gtest.h"
18 #include "include/coredumpctl.h"
19
20 TEST(TextTable, Alignment) {
21 TextTable t;
22
23 // test 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);
28
29 t << "1" << 2 << 3 << TextTable::endrow;
30 std::ostringstream oss;
31 oss << t;
32 ASSERT_STREQ("HEAD1 HEAD2 HEAD3 \n1 2 3 \n", oss.str().c_str());
33 }
34
35 TEST(TextTable, WidenAndClearShrink) {
36 TextTable t;
37
38 t.define_column("1", TextTable::LEFT, TextTable::LEFT);
39
40 // default column size is 1, widen to 5
41 t << "wider";
42
43 // validate wide output
44 std::ostringstream oss;
45 oss << t;
46 ASSERT_STREQ("1 \nwider \n", oss.str().c_str());
47 oss.str("");
48
49 // reset, validate single-char width output
50 t.clear();
51 t << "s";
52 oss << t;
53 ASSERT_STREQ("1 \ns \n", oss.str().c_str());
54 }
55
56 TEST(TextTable, Indent) {
57 TextTable t;
58
59 t.define_column("1", TextTable::LEFT, TextTable::LEFT);
60 t.set_indent(10);
61 t << "s";
62 std::ostringstream oss;
63 oss << t;
64 ASSERT_STREQ(" 1 \n s \n", oss.str().c_str());
65 }
66
67
68 TEST(TextTable, TooManyItems) {
69 TextTable t;
70
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);
74
75 // expect assertion failure on this, which throws FailedAssertion
76 PrCtl unset_dumpable;
77 ASSERT_DEATH((t << "1" << "2" << "3" << "4" << TextTable::endrow), "");
78 }