1 // Copyright 2012 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <gtest/gtest.h> 16 #include <polo/encoding/hexadecimalencoder.h> 17 18 namespace polo { 19 namespace encoding { 20 21 TEST(HexadecimalEncoderTest, EncodeToString) { 22 HexadecimalEncoder encoder; 23 24 std::vector<unsigned char> secret(4); 25 secret[0] = 0xAA; 26 secret[1] = 0xBB; 27 secret[2] = 0xCC; 28 secret[3] = 0xDD; 29 30 std::string result = encoder.EncodeToString(secret); 31 32 ASSERT_EQ(std::string("AABBCCDD"), result); 33 } 34 35 TEST(HexadecimalEncoderTest, DecodeToBytes) { 36 HexadecimalEncoder encoder; 37 38 std::string secret("AABBCCDD"); 39 40 std::vector<unsigned char> result = encoder.DecodeToBytes(secret); 41 42 ASSERT_EQ(4, result.size()); 43 ASSERT_EQ(0xAA, result[0]); 44 ASSERT_EQ(0xBB, result[1]); 45 ASSERT_EQ(0xCC, result[2]); 46 ASSERT_EQ(0xDD, result[3]); 47 } 48 49 } // namespace encoding 50 } // namespace polo 51