VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTProcIsRunningByName.cpp@ 52320

Last change on this file since 52320 was 44529, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* $Id: tstRTProcIsRunningByName.cpp 44529 2013-02-04 15:54:15Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTProcIsRunningByName
4 */
5
6/*
7 * Copyright (C) 2009-2011 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <iprt/process.h>
31#include <iprt/initterm.h>
32#include <iprt/stream.h>
33#include <iprt/err.h>
34#include <iprt/param.h>
35#include <iprt/path.h>
36#include <iprt/string.h>
37
38
39
40int main(int argc, char **argv)
41{
42 int cErrors = 0;
43
44 RTR3InitExe(argc, &argv, 0);
45 RTPrintf("tstRTPRocIsRunningByName: TESTING...\n");
46
47 /*
48 * Test 1: Check for a definitely not running process.
49 */
50 char szExecPath[RTPATH_MAX] = { "vbox-5b05e1ff-6ae2-4d10-885a-7d25018c4c5b" };
51 if (!RTProcIsRunningByName(szExecPath))
52 RTPrintf("tstRTProcIsRunningByName: Process '%s' is not running (expected).\n", szExecPath);
53 else
54 {
55 RTPrintf("tstRTProcIsRunningByName: FAILURE - '%s' is running! (test 1)\n", szExecPath);
56 cErrors++;
57 }
58
59 /*
60 * Test 2: Check for a definitely not running process.
61 */
62 strcpy(szExecPath, "/bin/vbox-5b05e1ff-6ae2-4d10-885a-7d25018c4c5b");
63 if (!RTProcIsRunningByName(szExecPath))
64 RTPrintf("tstRTProcIsRunningByName: Process '%s' is not running (expected).\n", szExecPath);
65 else
66 {
67 RTPrintf("tstRTProcIsRunningByName: FAILURE - '%s' is running! (test 1)\n", szExecPath);
68 cErrors++;
69 }
70
71 /*
72 * Test 3: Check for our own process, filename only.
73 */
74 if (RTProcGetExecutablePath(szExecPath, RTPATH_MAX))
75 {
76 /* Strip any path components */
77 char *pszFilename = RTPathFilename(szExecPath);
78 if (pszFilename)
79 {
80 if (RTProcIsRunningByName(pszFilename))
81 RTPrintf("tstRTProcIsRunningByName: Process '%s' (self) is running\n", pszFilename);
82 else
83 {
84 RTPrintf("tstRTProcIsRunningByName: FAILURE - Process '%s' (self) is not running!\n", pszFilename);
85 cErrors++;
86 }
87 }
88 else
89 {
90 RTPrintf("tstRTProcIsRunningByName: FAILURE - RTPathFilename failed!\n");
91 cErrors++;
92 }
93
94 /*
95 * Test 4: Check for our own process, full path.
96 */
97 if (RTProcIsRunningByName(szExecPath))
98 RTPrintf("tstRTProcIsRunningByName: Process '%s' (self) is running\n", szExecPath);
99 else
100 {
101 RTPrintf("tstRTProcIsRunningByName: FAILURE - Process '%s' (self) is not running!\n", szExecPath);
102 cErrors++;
103 }
104 }
105 else
106 {
107 RTPrintf("tstRTProcIsRunningByName: FAILURE - RTProcGetExecutablePath failed!\n");
108 cErrors++;
109 }
110
111
112 /*
113 * Summary.
114 */
115 if (!cErrors)
116 RTPrintf("tstRTProcIsRunningByName: SUCCESS\n");
117 else
118 RTPrintf("tstRTProcIsRunningByName: FAILURE - %d errors\n", cErrors);
119 return cErrors ? 1 : 0;
120}
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