-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCLITest.cpp
65 lines (61 loc) · 2.26 KB
/
CLITest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <gtest/gtest.h>
#include <string>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include "../BazCryptCLI/BazCryptCLI.h"
using namespace std;
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
/* UNIX-style OS. ------------------------------------------- */
static string path = "bazcrypt";
#else
static string path = "bazcrypt.exe";
#endif
void fileRead(const char* filepath, char* data, unsigned long dataLength)
{
ifstream file(filepath, ios::in | ios::binary);
file.read(data, dataLength);
file.seekg(0, ios::beg);
file.close();
}
TEST(BazCryptCliTest, goodWeather_message) {
string msg = "SomeTextWhitoutWhiteSpaces";
string key = "asimplepasswordtouse";
int gen = 1500;
int algorithm = 0;
string fullcmd = path + " -m " + msg + " -p " + key + " -g " + to_string(gen) + " -a " + to_string(algorithm);
int exitcode = system(fullcmd.c_str());
EXPECT_EQ(exitcode, 0);
}
TEST(BazCryptCliTest, goodWeather_message2) {
string msg = "This is a test plain text. This is also very important to hide!";
string key = "asimplepasswordtouse";
int gen = 1500;
int algorithm = 0;
string fullcmd = path + " -m \"" + msg + "\" -p \"" + key + "\" -g " + to_string(gen) + " -a " + to_string(algorithm);
int exitcode = system(fullcmd.c_str());
EXPECT_EQ(exitcode, 0);
}
TEST(BazCryptCliTest, goodWeather_file) {
string msgPath = "small.txt";
string msg = "This is a test plain text. This is also very important to hide!";
string key = "asimplepasswordtouse";
int gen = 1500;
int algorithm = 0;
string fullcmd = path + " -f " + msgPath + " -p " + key + " -g " + to_string(gen) + " -a " + to_string(algorithm);
// ENCR
int exitcode = system(fullcmd.c_str());
char* encoutput = new char[msg.size()];
fileRead(msgPath.c_str(), encoutput, msg.size());
string encstr = string(encoutput, msg.size());
EXPECT_NE(encstr, msg);
// DECR
int exitcode2 = system(fullcmd.c_str());
char* output = new char[msg.size()];
fileRead(msgPath.c_str(), output, msg.size());
string outputstr = string(output, msg.size());
EXPECT_EQ(outputstr, msg);
delete[] output;
EXPECT_EQ(exitcode, 0);
EXPECT_EQ(exitcode2, 0);
}