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 <resolv.h>
17 #include <stdio.h>
18 #include <string.h>
19
20 #include "test.h"
21
22 const int op = QUERY;
23 const int class = C_IN;
24 const int type = T_TXT;
25 const char dname[] = "www.example.com";
26 const unsigned char *data = (const unsigned char *)"";
27 const char qbuf[] = "\0\1\0\0\0\0\0\0";
28 const char qname[] = "\3www\7example\3com";
29
30 /**
31 * @tc.name : res_mkquery_0100
32 * @tc.desc : construct a query message
33 * @tc.level : Level 0
34 */
res_mkquery_0100(void)35 void res_mkquery_0100(void)
36 {
37 unsigned char buf[BUFSIZ] = {0};
38
39 int result = res_mkquery(op, dname, class, type, data, 0, NULL, buf, sizeof(buf));
40 if (result < 0) {
41 t_error("%s failed: result = %d\n", __func__, result);
42 }
43
44 result = memcmp(buf + 12, qname, sizeof(qname) - 1);
45 if (result != 0) {
46 t_error("%s failed: result = %d\n", __func__, result);
47 }
48
49 result = memcmp(buf + 4, qbuf, sizeof(qbuf) - 1);
50 if (result != 0) {
51 t_error("%s failed: result = %d\n", __func__, result);
52 }
53 }
54
55 /**
56 * @tc.name : res_mkquery_0200
57 * @tc.desc : construct a query message with an invalid type
58 * @tc.level : Level 2
59 */
res_mkquery_0200(void)60 void res_mkquery_0200(void)
61 {
62 int result = res_mkquery(op, dname, class, T_ANY + 1, data, 0, NULL, NULL, 0);
63 if (result == 0) {
64 t_error("%s failed: result = %d\n", __func__, result);
65 }
66 }
67
main(int argc,char * argv[])68 int main(int argc, char *argv[])
69 {
70 res_mkquery_0100();
71 res_mkquery_0200();
72
73 return t_status;
74 }
75