summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/compliance_1666/test209/test209.cpp
blob: da1066aef0142321de7321d4d1177580fda4ef3d (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <systemc>
using namespace sc_core;
using namespace sc_dt;
using std::cout;
using std::endl;

// 9) sc_object registered and named

struct i_f: virtual sc_interface
{
};

struct Chan: i_f, sc_object
{
  Chan() {}
  Chan(const char* _n): sc_object(_n) {}
};

SC_MODULE(M)
{
  SC_CTOR(M)
  {
    SC_THREAD(T);
  }
  void T()
  {
  }
};

struct Top: sc_module
{
  M *m;
  Top(sc_module_name)
  {
    m = new M("m");
  }
};

void check_form_of_suffix(std::string s)
{
  std::string charset = "0123456789";
  while (!s.empty())
  {
    sc_assert(s[0] == '_');
    s = s.substr(1);
    sc_assert(!s.empty());
    do
    {
      sc_assert(charset.find(s[0]) < charset.size());
      s = s.substr(1);
    } while (!s.empty() && (s[0] != '_'));
  }
}

int sc_main(int argc, char* argv[])
{
  cout << "Should be silent..." << endl;
  sc_report_handler::set_actions(SC_WARNING, SC_DO_NOTHING);

  Chan ch1(""); // object
  std::string s1 = std::string(ch1.name());
  sc_assert(s1.substr(0,6) == "object");
  check_form_of_suffix(s1.substr(6));

  Chan ch2;  // object_0
  const std::string s2 = std::string(ch2.name());
  sc_assert(s2.substr(0,6) == "object");
  check_form_of_suffix(s2.substr(6));
  sc_assert(s2 != s1);

  Chan ch3(s2.c_str()); // object_0_0 or object_1
  std::string s3 = std::string(ch3.name());
  sc_assert(s3.substr(0,6) == "object");
  check_form_of_suffix(s3.substr(6));
  sc_assert(s3 != s1);
  sc_assert(s3 != s2);

  Chan ch4("object_2");
  std::string s4 = std::string(ch4.name());
  sc_assert(s4.substr(0,6) == "object");
  check_form_of_suffix(s4.substr(6));
  sc_assert(s4 != s1);
  sc_assert(s4 != s2);
  sc_assert(s4 != s3);

  Chan ch5;
  std::string s5 = std::string(ch5.name());
  sc_assert(s5.substr(0,6) == "object");
  check_form_of_suffix(s5.substr(6));
  sc_assert(s5 != s1);
  sc_assert(s5 != s2);
  sc_assert(s5 != s3);
  sc_assert(s5 != s4);

  Chan ch6("");
  std::string s6 = std::string(ch6.name());
  sc_assert(s6.substr(0,6) == "object");
  check_form_of_suffix(s6.substr(6));
  sc_assert(s6 != s1);
  sc_assert(s6 != s2);
  sc_assert(s6 != s3);
  sc_assert(s6 != s4);
  sc_assert(s6 != s5);

  sc_signal<int> sig7("signal_0");
  std::string s7 = std::string(sig7.name());
  sc_assert(s7 == "signal_0");
  sc_assert(s7 != s1);
  sc_assert(s7 != s2);
  sc_assert(s7 != s3);
  sc_assert(s7 != s4);
  sc_assert(s7 != s5);
  sc_assert(s7 != s6);

  sc_signal<int> sig8;
  std::string s8 = std::string(sig8.name());
  sc_assert(s8.substr(0,6) == "signal");
  sc_assert(s8.size() > 6);
  check_form_of_suffix(s8.substr(6));
  sc_assert(s8 != s1);
  sc_assert(s8 != s2);
  sc_assert(s8 != s3);
  sc_assert(s8 != s4);
  sc_assert(s8 != s5);
  sc_assert(s8 != s6);
  sc_assert(s8 != s7);

  std::vector<sc_object*> children = sc_get_top_level_objects();
  sc_assert (children.size() == 8);

  Top top("top");
  sc_start();

  cout << endl << "Success" << endl;
  return 0;
}