CUnit Programmers Reference  3.0
Util.h
Go to the documentation of this file.
1 /*
2  * CUnit - A Unit testing framework library for C.
3  * Copyright (C) 2001 Anil Kumar
4  * Copyright (C) 2004-2006 Anil Kumar, Jerry St.Clair
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * Contains Type Definitions for some generic functions used across
23  * CUnit project files.
24  *
25  * 13/Oct/2001 Moved some of the generic functions declarations from
26  * other files to this one so as to use the functions
27  * consitently. This file is not included in the distribution
28  * headers because it is used internally by CUnit. (AK)
29  *
30  * 20-Jul-2004 New interface, support for deprecated version 1 names. (JDS)
31  *
32  * 5-Sep-2004 Added internal test interface. (JDS)
33  *
34  * 17-Apr-2006 Added CU_translated_strlen() and CU_number_width().
35  * Removed CUNIT_MAX_STRING_LENGTH - dangerous since not enforced.
36  * Fixed off-by-1 error in CU_translate_special_characters(),
37  * modifying implementation & results in some cases. User can
38  * now tell if conversion failed. (JDS)
39  */
40 
48 #ifndef CUNIT_UTIL_H_SEEN
49 #define CUNIT_UTIL_H_SEEN
50 
51 #include <stdlib.h>
52 #include "CUnit/CUnit.h"
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 #define CUNIT_MAX_ENTITY_LEN 5
61 CU_EXPORT size_t CU_translate_special_characters(const char *szSrc, char *szDest, size_t maxlen);
87 CU_EXPORT size_t CU_translated_strlen(const char *szSrc);
99 CU_EXPORT int CU_compare_strings(const char *szSrc, const char *szDest);
109 CU_EXPORT void CU_trim_left(char *szString);
115 CU_EXPORT void CU_trim_right(char *szString);
121 CU_EXPORT void CU_trim(char *szString);
127 CU_EXPORT size_t CU_number_width(int number);
133 CU_EXPORT const char* CU_get_basename(const char* path);
139 #define CU_MAIN_EXE_NAME CU_get_basename(argv[0])
140 
141 // yes PATH_MAX and _MAX_PATH exist but both are caveats and are filesystem type dependant, not compile time
142 #define CUNIT_FILE_PATH_MAX 4096
143 
144 #ifdef CUNIT_BUILD_TESTS
145 void test_cunit_Util(void);
146 #endif
147 
148 #ifdef __cplusplus
149 }
150 #endif
151 
152 #ifdef USE_DEPRECATED_CUNIT_NAMES
153 #define CUNIT_MAX_STRING_LENGTH 1024
155 #define translate_special_characters(src, dest, len) CU_translate_special_characters(src, dest, len)
157 #define compare_strings(src, dest) CU_compare_strings(src, dest)
160 #define trim_left(str) CU_trim_left(str)
162 #define trim_right(str) CU_trim_right(str)
164 #define trim(str) CU_trim(str)
167 #endif /* USE_DEPRECATED_CUNIT_NAMES */
168 
169 #endif /* CUNIT_UTIL_H_SEEN */
CU_EXPORT void CU_trim_right(char *szString)
Trims trailing whitespace from the specified string.
Definition: Util.c:228
CU_EXPORT const char * CU_get_basename(const char *path)
Given a file path, return a pointer to the last component (the basename).
Definition: Util.c:259
CU_EXPORT size_t CU_number_width(int number)
Calulates the number of places required to display number in decimal.
Definition: Util.c:246
CU_EXPORT void CU_trim(char *szString)
Trims leading and trailing whitespace from the specified string.
Definition: Util.c:200
CU_EXPORT void CU_trim_left(char *szString)
Trims leading whitespace from the specified string.
Definition: Util.c:207
CU_EXPORT int CU_compare_strings(const char *szSrc, const char *szDest)
Case-insensitive string comparison.
Definition: Util.c:186
CU_EXPORT size_t CU_translate_special_characters(const char *szSrc, char *szDest, size_t maxlen)
Converts special characters in szSrc to xml entity codes and stores result in szDest.
Definition: Util.c:96
CU_EXPORT size_t CU_translated_strlen(const char *szSrc)
Calculates the length of a translated string.
Definition: Util.c:167