chromium/third_party/blink/renderer/modules/bluetooth/testing/clusterfuzz/fuzz_integration_test.py

# Copyright 2016 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Test that the fuzzer works the way ClusterFuzz invokes it."""

import glob
import os
import shutil
import sys
import tempfile
import unittest

import setup


class WebBluetoothFuzzerTest(unittest.TestCase):
    def setUp(self):
        self._output_dir = tempfile.mkdtemp()
        self._resources_path = setup.RetrieveResources()

    def tearDown(self):
        shutil.rmtree(self._output_dir)
        shutil.rmtree(self._resources_path)

    def testCanGenerate100Files(self):
        sys.argv = [
            'fuzz_main_run.py', '--no_of_files=100', '--input_dir={}'.format(
                self._output_dir), '--output_dir={}'.format(self._output_dir)
        ]

        import fuzz_main_run
        fuzz_main_run.main()

        written_files = glob.glob(os.path.join(self._output_dir, '*.html'))

        self.assertEqual(100, len(written_files), 'Should have written 100 '
                         'test files.')

        for test_case in written_files:
            with open(test_case, encoding='utf-8') as f:
                self.assertFalse('TRANSFORM' in f.read())


if __name__ == '__main__':
    unittest.main()