File: test_strtouppercase_s.c

package info (click to toggle)
safeclib 3.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,832 kB
  • sloc: ansic: 52,639; makefile: 1,271; perl: 528; sh: 518
file content (121 lines) | stat: -rw-r--r-- 2,955 bytes parent folder | download | duplicates (2)
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
/*------------------------------------------------------------------
 * test_strtouppercase_s
 * File 'extstr/strtouppercase_s.c'
 * Lines executed:91.67% of 12
 *
 *------------------------------------------------------------------
 */

#include "test_private.h"
#include "safe_str_lib.h"

#define LEN (128)

int main(void) {
    errno_t rc;
    rsize_t len;
    char str[LEN];
    int errs = 0;

    /*--------------------------------------------------*/

    len = 5;
#ifndef HAVE_CT_BOS_OVR
    EXPECT_BOS("empty dest")
    rc = strtouppercase_s(NULL, len);
    ERR(ESNULLP)

    EXPECT_BOS("empty dest or dmax")
    rc = strtouppercase_s(str, 0);
    ERR(ESZEROL)

    EXPECT_BOS("dest overflow")
    rc = strtouppercase_s(str, RSIZE_MAX_STR + 1);
    ERR(ESLEMAX)

#ifdef HAVE___BUILTIN_OBJECT_SIZE
    EXPECT_BOS("dest overflow")
    rc = strtouppercase_s(str, LEN + 1);
    ERR(EOVERFLOW)

    EXPECT_BOS("dest overflow") /* flapping */
    rc = strtouppercase_s((char *)"", 2);
    ERR(EOVERFLOW)

    /* empty string: static */
    rc = strtouppercase_s((char *)"", 1);
    ERR(EOK)
#endif
#endif
    /*--------------------------------------------------*/

    /* dynamic */
    *str = '\0';
    rc = strtouppercase_s(str, 5);
    ERR(EOK)

    /*--------------------------------------------------*/

    strcpy(str, "n");
    len = strlen(str);

    debug_printf("debug - 05\n");
    rc = strtouppercase_s(str, len);
    ERR(EOK)
    debug_printf("debug - 06\n");

    if (strcmp(str, "N")) {
        debug_printf("%s %u   Error -%s- \n", __FUNCTION__, __LINE__, str);
        errs++;
    }
    /*--------------------------------------------------*/

    strcpy(str, "N");
    len = strlen(str);

    debug_printf("debug - 07\n");
    rc = strtouppercase_s(str, len);
    ERR(EOK)
    debug_printf("debug - 08\n");
    if (strcmp(str, "N")) {
        debug_printf("%s %u   Error -%s- \n", __FUNCTION__, __LINE__, str);
        errs++;
    }
    /*--------------------------------------------------*/

    strcpy(str, "nowisthetime");
    len = strlen(str);

    debug_printf("debug - 09\n");
    rc = strtouppercase_s(str, len);
    ERR(EOK)
    debug_printf("debug - 10\n");
    if (strcmp(str, "NOWISTHETIME")) {
        debug_printf("%s %u   Error -%s- \n", __FUNCTION__, __LINE__, str);
        errs++;
    }
    /*--------------------------------------------------*/

    strcpy(str, "qqeRo");
    len = strlen(str);

    debug_printf("debug - 11\n");
    rc = strtouppercase_s(str, len);
    ERR(EOK)
    debug_printf("debug - 12\n");
    if (strcmp(str, "QQERO")) {
        debug_printf("%s %u   Error -%s- \n", __FUNCTION__, __LINE__, str);
        errs++;
    }
    /*--------------------------------------------------*/

    strcpy(str, "1234");
    len = strlen(str);

    debug_printf("debug - 13\n");
    rc = strtouppercase_s(str, 22);
    ERR(EOK)
    /*--------------------------------------------------*/

    return (errs);
}