20 #include <gtest/gtest.h>
22 #ifndef IMPALA_REDACTOR_TEST_UTILS_H
23 #define IMPALA_REDACTOR_TEST_UTILS_H
32 :
name_(
"/tmp/rules_XXXXXX"),
34 int fd = mkstemp(&
name_[0]);
36 std::cout <<
"Error creating temp file; " << strerror(errno) << std::endl;
40 std::cout <<
"Error closing temp file; " << strerror(errno) << std::endl;
51 if (
remove(
name()) != 0) {
52 std::cout <<
"Error deleting temp file; " << strerror(errno) << std::endl;
58 FILE* handle = fopen(
name(),
"w");
60 std::cout <<
"Error creating temp file; " << strerror(errno) << std::endl;
63 int status = fputs(contents.c_str(), handle);
65 std::cout <<
"Error writing to temp file; " << strerror(errno) << std::endl;
68 status = fclose(handle);
70 std::cout <<
"Error closing temp file; " << strerror(errno) << std::endl;
85 clock_gettime(CLOCK_REALTIME, &now);
86 return now.tv_nsec + pthread_self();
93 int char_count =
static_cast<int>(
'~') - static_cast<int>(
' ') + 1;
94 for (
int i = 0; i < length - 1; ++i) {
95 string[i] =
' ' + rand_r(&rand_seed) % char_count;
97 string[length - 1] =
'\0';
101 ASSERT_TRUE(message.find(expected) != std::string::npos)
102 <<
"Expected substring <<" << expected <<
">> is not in <<" << message <<
">>";
106 std::string temp(message);
108 ASSERT_EQ(expected, temp);
111 temp = string(message);
114 ASSERT_EQ(expected, temp);
115 ASSERT_EQ(temp == message, !changed);
126 #define SCOPED_ASSERT(assertion) { \
129 if (HasFatalFailure()) return; \
132 #define ASSERT_ERROR_MESSAGE_CONTAINS(error, expected) \
133 SCOPED_ASSERT(AssertErrorMessageContains(error, expected))
135 #define ASSERT_REDACTED_EQ(actual, expected) \
136 SCOPED_ASSERT(AssertRedactedEquals(actual, expected))
138 #define ASSERT_UNREDACTED(string) SCOPED_ASSERT(AssertUnredacted(string))
const char * name() const
Returns the absolute path to the file.
void Redact(string *value, bool *changed)
void AssertRedactedEquals(const char *message, const char *expected)
void AssertUnredacted(const char *message)
void AssertErrorMessageContains(const std::string &message, const char *expected)
TempRulesFile(const std::string &contents)
void OverwriteContents(const std::string &contents)
void RandomlyFillString(char *string, const int length)
Randomly fills the contents of 'string' up to the given length.