Beispiel #1
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $foo = XP_SIG('foo');
    xp_signal($foo, function () {
    });
    xp_before($foo, function ($foo) {
        $foo->foo = 'foo';
    });
    xp_emit($foo);
    $test->equal($foo->foo, 'foo');
}, 'API Before function');
Beispiel #2
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
/**
 * Emit Unitest
 */
unittest\test(function ($test) {
    $foo = XP_SIG(spl_object_hash(new stdClass()));
    $process = xp_process(null);
    xp_signal($foo, $process);
    xp_delete_process($foo, $process);
    $test->count(xp_get_signal($foo), 0);
}, 'API Delete Process');
Beispiel #3
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $foo = XP_SIG('foo');
    $test->instanceof($foo, 'XPSPL\\SIG');
}, 'API SIG');
Beispiel #4
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once '__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $db_1 = new \XPSPL\database\Processes();
    $db_2 = new \XPSPL\database\Processes();
    $count = 0;
    for ($i = 0; $i < 1000; $i++) {
        $db_1->install(new \XPSPL\Process(null));
        $db_2->install(new \XPSPL\Process(null, null));
    }
    $test->instanceof($db_1->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY), 'XPSPL\\database\\Processes');
    logger(XPSPL_LOG)->info($db_1->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY)->count());
    $test->count($db_1->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY), 1000);
    $test->instanceof($db_2->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY), 'XPSPL\\database\\Processes');
    $test->count($db_2->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY), 1000);
    $org_db = clone $db_1;
    $db_1->merge($db_2);
    $test->equal($db_1->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY)->rewind(), $org_db->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY)->rewind());
    $test->equal($db_1->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY)->end(), $db_2->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY)->end());
});
Beispiel #5
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $foo = XP_SIG('foo');
    xp_signal($foo, function () {
    });
    xp_after($foo, function ($foo) {
        $foo->foo = 'foo';
    });
    xp_emit($foo);
    $test->equal($foo->foo, 'foo');
}, 'API after');
Beispiel #6
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once '__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $database = new \XPSPL\database\Processes();
    $count = 10;
    for ($i = 0; $i < $count; $i++) {
        $database->install(new \XPSPL\Process(function () {
        }));
    }
    $test->instanceof($database->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY), 'XPSPL\\database\\Processes');
    $test->count($database->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY), $count);
    $db = $database->offsetGet(XPSPL_PROCESS_DEFAULT_PRIORITY);
    for ($i = XPSPL_SUBDATABASE_DEFAULT_PRIORITY; $i < $count; $i++) {
        $test->equal($db->offsetGet($i)->get_priority(), $i);
    }
});
Beispiel #7
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $process = xp_high_priority(null);
    $test->equal(0, $process->get_priority());
}, 'API High Priority');
Beispiel #8
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $process = xp_exhaust(10, null);
    $test->equal(10, $process->exhaustion());
}, 'API Exhaust');
Beispiel #9
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once '__init__.php';
xp_import('unittest');
// tmp class for state test
class XPSPL_TEST_State
{
    use XPSPL\State;
}
unittest\test(function ($test) {
    $state = new XPSPL_TEST_State();
    $test->equal($state->get_state(), STATE_DECLARED);
    $state->set_state(STATE_RUNNING);
    $test->equal($state->get_state(), STATE_RUNNING);
}, 'Test state');
Beispiel #10
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $process = xp_null_exhaust(null);
    $test->equal(null, $process->exhaustion());
}, 'API null exhaust');
Beispiel #11
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $process = xp_priority(100, null);
    $test->equal(100, $process->get_priority());
}, 'API Priority');
Beispiel #12
0
}, "process construction");
unittest\test(function ($test) {
    $process = new XPSPL\Process(function () {
    });
    $test->false($process->is_exhausted());
    $process->decrement_exhaust();
    $test->false($process->is_exhausted());
    $process = new XPSPL\Process(function () {
    }, 2);
    $process->decrement_exhaust();
    $test->false($process->is_exhausted());
    $process->decrement_exhaust();
    $test->true($process->is_exhausted());
    $process = new XPSPL\Process(function () {
    }, null);
    for ($i = 0; $i != 5; $i++) {
        $process->decrement_exhaust();
    }
    $test->false($process->is_exhausted());
    $process = new XPSPL\Process(function () {
    }, 0);
    $test->true($process->is_exhausted());
}, "Process exhaustion");
unittest\test(function ($test) {
    $process = new XPSPL\Process(function () {
    });
    $process->set_priority(100);
    $test->equal(100, $process->get_priority());
    $process->set_priority('a');
    $test->equal($process->get_priority(), XPSPL_PROCESS_DEFAULT_PRIORITY);
}, "Process Priority");
Beispiel #13
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $process = xp_low_priority(null);
    $test->equal(PHP_INT_MAX, $process->get_priority());
}, 'API Low Priority');
Beispiel #14
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $foo = XP_SIG('foo');
    xp_register_signal($foo);
    $test->instanceof(xp_get_signal($foo), 'XPSPL\\database\\Processes');
}, 'API Find signal database');
Beispiel #15
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once '__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $db = new \XPSPL\database\Processes();
    $p1 = new \XPSPL\Process(null);
    $p2 = xp_high_priority(new \XPSPL\Process(null));
    $db->install($p1);
    $db->install($p2);
    $db->delete($p1);
    $test->equal($db->count(), 1);
    $test->equal($db->current()->get_priority(), 0);
}, "process delete");
Beispiel #16
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once '__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $foo = XP_SIG('foo');
    xp_before($foo, function ($foo) {
        $foo->bar = 'HelloWorld';
    });
    xp_after($foo, function ($foo) {
        unset($foo->bar);
    });
    xp_signal($foo, function ($foo) use($test) {
        $test->equal($foo->bar, 'HelloWorld');
    });
    xp_emit($foo);
    $test->false(isset($foo->bar));
}, 'Interruptions');
Beispiel #17
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
xp_import('time');
unittest\test(function ($test) {
    $processor = new \XPSPL\Processor();
    $start = time();
    $processor->signal(new \time\SIG_Awake(1, TIME_SECONDS), new \XPSPL\Process(function () use($start, $test) {
        $test->equal(1, time() - $start);
    }, 1));
    $processor->wait_loop();
}, 'Time Module');
Beispiel #18
0
<?php

/**
 * Copyright 2010-12 Nickolas Whiting. All rights reserved.
 * Use of this source code is governed by the Apache 2 license
 * that can be found in the LICENSE file.
 */
require_once dirname(realpath(__FILE__)) . '/../__init__.php';
xp_import('unittest');
unittest\test(function ($test) {
    $foo = XP_SIG('foo');
    xp_signal($foo, null);
    $test->instanceof(xp_get_signal($foo), 'XPSPL\\database\\Processes');
}, 'API Signal');