mtklein | 65e5824 | 2016-01-13 12:57:57 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 16 | class Fuzz : SkNoncopyable { |
| 17 | public: |
| 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 | |
| 27 | private: |
| 28 | SkAutoTUnref<SkData> fBytes; |
| 29 | }; |
| 30 | |
| 31 | struct 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 |