Darin Petkov | 877642b | 2011-06-27 13:37:22 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS 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. |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | #include "shill/crypto_rot47.h" |
| 8 | |
| 9 | using std::string; |
| 10 | using testing::Test; |
| 11 | |
| 12 | namespace shill { |
| 13 | |
| 14 | namespace { |
| 15 | const char kEmpty[] = ""; |
| 16 | const char kPlainText[] = "~{\"Hello world!\" OPQ ['1234']}"; |
| 17 | const char kCipherText[] = "OLQw6==@ H@C=5PQ ~!\" ,V`abcV.N"; |
| 18 | } // namespace {} |
| 19 | |
| 20 | class CryptoROT47Test : public Test { |
| 21 | protected: |
| 22 | CryptoROT47 crypto_; |
| 23 | }; |
| 24 | |
| 25 | TEST_F(CryptoROT47Test, GetID) { |
| 26 | EXPECT_EQ(CryptoROT47::kID, crypto_.GetID()); |
| 27 | } |
| 28 | |
| 29 | TEST_F(CryptoROT47Test, Encrypt) { |
| 30 | string text; |
| 31 | EXPECT_TRUE(crypto_.Encrypt(kPlainText, &text)); |
| 32 | EXPECT_EQ(kCipherText, text); |
| 33 | EXPECT_TRUE(crypto_.Encrypt(kEmpty, &text)); |
| 34 | EXPECT_EQ(kEmpty, text); |
| 35 | } |
| 36 | |
| 37 | TEST_F(CryptoROT47Test, Decrypt) { |
| 38 | string text; |
| 39 | EXPECT_TRUE(crypto_.Decrypt(kCipherText, &text)); |
| 40 | EXPECT_EQ(kPlainText, text); |
| 41 | EXPECT_TRUE(crypto_.Decrypt(kEmpty, &text)); |
| 42 | EXPECT_EQ(kEmpty, text); |
| 43 | } |
| 44 | |
| 45 | } // namespace shill |