Skip to content

Commit

Permalink
test clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ecdeye committed Jul 26, 2024
1 parent 38283ea commit 6aa1e4e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
8 changes: 1 addition & 7 deletions tool-openssl/md5_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@

size_t createTempFILEpath(char buffer[PATH_MAX]);

void RemoveFile(const char* path);

std::string ReadFileToString(const std::string& file_path);

RSA* CreateRSAKey();


// -------------------- MD5 OpenSSL Comparison Test ---------------------------

Expand Down Expand Up @@ -71,7 +65,7 @@ const std::string MODULUS = "MD5(stdin)= ";
// Test against OpenSSL output
TEST_F(MD5ComparisonTest, MD5ToolCompareOpenSSL) {
// Create input file with test string
std::string input_file = std::string(in_path) + "_md5_input";
std::string input_file = std::string(in_path);
std::ofstream ofs(input_file);
ofs << "AWS_LC_TEST_STRING_INPUT";
ofs.close();
Expand Down
4 changes: 0 additions & 4 deletions tool-openssl/rsa_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@

size_t createTempFILEpath(char buffer[PATH_MAX]);

void RemoveFile(const char* path);

std::string ReadFileToString(const std::string& file_path);

bool CheckBoundaries(const std::string &content, const std::string &begin1, const std::string &end1, const std::string &begin2, const std::string &end2);

RSA* CreateRSAKey();
Expand Down
10 changes: 10 additions & 0 deletions tool-openssl/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <string>
#include <iostream>


// Helper function to trim whitespace from both ends of a string to test comparison output
static inline std::string &trim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
Expand Down Expand Up @@ -55,4 +56,13 @@ inline void RunCommandsAndCompareOutput(const std::string &tool_command, const s
std::cout << "OpenSSL output:" << std::endl << openssl_output_str << std::endl;
}

inline void RemoveFile(const char* path) {
struct stat buffer;
if (path != nullptr && stat(path, &buffer) == 0) {
if (remove(path) != 0) {
fprintf(stderr, "Error deleting %s: %s\n", path, strerror(errno));
}
}
}

#endif //TEST_UTIL_H
11 changes: 0 additions & 11 deletions tool-openssl/x509_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

size_t createTempFILEpath(char buffer[PATH_MAX]);

void RemoveFile(const char* path);

X509* CreateAndSignX509Certificate() {
bssl::UniquePtr<X509> x509(X509_new());
if (!x509) return nullptr;
Expand Down Expand Up @@ -58,15 +56,6 @@ X509* CreateAndSignX509Certificate() {
return x509.release();
}

void RemoveFile(const char* path) {
struct stat buffer;
if (path != nullptr && stat(path, &buffer) == 0) {
if (remove(path) != 0) {
fprintf(stderr, "Error deleting %s: %s\n", path, strerror(errno));
}
}
}

class X509Test : public ::testing::Test {
protected:
void SetUp() override {
Expand Down

0 comments on commit 6aa1e4e

Please sign in to comment.