2011-05-14 Vincent Torri
* Add Eina_Condition API on Windows.
+
+2011-05-17 Tom Hacohen (TAsn)
+
+ * Added eina_binbuf: This is just like strbuf but for binary blobs.
+ Requested by discomfitor and honestly it looks needed.
+
#include "eina_matrixsparse.h"
#include "eina_str.h"
#include "eina_strbuf.h"
+#include "eina_binbuf.h"
#include "eina_ustrbuf.h"
#include "eina_unicode.h"
#include "eina_quadtree.h"
eina_magic.h \
eina_stringshare.h \
eina_binshare.h \
+eina_binbuf.h \
eina_ustringshare.h \
eina_inline_stringshare.x \
eina_inline_ustringshare.x \
--- /dev/null
+#ifndef EINA_BINBUF_H
+#define EINA_BINBUF_H
+
+#include <stddef.h>
+#include <stdarg.h>
+
+#include "eina_types.h"
+
+/**
+ * @addtogroup Eina_Binary_Buffer_Group Binary Buffer
+ *
+ * @brief These functions provide string buffers management.
+ *
+ * The Binary Buffer data type is designed to be a mutable string,
+ * allowing to append, prepend or insert a string to a buffer.
+ *
+ * @{
+ */
+
+/**
+ * @addtogroup Eina_Data_Types_Group Data Types
+ *
+ * @{
+ */
+
+/**
+ * @defgroup Eina_Binary_Buffer_Group Binary Buffer
+ *
+ * @{
+ */
+
+/**
+ * @typedef Eina_Binbuf
+ * Type for a string buffer.
+ */
+typedef struct _Eina_Binbuf Eina_Binbuf;
+
+/**
+ * @brief Create a new string buffer.
+ *
+ * @return Newly allocated string buffer instance.
+ *
+ * This function creates a new string buffer. On error, @c NULL is
+ * returned and Eina error is set to #EINA_ERROR_OUT_OF_MEMORY. To
+ * free the resources, use eina_binbuf_free().
+ *
+ * @see eina_binbuf_free()
+ * @see eina_binbuf_append()
+ * @see eina_binbuf_string_get()
+ */
+EAPI Eina_Binbuf *eina_binbuf_new(void) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
+
+/**
+ * @brief Free a string buffer.
+ *
+ * @param buf The string buffer to free.
+ *
+ * This function frees the memory of @p buf. @p buf must have been
+ * created by eina_binbuf_new().
+ */
+EAPI void eina_binbuf_free(Eina_Binbuf *buf) EINA_ARG_NONNULL(1);
+
+/**
+ * @brief Reset a string buffer.
+ *
+ * @param buf The string buffer to reset.
+ *
+ * This function reset @p buf: the buffer len is set to 0, and the
+ * string is set to '\\0'. No memory is free'd.
+ */
+EAPI void eina_binbuf_reset(Eina_Binbuf *buf) EINA_ARG_NONNULL(1);
+
+/**
+ * @brief Append a string of exact length to a buffer, reallocating as necessary.
+ *
+ * @param buf The string buffer to append to.
+ * @param str The string to append.
+ * @param length The exact length to use.
+ * @return #EINA_TRUE on success, #EINA_FALSE on failure.
+ *
+ * This function appends @p str to @p buf. @p str must be of size at
+ * most @p length. It is slightly faster than eina_binbuf_append() as
+ * it does not compute the size of @p str. It is useful when dealing
+ * with strings of known size, such as eina_strngshare. If @p buf
+ * can't append it, #EINA_FALSE is returned, otherwise #EINA_TRUE is
+ * returned.
+ *
+ * @see eina_stringshare_length()
+ * @see eina_binbuf_append()
+ * @see eina_binbuf_append_n()
+ */
+EAPI Eina_Bool eina_binbuf_append_length(Eina_Binbuf *buf, const char *str, size_t length) EINA_ARG_NONNULL(1, 2);
+
+/**
+ * @brief Append a character to a string buffer, reallocating as
+ * necessary.
+ *
+ * @param buf The string buffer to append to.
+ * @param c The char to append.
+ * @return #EINA_TRUE on success, #EINA_FALSE on failure.
+ *
+ * This function inserts @p c to @p buf. If it can not insert it,
+ * #EINA_FALSE is returned, otherwise #EINA_TRUE is returned.
+ */
+EAPI Eina_Bool eina_binbuf_append_char(Eina_Binbuf *buf, char c) EINA_ARG_NONNULL(1);
+
+/**
+ * @brief Insert a string of exact length to a buffer, reallocating as necessary.
+ *
+ * @param buf The string buffer to insert to.
+ * @param str The string to insert.
+ * @param length The exact length to use.
+ * @param pos The position to insert the string.
+ * @return #EINA_TRUE on success, #EINA_FALSE on failure.
+ *
+ * This function inserts @p str to @p buf. @p str must be of size at
+ * most @p length. It is slightly faster than eina_binbuf_insert() as
+ * it does not compute the size of @p str. It is useful when dealing
+ * with strings of known size, such as eina_strngshare. If @p buf
+ * can't insert it, #EINA_FALSE is returned, otherwise #EINA_TRUE is
+ * returned.
+ *
+ * @see eina_stringshare_length()
+ * @see eina_binbuf_insert()
+ * @see eina_binbuf_insert_n()
+ */
+EAPI Eina_Bool eina_binbuf_insert_length(Eina_Binbuf *buf, const char *str, size_t length, size_t pos) EINA_ARG_NONNULL(1, 2);
+
+/**
+ * @brief Insert a character to a string buffer, reallocating as
+ * necessary.
+ *
+ * @param buf The string buffer to insert to.
+ * @param c The char to insert.
+ * @param pos The position to insert the char.
+ * @return #EINA_TRUE on success, #EINA_FALSE on failure.
+ *
+ * This function inserts @p c to @p buf at position @p pos. If @p buf
+ * can't append it, #EINA_FALSE is returned, otherwise #EINA_TRUE is
+ * returned.
+ */
+EAPI Eina_Bool eina_binbuf_insert_char(Eina_Binbuf *buf, char c, size_t pos) EINA_ARG_NONNULL(1);
+
+/**
+ * @brief Remove a slice of the given string buffer.
+ *
+ * @param buf The string buffer to remove a slice.
+ * @param start The initial (inclusive) slice position to start
+ * removing, in bytes.
+ * @param end The final (non-inclusive) slice position to finish
+ * removing, in bytes.
+ * @return #EINA_TRUE on success, #EINA_FALSE on failure.
+ *
+ * This function removes a slice of @p buf, starting at @p start
+ * (inclusive) and ending at @p end (non-inclusive). Both values are
+ * in bytes. It returns #EINA_FALSE on failure, #EINA_TRUE otherwise.
+ */
+
+EAPI Eina_Bool eina_binbuf_remove(Eina_Binbuf *buf, size_t start, size_t end) EINA_ARG_NONNULL(1);
+
+/**
+ * @brief Retrieve a pointer to the contents of a string buffer
+ *
+ * @param buf The string buffer.
+ * @return The current string in the string buffer.
+ *
+ * This function returns the string contained in @p buf. The returned
+ * value must not be modified and will no longer be valid if @p buf is
+ * modified. In other words, any eina_binbuf_append() or similar will
+ * make that pointer invalid.
+ *
+ * @see eina_binbuf_string_steal()
+ */
+EAPI const char *eina_binbuf_string_get(const Eina_Binbuf *buf) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
+
+/**
+ * @brief Steal the contents of a string buffer.
+ *
+ * @param buf The string buffer to steal.
+ * @return The current string in the string buffer.
+ *
+ * This function returns the string contained in @p buf. @p buf is
+ * then initialized and does not own the returned string anymore. The
+ * caller must release the memory of the returned string by calling
+ * free().
+ *
+ * @see eina_binbuf_string_get()
+ */
+EAPI char *eina_binbuf_string_steal(Eina_Binbuf *buf) EINA_MALLOC EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
+
+/**
+ * @brief Free the contents of a string buffer but not the buffer.
+ *
+ * @param buf The string buffer to free the string of.
+ *
+ * This function frees the string contained in @p buf without freeing
+ * @p buf.
+ */
+EAPI void eina_binbuf_string_free(Eina_Binbuf *buf) EINA_ARG_NONNULL(1);
+
+/**
+ * @brief Retrieve the length of the string buffer content.
+ *
+ * @param buf The string buffer.
+ * @return The current length of the string, in bytes.
+ *
+ * This function returns the length of @p buf.
+ */
+EAPI size_t eina_binbuf_length_get(const Eina_Binbuf *buf) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#endif /* EINA_STRBUF_H */
eina_array.c \
eina_benchmark.c \
eina_binshare.c \
+eina_binbuf.c \
eina_convert.c \
eina_counter.c \
eina_cpu.c \
eina_share_common.h \
eina_private.h \
eina_strbuf_common.h \
-eina_strbuf_template_c.x
+eina_strbuf_template_c.x \
+eina_binbuf_template_c.x
--- /dev/null
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+
+#ifdef HAVE_EVIL
+# include <Evil.h>
+#endif
+
+#include "eina_private.h"
+#include "eina_str.h"
+#include "eina_strbuf_common.h"
+#include "eina_unicode.h"
+
+/*============================================================================*
+ * Local *
+ *============================================================================*/
+
+/**
+ * @cond LOCAL
+ */
+
+#ifdef _STRBUF_DATA_TYPE
+# undef _STRBUF_DATA_TYPE
+#endif
+
+#ifdef _STRBUF_CSIZE
+# undef _STRBUF_CSIZE
+#endif
+
+#ifdef _STRBUF_STRUCT_NAME
+# undef _STRBUF_STRUCT_NAME
+#endif
+
+#ifdef _STRBUF_MAGIC
+# undef _STRBUF_MAGIC
+#endif
+
+#ifdef _STRBUF_MAGIC_STR
+# undef _STRBUF_MAGIC_STR
+#endif
+
+#ifdef _FUNC_EXPAND
+# undef _FUNC_EXPAND
+#endif
+
+
+#define _STRBUF_DATA_TYPE char
+#define _STRBUF_CSIZE sizeof(_STRBUF_DATA_TYPE)
+#define _STRBUF_STRUCT_NAME Eina_Strbuf
+#define _STRBUF_MAGIC EINA_MAGIC_STRBUF
+#define _STRBUF_MAGIC_STR __STRBUF_MAGIC_STR
+static const char __STRBUF_MAGIC_STR[] = "Eina Binbuf";
+
+#define _FUNC_EXPAND(y) eina_binbuf_ ## y
+
+#include "eina_binbuf_template_c.x"
+
+/**
+ * @endcond
+ */
--- /dev/null
+/*
+ * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
+ */
+
+/* This file should be included from files implementing binbuf.
+ * The including file should define the following macros:
+ * _STRBUF_DATA_TYPE
+ * _STRBUF_CSIZE
+ * _STRBUF_STRUCT_NAME
+ * _STRBUF_MAGIC
+ * _STRBUF_MAGIC_STR
+ * _FUNC_EXPAND
+ * See how it's done in eina_ustrbuf.c and eina_strbuf.c. This just makes things
+ * a lot easier since those are essentially the same just with different sizes.
+ */
+
+/*============================================================================*
+ * Global *
+ *============================================================================*/
+
+/**
+ * @internal
+ * @brief Initialize the strbuf module.
+ *
+ * @return #EINA_TRUE on success, #EINA_FALSE on failure.
+ *
+ * This function sets up the strbuf module of Eina. It is called by
+ * eina_init().
+ *
+ * @see eina_init()
+ */
+Eina_Bool
+_FUNC_EXPAND(init)(void)
+{
+ eina_magic_string_static_set(_STRBUF_MAGIC, _STRBUF_MAGIC_STR);
+ return eina_strbuf_common_init();
+}
+
+/**
+ * @internal
+ * @brief Shut down the strbuf module.
+ *
+ * @return #EINA_TRUE on success, #EINA_FALSE on failure.
+ *
+ * This function shuts down the strbuf module set up by
+ * eina_ustrbuf_init(). It is called by eina_shutdown().
+ *
+ * @see eina_shutdown()
+ */
+Eina_Bool
+_FUNC_EXPAND(shutdown)(void)
+{
+ return eina_strbuf_common_shutdown();
+}
+
+/*============================================================================*
+ * API *
+ *============================================================================*/
+
+EAPI _STRBUF_STRUCT_NAME *
+_FUNC_EXPAND(new)(void)
+{
+ _STRBUF_STRUCT_NAME *buf = eina_strbuf_common_new(_STRBUF_CSIZE);
+ EINA_MAGIC_SET(buf, _STRBUF_MAGIC);
+ return buf;
+}
+
+EAPI void
+_FUNC_EXPAND(free)(_STRBUF_STRUCT_NAME *buf)
+{
+ EINA_MAGIC_CHECK_STRBUF(buf);
+ EINA_MAGIC_SET(buf, EINA_MAGIC_NONE);
+ eina_strbuf_common_free(buf);
+}
+
+EAPI void
+_FUNC_EXPAND(reset)(_STRBUF_STRUCT_NAME *buf)
+{
+ EINA_MAGIC_CHECK_STRBUF(buf);
+ eina_strbuf_common_reset(_STRBUF_CSIZE, buf);
+}
+
+EAPI Eina_Bool
+_FUNC_EXPAND(append_length)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t length)
+{
+ EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
+ return eina_strbuf_common_append_length(_STRBUF_CSIZE, buf, (const void *) str, length);
+}
+
+EAPI Eina_Bool
+_FUNC_EXPAND(insert_length)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t length, size_t pos)
+{
+ EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
+ return eina_strbuf_common_insert_length(_STRBUF_CSIZE, buf, (const void *) str, length, pos);
+}
+
+EAPI Eina_Bool
+_FUNC_EXPAND(append_char)(_STRBUF_STRUCT_NAME *buf, _STRBUF_DATA_TYPE c)
+{
+ EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
+ return eina_strbuf_common_append_char(_STRBUF_CSIZE, buf, (const void *) &c);
+}
+
+EAPI Eina_Bool
+_FUNC_EXPAND(insert_char)(_STRBUF_STRUCT_NAME *buf, _STRBUF_DATA_TYPE c, size_t pos)
+{
+ EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
+ return eina_strbuf_common_insert_char(_STRBUF_CSIZE, buf, (const void *) &c, pos);
+}
+
+EAPI Eina_Bool
+_FUNC_EXPAND(remove)(_STRBUF_STRUCT_NAME *buf, size_t start, size_t end)
+{
+ EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
+ return eina_strbuf_common_remove(_STRBUF_CSIZE, buf, start, end);
+}
+
+EAPI const _STRBUF_DATA_TYPE *
+_FUNC_EXPAND(string_get)(const _STRBUF_STRUCT_NAME *buf)
+{
+ EINA_MAGIC_CHECK_STRBUF(buf, NULL);
+ return (const _STRBUF_DATA_TYPE *) eina_strbuf_common_string_get(buf);
+}
+
+EAPI _STRBUF_DATA_TYPE *
+_FUNC_EXPAND(string_steal)(_STRBUF_STRUCT_NAME *buf)
+{
+ EINA_MAGIC_CHECK_STRBUF(buf, NULL);
+ return (_STRBUF_DATA_TYPE *) eina_strbuf_common_string_steal(_STRBUF_CSIZE, buf);
+}
+
+EAPI void
+_FUNC_EXPAND(string_free)(_STRBUF_STRUCT_NAME *buf)
+{
+ EINA_MAGIC_CHECK_STRBUF(buf);
+ eina_strbuf_common_string_free(_STRBUF_CSIZE, buf);
+}
+
+EAPI size_t
+_FUNC_EXPAND(length_get)(const _STRBUF_STRUCT_NAME *buf)
+{
+ EINA_MAGIC_CHECK_STRBUF(buf, 0);
+ return eina_strbuf_common_length_get(buf);
+}
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
-/* This file should be included from files implementing strbuf. The including file
- * should define the following macros:
+/* This file should be included from files implementing strbuf.
+ The including file should define the following macros:
* _STRBUF_DATA_TYPE
* _STRBUF_CSIZE
* _STRBUF_STRUCT_NAME
* a lot easier since those are essentially the same just with different sizes.
*/
-/*============================================================================*
- * Local *
- *============================================================================*/
-
-
-/*============================================================================*
- * Global *
- *============================================================================*/
-
-/**
- * @internal
- * @brief Initialize the strbuf module.
- *
- * @return #EINA_TRUE on success, #EINA_FALSE on failure.
- *
- * This function sets up the strbuf module of Eina. It is called by
- * eina_init().
- *
- * @see eina_init()
- */
-Eina_Bool
-_FUNC_EXPAND(init)(void)
-{
- eina_magic_string_static_set(_STRBUF_MAGIC, _STRBUF_MAGIC_STR);
- return eina_strbuf_common_init();
-}
-
-/**
- * @internal
- * @brief Shut down the strbuf module.
- *
- * @return #EINA_TRUE on success, #EINA_FALSE on failure.
- *
- * This function shuts down the strbuf module set up by
- * eina_ustrbuf_init(). It is called by eina_shutdown().
- *
- * @see eina_shutdown()
- */
-Eina_Bool
-_FUNC_EXPAND(shutdown)(void)
-{
- return eina_strbuf_common_shutdown();
-}
+#include "eina_binbuf_template_c.x"
/*============================================================================*
* API *
*============================================================================*/
-EAPI _STRBUF_STRUCT_NAME *
-_FUNC_EXPAND(new)(void)
-{
- _STRBUF_STRUCT_NAME *buf = eina_strbuf_common_new(_STRBUF_CSIZE);
- EINA_MAGIC_SET(buf, _STRBUF_MAGIC);
- return buf;
-}
-
-EAPI void
-_FUNC_EXPAND(free)(_STRBUF_STRUCT_NAME *buf)
-{
- EINA_MAGIC_CHECK_STRBUF(buf);
- EINA_MAGIC_SET(buf, EINA_MAGIC_NONE);
- eina_strbuf_common_free(buf);
-}
-
-EAPI void
-_FUNC_EXPAND(reset)(_STRBUF_STRUCT_NAME *buf)
-{
- EINA_MAGIC_CHECK_STRBUF(buf);
- eina_strbuf_common_reset(_STRBUF_CSIZE, buf);
-}
-
EAPI Eina_Bool
_FUNC_EXPAND(append)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str)
{
return eina_strbuf_common_append_n(_STRBUF_CSIZE, buf, (const void *) str, _STRBUF_STRLEN_FUNC(str), maxlen);
}
-EAPI Eina_Bool
-_FUNC_EXPAND(append_length)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t length)
-{
- EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
- return eina_strbuf_common_append_length(_STRBUF_CSIZE, buf, (const void *) str, length);
-}
-
EAPI Eina_Bool
_FUNC_EXPAND(insert)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t pos)
{
return eina_strbuf_common_insert_n(_STRBUF_CSIZE, buf, (const void *) str, _STRBUF_STRLEN_FUNC(str), maxlen, pos);
}
-EAPI Eina_Bool
-_FUNC_EXPAND(insert_length)(_STRBUF_STRUCT_NAME *buf, const _STRBUF_DATA_TYPE *str, size_t length, size_t pos)
-{
- EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
- return eina_strbuf_common_insert_length(_STRBUF_CSIZE, buf, (const void *) str, length, pos);
-}
-
-EAPI Eina_Bool
-_FUNC_EXPAND(append_char)(_STRBUF_STRUCT_NAME *buf, _STRBUF_DATA_TYPE c)
-{
- EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
- return eina_strbuf_common_append_char(_STRBUF_CSIZE, buf, (const void *) &c);
-}
-
-EAPI Eina_Bool
-_FUNC_EXPAND(insert_char)(_STRBUF_STRUCT_NAME *buf, _STRBUF_DATA_TYPE c, size_t pos)
-{
- EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
- return eina_strbuf_common_insert_char(_STRBUF_CSIZE, buf, (const void *) &c, pos);
-}
-
-EAPI Eina_Bool
-_FUNC_EXPAND(remove)(_STRBUF_STRUCT_NAME *buf, size_t start, size_t end)
-{
- EINA_MAGIC_CHECK_STRBUF(buf, EINA_FALSE);
- return eina_strbuf_common_remove(_STRBUF_CSIZE, buf, start, end);
-}
-
-EAPI const _STRBUF_DATA_TYPE *
-_FUNC_EXPAND(string_get)(const _STRBUF_STRUCT_NAME *buf)
-{
- EINA_MAGIC_CHECK_STRBUF(buf, NULL);
- return (const _STRBUF_DATA_TYPE *) eina_strbuf_common_string_get(buf);
-}
-
-EAPI _STRBUF_DATA_TYPE *
-_FUNC_EXPAND(string_steal)(_STRBUF_STRUCT_NAME *buf)
-{
- EINA_MAGIC_CHECK_STRBUF(buf, NULL);
- return (_STRBUF_DATA_TYPE *) eina_strbuf_common_string_steal(_STRBUF_CSIZE, buf);
-}
-
-
-EAPI void
-_FUNC_EXPAND(string_free)(_STRBUF_STRUCT_NAME *buf)
-{
- EINA_MAGIC_CHECK_STRBUF(buf);
- eina_strbuf_common_string_free(_STRBUF_CSIZE, buf);
-}
-
-EAPI size_t
-_FUNC_EXPAND(length_get)(const _STRBUF_STRUCT_NAME *buf)
-{
- EINA_MAGIC_CHECK_STRBUF(buf, 0);
- return eina_strbuf_common_length_get(buf);
-}
eina_test_ustringshare.c\
eina_test_ustr.c \
eina_test_binshare.c \
+eina_test_binbuf.c \
eina_test_array.c \
eina_test_error.c \
eina_test_sched.c \
{ "Matrix Sparse", eina_test_matrixsparse },
{ "Eina Tiler", eina_test_tiler },
{ "Eina Strbuf", eina_test_strbuf },
+ { "Eina Binbuf", eina_test_binbuf },
{ "String", eina_test_str },
{ "Unicode String", eina_test_ustr },
{ "QuadTree", eina_test_quadtree },
void eina_test_matrixsparse(TCase *tc);
void eina_test_tiler(TCase *tc);
void eina_test_strbuf(TCase *tc);
+void eina_test_binbuf(TCase *tc);
void eina_test_str(TCase *tc);
void eina_test_ustr(TCase *tc);
void eina_test_quadtree(TCase *tc);
--- /dev/null
+/* EINA - EFL data type library
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include "eina_suite.h"
+#include "Eina.h"
+
+START_TEST(binbuf_simple)
+{
+ Eina_Binbuf *buf;
+ char *txt;
+ const char cbuf[] = "Null in the middle \0 and more text afterwards and \0 anotehr null just there and another one \0 here.";
+ size_t size = sizeof(cbuf) - 1; /* We don't care about the real NULL */
+
+
+ eina_init();
+
+ buf = eina_binbuf_new();
+ fail_if(!buf);
+
+ eina_binbuf_append_length(buf, cbuf, size);
+ fail_if(memcmp(eina_binbuf_string_get(buf), cbuf, size));
+ fail_if(size != eina_binbuf_length_get(buf));
+
+ eina_binbuf_append_length(buf, cbuf, size);
+ fail_if(memcmp(eina_binbuf_string_get(buf), cbuf, size));
+ fail_if(memcmp(eina_binbuf_string_get(buf) + size, cbuf, size));
+ fail_if(2 * size != eina_binbuf_length_get(buf));
+
+ txt = eina_binbuf_string_steal(buf);
+ fail_if(memcmp(txt, cbuf, size));
+ fail_if(memcmp(txt + size, cbuf, size));
+ free(txt);
+ fail_if(eina_binbuf_length_get(buf) != 0);
+
+ eina_binbuf_append_length(buf, cbuf, size);
+ fail_if(memcmp(eina_binbuf_string_get(buf), cbuf, size));
+ fail_if(size != eina_binbuf_length_get(buf));
+
+ eina_binbuf_reset(buf);
+ fail_if(eina_binbuf_length_get(buf) != 0);
+
+ eina_binbuf_free(buf);
+
+ eina_shutdown();
+#undef TEXT
+}
+END_TEST
+
+START_TEST(binbuf_remove)
+{
+ Eina_Binbuf *buf;
+ const char cbuf[] = "12\0 456 78\0 abcthis is some more random junk here!";
+ size_t size = sizeof(cbuf) - 1; /* We don't care about the real NULL */
+
+ eina_init();
+
+ buf = eina_binbuf_new();
+ fail_if(!buf);
+
+ eina_binbuf_append_length(buf, cbuf, size);
+ fail_if(size != eina_binbuf_length_get(buf));
+ eina_binbuf_remove(buf, 0, 4);
+ fail_if(size - 4 != eina_binbuf_length_get(buf));
+ eina_binbuf_remove(buf, 8, 1000);
+ fail_if(8 != eina_binbuf_length_get(buf));
+ eina_binbuf_remove(buf, 7, eina_binbuf_length_get(buf));
+ fail_if(7 != eina_binbuf_length_get(buf));
+ eina_binbuf_remove(buf, 2, 4);
+ fail_if(5 != eina_binbuf_length_get(buf));
+ eina_binbuf_remove(buf, 4, 1);
+ fail_if(5 != eina_binbuf_length_get(buf));
+ eina_binbuf_remove(buf, 0, eina_binbuf_length_get(buf));
+ fail_if(0 != eina_binbuf_length_get(buf));
+
+ eina_binbuf_free(buf);
+
+ eina_shutdown();
+}
+END_TEST
+
+START_TEST(binbuf_insert)
+{
+#if 0
+ Eina_Binbuf *buf;
+
+ eina_init();
+
+ buf = eina_binbuf_new();
+ fail_if(!buf);
+
+ eina_binbuf_insert(buf, "abc", 10);
+ fail_if(strlen(eina_binbuf_string_get(buf)) != eina_binbuf_length_get(buf));
+ fail_if(strcmp(eina_binbuf_string_get(buf), "abc"));
+
+ eina_binbuf_insert(buf, "123", 0);
+ fail_if(strlen(eina_binbuf_string_get(buf)) != eina_binbuf_length_get(buf));
+ fail_if(strcmp(eina_binbuf_string_get(buf), "123abc"));
+
+ eina_binbuf_insert(buf, "xyz", eina_binbuf_length_get(buf));
+ fail_if(strlen(eina_binbuf_string_get(buf)) != eina_binbuf_length_get(buf));
+ fail_if(strcmp(eina_binbuf_string_get(buf), "123abcxyz"));
+
+ eina_binbuf_insert(buf, "xyz", 1);
+ fail_if(strlen(eina_binbuf_string_get(buf)) != eina_binbuf_length_get(buf));
+ fail_if(strcmp(eina_binbuf_string_get(buf), "1xyz23abcxyz"));
+
+ eina_binbuf_insert_n(buf, "ABCDEF", 2, 1);
+ fail_if(strlen(eina_binbuf_string_get(buf)) != eina_binbuf_length_get(buf));
+ fail_if(strcmp(eina_binbuf_string_get(buf), "1ABxyz23abcxyz"));
+
+ eina_binbuf_insert_n(buf, "EINA", 2, 3);
+ fail_if(strlen(eina_binbuf_string_get(buf)) != eina_binbuf_length_get(buf));
+ fail_if(strcmp(eina_binbuf_string_get(buf), "1ABEIxyz23abcxyz"));
+
+ eina_binbuf_insert_escaped(buf, "678", 3);
+ fail_if(strlen(eina_binbuf_string_get(buf)) != eina_binbuf_length_get(buf));
+ fail_if(strncmp(eina_binbuf_string_get(buf) + 3, "678", 3));
+
+ eina_binbuf_insert_escaped(buf, "089 '\\", 9);
+ fail_if(strlen(eina_binbuf_string_get(
+ buf)) != eina_binbuf_length_get(buf));
+ fail_if(strncmp(eina_binbuf_string_get(buf) + 9,
+ "089\\ \\'\\\\",
+ strlen("089\\ \\'\\\\")));
+ eina_binbuf_reset(buf);
+
+ eina_binbuf_free(buf);
+
+ eina_shutdown();
+#endif
+}
+END_TEST
+
+START_TEST(binbuf_realloc)
+{
+ Eina_Binbuf *buf;
+ char pattern[1024 * 16];
+ unsigned int i;
+ size_t sz;
+
+ for (i = 0; i < sizeof(pattern) - 1; i++)
+ {
+ if (i % 27 == 26)
+ pattern[i] = '\0';
+ else
+ pattern[i] = 'a' + (i % 27);
+ }
+ pattern[i] = '\0';
+
+ eina_init();
+
+ buf = eina_binbuf_new();
+ fail_if(!buf);
+
+ sz = 0;
+
+ eina_binbuf_append_length(buf, pattern, 1);
+ fail_if(eina_binbuf_length_get(buf) != sz + 1);
+ fail_if(memcmp(eina_binbuf_string_get(buf) + sz, pattern, 1));
+ sz += 1;
+
+ eina_binbuf_append_length(buf, pattern, 32);
+ fail_if(eina_binbuf_length_get(buf) != sz + 32);
+ fail_if(memcmp(eina_binbuf_string_get(buf) + sz, pattern, 32));
+ sz += 32;
+
+ eina_binbuf_append_length(buf, pattern, 64);
+ fail_if(eina_binbuf_length_get(buf) != sz + 64);
+ fail_if(memcmp(eina_binbuf_string_get(buf) + sz, pattern, 64));
+ sz += 64;
+
+ eina_binbuf_append_length(buf, pattern, 128);
+ fail_if(eina_binbuf_length_get(buf) != sz + 128);
+ fail_if(memcmp(eina_binbuf_string_get(buf) + sz, pattern, 128));
+ sz += 128;
+
+ eina_binbuf_append_length(buf, pattern, 4096);
+ fail_if(eina_binbuf_length_get(buf) != sz + 4096);
+ fail_if(memcmp(eina_binbuf_string_get(buf) + sz, pattern, 4096));
+ sz += 4096;
+
+ eina_binbuf_append_length(buf, pattern, sizeof(pattern) - 1);
+ fail_if(eina_binbuf_length_get(buf) != sz + sizeof(pattern) - 1);
+ fail_if(memcmp(eina_binbuf_string_get(buf) + sz, pattern, sizeof(pattern) -
+ 1));
+ sz += sizeof(pattern) - 1;
+
+
+ eina_binbuf_remove(buf, 1024, 1024 + 1234);
+ fail_if(eina_binbuf_length_get(buf) != sz - 1234);
+ sz -= 1234;
+
+ eina_binbuf_remove(buf, 0, 0 + 8192);
+ fail_if(eina_binbuf_length_get(buf) != sz - 8192);
+ sz -= 8192;
+
+ eina_binbuf_remove(buf, 0, 0 + 32);
+ fail_if(eina_binbuf_length_get(buf) != sz - 32);
+ sz -= 32;
+
+
+ eina_binbuf_free(buf);
+
+ eina_shutdown();
+}
+END_TEST
+
+void
+eina_test_binbuf(TCase *tc)
+{
+ tcase_add_test(tc, binbuf_simple);
+ tcase_add_test(tc, binbuf_remove);
+ tcase_add_test(tc, binbuf_insert);
+ tcase_add_test(tc, binbuf_realloc);
+}