Use gdb_bfd_sections in get_stap_base_address
[deliverable/binutils-gdb.git] / gdb / unittests / array-view-selftests.c
index c4c95bc7ec8426016ba66e24111365763413fa08..b4fc86646ef51fd82b811d1b87a1046c7a499225 100644 (file)
@@ -1,6 +1,6 @@
 /* Self tests for array_view for GDB, the GNU debugger.
 
-   Copyright (C) 2017 Free Software Foundation, Inc.
+   Copyright (C) 2017-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -18,8 +18,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "selftest.h"
-#include "common/array-view.h"
+#include "gdbsupport/selftest.h"
+#include "gdbsupport/array-view.h"
+#include <array>
 
 namespace selftests {
 namespace array_view_tests {
@@ -258,7 +259,7 @@ require_not_constructible ()
 
 /* Check the array_view<T>(PTR, SIZE) ctor, when T is a pointer.  */
 
-void
+static void
 check_ptr_size_ctor2 ()
 {
   struct A {};
@@ -443,14 +444,14 @@ run_tests ()
 
   /* op[] */
   {
-    std::vector<gdb_byte> vec = {0x11, 0x22};
-    gdb::array_view<gdb_byte> view = vec;
-    gdb::array_view<const gdb_byte> cview = vec;
+    std::vector<gdb_byte> vec2 = {0x11, 0x22};
+    gdb::array_view<gdb_byte> view = vec2;
+    gdb::array_view<const gdb_byte> cview = vec2;
 
     /* Check that op[] on a non-const view of non-const T returns a
        mutable reference.  */
     view[0] = 0x33;
-    SELF_CHECK (vec[0] == 0x33);
+    SELF_CHECK (vec2[0] == 0x33);
 
     /* OTOH, check that assigning through op[] on a view of const T
        wouldn't compile.  */
@@ -482,13 +483,50 @@ run_tests ()
     gdb::array_view<Vec> view_elem = elem;
     SELF_CHECK (view_elem.size () == 1);
   }
+
+  /* gdb::make_array_view, int length.  */
+  {
+    gdb_byte data[] = {0x55, 0x66, 0x77, 0x88};
+    int len = sizeof (data) / sizeof (data[0]);
+    auto view = gdb::make_array_view (data, len);
+
+    SELF_CHECK (view.data () == data);
+    SELF_CHECK (view.size () == len);
+
+    for (size_t i = 0; i < len; i++)
+      SELF_CHECK (view[i] == data[i]);
+  }
+
+  /* Test slicing.  */
+  {
+    gdb_byte data[] = {0x55, 0x66, 0x77, 0x88, 0x99};
+    gdb::array_view<gdb_byte> view = data;
+
+    {
+      auto slc = view.slice (1, 3);
+      SELF_CHECK (slc.data () == data + 1);
+      SELF_CHECK (slc.size () == 3);
+      SELF_CHECK (slc[0] == data[1]);
+      SELF_CHECK (slc[0] == view[1]);
+    }
+
+    {
+      auto slc = view.slice (2);
+      SELF_CHECK (slc.data () == data + 2);
+      SELF_CHECK (slc.size () == 3);
+      SELF_CHECK (slc[0] == view[2]);
+      SELF_CHECK (slc[0] == data[2]);
+    }
+  }
 }
 
 } /* namespace array_view_tests */
 } /* namespace selftests */
 
+void _initialize_array_view_selftests ();
 void
 _initialize_array_view_selftests ()
 {
-  selftests::register_test (selftests::array_view_tests::run_tests);
+  selftests::register_test ("array_view",
+                           selftests::array_view_tests::run_tests);
 }
This page took 0.026537 seconds and 4 git commands to generate.