view src/parallel_execution/test/stack_test.cbc @ 390:c93216e68d70

Can work queue_test converted by generate_stub
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Mon, 31 Jul 2017 22:40:08 +0900
parents 3529c7e93c4f
children 481fce540daf
line wrap: on
line source

#include "../../context.h"
#include <assert.h>

__code stackTest1(struct Stack* stack) {
    stack->stack = (union Data*)createSingleLinkedStack(context);
    Node* node = new Node();
    node->color = Red;
    goto stack->push(node, stackTest2);
}

__code stackTest2(struct Stack* stack) {
    Node* node = new Node();
    node->color = Black;
    goto stack->push(node, stackTest3);
}

__code stackTest2_stub(struct Context* context) {
    SingleLinkedStack* singleLinkedStack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
    assert(singleLinkedStack->top->data->Node.color == Red);
    Stack* stack = Gearef(context, Stack);
    goto stackTest2(context, stack);
}

__code stackTest3(struct Stack* stack) {
    goto stack->pop(assert3);
}

__code stackTest3_stub(struct Context* context) {
    /*
        assert on stack implementation
    */
    SingleLinkedStack* singleLinkedStack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
    assert(singleLinkedStack->top->data->Node.color == Black);
    Stack* stack = Gearef(context, Stack);
    goto stackTest3(context, stack);
} 

__code assert3(struct Node* node, struct Stack* stack) {
    /*
        assert in normal level
    */
    assert(node->color == Red);
    goto exit_code(0);
}

int main(int argc, char const* argv[]) {
    goto stackTest1();
}