1//
2// Copyright (C) 2011 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#include "shill/crypto_rot47.h"
18
19#include <string>
20
21#include <gtest/gtest.h>
22
23using std::string;
24using testing::Test;
25
26namespace shill {
27
28namespace {
29const char kEmpty[] = "";
30const char kPlainText[] = "~{\"Hello world!\" OPQ ['1234']}";
31const char kCipherText[] = "OLQw6==@ H@C=5PQ ~!\" ,V`abcV.N";
32}  // namespace
33
34class CryptoROT47Test : public Test {
35 protected:
36  CryptoROT47 crypto_;
37};
38
39TEST_F(CryptoROT47Test, GetID) {
40  EXPECT_EQ(CryptoROT47::kID, crypto_.GetID());
41}
42
43TEST_F(CryptoROT47Test, Encrypt) {
44  string text;
45  EXPECT_TRUE(crypto_.Encrypt(kPlainText, &text));
46  EXPECT_EQ(kCipherText, text);
47  EXPECT_TRUE(crypto_.Encrypt(kEmpty, &text));
48  EXPECT_EQ(kEmpty, text);
49}
50
51TEST_F(CryptoROT47Test, Decrypt) {
52  string text;
53  EXPECT_TRUE(crypto_.Decrypt(kCipherText, &text));
54  EXPECT_EQ(kPlainText, text);
55  EXPECT_TRUE(crypto_.Decrypt(kEmpty, &text));
56  EXPECT_EQ(kEmpty, text);
57}
58
59}  // namespace shill
60