]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Move the testing code of wrap.cc to tests/test-wrap.cc
authorPetr Machata <pmachata@redhat.com>
Fri, 22 Oct 2010 14:02:21 +0000 (16:02 +0200)
committerPetr Machata <pmachata@redhat.com>
Fri, 22 Oct 2010 14:02:21 +0000 (16:02 +0200)
dwarflint/Makefile.am
dwarflint/tests/test-wrap.cc [new file with mode: 0644]
dwarflint/wrap.cc

index 844f83d8686fa8526e1fe034c0229e03eac45b42..4b0f592cef6b6d40064bc104d4f5e4fb4990bbf1 100644 (file)
@@ -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 (file)
index 0000000..ee9ca38
--- /dev/null
@@ -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
+   <http://www.openinventionnetwork.com>.  */
+
+#include "../wrap.hh"
+#include <cassert>
+
+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");
+}
index 3295179eaddea287abd90b37a6946e88bba1fc48..bade35ca5abe35bb0583a7e9f6a35b25ac59ce43 100644 (file)
@@ -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");
-    }
-  } _;
-}