[glibmm/vector] Added test for std::vector<bool>.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/vector] Added test for std::vector<bool>.
- Date: Fri, 21 Jan 2011 17:11:24 +0000 (UTC)
commit 2b808751ec9aa8719b029177c2b08258a35aa64e
Author: Krzesimir Nowak <qdlacz gmail com>
Date: Fri Jan 21 12:22:29 2011 +0100
Added test for std::vector<bool>.
tests/Makefile.am | 6 ++-
tests/glibmm_bool_vector/main.cc | 78 ++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f60664b..c31d9cb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,7 +29,8 @@ check_PROGRAMS = \
glibmm_value/test \
glibmm_valuearray/test \
glibmm_variant/test \
- glibmm_vector/test
+ glibmm_vector/test \
+ glibmm_bool_vector/test
glibmm_includes = -I$(top_builddir)/glib $(if $(srcdir:.=),-I$(top_srcdir)/glib)
giomm_includes = -I$(top_builddir)/gio $(if $(srcdir:.=),-I$(top_srcdir)/gio)
@@ -57,9 +58,10 @@ glibmm_btree_test_SOURCES = glibmm_btree/main.cc
glibmm_date_test_SOURCES = glibmm_date/main.cc
glibmm_nodetree_test_SOURCES = glibmm_nodetree/main.cc
glibmm_ustring_compose_test_SOURCES = glibmm_ustring_compose/main.cc
-glibmm_ustring_format_test_SOURCES = glibmm_ustring_format/main.cc
+glibmm_ustring_format_test_SOURCES = glibmm_ustring_format/main.cc
glibmm_value_test_SOURCES = glibmm_value/glibmm_value.cc glibmm_value/main.cc
glibmm_valuearray_test_SOURCES = glibmm_valuearray/main.cc
glibmm_variant_test_SOURCES = glibmm_variant/main.cc
glibmm_vector_test_SOURCES = glibmm_vector/main.cc
glibmm_vector_test_LDADD = $(giomm_ldadd)
+glibmm_bool_vector_test_SOURCES = glibmm_bool_vector/main.cc
diff --git a/tests/glibmm_bool_vector/main.cc b/tests/glibmm_bool_vector/main.cc
new file mode 100644
index 0000000..03d2993
--- /dev/null
+++ b/tests/glibmm_bool_vector/main.cc
@@ -0,0 +1,78 @@
+/* Copyright (C) 2011 The glibmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#include <cstdlib>
+#include <iostream>
+#include <glibmm.h>
+
+const unsigned int magic_limit (5);
+
+void
+setup_rand ()
+{
+ static bool setup (false);
+
+ if (!setup)
+ {
+ std::srand (std::time (0));
+ }
+}
+
+gboolean*
+c_get_bool_array ()
+{
+ gboolean* array (static_cast<gboolean*> (g_malloc ((magic_limit + 1) * sizeof (gboolean))));
+
+ setup_rand ();
+ for (unsigned int iter (0); iter < magic_limit; ++iter)
+ {
+ array[iter] = std::rand() % 2 ? TRUE : FALSE;
+ }
+ array[magic_limit] = FALSE;
+ return array;
+}
+
+void
+c_print_bool_array (gboolean* array)
+{
+ for (unsigned int iter (0); iter < magic_limit; ++iter)
+ {
+ std::cout << iter << ": " << (array[iter] ? "TRUE" : "FALSE") << "\n";
+ }
+}
+
+std::vector<bool>
+cxx_get_bool_array ()
+{
+ return Glib::ArrayHandler<bool>::array_to_vector (c_get_bool_array (), Glib::OWNERSHIP_SHALLOW);
+}
+
+void
+cxx_print_bool_array (const std::vector<bool>& v)
+{
+ c_print_bool_array (const_cast<gboolean*> (Glib::ArrayHandler<bool>::vector_to_array (v).data ()));
+}
+
+int main(int, char**)
+{
+ Glib::init();
+
+ std::vector<bool> va (cxx_get_bool_array ());
+
+ cxx_print_bool_array (va);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]