| 1 |
// Copyright(C) 1999-2021 National Technology & Engineering Solutions |
| 2 |
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
// NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
// |
| 5 |
// See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
#include "CatalystTestFixture.h" |
| 8 |
#include "catch.hpp" |
| 9 |
#include <Iovs_CatalystLogging.h> |
| 10 |
|
| 11 |
TEST_CASE_METHOD(Iovs::CatalystLogging, "CatalystLoggingDefault", "[catalystLogging]") |
| 12 |
{ |
| 13 |
|
| 14 |
REQUIRE(isCatalystLoggingON() == false); |
| 15 |
REQUIRE(getLogFileName() == getDefaultLogFileName()); |
| 16 |
REQUIRE(getLogOutputDirectoryPath() == getDefaultLogOutputDirectoryPath()); |
| 17 |
} |
| 18 |
|
| 19 |
TEST_CASE_METHOD(Iovs::CatalystLogging, "CatalystLoggingEnabled", "[catalystLogging]") |
| 20 |
{ |
| 21 |
Ioss::PropertyManager props; |
| 22 |
props.add(Ioss::Property("CATALYST_LOGGING_ENABLED", true)); |
| 23 |
props.add(Ioss::Property("CATALYST_LOGGING_FILE_NAME", "foo.csv")); |
| 24 |
props.add(Ioss::Property("CATALYST_LOGGING_OUTPUT_DIRECTORY_PATH", "/projects/bar/")); |
| 25 |
setProperties(&props); |
| 26 |
|
| 27 |
REQUIRE(isCatalystLoggingON() == true); |
| 28 |
REQUIRE(getLogFileName() == "foo.csv"); |
| 29 |
REQUIRE(getLogOutputDirectoryPath() == "/projects/bar/"); |
| 30 |
} |
| 31 |
|
| 32 |
TEST_CASE_METHOD(Iovs::CatalystLogging, "CatalystLoggingWrite", "[catalystLogging]") |
| 33 |
{ |
| 34 |
Ioss::PropertyManager props; |
| 35 |
props.add(Ioss::Property("CATALYST_LOGGING_ENABLED", true)); |
| 36 |
remove(getLogFileName().c_str()); |
| 37 |
|
| 38 |
SECTION("Write Log Default") |
| 39 |
{ |
| 40 |
setProperties(&props); |
| 41 |
|
| 42 |
if (isCatalystLoggingON()) { |
| 43 |
writeToLogFile(); |
| 44 |
} |
| 45 |
|
| 46 |
CatalystTestFixture::checkTestOutputFileExists(getLogFileName().c_str()); |
| 47 |
std::vector<std::vector<std::string>> lfc = readLogFile(); |
| 48 |
|
| 49 |
REQUIRE(lfc.size() == 0); |
| 50 |
} |
| 51 |
|
| 52 |
SECTION("Write Log Once With All Supported Property Types") |
| 53 |
{ |
| 54 |
props.add(Ioss::Property("CATALYST_LOGGING_STRING_PROP", "foo")); |
| 55 |
props.add(Ioss::Property("CATALYST_LOGGING_INTEGER_PROP", 6)); |
| 56 |
props.add(Ioss::Property("CATALYST_LOGGING_REAL_PROP", 3.7556)); |
| 57 |
setProperties(&props); |
| 58 |
|
| 59 |
std::vector<std::string> logLine; |
| 60 |
if (isCatalystLoggingON()) { |
| 61 |
logLine = writeToLogFile(); |
| 62 |
} |
| 63 |
|
| 64 |
CatalystTestFixture::checkTestOutputFileExists(getLogFileName().c_str()); |
| 65 |
std::vector<std::vector<std::string>> lfc = readLogFile(); |
| 66 |
|
| 67 |
REQUIRE(lfc.size() == 2); |
| 68 |
REQUIRE(lfc[0] == getLogFileHeaders()); |
| 69 |
REQUIRE(lfc[1] == logLine); |
| 70 |
} |
| 71 |
|
| 72 |
SECTION("Write Log Twice With All Supported Property Types") |
| 73 |
{ |
| 74 |
props.add(Ioss::Property("CATALYST_LOGGING_STRING_PROP", "bar")); |
| 75 |
props.add(Ioss::Property("CATALYST_LOGGING_INTEGER_PROP", 12)); |
| 76 |
props.add(Ioss::Property("CATALYST_LOGGING_REAL_PROP", 7.45454)); |
| 77 |
setProperties(&props); |
| 78 |
|
| 79 |
std::vector<std::string> logLineOne; |
| 80 |
if (isCatalystLoggingON()) { |
| 81 |
logLineOne = writeToLogFile(); |
| 82 |
} |
| 83 |
|
| 84 |
Ioss::PropertyManager propsTwo; |
| 85 |
propsTwo.add(Ioss::Property("CATALYST_LOGGING_ENABLED", true)); |
| 86 |
propsTwo.add(Ioss::Property("CATALYST_LOGGING_REAL_PROP", 90.3)); |
| 87 |
propsTwo.add(Ioss::Property("CATALYST_LOGGING_STRING_PROP", "foo")); |
| 88 |
propsTwo.add(Ioss::Property("CATALYST_LOGGING_INTEGER_PROP", 107)); |
| 89 |
setProperties(&propsTwo); |
| 90 |
|
| 91 |
std::vector<std::string> logLineTwo; |
| 92 |
if (isCatalystLoggingON()) { |
| 93 |
logLineTwo = writeToLogFile(); |
| 94 |
} |
| 95 |
|
| 96 |
CatalystTestFixture::checkTestOutputFileExists(getLogFileName().c_str()); |
| 97 |
std::vector<std::vector<std::string>> lfc = readLogFile(); |
| 98 |
|
| 99 |
REQUIRE(lfc.size() == 3); |
| 100 |
REQUIRE(lfc[0] == getLogFileHeaders()); |
| 101 |
REQUIRE(lfc[1] == logLineOne); |
| 102 |
REQUIRE(lfc[2] == logLineTwo); |
| 103 |
} |
| 104 |
|
| 105 |
SECTION("Write Log With Unsupported Property Types") |
| 106 |
{ |
| 107 |
props.add(Ioss::Property("CATALYST_LOGGING_STRING_PROP", "bar")); |
| 108 |
int ten = 10; |
| 109 |
props.add(Ioss::Property("CATALYST_LOGGING_POINTER_PROP", (void *)&ten)); |
| 110 |
std::vector<int> iv = {1, 2, 3}; |
| 111 |
props.add(Ioss::Property("CATALYST_LOGGING_VEC_INTEGER_PROP", iv)); |
| 112 |
std::vector<double> dv = {1.4, 2.2, -56.3}; |
| 113 |
props.add(Ioss::Property("CATALYST_LOGGING_VEC_DOUBLE_PROP", dv)); |
| 114 |
setProperties(&props); |
| 115 |
|
| 116 |
std::vector<std::string> logLine; |
| 117 |
if (isCatalystLoggingON()) { |
| 118 |
logLine = writeToLogFile(); |
| 119 |
} |
| 120 |
|
| 121 |
CatalystTestFixture::checkTestOutputFileExists(getLogFileName().c_str()); |
| 122 |
std::vector<std::vector<std::string>> lfc = readLogFile(); |
| 123 |
|
| 124 |
std::vector<std::string> h = {"STRING_PROP"}; |
| 125 |
REQUIRE(h == getLogFileHeaders()); |
| 126 |
REQUIRE(lfc.size() == 2); |
| 127 |
REQUIRE(lfc[0] == getLogFileHeaders()); |
| 128 |
REQUIRE(lfc[1] == logLine); |
| 129 |
} |
| 130 |
|
| 131 |
SECTION("Write Log with quoted commas") |
| 132 |
{ |
| 133 |
props.add(Ioss::Property("CATALYST_LOGGING_STRING_PROP", "foo")); |
| 134 |
props.add(Ioss::Property("CATALYST_LOGGING_QUOTED_COMMA_PROP", "\"8,7,go,3.2\"")); |
| 135 |
props.add(Ioss::Property("CATALYST_LOGGING_QUOTED_ANOTHER_COMMA_PROP", |
| 136 |
"This address \", 343 Far Lane, ND 8732, RT 3\"")); |
| 137 |
setProperties(&props); |
| 138 |
|
| 139 |
std::vector<std::string> logLine; |
| 140 |
if (isCatalystLoggingON()) { |
| 141 |
logLine = writeToLogFile(); |
| 142 |
} |
| 143 |
|
| 144 |
CatalystTestFixture::checkTestOutputFileExists(getLogFileName().c_str()); |
| 145 |
std::vector<std::vector<std::string>> lfc = readLogFile(); |
| 146 |
|
| 147 |
REQUIRE(lfc.size() == 2); |
| 148 |
REQUIRE(lfc[0] == getLogFileHeaders()); |
| 149 |
REQUIRE(lfc[1] == logLine); |
| 150 |
} |
| 151 |
|
| 152 |
SECTION("Write Log with quoted quotes") |
| 153 |
{ |
| 154 |
props.add(Ioss::Property("CATALYST_LOGGING_STRING_PROP", "bar")); |
| 155 |
props.add(Ioss::Property("CATALYST_LOGGING_QUOTED_QUOTE_PROP", "\"\"foo\"\" bar \"1,3,2\"")); |
| 156 |
props.add( |
| 157 |
Ioss::Property("CATALYST_LOGGING_ANOTHER_QUOTED_QUOTE_PROP", "This has \"\"quote\"\"")); |
| 158 |
|
| 159 |
setProperties(&props); |
| 160 |
|
| 161 |
std::vector<std::string> logLine; |
| 162 |
if (isCatalystLoggingON()) { |
| 163 |
logLine = writeToLogFile(); |
| 164 |
} |
| 165 |
|
| 166 |
CatalystTestFixture::checkTestOutputFileExists(getLogFileName().c_str()); |
| 167 |
std::vector<std::vector<std::string>> lfc = readLogFile(); |
| 168 |
|
| 169 |
REQUIRE(lfc.size() == 2); |
| 170 |
REQUIRE(lfc[0] == getLogFileHeaders()); |
| 171 |
REQUIRE(lfc[1] == logLine); |
| 172 |
} |
| 173 |
|
| 174 |
remove(getLogFileName().c_str()); |
| 175 |
} |