mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-23 15:50:49 +01:00
AllocationFail
This commit is contained in:
22
allocation_failed_expression_node.h
Normal file
22
allocation_failed_expression_node.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef ALLOCATION_FAILED_EXPRESSION_NODE_H
|
||||
#define ALLOCATION_FAILED_EXPRESSION_NODE_H
|
||||
|
||||
#include "expression_node.h"
|
||||
|
||||
class AllocationFailedExpressionNode : public ExpressionNode {
|
||||
public:
|
||||
// ExpressionNode
|
||||
float approximate() override { return -1; } // Should return nan
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(AllocationFailedExpressionNode); }
|
||||
const char * description() const override { return "Allocation Failed"; }
|
||||
int numberOfChildren() const override { return 0; }
|
||||
};
|
||||
|
||||
class AllocationFailedExpressionRef : public ExpressionReference<AllocationFailedExpressionNode> {
|
||||
public:
|
||||
AllocationFailedExpressionRef() : ExpressionReference<AllocationFailedExpressionNode>() {}
|
||||
};
|
||||
|
||||
#endif
|
||||
8
refs.h
Normal file
8
refs.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "addition_node.h"
|
||||
#include "allocation_failed_expression_node.h"
|
||||
#include "float_node.h"
|
||||
|
||||
#include "char_layout_node.h"
|
||||
#include "horizontal_layout_node.h"
|
||||
|
||||
#include "layout_cursor.h"
|
||||
23
test.cpp
23
test.cpp
@@ -1,8 +1,4 @@
|
||||
#include "float_node.h"
|
||||
#include "char_layout_node.h"
|
||||
#include "horizontal_layout_node.h"
|
||||
#include "addition_node.h"
|
||||
#include "layout_cursor.h"
|
||||
#include "refs.h"
|
||||
#include <stdio.h>
|
||||
|
||||
AdditionRef buildAddition() {
|
||||
@@ -98,6 +94,20 @@ void testCursorMoveLeft() {
|
||||
assert(aChar.nodeRetainCount() == 3);
|
||||
}
|
||||
|
||||
void testPoolAllocationFail() {
|
||||
printf("Pool allocation fail test\n");
|
||||
|
||||
// Fill the pool for size 256
|
||||
|
||||
// Allocation fail
|
||||
assert(TreePool::sharedPool()->numberOfNodes() == 0);
|
||||
AllocationFailedExpressionRef a;
|
||||
assert(TreePool::sharedPool()->numberOfNodes() == 1);
|
||||
|
||||
/*Expression e = ;
|
||||
e.simplify*/
|
||||
}
|
||||
|
||||
typedef void (test)();
|
||||
void runTest(test t) {
|
||||
assert(TreePool::sharedPool()->numberOfNodes() == 0);
|
||||
@@ -106,9 +116,12 @@ void runTest(test t) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("\n*******************\nStart running tests\n*******************\n\n");
|
||||
runTest(testAddition);
|
||||
runTest(testPoolEmpties);
|
||||
runTest(testCursorCreateAndRetain);
|
||||
runTest(testCursorMoveLeft);
|
||||
runTest(testPoolAllocationFail);
|
||||
printf("\n*******************\nEnd of tests\n*******************\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ public:
|
||||
return nullptr; // TODO return static node "failedAllocation"
|
||||
}
|
||||
void * ptr = alloc(sizeof(T));
|
||||
// TODO handle allocation problem!
|
||||
if (ptr == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
T * node = new(ptr) T();
|
||||
node->rename(nodeIdentifier);
|
||||
registerNode(node);
|
||||
|
||||
Reference in New Issue
Block a user