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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/policy/tools/generate_policy_source_test.py
diff --git a/components/policy/tools/generate_policy_source_test.py b/components/policy/tools/generate_policy_source_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..44fa29a0d88c180a525b2f19d73f41d81232334e
--- /dev/null
+++ b/components/policy/tools/generate_policy_source_test.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import unittest
+
+import generate_policy_source
+
+class CppGenerationTest(unittest.TestCase):
+ def testDefaultValueGeneration(self):
+ """Tests generation of default policy values."""
+ # Bools
+ stmts, expr = generate_policy_source._GenerateDefaultValue(True)
+ self.assertListEqual([], stmts)
+ self.assertEqual('base::MakeUnique<base::FundamentalValue>(true)', expr)
+ stmts, expr = generate_policy_source._GenerateDefaultValue(False)
+ self.assertListEqual([], stmts)
+ self.assertEqual('base::MakeUnique<base::FundamentalValue>(false)', expr)
+
+ # Ints
+ stmts, expr = generate_policy_source._GenerateDefaultValue(33)
+ self.assertListEqual([], stmts)
+ self.assertEqual('base::MakeUnique<base::FundamentalValue>(33)', expr)
+
+ # Strings
+ stmts, expr = generate_policy_source._GenerateDefaultValue('foo')
+ self.assertListEqual([], stmts)
+ self.assertEqual('base::MakeUnique<base::StringValue>("foo")', expr)
+
+ # Empty list
+ stmts, expr = generate_policy_source._GenerateDefaultValue([])
+ self.assertListEqual(
+ ['auto default_value = base::MakeUnique<base::ListValue>();'], stmts)
+ self.assertEqual('std::move(default_value)', expr)
+
+ # List with values
+ stmts, expr = generate_policy_source._GenerateDefaultValue([1, '2'])
+ self.assertListEqual([
+ 'auto default_value = base::MakeUnique<base::ListValue>();',
+ 'default_value->Append(base::MakeUnique<base::FundamentalValue>(1));',
+ 'default_value->Append(base::MakeUnique<base::StringValue>("2"));'
+ ], stmts)
+ self.assertEqual('std::move(default_value)', expr)
+
+ # Recursive lists are not supported.
+ stmts, expr = generate_policy_source._GenerateDefaultValue([1, []])
+ self.assertListEqual([], stmts)
+ self.assertIsNone(expr)
+
+ # Arbitary types are not supported.
+ stmts, expr = generate_policy_source._GenerateDefaultValue(object())
+ self.assertListEqual([], stmts)
+ self.assertIsNone(expr)
+
+
+if __name__ == '__main__':
+ unittest.main()
« 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