From e4b569a69ce897c80ab260376bbfb510d3bc79ce Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 14 Feb 2009 11:39:30 +0000 Subject: Move css_error_from_string into test utilities svn path=/trunk/libcss/; revision=6480 --- test/number.c | 2 ++ test/testutils.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'test') diff --git a/test/number.c b/test/number.c index dd44730..bc5ea52 100644 --- a/test/number.c +++ b/test/number.c @@ -2,6 +2,8 @@ #include #include +#include "libcss/libcss.h" + #include "utils/utils.h" #include "testutils.h" diff --git a/test/testutils.h b/test/testutils.h index 3e23c07..5471fed 100644 --- a/test/testutils.h +++ b/test/testutils.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include #ifndef UNUSED #define UNUSED(x) ((x) = (x)) @@ -147,4 +149,35 @@ size_t parse_filesize(const char *filename) } +/** + * Convert a string representation of an error name to a LibCSS error code + * + * \param str String containing error name + * \param len Length of string (bytes) + * \return LibCSS error code, or CSS_OK if unknown + */ +css_error css_error_from_string(const char *str, size_t len); +css_error css_error_from_string(const char *str, size_t len) +{ + if (strncmp(str, "CSS_OK", len) == 0) { + return CSS_OK; + } else if (strncmp(str, "CSS_NOMEM", len) == 0) { + return CSS_NOMEM; + } else if (strncmp(str, "CSS_BADPARM", len) == 0) { + return CSS_BADPARM; + } else if (strncmp(str, "CSS_INVALID", len) == 0) { + return CSS_INVALID; + } else if (strncmp(str, "CSS_FILENOTFOUND", len) == 0) { + return CSS_FILENOTFOUND; + } else if (strncmp(str, "CSS_NEEDDATA", len) == 0) { + return CSS_NEEDDATA; + } else if (strncmp(str, "CSS_BADCHARSET", len) == 0) { + return CSS_BADCHARSET; + } else if (strncmp(str, "CSS_EOF", len) == 0) { + return CSS_EOF; + } + + return CSS_OK; +} + #endif -- cgit v1.2.3