~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/platform/darwin/tstDarwinKeyboard.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: tstDarwinKeyboard.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
 
2
/** @file
 
3
 * Common GUI Library - Testcase - Darwin Keyboard routines.
 
4
 *
 
5
 * @todo Move this up somewhere so that the two SDL GUIs can use parts of this code too (-HID crap).
 
6
 */
 
7
 
 
8
/*
 
9
 * Copyright (C) 2006-2007 Oracle Corporation
 
10
 *
 
11
 * This file is part of VirtualBox Open Source Edition (OSE), as
 
12
 * available from http://www.virtualbox.org. This file is free software;
 
13
 * you can redistribute it and/or modify it under the terms of the GNU
 
14
 * General Public License (GPL) as published by the Free Software
 
15
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 
16
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 
17
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 
18
 */
 
19
 
 
20
 
 
21
/*******************************************************************************
 
22
*   Header Files                                                               *
 
23
*******************************************************************************/
 
24
#include <iprt/initterm.h>
 
25
#include <iprt/stream.h>
 
26
#include <iprt/string.h>
 
27
#include <iprt/time.h>
 
28
#include <iprt/assert.h>
 
29
 
 
30
#include "DarwinKeyboard.h"
 
31
 
 
32
int main(int argc, char **argv)
 
33
{
 
34
    int rc = RTR3Init();
 
35
    AssertReleaseRCReturn(rc, 1);
 
36
 
 
37
    /*
 
38
     * Warmup tests.
 
39
     */
 
40
    RTPrintf("tstDarwinKeyboard: Warmup...\n");
 
41
 
 
42
    RTTimeNanoTS();
 
43
    DarwinGrabKeyboard(true);
 
44
    DarwinReleaseKeyboard();
 
45
 
 
46
    RTTimeNanoTS();
 
47
    DarwinGrabKeyboard(true);
 
48
    DarwinReleaseKeyboard();
 
49
 
 
50
/* Test these too:
 
51
unsigned DarwinKeycodeToSet1Scancode(unsigned uKeyCode);
 
52
UInt32   DarwinAdjustModifierMask(UInt32 fModifiers);
 
53
unsigned DarwinModifierMaskToSet1Scancode(UInt32 fModifiers);
 
54
unsigned DarwinModifierMaskToDarwinKeycode(UInt32 fModifiers);
 
55
UInt32   DarwinKeyCodeToDarwinModifierMask(unsigned uKeyCode);
 
56
unsigned DarwinEventToSet1Scancode(EventRef Event, UInt32 *pfCurKeyModifiers);
 
57
void     DarwinDisableGlobalHotKeys(bool fDisable);
 
58
*/
 
59
 
 
60
    /*
 
61
     * Grab and release the keyboard a lot of times and time it.
 
62
     * We're looking both at performance and for memory and reference leaks here.
 
63
     */
 
64
    RTPrintf("tstDarwinKeyboard: Profiling Grab and Release");
 
65
    RTStrmFlush(g_pStdOut);
 
66
    const uint64_t u64Start = RTTimeNanoTS();
 
67
    uint64_t u64Grab = 0;
 
68
    uint64_t u64Release = 0;
 
69
    unsigned i;
 
70
    for (i = 0; i < 20; i++)
 
71
    {
 
72
        uint64_t u64 = RTTimeNanoTS();
 
73
        DarwinGrabKeyboard(argc != 1);
 
74
        u64Grab += RTTimeNanoTS() - u64;
 
75
 
 
76
        u64 = RTTimeNanoTS();
 
77
        DarwinReleaseKeyboard();
 
78
        u64Release += RTTimeNanoTS() - u64;
 
79
 
 
80
        if ((i % 10) == 0)
 
81
        {
 
82
            RTPrintf(".");
 
83
            RTStrmFlush(g_pStdOut);
 
84
        }
 
85
    }
 
86
    const uint64_t u64Elapsed = RTTimeNanoTS() - u64Start;
 
87
    RTPrintf("\n"
 
88
             "tstDarwinKeyboard: %u times in %RU64 ms - %RU64 ms per call\n",
 
89
             i, u64Elapsed / 1000000, (u64Elapsed / i) / 1000000);
 
90
    RTPrintf("tstDarwinKeyboard: DarwinGrabKeyboard: %RU64 ms total - %RU64 ms per call\n",
 
91
             u64Grab / 1000000, (u64Grab / i) / 1000000);
 
92
    RTPrintf("tstDarwinKeyboard: DarwinReleaseKeyboard: %RU64 ms total - %RU64 ms per call\n",
 
93
             u64Release / 1000000, (u64Release / i) / 1000000);
 
94
 
 
95
    return 0;
 
96
}
 
97