From 97ec3766141052e557a4eb8c39883fd1b7d6536f Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 14 Jul 2014 16:16:20 -0400 Subject: [PATCH] C++ exception with description "array value has unexpected number of elements" thrown in the test body. --- bin/build-style.js | 4 +++- bin/fuzz-functions.js | 27 +++++++++++++++++++++++++++ bin/fuzz-layers.js | 23 +++++++++++++++++++++++ llmr.gyp | 6 ++++++ test/style.cpp | 21 +++++++++++++++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100755 bin/fuzz-functions.js create mode 100755 bin/fuzz-layers.js diff --git a/bin/build-style.js b/bin/build-style.js index 5ef8d317d..4118faa3c 100755 --- a/bin/build-style.js +++ b/bin/build-style.js @@ -8,7 +8,9 @@ var fs = require('fs'); var transforms = { 'style.min.js': require('./minify.js'), - 'fuzz-colors.min.js': require('./fuzz-colors.js') + 'fuzz-colors.min.js': require('./fuzz-colors.js'), + 'fuzz-functions.min.js': require('./fuzz-functions.js'), + 'fuzz-layers.min.js': require('./fuzz-layers.js') }; var source = load(process.argv[2]); diff --git a/bin/fuzz-functions.js b/bin/fuzz-functions.js new file mode 100755 index 000000000..26a079d6d --- /dev/null +++ b/bin/fuzz-functions.js @@ -0,0 +1,27 @@ +#!/usr/bin/env node +'use strict'; + +var through = require('through2'); +var fuzzer = require('fuzzer'); +fuzzer.seed(0); + +module.exports = function() { + return through.obj(function(chunk, env, callback) { + var json = JSON.parse(chunk.toString()); + + json.constants = Object.keys(json.constants).reduce(function(obj, key, index) { + var value = json.constants[key]; + if (typeof value === 'object' && value.hasOwnProperty('fn')) { + var mutator = fuzzer.mutate.object(value); + obj[key] = mutator(); + } + return obj; + }, {}); + + var data = JSON.stringify(json); + this.push(data); + callback(); + }); +}; + +if (!module.parent) process.stdin.pipe(module.exports()).pipe(process.stdout); diff --git a/bin/fuzz-layers.js b/bin/fuzz-layers.js new file mode 100755 index 000000000..547775799 --- /dev/null +++ b/bin/fuzz-layers.js @@ -0,0 +1,23 @@ +#!/usr/bin/env node +'use strict'; + +var through = require('through2'); +var fuzzer = require('fuzzer'); +fuzzer.seed(0); + +module.exports = function() { + return through.obj(function(chunk, env, callback) { + var json = JSON.parse(chunk.toString()); + + json.layers.map(function(value) { + var mutator = fuzzer.mutate.object(value); + return mutator(); + }); + + var data = JSON.stringify(json); + this.push(data); + callback(); + }); +}; + +if (!module.parent) process.stdin.pipe(module.exports()).pipe(process.stdout); diff --git a/llmr.gyp b/llmr.gyp index 392552310..2e17c2c6a 100644 --- a/llmr.gyp +++ b/llmr.gyp @@ -69,6 +69,8 @@ 'outputs': [ '<(SHARED_INTERMEDIATE_DIR)/bin/style.min.js', '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-colors.min.js', + '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-functions.min.js', + '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-layers.min.js', ], 'action': ['<@(node)', 'bin/build-style.js', '<@(_inputs)', '<(SHARED_INTERMEDIATE_DIR)/bin'] } @@ -77,6 +79,8 @@ 'sources': [ '<(SHARED_INTERMEDIATE_DIR)/bin/style.min.js', '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-colors.min.js', + '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-functions.min.js', + '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-layers.min.js', ], } }, @@ -92,6 +96,8 @@ 'files': [ '<(SHARED_INTERMEDIATE_DIR)/bin/style.min.js', '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-colors.min.js', + '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-functions.min.js', + '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-layers.min.js', ], 'destination': '<(PRODUCT_DIR)' } diff --git a/test/style.cpp b/test/style.cpp index a321fe835..3eb1644b0 100644 --- a/test/style.cpp +++ b/test/style.cpp @@ -26,3 +26,24 @@ TEST(Style, Colors) { Style style; style.loadJSON((const uint8_t *)stylejson.str().c_str()); } + +TEST(Style, Functions) { + std::ifstream stylefile("./fuzz-functions.min.js"); + ASSERT_TRUE(stylefile.good()); + std::stringstream stylejson; + stylejson << stylefile.rdbuf(); + + Style style; + style.loadJSON((const uint8_t *)stylejson.str().c_str()); +} + +TEST(Style, Layers) { + std::ifstream stylefile("./fuzz-layers.min.js"); + ASSERT_TRUE(stylefile.good()); + std::stringstream stylejson; + stylejson << stylefile.rdbuf(); + + Style style; + style.loadJSON((const uint8_t *)stylejson.str().c_str()); +} +