[glibmm] ByteArray: Add some tests for methods returning self.



commit eea7cef1c7bdfcabab7b70bc29d00899a89532ae
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Sun Sep 22 15:15:56 2013 +0200

    ByteArray: Add some tests for methods returning self.
    
    * tests/Makefile.am:
    * tests/glibmm_bytearray/main.cc: New file with tests. These are
    failing now.

 tests/Makefile.am              |    8 +++++---
 tests/glibmm_bytearray/main.cc |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 36eb067..be9c4c6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -39,9 +39,10 @@ check_PROGRAMS =                             \
        glibmm_bool_vector/test                 \
        glibmm_bool_arrayhandle/test            \
        glibmm_null_vectorutils/test            \
-       glibmm_null_containerhandle/test \
-       glibmm_refptr_sigc_bind/test
-       
+       glibmm_null_containerhandle/test        \
+       glibmm_refptr_sigc_bind/test            \
+       glibmm_bytearray/test
+
 TESTS =        $(check_PROGRAMS)
 
 glibmm_includes = -I$(top_builddir)/glib $(if $(srcdir:.=),-I$(top_srcdir)/glib)
@@ -97,3 +98,4 @@ glibmm_null_vectorutils_test_LDADD       = $(giomm_ldadd)
 glibmm_null_containerhandle_test_SOURCES = glibmm_null_containerhandle/main.cc
 glibmm_null_containerhandle_test_LDADD   = $(giomm_ldadd)
 glibmm_refptr_sigc_bind_test_SOURCES     = glibmm_refptr_sigc_bind/main.cc
+glibmm_bytearray_test_SOURCES            = glibmm_bytearray/main.cc
diff --git a/tests/glibmm_bytearray/main.cc b/tests/glibmm_bytearray/main.cc
new file mode 100644
index 0000000..ff05f3c
--- /dev/null
+++ b/tests/glibmm_bytearray/main.cc
@@ -0,0 +1,38 @@
+#include <glibmm.h>
+#include <iostream>
+#include <string>
+
+int
+main()
+{
+  Glib::RefPtr< Glib::ByteArray > array(Glib::ByteArray::create());
+  guint8 data[] = {1, 2, 3, 4, 5, 6};
+
+  array->append(data, sizeof(data));
+  // |1, 2, 3, 4, 5, 6| = 6
+  g_assert (array->size() == 6);
+
+  array->prepend(data, sizeof(data));
+  // |1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6| = 12
+  g_assert (array->size() == 12);
+
+  array->remove_index(0);
+  // |2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6| = 11
+  g_assert (array->size() == 11);
+
+  array->remove_index_fast(0);
+  // |6, 3, 4, 5, 6, 1, 2, 3, 4, 5| = 10
+  g_assert (array->size() == 10);
+
+  array->remove_range(0, 4);
+  // |6, 1, 2, 3, 4, 5,| = 6
+  g_assert (array->size() == 6);
+
+  array->set_size(2);
+  // |6, 1| = 2
+  g_assert (array->size() == 2);
+
+  guint8* array_data = array->get_data();
+  g_assert (array_data[0] == 6);
+  g_assert (array_data[1] == 1);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]