Skip to content

Commit 155e3b3

Browse files
author
Julian Hall
committed
Created log-independence for consol/file/callback logging test
1 parent c58c2b6 commit 155e3b3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

check/TestIO.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,32 @@ TEST_CASE("log-callback", "[highs_io]") {
8888
REQUIRE(strlen(alt_printed_log) <= sizeof(alt_printed_log));
8989
}
9090
}
91+
92+
HighsCallbackFunctionType userLoggingCallback =
93+
[](int callback_type, const std::string& message,
94+
const HighsCallbackOutput* data_out, HighsCallbackInput* data_in,
95+
void* user_callback_data) {
96+
fprintf(static_cast<FILE*>(user_callback_data), "%s", message.c_str());
97+
};
98+
99+
TEST_CASE("log-independence", "[highs_io]") {
100+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
101+
const std::string test_highs_log = test_name + ".log";
102+
const std::string test_user_log = test_name + ".ulog";
103+
std::string filename = std::string(HIGHS_DIR) + "/check/instances/avgas.mps";
104+
Highs h;
105+
// h.setOptionValue("output_flag", dev_run);
106+
h.setOptionValue("log_file", test_highs_log);
107+
FILE* file = fopen(test_user_log.c_str(), "w");
108+
// void* p_user_callback_data = file;
109+
110+
h.setCallback(userLoggingCallback, file); // p_user_callback_data);
111+
h.startCallback(kCallbackLogging);
112+
113+
h.readModel(filename);
114+
h.run();
115+
116+
std::remove(test_highs_log.c_str());
117+
std::remove(test_user_log.c_str());
118+
h.resetGlobalScheduler(true);
119+
}

0 commit comments

Comments
 (0)