From a45047c966889a00d0ad0618ede4f8b1947f9a90 Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Fri, 22 Oct 2010 16:02:21 +0200 Subject: [PATCH] dwarflint: Move the testing code of wrap.cc to tests/test-wrap.cc --- dwarflint/Makefile.am | 7 ++-- dwarflint/tests/test-wrap.cc | 66 ++++++++++++++++++++++++++++++++++++ dwarflint/wrap.cc | 46 ------------------------- 3 files changed, 71 insertions(+), 48 deletions(-) create mode 100644 dwarflint/tests/test-wrap.cc diff --git a/dwarflint/Makefile.am b/dwarflint/Makefile.am index 844f83d86..4b0f592ce 100644 --- a/dwarflint/Makefile.am +++ b/dwarflint/Makefile.am @@ -36,7 +36,7 @@ AM_LDFLAGS = -Wl,-rpath-link,../libelf:../libdw no_mudflap.os = -fmudflap bin_PROGRAMS = dwarflint -noinst_PROGRAMS = tests/test-coverage +noinst_PROGRAMS = tests/test-coverage tests/test-wrap dwarflint_SOURCES = \ addr-record.cc addr-record.hh \ @@ -90,6 +90,8 @@ dwarflint_SOURCES = \ tests_test_coverage_SOURCES = tests/test-coverage.cc coverage.cc pri.cc \ ../src/dwarfstrings.c +tests_test_wrap_SOURCES = tests/test-wrap.cc wrap.cc + EXTRA_TESTS = tests/run-debug_abbrev-duplicate-attribute.sh \ tests/run-check_duplicate_DW_tag_variable.sh \ tests/run-location-leaks.sh \ @@ -100,7 +102,8 @@ EXTRA_TESTS = tests/run-debug_abbrev-duplicate-attribute.sh \ tests/run-libdl-2.12.so.debug.sh TESTS = $(EXTRA_TESTS) \ - tests/test-coverage + tests/test-coverage \ + tests/test-wrap EXTRA_DIST = $(EXTRA_TESTS) \ tests/debug_abbrev-duplicate-attribute.bz2 \ diff --git a/dwarflint/tests/test-wrap.cc b/dwarflint/tests/test-wrap.cc new file mode 100644 index 000000000..ee9ca38fb --- /dev/null +++ b/dwarflint/tests/test-wrap.cc @@ -0,0 +1,66 @@ +/* + Copyright (C) 2010 Red Hat, Inc. + This file is part of Red Hat elfutils. + + Red Hat elfutils 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; version 2 of the License. + + Red Hat elfutils 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. + + You should have received a copy of the GNU General Public License along + with Red Hat elfutils; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. + + Red Hat elfutils is an included package of the Open Invention Network. + An included package of the Open Invention Network is a package for which + Open Invention Network licensees cross-license their patents. No patent + license is granted, either expressly or impliedly, by designation as an + included package. Should you wish to participate in the Open Invention + Network licensing program, please visit www.openinventionnetwork.com + . */ + +#include "../wrap.hh" +#include + +std::string +wrap (char const *str, size_t width) +{ + return wrap_str (str, width).join (); +} + +std::string +sspaces (size_t i) +{ + return spaces (i); +} + +int main (void) +{ + assert (sspaces (0) == ""); + assert (sspaces (1) == " "); + assert (sspaces (2) == " "); + assert (sspaces (10) == " "); + assert (wrap ("a b c d", 1) == "a\nb\nc\nd\n"); + assert (wrap ("a bbbbb c d", 1) == "a\nbbbbb\nc\nd\n"); + assert (wrap ("a b", 3) == "a b\n"); + assert (wrap (" a b", 3) == " a\n b\n"); + assert (wrap (" a b", 4) == " a b\n"); + assert (wrap (" a b c d", 4) == " a b\n c d\n"); + assert (wrap ("ab cd ef gh ij", 2) == "ab\ncd\nef\ngh\nij\n"); + assert (wrap ("ab cd ef gh ij", 3) == "ab\ncd\nef\ngh\nij\n"); + assert (wrap ("ab cd ef gh ij", 4) == "ab\ncd\nef\ngh\nij\n"); + assert (wrap ("ab cd ef gh ij", 5) == "ab cd\nef gh\nij\n"); + assert (wrap ("", 5) == ""); + assert (wrap ("", 0) == ""); + assert (wrap ("\n", 5) == "\n"); + assert (wrap ("\n\n", 5) == "\n\n"); + assert (wrap ("\n\n", 0) == "\n\n"); + assert (wrap ("ab\ncd ef gh ij", 5) == "ab\ncd ef\ngh ij\n"); + assert (wrap (" - abcd abbb accc", 3) == " - abcd\n abbb\n accc\n"); + assert (wrap (" -abcd abbb accc", 3) == " -abcd\n abbb\n accc\n"); + assert (wrap (" abcd abbb accc", 3) == " abcd\n abbb\n accc\n"); +} diff --git a/dwarflint/wrap.cc b/dwarflint/wrap.cc index 3295179ea..bade35ca5 100644 --- a/dwarflint/wrap.cc +++ b/dwarflint/wrap.cc @@ -174,49 +174,3 @@ spaces (size_t n) static spc<128> spaces; return spaces.get (n); } - -namespace -{ - class tests - { - std::string - wrap (char const *str, size_t width) - { - return wrap_str (str, width).join (); - } - - std::string - spacess (size_t i) - { - return spaces (i); - } - - public: - tests () - { - assert (spacess (0) == ""); - assert (spacess (1) == " "); - assert (spacess (2) == " "); - assert (spacess (10) == " "); - assert (wrap ("a b c d", 1) == "a\nb\nc\nd\n"); - assert (wrap ("a bbbbb c d", 1) == "a\nbbbbb\nc\nd\n"); - assert (wrap ("a b", 3) == "a b\n"); - assert (wrap (" a b", 3) == " a\n b\n"); - assert (wrap (" a b", 4) == " a b\n"); - assert (wrap (" a b c d", 4) == " a b\n c d\n"); - assert (wrap ("ab cd ef gh ij", 2) == "ab\ncd\nef\ngh\nij\n"); - assert (wrap ("ab cd ef gh ij", 3) == "ab\ncd\nef\ngh\nij\n"); - assert (wrap ("ab cd ef gh ij", 4) == "ab\ncd\nef\ngh\nij\n"); - assert (wrap ("ab cd ef gh ij", 5) == "ab cd\nef gh\nij\n"); - assert (wrap ("", 5) == ""); - assert (wrap ("", 0) == ""); - assert (wrap ("\n", 5) == "\n"); - assert (wrap ("\n\n", 5) == "\n\n"); - assert (wrap ("\n\n", 0) == "\n\n"); - assert (wrap ("ab\ncd ef gh ij", 5) == "ab\ncd ef\ngh ij\n"); - assert (wrap (" - abcd abbb accc", 3) == " - abcd\n abbb\n accc\n"); - assert (wrap (" -abcd abbb accc", 3) == " -abcd\n abbb\n accc\n"); - assert (wrap (" abcd abbb accc", 3) == " abcd\n abbb\n accc\n"); - } - } _; -} -- 2.47.2