blob: bf87740ea5354afacf48142997e87e8e2150aff5 [file] [log] [blame]
Hasnain Lakhanic51ab5f2025-08-25 10:24:14 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20namespace cpp fuzz
21namespace java org.apache.thrift.fuzz
22namespace py fuzz
23namespace swift Fuzz
24
25// Test typedefs
26typedef i64 UserId
27typedef binary BinaryData
28
29// Test all primitive types in a compact struct
30struct BasicTypes {
31 1: bool bool_field,
32 2: i8 byte_field,
33 3: i16 i16_field,
34 4: i32 i32_field,
35 5: i64 i64_field,
36 6: double double_field,
37 7: string string_field,
38 8: binary binary_field,
39}
40
41// Test optional/required/default requiredness
42struct Requiredness {
43 1: required i32 req_field,
44 2: optional i32 opt_field,
45 3: i32 default_field, // default requiredness
46 4: optional string opt_with_default = "test",
47 5: required bool req_with_default = true
48}
49
50// Test field ID edge cases
51struct FieldIDTest {
52 1: i32 first,
53 100: i32 gap,
54 255: i32 medium_id,
55 32767: i32 large_id,
56}
57
58// Test empty struct
59struct EmptyStruct {}
60
61// Test union
62union TestUnion {
63 1: i32 int_field,
64 2: string string_field,
65 3: BasicTypes struct_field,
66 4: binary binary_field
67}
68
69// Test containers (but not too deeply nested)
70struct Containers {
71 1: list<i32> int_list,
72 2: set<string> string_set,
73 3: map<i32, string> int_string_map,
74 4: list<BasicTypes> struct_list,
75 5: map<string, list<i32>> nested_map,
76 6: set<UserId> typedef_set,
77}
78
79// Test enum with various values
80enum TestEnum {
81 ZERO = 0,
82 ONE = 1,
83 TWO = 2,
84 NEGATIVE = -1,
85 LARGE = 32767,
86 HEX_VALUE = 0xFF
87}
88
89// Do not test recursive structures here, as not all languages (e.g. c_glib) support them.
90// struct RecursiveStruct {
91// 1: optional RecursiveStruct recurse,
92// 2: i32 data,
93// 3: optional list<RecursiveStruct> children
94// }
95
96// Main test structure - kept minimal but comprehensive
97struct FuzzTest {
98 1: required BasicTypes basic,
99 2: required Requiredness required_test,
100 3: required Containers containers,
101 4: required TestUnion union_field,
102// 5: optional RecursiveStruct recursive,
103 6: optional EmptyStruct empty,
104 7: optional FieldIDTest field_ids,
105 8: required TestEnum enum_field,
106 9: optional map<TestEnum, string> enum_map,
107 10: UserId user_id,
108 11: BinaryData data,
109}