• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdlib.h>
17 #include <string.h>
18 #include "functionalext.h"
19 
20 const int INIT_LEN = 0;
21 
22 /**
23  * @tc.name       :memchr_0100
24  * @tc.desc       :Verify memchr is successed and return 0.
25  * @tc.level      :level 0.
26  */
memchr_0100(void)27 void memchr_0100(void)
28 {
29     const char *srcstring = "this is a unittest";
30     char fitch = 'u';
31     char *findch = (char *)memchr(srcstring, fitch, strlen(srcstring));
32     if (findch) {
33         EXPECT_EQ("memchr_0100", fitch, findch[0]);
34         EXPECT_STREQ("memchr_0100", "unittest", findch);
35     } else {
36         EXPECT_PTRNE("memchr_0100", findch, NULL);
37     }
38 }
39 
40 /**
41  * @tc.name       :memchr_0200
42  * @tc.desc       :Verify memchr is failed and return NULL.
43  * @tc.level      :level 1.
44  */
memchr_0200(void)45 void memchr_0200(void)
46 {
47     const char *srcstring = "this is a unittest";
48     char *findch = (char *)memchr(srcstring, 'w', strlen(srcstring));
49     EXPECT_PTREQ("memchr_0200", findch, NULL);
50 }
51 
52 /**
53  * @tc.name       :memchr_0300
54  * @tc.desc       :Verify memchr is failed when first param src is invalid.
55  * @tc.level      :level 2.
56  */
memchr_0300(void)57 void memchr_0300(void)
58 {
59     const char *srcstring = "";
60     char *findch = (char *)memchr(srcstring, 'w', strlen(srcstring));
61     EXPECT_PTREQ("memchr_0300", findch, NULL);
62 }
63 
64 /**
65  * @tc.name       :memchr_0400
66  * @tc.desc       :Verify memchr is failed when second param c is invalid.
67  * @tc.level      :level 2.
68  */
memchr_0400(void)69 void memchr_0400(void)
70 {
71     const char *srcstring = "this is a unittest";
72     char *findch = (char *)memchr(srcstring, '\0', strlen(srcstring));
73     EXPECT_PTREQ("memchr_0400", findch, NULL);
74 }
75 
76 /**
77  * @tc.name       :memchr_0500
78  * @tc.desc       :Verify memchr is failed when third param n is invalid.
79  * @tc.level      :level 2.
80  */
memchr_0500(void)81 void memchr_0500(void)
82 {
83     const char *srcstring = "this is a unittest";
84     char *findch = (char *)memchr(srcstring, 'u', INIT_LEN);
85     EXPECT_PTREQ("memchr_0500", findch, NULL);
86 }
87 
main(void)88 int main(void)
89 {
90     memchr_0100();
91     memchr_0200();
92     memchr_0300();
93     memchr_0400();
94     memchr_0500();
95     return t_status;
96 }
97