• 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 "functionalext.h"
17 
18 const char *path = "/data/test.txt";
19 
20 /**
21  * @tc.name      : fwrite_0100
22  * @tc.desc      : File pointer at the end of a file, the position to which the current file pointer points
23  * @tc.level     : Level 0
24  */
fwrite_0100(void)25 void fwrite_0100(void)
26 {
27     FILE *fptr = fopen(path, "w+");
28     EXPECT_PTRNE("fwrite_0100", fptr, NULL);
29 
30     char buf[] = "this is test";
31     int result = fwrite(buf, sizeof(char), strlen(buf), fptr);
32     EXPECT_TRUE("fwrite_0100", result == strlen(buf));
33 
34     fclose(fptr);
35     remove(path);
36 }
37 
38 /**
39  * @tc.name      : fwrite_0200
40  * @tc.desc      : File pointer at the beginning of a file, the location to which the current file pointer points
41  * @tc.level     : Level 0
42  */
fwrite_0200(void)43 void fwrite_0200(void)
44 {
45     FILE *fptr = fopen(path, "w+");
46     EXPECT_PTRNE("fwrite_0200", fptr, NULL);
47 
48     char buf[] = "this is test";
49     int result = fwrite(buf, 0, strlen(buf), fptr);
50     EXPECT_EQ("fwrite_0200", result, 0);
51 
52     fclose(fptr);
53     remove(path);
54 }
55 
56 /**
57  * @tc.name      : fwrite_0300
58  * @tc.desc      : Invalid argument. Cannot get the location of the current file pointer
59  * @tc.level     : Level 2
60  */
fwrite_0300(void)61 void fwrite_0300(void)
62 {
63     FILE *fptr = fopen(path, "w+");
64     EXPECT_PTRNE("fwrite_0300", fptr, NULL);
65 
66     char buf[] = "this is test";
67     int result = fwrite(buf, sizeof(char), 0, fptr);
68     EXPECT_EQ("fwrite_0300", result, 0);
69 
70     fclose(fptr);
71     remove(path);
72 }
73 
main(int argc,char * argv[])74 int main(int argc, char *argv[])
75 {
76     fwrite_0100();
77     fwrite_0200();
78     fwrite_0300();
79     return t_status;
80 }