VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstTermCallbacks.cpp@ 31829

Last change on this file since 31829 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: tstTermCallbacks.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Termination Callbacks.
4 */
5
6/*
7 * Copyright (C) 2009 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/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/initterm.h>
32
33#include <iprt/test.h>
34#include <iprt/stream.h>
35#include <iprt/err.h>
36#include <iprt/initterm.h>
37
38/*******************************************************************************
39* Global Variables *
40*******************************************************************************/
41static uint32_t g_cCalls;
42static uint32_t g_fCalled;
43
44
45static DECLCALLBACK(void) tstTermCallback0(RTTERMREASON enmReason, int32_t iStatus, void *pvUser)
46{
47 RTTESTI_CHECK(pvUser == (void *)0);
48 g_cCalls++;
49 g_fCalled |= RT_BIT_32(0);
50}
51
52
53static DECLCALLBACK(void) tstTermCallback1(RTTERMREASON enmReason, int32_t iStatus, void *pvUser)
54{
55 RTTESTI_CHECK(pvUser == (void *)1);
56 g_cCalls++;
57 g_fCalled |= RT_BIT_32(1);
58}
59
60
61static DECLCALLBACK(void) tstTermCallback2(RTTERMREASON enmReason, int32_t iStatus, void *pvUser)
62{
63 RTTESTI_CHECK(pvUser == (void *)2);
64 g_cCalls++;
65 g_fCalled |= RT_BIT_32(2);
66}
67
68
69static DECLCALLBACK(void) tstTermCallback3(RTTERMREASON enmReason, int32_t iStatus, void *pvUser)
70{
71 RTTESTI_CHECK(pvUser == (void *)3);
72 g_cCalls++;
73 g_fCalled |= RT_BIT_32(3);
74}
75
76
77int main(int argc, char **argv)
78{
79 RTTEST hTest;
80 int rc = RTTestInitAndCreate("tstTermCallback", &hTest);
81 if (rc)
82 return rc;
83 RTTestBanner(hTest);
84
85 /*
86 * Just some basics.
87 */
88 RTTestSub(hTest, "Uninitialized");
89 RTTESTI_CHECK_RC(RTTermDeregisterCallback(tstTermCallback1, (void *)1), VERR_NOT_FOUND);
90 RTTermRunCallbacks(RTTERMREASON_UNLOAD, 0);
91
92 RTTestSub(hTest, "One callback");
93 g_cCalls = g_fCalled = 0;
94 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback0, (void *)0), VINF_SUCCESS);
95 RTTermRunCallbacks(RTTERMREASON_UNLOAD, 0);
96 RTTESTI_CHECK(g_cCalls == 1);
97 RTTESTI_CHECK(g_fCalled == RT_BIT_32(0));
98
99 RTTestSub(hTest, "Two callbacks");
100 g_cCalls = g_fCalled = 0;
101 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback0, (void *)0), VINF_SUCCESS);
102 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback1, (void *)1), VINF_SUCCESS);
103 RTTermRunCallbacks(RTTERMREASON_UNLOAD, 0);
104 RTTESTI_CHECK(g_cCalls == 2);
105 RTTESTI_CHECK(g_fCalled == (RT_BIT_32(0) | RT_BIT_32(1)));
106
107 RTTestSub(hTest, "Three callbacks");
108 g_cCalls = g_fCalled = 0;
109 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback0, (void *)0), VINF_SUCCESS);
110 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback1, (void *)1), VINF_SUCCESS);
111 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback2, (void *)2), VINF_SUCCESS);
112 RTTermRunCallbacks(RTTERMREASON_UNLOAD, 0);
113 RTTESTI_CHECK(g_cCalls == 3);
114 RTTESTI_CHECK(g_fCalled == (RT_BIT_32(0) | RT_BIT_32(1) | RT_BIT_32(2)));
115
116 RTTestSub(hTest, "Four callbacks");
117 g_cCalls = g_fCalled = 0;
118 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback0, (void *)0), VINF_SUCCESS);
119 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback1, (void *)1), VINF_SUCCESS);
120 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback2, (void *)2), VINF_SUCCESS);
121 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback3, (void *)3), VINF_SUCCESS);
122 RTTermRunCallbacks(RTTERMREASON_UNLOAD, 0);
123 RTTESTI_CHECK(g_cCalls == 4);
124 RTTESTI_CHECK(g_fCalled == (RT_BIT_32(0) | RT_BIT_32(1) | RT_BIT_32(2) | RT_BIT_32(3)));
125
126 RTTestSub(hTest, "Callback deregistration");
127 g_cCalls = g_fCalled = 0;
128 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback0, (void *)1), VINF_SUCCESS);
129 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback0, (void *)1), VINF_SUCCESS);
130 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback0, (void *)0), VINF_SUCCESS);
131 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback1, (void *)1), VINF_SUCCESS);
132 RTTESTI_CHECK_RC(RTTermRegisterCallback(tstTermCallback1, (void *)0), VINF_SUCCESS);
133 RTTESTI_CHECK_RC(RTTermDeregisterCallback(tstTermCallback0, (void *)1), VINF_SUCCESS);
134 RTTESTI_CHECK_RC(RTTermDeregisterCallback(tstTermCallback0, (void *)1), VINF_SUCCESS);
135 RTTESTI_CHECK_RC(RTTermDeregisterCallback(tstTermCallback0, (void *)1), VERR_NOT_FOUND);
136 RTTESTI_CHECK_RC(RTTermDeregisterCallback(tstTermCallback1, (void *)0), VINF_SUCCESS);
137 RTTESTI_CHECK_RC(RTTermDeregisterCallback(tstTermCallback1, (void *)0), VERR_NOT_FOUND);
138 RTTermRunCallbacks(RTTERMREASON_UNLOAD, 0);
139 RTTESTI_CHECK(g_cCalls == 2);
140 RTTESTI_CHECK(g_fCalled == (RT_BIT_32(0) | RT_BIT_32(1)));
141
142 /*
143 * Summary.
144 */
145 return RTTestSummaryAndDestroy(hTest);
146}
147
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