...

Source file src/github.com/AdaLogics/go-fuzz-headers/funcs_test.go

Documentation: github.com/AdaLogics/go-fuzz-headers

     1  // Copyright 2023 The go-fuzz-headers Authors.
     2  //
     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  package gofuzzheaders
    16  
    17  /*
    18  import (
    19  	"testing"
    20  )
    21  
    22  type TestStructFuncs1 struct {
    23  	Field1 string
    24  	Field2 string
    25  	Field3 []byte
    26  	field4 string
    27  }
    28  
    29  type TestStructFuncs2 struct {
    30  	Field1 []byte
    31  }
    32  
    33  type TestStructFuncs3 struct {
    34  	Field1 *TestStructFuncs4
    35  	Field2 string
    36  }
    37  
    38  type TestStructFuncs4 struct {
    39  	Field1 string
    40  	Field2 string
    41  }
    42  
    43  func TestStruct_fuzzing_CustomFuncs1(t *testing.T) {
    44  	data := []byte{
    45  		0x02, 0x41, 0x42, // Field1
    46  		0x03, 0x41, 0x42, 0x43, // Field2
    47  	}
    48  
    49  	ts1 := TestStructFuncs3{}
    50  	fuzz1 := NewConsumer(data)
    51  	testfuncss := testFuncs()
    52  	fuzz1.AddFuncs(testfuncss)
    53  	err := fuzz1.GenerateWithCustom(&ts1)
    54  	if err != nil {
    55  		t.Errorf("%v", err)
    56  	}
    57  	if ts1.Field1.Field1 != "AB" {
    58  		t.Errorf("ts1.Field1.Field1 was %v but should be 'AB'", ts1.Field1)
    59  	}
    60  	if ts1.Field1.Field2 != "staticString" {
    61  		t.Errorf("ts1.Field1.Field2 was %v but should be 'staticString'", ts1.Field1)
    62  	}
    63  	if ts1.Field2 != "ABC" {
    64  		t.Errorf("ts1.Field1 was %v but should be 'ABC'", ts1.Field1)
    65  	}
    66  }
    67  
    68  func testFuncs() []interface{} {
    69  	return []interface{}{
    70  		func(j *TestStructFuncs4, c Continue) error {
    71  			newString, err := c.F.GetString()
    72  			if err != nil {
    73  				return err
    74  			}
    75  			j.Field1 = newString
    76  			j.Field2 = "staticString"
    77  			return nil
    78  		},
    79  	}
    80  }
    81  */
    82  

View as plain text