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 <stdarg.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <signal.h>
21 #include <fcntl.h>
22 #include <wchar.h>
23 #include "test.h"
24
deal_aberrant(int code)25 void deal_aberrant(int code)
26 {
27 if (code != SIGSEGV) {
28 t_error("putw_0200 code is %d are not SIGSEGV", __func__, code);
29 }
30 exit(t_status);
31 }
32
33 /**
34 * @tc.name : putw_0100
35 * @tc.desc : Test the putw method to write integers to the file
36 * @tc.level : Level 0
37 */
putw_0100(void)38 void putw_0100(void)
39 {
40 FILE *fp;
41 char *file = "putw_test.txt";
42 fp = fopen(file, "w+");
43 if (fp == NULL) {
44 t_error("%s fopen failed\n", __func__);
45 return;
46 }
47 int result = putw(10, fp);
48 if (result != 0) {
49 t_error("%s putw error get result is %d are not want 0\n", __func__, result);
50 }
51 fclose(fp);
52 remove(file);
53 }
54
55 /**
56 * @tc.name : putw_0200
57 * @tc.desc : Test the result of putw when the incoming file pointer is empty
58 * @tc.level : Level 2
59 */
putw_0200(void)60 void putw_0200(void)
61 {
62 FILE *fp = NULL;
63 signal(SIGSEGV, deal_aberrant);
64 int result = putw(10, fp);
65 }
66
main(int argc,char * argv[])67 int main(int argc, char *argv[])
68 {
69 putw_0100();
70 putw_0200();
71 return t_status;
72 }