OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <locale> | 5 #include <locale> |
6 | 6 |
7 #include "chrome/browser/autofill/password_generator.h" | 7 #include "chrome/browser/autofill/password_generator.h" |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace autofill { | 11 namespace autofill { |
12 | 12 |
13 TEST(PasswordGeneratorTest, PasswordGeneratorSimpleTest) { | 13 TEST(PasswordGeneratorTest, PasswordGeneratorSimpleTest) { |
14 // Not much to test, just make sure that the characters in a generated | |
15 // password are reasonable. | |
16 PasswordGenerator pg; | 14 PasswordGenerator pg; |
17 std::string password = pg.Generate(); | 15 // Check max_length. |
Ilya Sherman
2012/05/30 00:04:32
nit: Please separate this out to a separate named
Ilya Sherman
2012/05/30 00:04:32
nit: Please add a test case for max_length < 0.
zysxqn
2012/05/31 21:54:08
Done.
zysxqn
2012/05/31 21:54:08
Done.
| |
16 std::string password = pg.Generate(10); | |
17 EXPECT_TRUE(password.size() == 10); | |
18 password = pg.Generate(0); | |
19 EXPECT_TRUE(password.size() == 12); | |
Ilya Sherman
2012/05/30 00:04:32
nit: 12 is a magic number here. If you need to us
zysxqn
2012/05/31 21:54:08
Seems that it's easier to just define that constan
| |
20 // Check password. | |
Ilya Sherman
2012/05/30 00:04:32
nit: Please separate this out to a separate named
zysxqn
2012/05/31 21:54:08
Done.
| |
21 int num_upper_case_letters; | |
22 int num_lower_case_letters; | |
23 int num_digits; | |
24 int num_other_symbols; | |
18 for (size_t i = 0; i < password.size(); i++) { | 25 for (size_t i = 0; i < password.size(); i++) { |
19 // Make sure that the character is printable. | 26 // Make sure that the character is printable. |
20 EXPECT_TRUE(isgraph(password[i])); | 27 EXPECT_TRUE(isgraph(password[i])); |
28 if (isupper(password[i])) { | |
29 ++num_upper_case_letters; | |
30 } else if (islower(password[i])) { | |
31 ++num_lower_case_letters; | |
32 } else if (isdigit(password[i])) { | |
33 ++num_digits; | |
34 } else { | |
35 ++num_other_symbols; | |
36 } | |
Ilya Sherman
2012/05/30 00:04:32
nit: No need for curly braces, since these are all
zysxqn
2012/05/31 21:54:08
Done.
| |
21 } | 37 } |
38 EXPECT_TRUE(num_upper_case_letters > 0); | |
Ilya Sherman
2012/05/30 00:04:32
nit: EXPECT_GT
zysxqn
2012/05/31 21:54:08
Done.
| |
39 EXPECT_TRUE(num_lower_case_letters > 0); | |
40 EXPECT_TRUE(num_digits > 0); | |
41 EXPECT_TRUE(num_other_symbols > 0); | |
22 } | 42 } |
23 | 43 |
24 } // namespace autofill | 44 } // namespace autofill |
OLD | NEW |