Google OR-Tools v9.12
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 <memory>
18#include <string>
19#include <string_view>
20#include <tuple>
21#include <vector>
22
23#include "fuzztest/domain.h"
24#include "fuzztest/fuzztest.h"
25#include "fuzztest/googletest_fixture_adapter.h"
26#include "fuzztest/init_fuzztest.h"
27#include "google/protobuf/message.h"
28#include "google/protobuf/text_format.h"
30
31namespace fuzztest {
32
33// Reads protos from directory and returns a vector usable by the .WithSeeds()
34// function to aid in fuzz test migrations. `is_text_format` should be true iff
35// the protos are in text format.
36template <class ProtoType>
37std::vector<std::tuple<ProtoType>> ReadFilesFromDirectory(
38 std::string_view dir) {
39 std::vector<std::tuple<ProtoType>> corpus;
40
41 for (std::tuple<std::string>& proto_tuple : ReadFilesFromDirectory(dir)) {
42 std::string text_proto = std::get<0>(proto_tuple);
43 ProtoType proto;
44 bool was_parsed =
45 google::protobuf::TextFormat::ParseFromString(text_proto, &proto);
46 if (was_parsed) {
47 corpus.push_back(std::make_tuple(proto));
48 }
49 }
50 return corpus;
51}
52
53} // namespace fuzztest
54
55#endif // OR_TOOLS_BASE_FUZZTEST_H_
std::vector< std::tuple< ProtoType > > ReadFilesFromDirectory(std::string_view dir)
Definition fuzztest.h:37