• 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 <fcntl.h>
17 #include "functionalext.h"
18 
19 const int SIZE = 20;
20 
21 /**
22  * @tc.name      : read_0100
23  * @tc.desc      : The parameters are valid and the actual number of characters can be read.
24  * @tc.level     : Level 0
25  */
read_0100(void)26 void read_0100(void)
27 {
28     char str[] = "this is a readtest\n";
29     char buffer[1024] = {0};
30     int fd = open("/data/readtest.txt", O_RDWR | O_CREAT, TEST_MODE);
31     EXPECT_TRUE("read_0100", fd >= 0);
32     int retwrite = write(fd, str, sizeof(str));
33     EXPECT_EQ("read_0100", retwrite, SIZE);
34     lseek(fd, 0, SEEK_SET);
35     int size = read(fd, buffer, 1024);
36     EXPECT_EQ("read_0100", size, SIZE);
37     close(fd);
38     remove("/data/readtest.txt");
39 }
40 
main(int argc,char * argv[])41 int main(int argc, char *argv[])
42 {
43     read_0100();
44     return t_status;
45 }