File: Compiler_Features_41_Test.cpp

package info (click to toggle)
ace 8.0.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,088 kB
  • sloc: cpp: 342,864; perl: 31,902; sh: 1,963; python: 532; yacc: 524; xml: 330; lex: 158; lisp: 116; makefile: 85; csh: 20; ansic: 19; tcl: 5
file content (70 lines) | stat: -rw-r--r-- 1,905 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
 * This program checks if the compiler/RTL does have correct support
 * for structured exception handling using __try/__finally
 */

#include "test_config.h"

#if defined (ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS)
void test()
{
  ACE_DEBUG ((LM_DEBUG,("In test\n")));
  volatile int* pInt = 0x0000000;
  *pInt = 20;
}
#endif /* ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS */

int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT("Compiler_Features_41_Test"));
  int result = 0;

#if defined (ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS)
  bool finally_executed = false;

  ACE_DEBUG ((LM_DEBUG,("Testing __try/__finally\n")));

  ACE_SEH_TRY
    {
      ACE_DEBUG ((LM_DEBUG,("In SEH_TRY\n")));

      // Intentionally cause an access violation exception, use a helper function
      // as non-call SEH isn't supported with clang based windows compilers
      test();

      // If we get here without an exception, SEH isn't working
      ACE_ERROR ((LM_ERROR, "No exception was raised from null pointer dereference\n"));
      result = -1;
    }
  ACE_SEH_FINALLY
    {
      ACE_DEBUG ((LM_DEBUG,("In SEH_FINALLY\n")));
      finally_executed = true;
      // If we're here due to an exception, that's the expected behavior - test passes
    }

  ACE_DEBUG ((LM_DEBUG,("After SEH_FINALLY\n")));

  // On successful SEH handling:
  // 1. The null pointer dereference should raise an exception
  // 2. The FINALLY block should execute
  // 3. Execution should continue after the SEH blocks
  if (finally_executed)
  {
    ACE_DEBUG ((LM_DEBUG, "SEH test passed - FINALLY block was executed\n"));
  }
  else
  {
    ACE_ERROR ((LM_ERROR, "SEH test failed - FINALLY block was not executed\n"));
    result = -1;
  }
#else
  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("Platform lacks ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS\n")));
#endif /* ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS */

  ACE_END_TEST;

  return result;
}