]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/UUIDTest.php
Merge remote branch 'gitorious/testing' into testing
[quix0rs-gnu-social.git] / tests / UUIDTest.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('STATUSNET', true);
10
11 require_once INSTALLDIR . '/lib/common.php';
12
13 class UUIDTest extends PHPUnit_Framework_TestCase
14 {
15     public function testGenerate()
16     {
17         $result = UUID::gen();
18         $this->assertRegExp('/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/',
19                             $result);
20         // Check version number
21         $this->assertEquals(0x4000, hexdec(substr($result, 14, 4)) & 0xF000);
22         $this->assertEquals(0x8000, hexdec(substr($result, 19, 4)) & 0xC000);
23     }
24
25     public function testUnique()
26     {
27         $reps = 100;
28         $ids = array();
29
30         for ($i = 0; $i < $reps; $i++) {
31             $ids[] = UUID::gen();
32         }
33
34         $this->assertEquals(count($ids), count(array_unique($ids)), "UUIDs must be unique");
35     }
36 }
37