VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/tstDarwinKeyboard.cpp

Last change on this file was 106061, checked in by vboxsync, 3 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/* $Id: tstDarwinKeyboard.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VBox Qt GUI Testcase - Common GUI Library - 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-2024 Oracle and/or its affiliates.
10 *
11 * This file is part of VirtualBox base platform packages, as
12 * available from https://www.virtualbox.org.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation, in version 3 of the
17 * License.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <https://www.gnu.org/licenses>.
26 *
27 * SPDX-License-Identifier: GPL-3.0-only
28 */
29
30
31/*********************************************************************************************************************************
32* Header Files *
33*********************************************************************************************************************************/
34#include <iprt/initterm.h>
35#include <iprt/stream.h>
36#include <iprt/string.h>
37#include <iprt/time.h>
38#include <iprt/assert.h>
39
40#include "DarwinKeyboard.h"
41
42
43int main(int argc, char **argv)
44{
45 int rc = RTR3InitExe(argc, &argv, 0);
46 AssertReleaseRCReturn(rc, 1);
47
48 /*
49 * Warmup tests.
50 */
51 RTPrintf("tstDarwinKeyboard: Warmup...\n");
52
53 RTTimeNanoTS();
54 DarwinGrabKeyboard(true);
55 DarwinReleaseKeyboard();
56
57 RTTimeNanoTS();
58 DarwinGrabKeyboard(true);
59 DarwinReleaseKeyboard();
60
61/* Test these too:
62unsigned DarwinKeycodeToSet1Scancode(unsigned uKeyCode);
63UInt32 DarwinAdjustModifierMask(UInt32 fModifiers);
64unsigned DarwinModifierMaskToSet1Scancode(UInt32 fModifiers);
65unsigned DarwinModifierMaskToDarwinKeycode(UInt32 fModifiers);
66UInt32 DarwinKeyCodeToDarwinModifierMask(unsigned uKeyCode);
67unsigned DarwinEventToSet1Scancode(EventRef Event, UInt32 *pfCurKeyModifiers);
68void DarwinDisableGlobalHotKeys(bool fDisable);
69*/
70
71 /*
72 * Grab and release the keyboard a lot of times and time it.
73 * We're looking both at performance and for memory and reference leaks here.
74 */
75 RTPrintf("tstDarwinKeyboard: Profiling Grab and Release");
76 RTStrmFlush(g_pStdOut);
77 const uint64_t u64Start = RTTimeNanoTS();
78 uint64_t u64Grab = 0;
79 uint64_t u64Release = 0;
80 unsigned i;
81 for (i = 0; i < 20; i++)
82 {
83 uint64_t u64 = RTTimeNanoTS();
84 DarwinGrabKeyboard(argc != 1);
85 u64Grab += RTTimeNanoTS() - u64;
86
87 u64 = RTTimeNanoTS();
88 DarwinReleaseKeyboard();
89 u64Release += RTTimeNanoTS() - u64;
90
91 if ((i % 10) == 0)
92 {
93 RTPrintf(".");
94 RTStrmFlush(g_pStdOut);
95 }
96 }
97 const uint64_t u64Elapsed = RTTimeNanoTS() - u64Start;
98 RTPrintf("\n"
99 "tstDarwinKeyboard: %u times in %RU64 ms - %RU64 ms per call\n",
100 i, u64Elapsed / 1000000, (u64Elapsed / i) / 1000000);
101 RTPrintf("tstDarwinKeyboard: DarwinGrabKeyboard: %RU64 ms total - %RU64 ms per call\n",
102 u64Grab / 1000000, (u64Grab / i) / 1000000);
103 RTPrintf("tstDarwinKeyboard: DarwinReleaseKeyboard: %RU64 ms total - %RU64 ms per call\n",
104 u64Release / 1000000, (u64Release / i) / 1000000);
105
106 return 0;
107}
108
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette