2 # Copyright 2014 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.
6 """Unittests for generate_resources_map.py"""
10 import generate_resources_map
13 class GenerateResourcesMapUnittest(unittest
.TestCase
):
15 // This file is automatically generated by GRIT. Do not edit.
19 #define IDS_BOOKMARKS_NO_ITEMS 12500
20 #define IDS_BOOKMARK_BAR_IMPORT_LINK 12501
21 #define IDS_BOOKMARK_GROUP_FROM_IE 12502
22 #define IDS_BOOKMARK_GROUP_FROM_FIREFOX 12503
25 def testGetResourceListFromString(self
):
26 expected_tuples
= [(301430091, "IDS_BOOKMARKS_NO_ITEMS", "12500"),
27 (2654138887, "IDS_BOOKMARK_BAR_IMPORT_LINK", "12501"),
28 (2894469061, "IDS_BOOKMARK_GROUP_FROM_IE", "12502"),
29 (3847176170, "IDS_BOOKMARK_GROUP_FROM_FIREFOX", "12503")]
30 expected
= [generate_resources_map
.Resource(*t
) for t
in expected_tuples
]
32 actual_tuples
= generate_resources_map
._GetResourceListFromString
(
35 self
.assertEqual(expected_tuples
, actual_tuples
)
38 def testCheckForHashCollisions(self
):
39 collisions_tuples
= [(123, "IDS_FOO", "12500"),
40 (456, "IDS_BAR", "12501"),
41 (456, "IDS_BAZ", "12502"),
42 (890, "IDS_QUX", "12503"),
43 (899, "IDS_NO", "12504"),
44 (899, "IDS_YES", "12505")]
45 list_with_collisions
= [generate_resources_map
.Resource(*t
)
46 for t
in collisions_tuples
]
48 expected_collision_tuples
= [(456, "IDS_BAR", "12501"),
49 (456, "IDS_BAZ", "12502"),
50 (899, "IDS_NO", "12504"),
51 (899, "IDS_YES", "12505")]
52 expected_collisions
= [generate_resources_map
.Resource(*t
)
53 for t
in expected_collision_tuples
]
55 actual_collisions
= sorted(
56 generate_resources_map
._CheckForHashCollisions
(list_with_collisions
))
59 self
.assertEqual(expected_collisions
, actual_collisions
)
61 def testGenerateFileContent(self
):
63 """// This file was generated by generate_resources_map.py. Do not edit.
66 #include "chrome/browser/metrics/variations/generated_resources_map.h"
68 namespace chrome_variations {
70 const size_t kNumResources = 4;
72 const uint32_t kResourceHashes[] = {
73 301430091U, // IDS_BOOKMARKS_NO_ITEMS
74 2654138887U, // IDS_BOOKMARK_BAR_IMPORT_LINK
75 2894469061U, // IDS_BOOKMARK_GROUP_FROM_IE
76 3847176170U, // IDS_BOOKMARK_GROUP_FROM_FIREFOX
79 const int kResourceIndices[] = {
80 12500, // IDS_BOOKMARKS_NO_ITEMS
81 12501, // IDS_BOOKMARK_BAR_IMPORT_LINK
82 12502, // IDS_BOOKMARK_GROUP_FROM_IE
83 12503, // IDS_BOOKMARK_GROUP_FROM_FIREFOX
86 } // namespace chrome_variations
88 actual
= generate_resources_map
._GenerateFileContent
(self
.TEST_INPUT
)
90 self
.assertEqual(expected
, actual
)
92 if __name__
== '__main__':