Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
fuzztest.h
Go to the documentation of this file.
1// Copyright 2010-2025 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14#ifndef OR_TOOLS_BASE_FUZZTEST_H_
15#define OR_TOOLS_BASE_FUZZTEST_H_
16
17#include <string_view>
18#include <tuple>
19#include <vector>
20
21// #include "fuzztest/googletest_fixture_adapter.h"
22#include "fuzztest/domain.h"
23#include "fuzztest/fuzztest.h"
24#include "fuzztest/init_fuzztest.h"
25#include "google/protobuf/text_format.h"
26
27namespace fuzztest {
28
29// Reads protos from directory and returns a vector usable by the .WithSeeds()
30// function to aid in fuzz test migrations. `is_text_format` should be true iff
31// the protos are in text format.
32template <class ProtoType>
33std::vector<std::tuple<ProtoType>> ReadFilesFromDirectory(
34 std::string_view dir) {
35 std::vector<std::tuple<ProtoType>> corpus;
36
37 for (std::tuple<std::string>& proto_tuple : ReadFilesFromDirectory(dir)) {
38 std::string text_proto = std::get<0>(proto_tuple);
39 ProtoType proto;
40 bool was_parsed =
41 google::protobuf::TextFormat::ParseFromString(text_proto, &proto);
42 if (was_parsed) {
43 corpus.push_back(std::make_tuple(proto));
44 }
45 }
46 return corpus;
47}
48
49} // namespace fuzztest
50
51#endif // OR_TOOLS_BASE_FUZZTEST_H_
include "fuzztest/googletest_fixture_adapter.h"
Definition fuzztest.h:27
std::vector< std::tuple< ProtoType > > ReadFilesFromDirectory(std::string_view dir)
Definition fuzztest.h:33