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

Upload New File

parent fa763121
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <cstddef>
#include "bumpalld.hpp" // Include the BumpAllocator class definition
// Simple Test Framework
#define TEST_MESSAGE(condition, message) \
if (!(condition)) { \
std::cout << "Test failed: " << message << std::endl; \
return 1; \
} \
else { \
std::cout << "Test passed: " << #condition << std::endl; \
}
int BumpTest() {
std::cout << "Running BumpTest..." << std::endl;
BumpAllocator bumper(20 * sizeof(int)); // Create an allocator with space for 20 integers
int *x = static_cast<int*>(bumper.allocate(10 * sizeof(int))); // Allocate space for 10 integers
TEST_MESSAGE(x != nullptr, "Failed to allocate 10 integers");
int *y = static_cast<int*>(bumper.allocate(10 * sizeof(int))); // Allocate space for another 10 integers
TEST_MESSAGE(y != nullptr, "Failed to allocate another 10 integers");
int *z = static_cast<int*>(bumper.allocate(10 * sizeof(int))); // Try to allocate space for 10 more integers
TEST_MESSAGE(z == nullptr, "Should have failed to allocate 10 more integers");
return 0; // Return 0 to indicate success
}
int main() {
int result = BumpTest();
if (result != 0) {
std::cerr << "Some tests failed." << std::endl;
return 1;
}
std::cout << "All tests passed!" << std::endl;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment