MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / SetUpTestSuite

Method SetUpTestSuite

lib/mdflib/mdflib_test/src/testwrite.cpp:75–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73namespace mdf::test {
74
75void TestWrite::SetUpTestSuite() {
76
77 try {
78 // Create the root asn log directory. Note that this directory
79 // exists in the temp dir of the operating system and is not
80 // deleted by this test program. May be deleted at restart
81 // of the operating system.
82 auto temp_dir = temp_directory_path();
83 temp_dir.append("test");
84 kTestRootDir = temp_dir.string();
85 create_directories(temp_dir); // Not deleted
86
87
88 // Log to a file as this file is used as attachment file
89 auto& log_config = LogConfig::Instance();
90 log_config.RootDir(kTestRootDir);
91 log_config.BaseName("mdf_write");
92 log_config.Type(LogType::LogToFile);
93 log_config.CreateDefaultLogger();
94
95 remove(log_config.GetLogFile()); // Remove any old log files
96
97 // Connect MDF library to the util logging functionality
98 MdfLogStream::SetLogFunction1(LogFunc);
99
100
101 // Add console logging
102 log_config.AddLogger("Console",LogType::LogToConsole, {});
103 LOG_TRACE() << "Log file created. File: " << log_config.GetLogFile();
104
105 // Create the test directory. Note that this directory is deleted before
106 // running the test, not after. This give the
107 temp_dir.append("mdf");
108 temp_dir.append("write");
109 std::error_code err;
110 remove_all(temp_dir, err);
111 if (err) {
112 LOG_TRACE() << "Remove error. Message: " << err.message();
113 }
114 create_directories(temp_dir);
115 kTestDir = temp_dir.string();
116
117
118 LOG_TRACE() << "Created the test directory. Dir: " << kTestDir;
119 kSkipTest = false;
120 // The log file is actually not created directly. So wait until the log
121 // file exist, otherwise the attachment test will fail.
122
123 for (size_t log = 0; log < 600; ++log) {
124 if (exists(log_config.GetLogFile()) ) {
125 LOG_TRACE() << "Waited for log file. Ticks: " << log;
126 break;
127 }
128 LOG_INFO() << "Fill with dummy messages for the attachment test.";
129 std::this_thread::sleep_for(100ms);
130 }
131
132 } catch (const std::exception& err) {

Callers

nothing calls this directly

Calls 7

RootDirMethod · 0.80
BaseNameMethod · 0.80
CreateDefaultLoggerMethod · 0.80
GetLogFileMethod · 0.80
AddLoggerMethod · 0.80
appendMethod · 0.45
TypeMethod · 0.45

Tested by

no test coverage detected