diff options
-rwxr-xr-x | bin/build-style.js | 1 | ||||
-rw-r--r-- | bin/fuzz-style.js | 24 | ||||
-rw-r--r-- | bin/package.json | 11 | ||||
-rw-r--r-- | llmr.gyp | 24 | ||||
-rw-r--r-- | test/style.cpp | 26 | ||||
-rw-r--r-- | test/test.gyp | 16 |
6 files changed, 95 insertions, 7 deletions
diff --git a/bin/build-style.js b/bin/build-style.js index c69fcb8b40..9b931c8112 100755 --- a/bin/build-style.js +++ b/bin/build-style.js @@ -4,7 +4,6 @@ var path = require('path'); var fs = require('fs'); var mkdirp = require('./mkdirp'); -var name = 'style'; var data = JSON.stringify(require(path.join(process.cwd(), process.argv[2]))); var out_path = path.join(process.argv[3], 'bin/style.min.js'); diff --git a/bin/fuzz-style.js b/bin/fuzz-style.js new file mode 100644 index 0000000000..8dae68e4a3 --- /dev/null +++ b/bin/fuzz-style.js @@ -0,0 +1,24 @@ +#!/usr/bin/env node +'use strict'; + +var fuzzer = require('fuzzer'); +var path = require('path'); +var fs = require('fs'); +var mkdirp = require('./mkdirp'); +var json = require(path.join(process.cwd(), process.argv[2])); + +fuzzer.seed(0); + +json.constants = Object.keys(json.constants).reduce(function(obj, key, index) { + var value = json.constants[key]; + if (typeof value === 'string') { + obj[key] = fuzzer.mutate.string(value); + } + return obj; +}, {}); + +var data = JSON.stringify(json); + +var out_path = path.join(process.argv[3], 'bin/style-fuzzed.min.js'); +mkdirp.sync(path.dirname(out_path)); +fs.writeFileSync(out_path, data); diff --git a/bin/package.json b/bin/package.json index 4431471e99..0eefafd26a 100644 --- a/bin/package.json +++ b/bin/package.json @@ -1,7 +1,8 @@ { - "name": "llmr-native", - "version": "0.0.1", - "dependencies": { - "glsl-optimizer": "git://github.com/kkaefer/glsl-optimizer.git#amalgamation" - } + "name": "llmr-native", + "version": "0.0.1", + "dependencies": { + "fuzzer": "^0.2.0", + "glsl-optimizer": "git://github.com/kkaefer/glsl-optimizer.git#amalgamation" + } } @@ -56,6 +56,28 @@ } }, { + 'target_name': 'fuzz_stylesheet', + 'type': 'none', + 'hard_dependency': 1, + 'actions': [ + { + 'action_name': 'Fuzz Stylesheet', + 'inputs': [ + 'bin/style.js', + ], + 'outputs': [ + '<(SHARED_INTERMEDIATE_DIR)/bin/style-fuzzed.min.js' + ], + 'action': ['<@(node)', 'bin/fuzz-style.js', '<@(_inputs)', '<(SHARED_INTERMEDIATE_DIR)'] + } + ], + 'direct_dependent_settings': { + 'sources': [ + '<(SHARED_INTERMEDIATE_DIR)/bin/style-fuzzed.min.js' + ], + } + }, + { 'target_name': 'llmr-x86', 'product_name': 'llmr-x86', 'type': 'static_library', @@ -194,4 +216,4 @@ } } ] -}
\ No newline at end of file +} diff --git a/test/style.cpp b/test/style.cpp new file mode 100644 index 0000000000..5869bf7874 --- /dev/null +++ b/test/style.cpp @@ -0,0 +1,26 @@ +#include "gtest/gtest.h" + +#include <llmr/map/map.hpp> + +#include "../common/headless_view.hpp" + +#include <iostream> +#include <fstream> + +using namespace llmr; + +TEST(Style, Color) { + // Setup OpenGL + llmr::HeadlessView view; + llmr::Map map(view); + + std::ifstream stylefile("./style-fuzzed.min.js"); + ASSERT_TRUE(stylefile.good()); + std::stringstream stylejson; + stylejson << stylefile.rdbuf(); + + map.setStyleJSON(stylejson.str()); + + // ASSERT_EQ(std::string(""), styles[0]->clip.mask); + // ASSERT_EQ(3, styles[0]->clip.length); +} diff --git a/test/test.gyp b/test/test.gyp index 98effdfa9e..00dd79331e 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -81,6 +81,22 @@ ] }, { + "target_name": "style", + "product_name": "test_style", + "type": "executable", + "libraries": [ + "-lpthread", + ], + "sources": [ + "./main.cpp", + "./style.cpp", + ], + "dependencies": [ + "../deps/gtest/gtest.gyp:gtest", + "../llmr.gyp:llmr-x86" + ] + }, + { "target_name": "variant", "product_name": "test_variant", "type": "executable", |