[Presentation API, Android] Implement basic messaging
[chromium-blink-merge.git] / chrome / browser / install_verification / win / module_ids_unittest.cc
blob55b1f0c5902ede64a5a1090ad0fe4825cd9123bb
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/install_verification/win/module_ids.h"
7 #include "base/strings/string_piece.h"
8 #include "chrome/browser/install_verification/win/module_verification_common.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 TEST(ModuleIDsTest, LoadModuleIDs) {
12 ModuleIDs module_ids;
13 LoadModuleIDs(&module_ids);
14 ASSERT_EQ(1u, module_ids[CalculateModuleNameDigest(L"chrome.dll")]);
17 TEST(ModuleIDsTest, ParseAdditionalModuleIDs) {
18 ModuleIDs module_ids;
20 ParseAdditionalModuleIDs(base::StringPiece(), &module_ids);
21 ASSERT_EQ(0u, module_ids.size());
23 // Invalid input.
24 ParseAdditionalModuleIDs("hello", &module_ids);
25 ASSERT_EQ(0u, module_ids.size());
26 ParseAdditionalModuleIDs("hello world", &module_ids);
27 ASSERT_EQ(0u, module_ids.size());
28 ParseAdditionalModuleIDs("hello world\nfoo bar", &module_ids);
29 ASSERT_EQ(0u, module_ids.size());
30 ParseAdditionalModuleIDs("123 world\nfoo bar", &module_ids);
31 ASSERT_EQ(0u, module_ids.size());
32 ParseAdditionalModuleIDs("hello 0123456789abcdef0123456789abcdef\nfoo bar",
33 &module_ids);
34 ASSERT_EQ(0u, module_ids.size());
36 // A single valid line followed by an invalid line.
37 ParseAdditionalModuleIDs("123 0123456789abcdef0123456789abcdef\nfoo bar",
38 &module_ids);
39 ASSERT_EQ(1u, module_ids.size());
40 ASSERT_EQ(123u, module_ids.begin()->second);
41 ASSERT_EQ("0123456789abcdef0123456789abcdef", module_ids.begin()->first);
42 module_ids.clear();
44 // The same, but with \r\n.
45 ParseAdditionalModuleIDs("123 0123456789abcdef0123456789abcdef\r\nfoo bar",
46 &module_ids);
47 ASSERT_EQ(1u, module_ids.size());
48 ASSERT_EQ(123u, module_ids.begin()->second);
49 ASSERT_EQ("0123456789abcdef0123456789abcdef", module_ids.begin()->first);
50 module_ids.clear();
52 // Several valid and invalid lines, with varying line terminations etc.
53 ParseAdditionalModuleIDs("123 0123456789abcdef0123456789abcdef\r\n"
54 "456 DEADBEEFDEADBEEF\r"
55 "789 DEADBEEFDEADBEEFDEADBEEFDEADBEEF\n"
56 "\n"
57 "\n"
58 "321 BAADCAFEBAADCAFEBAADCAFEBAADCAFE\n",
59 &module_ids);
60 ASSERT_EQ(3u, module_ids.size());
61 ASSERT_EQ(123u, module_ids["0123456789abcdef0123456789abcdef"]);
62 ASSERT_EQ(789u, module_ids["DEADBEEFDEADBEEFDEADBEEFDEADBEEF"]);
63 ASSERT_EQ(321u, module_ids["BAADCAFEBAADCAFEBAADCAFEBAADCAFE"]);
64 module_ids.clear();
66 // Leading empty lines, no termination on final line.
67 ParseAdditionalModuleIDs("\n"
68 "123 0123456789abcdef0123456789abcdef\r\n"
69 "321 BAADCAFEBAADCAFEBAADCAFEBAADCAFE",
70 &module_ids);
71 ASSERT_EQ(2u, module_ids.size());
72 ASSERT_EQ(123u, module_ids["0123456789abcdef0123456789abcdef"]);
73 ASSERT_EQ(321u, module_ids["BAADCAFEBAADCAFEBAADCAFEBAADCAFE"]);
74 module_ids.clear();