LCOV - code coverage report
Current view: top level - tests/nt - t_cipher.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 45 45 100.0 %
Date: 2024-05-13 05:06:06 Functions: 24 24 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Testing the implementation of random cipher algorithms
       3             :  */
       4             : #include <gtest/gtest.h>
       5             : #include <limits.h>
       6             : #include <openGPMP/nt/cipher.hpp>
       7             : 
       8             : using ::testing::DoubleLE;
       9             : using ::testing::FloatLE;
      10             : using ::testing::InitGoogleTest;
      11             : 
      12             : namespace {
      13             : gpmp::Cipher cc;
      14             : 
      15           4 : TEST(CipherTest, caesar_0) {
      16           1 :     std::string text_0 = "Plaintext";
      17           1 :     int key_shift_0 = 5;
      18           1 :     std::string hashtext_0 = cc.caesar(text_0, key_shift_0);
      19           1 :     std::string expected_0 = "Uqfnsyjcy";
      20             : 
      21           1 :     EXPECT_EQ(expected_0, hashtext_0);
      22           1 : }
      23             : 
      24           4 : TEST(CipherTest, caesar_1) {
      25           1 :     std::string text_1 = "ATTACKATONCE";
      26           1 :     int key_shift_1 = 4;
      27           1 :     std::string hashtext_1 = cc.caesar(text_1, key_shift_1);
      28           1 :     std::string expected_1 = "EXXEGOEXSRGI";
      29             : 
      30           1 :     EXPECT_EQ(expected_1, hashtext_1);
      31           1 : }
      32             : 
      33           4 : TEST(CipherTest, caesar_2) {
      34           1 :     std::string text_2 = "EaSyPASsWorD";
      35           1 :     int key_shift_2 = 14;
      36           1 :     std::string hashtext_2 = cc.caesar(text_2, key_shift_2);
      37           1 :     std::string expected_2 = "SoGmDOGgKcfR";
      38             : 
      39           1 :     EXPECT_EQ(expected_2, hashtext_2);
      40           1 : }
      41             : 
      42           4 : TEST(CipherTest, keyword_0) {
      43           1 :     std::string text_3 = "Password";
      44           1 :     std::string key_shift_3 = "Computer";
      45             : 
      46             :     // encode
      47           1 :     std::string encoded_text_0 = cc.keyword_encode(key_shift_3);
      48             :     // cipher
      49           2 :     std::string hashtext_3 = cc.keyword(text_3, encoded_text_0);
      50             : 
      51           1 :     std::string expected_3 = "JCNNWILP";
      52             : 
      53           1 :     EXPECT_EQ(expected_3, hashtext_3);
      54           1 : }
      55             : 
      56           4 : TEST(CipherTest, keyword_1) {
      57           1 :     std::string text_4 = "Password";
      58           1 :     std::string key_shift_4 = "Password";
      59             : 
      60             :     // encode
      61           1 :     std::string encoded_text_1 = cc.keyword_encode(key_shift_4);
      62             :     // cipher
      63           2 :     std::string hashtext_4 = cc.keyword(text_4, encoded_text_1);
      64             : 
      65           1 :     std::string expected_4 = "KPNNVJMW";
      66             : 
      67           1 :     EXPECT_EQ(expected_4, hashtext_4);
      68           1 : }
      69             : 
      70           4 : TEST(CipherTest, error_cipher_text) {
      71           1 :     std::string text_4 = "P455W0RD";
      72           1 :     std::string key_shift_4 = "IN1T_d";
      73             : 
      74             :     // encode
      75           1 :     std::string encoded_text_1 = cc.keyword_encode(key_shift_4);
      76             :     // cipher
      77           2 :     std::string hashtext_4 = cc.keyword(text_4, encoded_text_1);
      78             : 
      79           1 :     std::string expected_4 = "O455W0QD";
      80             : 
      81           1 :     EXPECT_EQ(expected_4, hashtext_4);
      82           1 : }
      83             : } // namespace
      84             : 
      85             : /*
      86             : int main() {
      87             :     InitGoogleTest();
      88             : 
      89             :     return RUN_ALL_TESTS();
      90             : }
      91             : */

Generated by: LCOV version 1.14