Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

test-main.cpp 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <iostream>
  2. #include <string.h>
  3. #include <gtest/gtest.h>
  4. #include <Business/CryptoBusiness.h>
  5. TEST(Crypto, Basic)
  6. {
  7. std::string key = "m{L%H$HgY##LJ&6Fs";
  8. CryptoBusiness cryptoBusiness;
  9. cryptoBusiness.setKey(key);
  10. std::string data = "some data";
  11. std::string encrypted = cryptoBusiness.encrypt(data);
  12. std::string decrypted = cryptoBusiness.decrypt(encrypted);
  13. ASSERT_NE(encrypted, decrypted);
  14. ASSERT_EQ(data, decrypted);
  15. }
  16. TEST(Crypto, Hex1)
  17. {
  18. CryptoBusiness cryptoBusiness;
  19. std::string data = "some data";
  20. std::string toHex = cryptoBusiness.toHex(data);
  21. std::string fromHex = cryptoBusiness.fromHex(toHex);
  22. ASSERT_NE(toHex, fromHex);
  23. ASSERT_EQ(data, fromHex);
  24. }
  25. TEST(Crypto, Hex2)
  26. {
  27. CryptoBusiness cryptoBusiness;
  28. std::string data;
  29. for (int i = 0; i <= 255; ++i)
  30. {
  31. data += (char)i;
  32. }
  33. std::string toHex = cryptoBusiness.toHex(data);
  34. std::string fromHex = cryptoBusiness.fromHex(toHex);
  35. ASSERT_NE(toHex, fromHex);
  36. ASSERT_EQ(data, fromHex);
  37. }
  38. TEST(Crypto, EncryptHex)
  39. {
  40. std::string key = "m{L%H$HgY##LJ&6Fs";
  41. CryptoBusiness cryptoBusiness;
  42. cryptoBusiness.setKey(key);
  43. std::string data = "some data";
  44. std::string encrypted = cryptoBusiness.encryptToHex(data);
  45. std::string decrypted = cryptoBusiness.decryptFromHex(encrypted);
  46. ASSERT_NE(encrypted, decrypted);
  47. ASSERT_EQ(data, decrypted);
  48. }
  49. int main(int argc, char* argv[])
  50. {
  51. ::testing::InitGoogleTest(&argc, argv);
  52. return RUN_ALL_TESTS();
  53. }