mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-03 19:50:34 +08:00
Matrix: capture stdout for print() test
I want to switch the print() function back to use printf() such that it's fully compatible with all (embedded) platforms. To still test the print function I'm capturing stdout into a file such that the print() function can stay unchanged and the result of the printf()s can be evaluated.
This commit is contained in:
committed by
Julian Kent
parent
c6db357c92
commit
a32892926c
@@ -235,13 +235,13 @@ int main()
|
||||
}
|
||||
|
||||
// check print()
|
||||
// Redirect stdout
|
||||
TEST(freopen("testoutput.txt", "w", stdout) != NULL);
|
||||
// write
|
||||
FILE *fp = fopen("testoutput.txt", "w+");
|
||||
TEST(fp != nullptr);
|
||||
Comma.print(fp);
|
||||
TEST(!fclose(fp));
|
||||
Comma.print();
|
||||
fclose(stdout);
|
||||
// read
|
||||
fp = fopen("testoutput.txt", "r");
|
||||
FILE *fp = fopen("testoutput.txt", "r");
|
||||
TEST(fp != nullptr);
|
||||
TEST(!fseek(fp, 0, SEEK_SET));
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
@@ -249,7 +249,7 @@ int main()
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
printf("%d %d %c\n", static_cast<int>(i), c, c);
|
||||
printf("%d %d %d\n", static_cast<int>(i), output[i], c);
|
||||
TEST(c == output[i]);
|
||||
}
|
||||
TEST(!fclose(fp));
|
||||
|
||||
Reference in New Issue
Block a user