Compile fixes
[ACE_TAO.git] / ACE / tests / ACE_Init_Test.cpp
blob62dad5f2ad636cb8e4889f589101c66f3d9c43c2
1 // This is a Win32-only test for verifying that the ACE dll
2 // initializes itself without having a nonstatic object manager
3 // present by way of a console app's main function. It's a MFC dialog
4 // app - it pops up a dialog and spawns a thread - the thread will
5 // wait 2 seconds and programatically dismiss the dialog box. The
6 // main thread waits for the other one to exit, and that's the test.
7 // If the ACE DLL doesn't initialize correctly, it will go boom!
8 //
9 // This test program was initially generated from MSVC AppWizard, then
10 // some files were renamed and moved around to fit in with the ACE
11 // test directory structure.
13 // ACE_Init_Test.cpp : Defines the class behaviors for the application.
15 #if !defined(ACE_HAS_MFC)
17 #include "test_config.h"
19 // If this is not a WIN32 platform do not even try to compile the
20 // test, many of the #includes make little sense.
21 int
22 run_main (int, ACE_TCHAR *[])
24 ACE_START_TEST (ACE_TEXT ("ACE_Init_Test"));
25 ACE_ERROR ((LM_INFO,
26 ACE_TEXT ("This is not a Win32 platform with MFC support, test skipped\n")));
27 ACE_END_TEST;
28 return 0;
31 #else
33 #include "ACE_Init_Test_StdAfx.h"
34 #include "ACE_Init_Test.h"
35 #include "ACE_Init_TestDlg.h"
36 #include "test_config.h"
37 #include "ace/ACE.h"
38 #include "ace/Init_ACE.h"
39 #include "ace/OS_NS_unistd.h"
40 #include "ace/Thread_Manager.h"
43 #ifdef _DEBUG
44 #define new DEBUG_NEW
45 #undef THIS_FILE
46 static char THIS_FILE[] = __FILE__;
47 #endif
49 static ACE_THR_FUNC_RETURN wait_and_kill_dialog (void *pBox);
51 /////////////////////////////////////////////////////////////////////////////
52 // CACE_Init_TestApp
54 BEGIN_MESSAGE_MAP(CACE_Init_TestApp, CWinApp)
55 //{{AFX_MSG_MAP(CACE_Init_TestApp)
56 // NOTE - the ClassWizard will add and remove mapping macros here.
57 // DO NOT EDIT what you see in these blocks of generated code!
58 //}}AFX_MSG
59 ON_COMMAND(ID_HELP, CWinApp::OnHelp)
60 END_MESSAGE_MAP()
62 /////////////////////////////////////////////////////////////////////////////
63 // CACE_Init_TestApp construction
65 CACE_Init_TestApp::CACE_Init_TestApp()
67 // TODO: add construction code here,
68 // Place all significant initialization in InitInstance
71 /////////////////////////////////////////////////////////////////////////////
72 // The one and only CACE_Init_TestApp object
74 CACE_Init_TestApp theApp;
76 /////////////////////////////////////////////////////////////////////////////
77 // CACE_Init_TestApp initialization
79 BOOL CACE_Init_TestApp::InitInstance()
81 // This is needed because there's no overridden main(int, char *[])
82 // which would normally handle the initialization. Also see the
83 // corresponding ACE::fini, below.
84 ACE::init();
86 ACE_START_TEST (ACE_TEXT ("ACE_Init_Test"));
88 CACE_Init_TestDlg dlg;
89 m_pMainWnd = &dlg;
90 ACE_Thread_Manager::instance()->spawn (wait_and_kill_dialog,
91 m_pMainWnd);
92 int nResponse = dlg.DoModal();
93 if (nResponse == IDOK)
95 // TODO: Place code here to handle when the dialog is
96 // dismissed with OK
98 else if (nResponse == IDCANCEL)
100 // TODO: Place code here to handle when the dialog is
101 // dismissed with Cancel
104 ACE_Thread_Manager::instance()->wait();
106 ACE_END_TEST;
108 // Since the dialog has been closed, return FALSE so that we exit the
109 // application, rather than start the application's message pump.
110 ACE::fini();
112 return FALSE;
115 // This function runs in a separate thread - it will wait a couple of
116 // seconds and then programatically dismiss the dialog box. If ACE is
117 // not properly initialized, we will have crashed before getting here.
118 static ACE_THR_FUNC_RETURN
119 wait_and_kill_dialog (void *pBox)
121 CACE_Init_TestDlg *pDialog = reinterpret_cast<CACE_Init_TestDlg *> (pBox);
122 ACE_OS::sleep(2);
123 pDialog->EndModalLoop (IDOK);
124 return 0;
127 #endif /* ACE_HAS_MFC */