1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
/*------------------------------------------------------------------
* test_strlastchar_s
* File 'extstr/strlastchar_s.c'
* Lines executed:93.75% of 16
*
*------------------------------------------------------------------
*/
#include "test_private.h"
#include "safe_str_lib.h"
#define LEN (128)
#define SHORT_LEN (5)
#define EXPLAST(x) \
if (rc != x) { \
debug_printf("%s %u Error str1=%p first=%p rc=%d \n", \
__FUNCTION__, __LINE__, (void *)str1, (void *)last, rc); \
errs++; \
}
#define NOLAST() \
if (last) { \
debug_printf("%s %u Error str1=%p first=%p rc=%d \n", \
__FUNCTION__, __LINE__, (void *)str1, (void *)last, rc); \
errs++; \
}
int main(void) {
errno_t rc;
char *last;
char str1[LEN];
int errs = 0;
/*--------------------------------------------------*/
#ifndef HAVE_CT_BOS_OVR
EXPECT_BOS("empty dest")
rc = strlastchar_s(NULL, LEN, 'a', &last);
EXPLAST(ESNULLP)
NOLAST()
/*--------------------------------------------------*/
EXPECT_BOS("empty lastp")
rc = strlastchar_s(str1, LEN, 'a', NULL);
EXPLAST(ESNULLP)
/*--------------------------------------------------*/
EXPECT_BOS("empty dest or dmax")
rc = strlastchar_s(str1, 0, 'a', &last);
EXPLAST(ESZEROL)
NOLAST()
/*--------------------------------------------------*/
EXPECT_BOS("dest overflow")
rc = strlastchar_s(str1, RSIZE_MAX_STR + 1, 'a', &last);
EXPLAST(ESLEMAX)
NOLAST()
#endif
/*--------------------------------------------------*/
str1[0] = '\0';
rc = strlastchar_s(str1, LEN, 'a', &last);
EXPLAST(ESNOTFND)
NOLAST()
/*--------------------------------------------------*/
strcpy(str1, "Keep it simple");
rc = strlastchar_s(str1, 5, 'z', &last);
EXPLAST(ESNOTFND)
NOLAST()
/*--------------------------------------------------*/
strcpy(str1, "Keep it simplezz");
rc = strlastchar_s(str1, LEN, 'z', &last);
EXPLAST(EOK)
if (last != &str1[15]) {
debug_printf("%s %u Error str1=%p last=%p rc=%d \n", __FUNCTION__,
__LINE__, (void *)str1, (void *)last, rc);
errs++;
}
/*--------------------------------------------------*/
strcpy(str1, "Keep it simple");
rc = strlastchar_s(str1, LEN, 'K', &last);
ERR(EOK)
if (last != &str1[0]) {
debug_printf("%s %u Error str1=%p last=%p rc=%d \n", __FUNCTION__,
__LINE__, (void *)str1, (void *)last, rc);
errs++;
}
/*--------------------------------------------------*/
strcpy(str1, "kEEp it simple");
rc = strlastchar_s(str1, LEN, 'E', &last);
ERR(EOK)
if (last != &str1[2]) {
debug_printf("%s %u Error str1=%p last=%p rc=%d \n", __FUNCTION__,
__LINE__, (void *)str1, (void *)last, rc);
errs++;
}
/*--------------------------------------------------*/
strcpy(str1, "kEep it Simple");
rc = strlastchar_s(str1, LEN, 'S', &last);
ERR(EOK)
if (last != &str1[8]) {
debug_printf("%s %u Error str1=%p last=%p rc=%d \n", __FUNCTION__,
__LINE__, (void *)str1, (void *)last, rc);
errs++;
}
/*--------------------------------------------------*/
return (errs);
}
|