~ubuntu-branches/ubuntu/vivid/emscripten/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/uuid/test.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140119141240-nfiw0p8033oitpfz
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <uuid/uuid.h>
 
2
#include <assert.h>
 
3
#include <ctype.h>
 
4
#include <stdio.h>
 
5
#include <stdlib.h>
 
6
#include <emscripten.h>
 
7
 
 
8
int isUUID(char* p, int upper) {
 
9
    char* p1 = p;
 
10
    do {
 
11
        if (!(isxdigit(*p1) || (*p1 == '-')) || (upper && islower(*p1)) || (!upper && isupper(*p1))) {
 
12
            return 0;
 
13
        } else {
 
14
        }
 
15
    } while (*++p1 != 0);
 
16
 
 
17
    if ((p[8] == '-') && (p[13] == '-') && (p[18] == '-') && (p[23] == '-')) {
 
18
        return 1;
 
19
    } else {
 
20
        return 0;
 
21
    }   
 
22
}
 
23
 
 
24
int main() {
 
25
    uuid_t uuid;
 
26
    uuid_t uuid1;
 
27
    uuid_t uuid2;
 
28
    uuid_t empty_uuid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
29
    uuid_generate(uuid);
 
30
 
 
31
    assert(uuid_is_null(uuid) == 0);
 
32
    assert(uuid_type(uuid) == UUID_TYPE_DCE_RANDOM);
 
33
    assert(uuid_variant(uuid) == UUID_VARIANT_DCE);
 
34
 
 
35
    char *generated = (char *)malloc(37*sizeof(char));
 
36
    uuid_unparse(uuid, generated);
 
37
    assert(isUUID(generated, 0) == 1); // Check it's a valid lower case UUID string.
 
38
    printf("\nuuid = %s\n", generated);
 
39
 
 
40
    assert(uuid_parse(generated, uuid1) == 0); // Check the generated UUID parses correctly into a compact UUID.
 
41
    assert(uuid_compare(uuid1, uuid) == 0);    // Compare the parsed UUID with the original.
 
42
 
 
43
    uuid_unparse_lower(uuid, generated);
 
44
    assert(isUUID(generated, 0) == 1); // Check it's a valid lower case UUID string.
 
45
    printf("uuid = %s\n", generated);
 
46
 
 
47
    uuid_unparse_upper(uuid, generated);
 
48
    assert(isUUID(generated, 1) == 1); // Check it's a valid upper case UUID string.
 
49
    printf("uuid = %s\n", generated);
 
50
 
 
51
 
 
52
    uuid_copy(uuid2, uuid);
 
53
    assert(uuid_compare(uuid2, uuid) == 0);
 
54
 
 
55
    uuid_clear(uuid);
 
56
    assert(uuid_compare(empty_uuid, uuid) == 0);
 
57
 
 
58
    assert(uuid_is_null(uuid) == 1);
 
59
 
 
60
    // The following lets the browser test exit cleanly.
 
61
    int result = 1;
 
62
    #if EMSCRIPTEN
 
63
        #ifdef REPORT_RESULT
 
64
            REPORT_RESULT();
 
65
        #endif
 
66
    #endif
 
67
    exit(0);
 
68
}
 
69