Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: components/policy/tools/generate_policy_source_test.py

Issue 2653393004: cros: Add unit test for default policy value generation. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import unittest
7
8 import generate_policy_source
9
10 class CppGenerationTest(unittest.TestCase):
11 def testDefaultValueGeneration(self):
12 """Tests generation of default policy values."""
13 # Bools
14 stmts, expr = generate_policy_source._GenerateDefaultValue(True)
15 self.assertListEqual([], stmts)
16 self.assertEqual('base::MakeUnique<base::FundamentalValue>(true)', expr)
17 stmts, expr = generate_policy_source._GenerateDefaultValue(False)
18 self.assertListEqual([], stmts)
19 self.assertEqual('base::MakeUnique<base::FundamentalValue>(false)', expr)
20
21 # Ints
22 stmts, expr = generate_policy_source._GenerateDefaultValue(33)
23 self.assertListEqual([], stmts)
24 self.assertEqual('base::MakeUnique<base::FundamentalValue>(33)', expr)
25
26 # Strings
27 stmts, expr = generate_policy_source._GenerateDefaultValue('foo')
28 self.assertListEqual([], stmts)
29 self.assertEqual('base::MakeUnique<base::StringValue>("foo")', expr)
30
31 # Empty list
32 stmts, expr = generate_policy_source._GenerateDefaultValue([])
33 self.assertListEqual(
34 ['auto default_value = base::MakeUnique<base::ListValue>();'], stmts)
35 self.assertEqual('std::move(default_value)', expr)
36
37 # List with values
38 stmts, expr = generate_policy_source._GenerateDefaultValue([1, '2'])
39 self.assertListEqual([
40 'auto default_value = base::MakeUnique<base::ListValue>();',
41 'default_value->Append(base::MakeUnique<base::FundamentalValue>(1));',
42 'default_value->Append(base::MakeUnique<base::StringValue>("2"));'
43 ], stmts)
44 self.assertEqual('std::move(default_value)', expr)
45
46 # Recursive lists are not supported.
47 stmts, expr = generate_policy_source._GenerateDefaultValue([1, []])
48 self.assertListEqual([], stmts)
49 self.assertIsNone(expr)
50
51 # Arbitary types are not supported.
52 stmts, expr = generate_policy_source._GenerateDefaultValue(object())
53 self.assertListEqual([], stmts)
54 self.assertIsNone(expr)
55
56
57 if __name__ == '__main__':
58 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698