blob: cf5bcb9ead60df8d261830d74fadcd1c6ba2c004 [file] [log] [blame]
mtklein65e58242016-01-13 12:57:57 -08001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef Fuzz_DEFINED
9#define Fuzz_DEFINED
10
11#include "SkData.h"
12#include "SkTRegistry.h"
13#include "SkTypes.h"
14#include <stdlib.h>
15
16class Fuzz : SkNoncopyable {
17public:
18 explicit Fuzz(SkData*);
19
20 uint32_t nextU();
21 float nextF();
22
23 // These return a value in [min, max).
24 uint32_t nextURange(uint32_t min, uint32_t max);
25 float nextFRange(float min, float max);
26
27private:
28 SkAutoTUnref<SkData> fBytes;
29};
30
31struct Fuzzable {
32 const char* name;
33 void (*fn)(Fuzz*);
34};
35
36#define DEF_FUZZ(name, f) \
37 static void fuzz_##name(Fuzz*); \
38 SkTRegistry<Fuzzable> register_##name({#name, fuzz_##name}); \
39 static void fuzz_##name(Fuzz* f)
40
41#define ASSERT(cond) do { if (!(cond)) abort(); } while(false)
42
43#endif//Fuzz_DEFINED