| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 | #include <iostream>
#include <string.h>
#include <gtest/gtest.h>
#include <Business/CryptoBusiness.h>
TEST(Crypto, Basic)
{
  std::string key = "m{L%H$HgY##LJ&6Fs";
  CryptoBusiness cryptoBusiness;
  cryptoBusiness.setKey(key);
  std::string data = "some data";
  std::string encrypted = cryptoBusiness.encrypt(data);
  std::string decrypted = cryptoBusiness.decrypt(encrypted);
  ASSERT_NE(encrypted, decrypted);
  ASSERT_EQ(data, decrypted);
}
TEST(Crypto, Hex1)
{
  CryptoBusiness cryptoBusiness;
  std::string data = "some data";
  std::string toHex = cryptoBusiness.toHex(data);
  std::string fromHex = cryptoBusiness.fromHex(toHex);
  ASSERT_NE(toHex, fromHex);
  ASSERT_EQ(data, fromHex);
}
TEST(Crypto, Hex2)
{
  CryptoBusiness cryptoBusiness;
  std::string data;
  for (int i = 0; i <= 255; ++i)
  {
    data += (char)i;
  }
  std::string toHex = cryptoBusiness.toHex(data);
  std::string fromHex = cryptoBusiness.fromHex(toHex);
  ASSERT_NE(toHex, fromHex);
  ASSERT_EQ(data, fromHex);
}
TEST(Crypto, EncryptHex)
{
  std::string key = "m{L%H$HgY##LJ&6Fs";
  CryptoBusiness cryptoBusiness;
  cryptoBusiness.setKey(key);
  std::string data = "some data";
  std::string encrypted = cryptoBusiness.encryptToHex(data);
  std::string decrypted = cryptoBusiness.decryptFromHex(encrypted);
  ASSERT_NE(encrypted, decrypted);
  ASSERT_EQ(data, decrypted);
}
int main(int argc, char* argv[])
{
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
 |