Skip to content
Snippets Groups Projects
Commit ff5cb1c6 authored by j2-tulloch's avatar j2-tulloch :speech_balloon:
Browse files

Test File

parent 568ec09f
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include "your_fiber_header.h" // Replace with your actual fiber system header file
// Function prototypes
void testRunWithoutErrors();
void testSpawnAndExecuteTwoFibers();
void testPrintOrder();
// Add more prototypes for other tests
int main() {
testRunWithoutErrors();
testSpawnAndExecuteTwoFibers();
testPrintOrder();
// Call other test functions
std::cout << "All tests passed." << std::endl;
return 0;
}
void testRunWithoutErrors() {
int result = main();
assert(result == 0);
}
void testSpawnAndExecuteTwoFibers() {
// Redirect cout to capture output
std::streambuf* originalCout = std::cout.rdbuf();
std::ostringstream capturedCout;
std::cout.rdbuf(capturedCout.rdbuf());
main();
std::string output = capturedCout.str();
// Restore original cout buffer
std::cout.rdbuf(originalCout);
assert(output.find("fiber 1 before") != std::string::npos);
assert(output.find("fiber 1 after") != std::string::npos);
assert(output.find("fiber 2") != std::string::npos);
}
void testPrintOrder() {
// Redirect cout to capture output
std::streambuf* originalCout = std::cout.rdbuf();
std::ostringstream capturedCout;
std::cout.rdbuf(capturedCout.rdbuf());
main();
std::string output = capturedCout.str();
// Restore original cout buffer
std::cout.rdbuf(originalCout);
auto posBefore = output.find("fiber 1 before");
auto posAfter = output.find("fiber 1 after");
assert(posBefore < posAfter);
}
// Implement other test functions similarly
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment