summaryrefslogtreecommitdiff
path: root/ACE/tests/Compiler_Features_40_Test.cpp
blob: b4a18d832afd6c844b6241d2e7e18a739a2190df (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
 * This program checks if the compiler/RTL does have correct support
 * for stack unwinding
 */

#include "test_config.h"
#include <vector>
#include <string>

class TTestClass;

static TTestClass* this_pointer {};
static bool isDataCorrupt = false;

class TTestClass
{
  unsigned char data[256];

public:
  TTestClass()
  {
    this_pointer = this;

    // Generate a sequence of numbers (0 - 255)
    for (int i = 0; i < 256; i++)
    {
      data[i] = i;
    }
  }

  ~TTestClass()
  {
    if (this != this_pointer)
    {
      ACE_ERROR ((LM_ERROR, "ERROR: Invalid this %@ != %@\n", this, this_pointer));
    }

    // Check if number sequence is still the same
    for (int i = 0; i < 256; i++)
    {
      if (data[i] != i)
      {
        isDataCorrupt = true;
        break;
      }
    }
  }

private:
  std::vector<std::string> SomeData;
};

void SomeFunction(std::string)
{
  // Unused function
}

void Test()
{
  std::string str = "branch_b";

  if (str == "branch_a")
  {
    SomeFunction("");
  }
  else if (str == "branch_b")
  {
    TTestClass test;
    throw std::runtime_error("Some exception");
  }
}

int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT("Compiler_Features_40_Test"));

  int retval = 0;
  try
  {
     Test();
  }
  catch (...)
  {
  }

  if (isDataCorrupt)
  {
    ACE_ERROR((LM_ERROR, "ERROR: Invalid data\n"));
    ++retval;
  }
  else
  {
    ACE_DEBUG ((LM_DEBUG, "Correct data\n"));
  }

  ACE_END_TEST;

  return retval;
}