1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace Tests\Unit;
- if (!defined('INSTALLDIR')) {
- define('INSTALLDIR', dirname(dirname(__DIR__)));
- }
- if (!defined('PUBLICDIR')) {
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- }
- if (!defined('GNUSOCIAL')) {
- define('GNUSOCIAL', true);
- }
- if (!defined('STATUSNET')) {
- define('STATUSNET', true);
- }
- use PHPUnit\Framework\TestCase;
- use UUID;
- require_once INSTALLDIR . '/lib/util/common.php';
- final class UUIDTest extends TestCase
- {
- public function testGenerate()
- {
- $result = UUID::gen();
- $this->assertRegExp('/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/',
- $result);
-
- $this->assertEquals(0x4000, hexdec(substr($result, 14, 4)) & 0xF000);
- $this->assertEquals(0x8000, hexdec(substr($result, 19, 4)) & 0xC000);
- }
- public function testUnique()
- {
- $reps = 100;
- $ids = array();
- for ($i = 0; $i < $reps; $i++) {
- $ids[] = UUID::gen();
- }
- $this->assertEquals(count($ids), count(array_unique($ids)), "UUIDs must be unique");
- }
- }
|