Revert "[M120 Migration]Fix for crash during chrome exit"
[platform/framework/web/chromium-efl.git] / tools / protoc_wrapper / protoc_wrapper_test.py
1 #!/usr/bin/env python
2 # Copyright 2020 The Chromium Authors
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 """Tests for protoc_wrapper."""
6
7 from __future__ import print_function
8
9 import logging
10 import sys
11 import unittest
12
13 if sys.version_info.major == 2:
14   from StringIO import StringIO
15   import mock
16 else:
17   from io import StringIO
18   from unittest import mock
19
20 import protoc_wrapper
21
22
23 class ProtocWrapperTest(unittest.TestCase):
24   @mock.patch('subprocess.call', return_value=0)
25   def test_minimal_arguments(self, mock_call):
26     protoc_wrapper.main(
27         ['--proto-in-dir', './', '--protoc', '/foo/protoc', 'foo.proto'])
28     mock_call.assert_called_once_with(
29         ['/foo/protoc', '--proto_path', '.', './foo.proto'])
30
31   @mock.patch('subprocess.call', return_value=0)
32   def test_kythe_no_out(self, mock_call):
33     protoc_wrapper.main([
34         '--proto-in-dir', './', '--enable-kythe-annotation', '--protoc',
35         '/foo/protoc', 'foo.proto'
36     ])
37     mock_call.assert_called_once_with(
38         ['/foo/protoc', '--proto_path', '.', './foo.proto'])
39
40   @mock.patch('subprocess.call', return_value=0)
41   def test_kythe_cpp_out_no_options(self, mock_call):
42     protoc_wrapper.main([
43         '--proto-in-dir', './', '--enable-kythe-annotation', '--cc-out-dir',
44         './bar', '--protoc', '/foo/protoc', 'foo.proto'
45     ])
46     mock_call.assert_called_once_with([
47         '/foo/protoc', '--cpp_out',
48         'annotate_headers,annotation_pragma_name=kythe_metadata,annotation_guard_name=KYTHE_IS_RUNNING:./bar',
49         '--proto_path', '.', './foo.proto'
50     ])
51
52   @mock.patch('subprocess.call', return_value=0)
53   def test_kythe_cpp_out_with_options(self, mock_call):
54     protoc_wrapper.main([
55         '--proto-in-dir', './', '--enable-kythe-annotation', '--cc-options',
56         'foo=bar:', '--cc-out-dir', './bar', '--protoc', '/foo/protoc',
57         'foo.proto'
58     ])
59     mock_call.assert_called_once_with([
60         '/foo/protoc', '--cpp_out',
61         'annotate_headers,annotation_pragma_name=kythe_metadata,annotation_guard_name=KYTHE_IS_RUNNING,foo=bar:./bar',
62         '--proto_path', '.', './foo.proto'
63     ])
64
65   @mock.patch('subprocess.call', return_value=0)
66   def test_kythe_cpp_out_with_options_no_colon(self, mock_call):
67     protoc_wrapper.main([
68         '--proto-in-dir', './', '--enable-kythe-annotation', '--cc-options',
69         'foo=bar', '--cc-out-dir', './bar', '--protoc', '/foo/protoc',
70         'foo.proto'
71     ])
72     mock_call.assert_called_once_with([
73         '/foo/protoc', '--cpp_out',
74         'annotate_headers,annotation_pragma_name=kythe_metadata,annotation_guard_name=KYTHE_IS_RUNNING,foo=bar:./bar',
75         '--proto_path', '.', './foo.proto'
76     ])
77
78   @mock.patch('subprocess.call', return_value=0)
79   def test_cpp_out_with_options_no_colon(self, mock_call):
80     protoc_wrapper.main([
81         '--proto-in-dir', './', '--cc-options', 'foo=bar:', '--cc-out-dir',
82         './bar', '--protoc', '/foo/protoc', 'foo.proto'
83     ])
84     mock_call.assert_called_once_with([
85         '/foo/protoc', '--cpp_out', 'foo=bar:./bar', '--proto_path', '.',
86         './foo.proto'
87     ])
88
89
90 if __name__ == '__main__':
91   logging.basicConfig(
92       level=logging.DEBUG if '-v' in sys.argv else logging.ERROR)
93   unittest.main()