|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.api.logs; |
| 7 | + |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
| 9 | + |
| 10 | +import edu.berkeley.cs.jqf.fuzz.Fuzz; |
| 11 | +import edu.berkeley.cs.jqf.fuzz.JQF; |
| 12 | +import edu.berkeley.cs.jqf.fuzz.junit.GuidedFuzzing; |
| 13 | +import edu.berkeley.cs.jqf.fuzz.random.NoGuidance; |
| 14 | +import io.opentelemetry.api.common.Value; |
| 15 | +import java.nio.charset.StandardCharsets; |
| 16 | +import java.util.Base64; |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | +import org.junit.runner.Result; |
| 19 | +import org.junit.runner.RunWith; |
| 20 | + |
| 21 | +public class ValueFuzzTest { |
| 22 | + @RunWith(JQF.class) |
| 23 | + public static class FuzzTestCases { |
| 24 | + @Fuzz |
| 25 | + public void valueByteAsStringFuzz(String randomString) { |
| 26 | + String base64Encoded = Value.of(randomString.getBytes(StandardCharsets.UTF_8)).asString(); |
| 27 | + byte[] decodedBytes = Base64.getDecoder().decode(base64Encoded); |
| 28 | + assertThat(new String(decodedBytes, StandardCharsets.UTF_8)).isEqualTo(randomString); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + @SuppressWarnings("SystemOut") |
| 33 | + @Test |
| 34 | + void valueByteAsStringFuzzing() { |
| 35 | + Result result = |
| 36 | + GuidedFuzzing.run( |
| 37 | + FuzzTestCases.class, |
| 38 | + "valueByteAsStringFuzz", |
| 39 | + new NoGuidance(10000, System.out), |
| 40 | + System.out); |
| 41 | + assertThat(result.wasSuccessful()).isTrue(); |
| 42 | + } |
| 43 | +} |
0 commit comments