github.com/DataDog/datadog-agent/pkg/security/secl@v0.55.0-devel.0.20240517055856-10c4965fea94/model/utils_test.go (about)

     1  // Unless explicitly stated otherwise all files in this repository are licensed
     2  // under the Apache License Version 2.0.
     3  // This product includes software developed at Datadog (https://www.datadoghq.com/).
     4  // Copyright 2016-present Datadog, Inc.
     5  
     6  // Package model holds model related files
     7  package model
     8  
     9  import (
    10  	"runtime"
    11  	"testing"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestUnmarshalString(t *testing.T) {
    17  	array := []byte{65, 66, 67, 0, 0, 0, 65, 66}
    18  	str, err := UnmarshalString(array, 8)
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  
    23  	assert.Equal(t, "ABC", str)
    24  }
    25  
    26  func BenchmarkNullTerminatedString(b *testing.B) {
    27  	array := []byte{65, 66, 67, 0, 0, 0, 65, 66}
    28  	var s string
    29  	for i := 0; i < b.N; i++ {
    30  		s = NullTerminatedString(array)
    31  	}
    32  	runtime.KeepAlive(s)
    33  }