diff --git a/Assignment/Task 3/test1.cpp b/Assignment/Task 3/test1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c304bfeeaf567f6733e7229a41da89c09c76d365 --- /dev/null +++ b/Assignment/Task 3/test1.cpp @@ -0,0 +1,62 @@ +#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