-
Notifications
You must be signed in to change notification settings - Fork 939
/
Copy pathtest_string.c
82 lines (63 loc) · 2.25 KB
/
test_string.c
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
/* #include "StdAfx.h"*/
#ifndef ACL_PREPARE_COMPILE
#include "lib_acl.h"
#include <stdio.h>
#include <stdlib.h>
#endif
#include "test_stdlib.h"
int test_strrncasecmp(AUT_LINE *test_line acl_unused, void *arg acl_unused)
{
const char *s01 = "hello WorLd", *s02 = "world";
const char *s11 = "hello", *s12 = "world";
acl_assert(strrncasecmp(s01, s02, strlen(s02)) == 0);
acl_assert(strrncasecmp(s01, s02, strlen(s02) + 1) != 0);
acl_assert(strrncasecmp(s11, s12, strlen(s12)) != 0);
return (0);
}
int test_strrncmp(AUT_LINE *test_line acl_unused, void *arg acl_unused)
{
const char *s01 = "hello world", *s02 = "world";
const char *s11 = "hello", *s12 = "world";
acl_assert(strrncmp(s01, s02, strlen(s02)) == 0);
acl_assert(strrncmp(s01, s02, strlen(s02) + 1) != 0);
acl_assert(strrncmp(s11, s12, strlen(s12)) != 0);
return (0);
}
int test_x64toa(AUT_LINE *test_line acl_unused, void *arg acl_unused)
{
char buf[32], buf2[32];
acl_uint64 n = -1;
int max = 10240000, i;
acl_ui64toa_radix(n, buf, sizeof(buf), 10);
acl_ui64toa(n, buf2, sizeof(buf2));
printf("buf: %s, len: %d; buf2: %s, len: %d; %llu\n",
buf, (int) strlen(buf), buf2, (int) strlen(buf2), (acl_uint64) (-1));
ACL_METER_TIME("use acl_uint64toa_radix begin");
for (i = 0; i < max; i++)
acl_ui64toa_radix(n, buf, sizeof(buf), 10);
ACL_METER_TIME("use acl_uint64toa_radix end");
ACL_METER_TIME("use acl_uint64toa begin");
for (i = 0; i < max; i++)
acl_ui64toa(n, buf, sizeof(buf));
ACL_METER_TIME("use acl_uint64toa end");
return (0);
}
int test_strcasestr(AUT_LINE *test_line acl_unused, void *arg acl_unused)
{
char *src = "href=\"http://3g.hexun.com\" target=\"_blank\" style=\"background:url(http://www.hexun.com/upload/phaone2.png) no-repeat; padding:2px 0 2px 13px;\">ÊÖ»ú°æ</a></div>";
const char *ptr = ">", *ptr1;
ptr1 = acl_strcasestr(src, ptr);
if (ptr1 == NULL) {
printf(">>>error, not found %s from %s\n", ptr, src);
return (-1);
}
printf(">>>ok, find it(%s): %s\n", ptr, ptr1);
ptr = "http://";
ptr1 = acl_strcasestr(src, ptr);
if (ptr1 == NULL) {
printf(">>>error, not found %s from %s\n", ptr, src);
return (-1);
}
printf(">>>ok, find it(%s): %s\n", ptr, ptr1);
return (0);
}