112855Sgabeblack@google.com/*****************************************************************************
212855Sgabeblack@google.com
312855Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412855Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512855Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612855Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712855Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812855Sgabeblack@google.com  License.  You may obtain a copy of the License at
912855Sgabeblack@google.com
1012855Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112855Sgabeblack@google.com
1212855Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312855Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412855Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512855Sgabeblack@google.com  implied.  See the License for the specific language governing
1612855Sgabeblack@google.com  permissions and limitations under the License.
1712855Sgabeblack@google.com
1812855Sgabeblack@google.com *****************************************************************************/
1912855Sgabeblack@google.com
2012855Sgabeblack@google.com/*****************************************************************************
2112855Sgabeblack@google.com
2212855Sgabeblack@google.com  test01.cpp --
2312855Sgabeblack@google.com
2412855Sgabeblack@google.com  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
2512855Sgabeblack@google.com
2612855Sgabeblack@google.com *****************************************************************************/
2712855Sgabeblack@google.com
2812855Sgabeblack@google.com/*****************************************************************************
2912855Sgabeblack@google.com
3012855Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
3112855Sgabeblack@google.com  changes you are making here.
3212855Sgabeblack@google.com
3312855Sgabeblack@google.com      Name, Affiliation, Date:
3412855Sgabeblack@google.com  Description of Modification:
3512855Sgabeblack@google.com
3612855Sgabeblack@google.com *****************************************************************************/
3712855Sgabeblack@google.com
3812855Sgabeblack@google.com// test of sc_time's methods
3912855Sgabeblack@google.com
4012855Sgabeblack@google.com#include "systemc.h"
4112855Sgabeblack@google.com
4212855Sgabeblack@google.comvoid
4312855Sgabeblack@google.comtest_print()
4412855Sgabeblack@google.com{
4512855Sgabeblack@google.com    cout << "test_print" << endl;
4612855Sgabeblack@google.com
4712855Sgabeblack@google.com    sc_time t1;
4812855Sgabeblack@google.com    cout << t1 << endl;
4912855Sgabeblack@google.com
5012855Sgabeblack@google.com    uint64 v = 1230;
5112855Sgabeblack@google.com    sc_time t2 = sc_time::from_value( v );
5212855Sgabeblack@google.com    cout << t2 << endl;
5312855Sgabeblack@google.com
5412855Sgabeblack@google.com    v *= 10000;
5512855Sgabeblack@google.com    sc_time t3 = sc_time::from_value( v );
5612855Sgabeblack@google.com    cout << t3 << endl;
5712855Sgabeblack@google.com
5812855Sgabeblack@google.com    v *= 100;
5912855Sgabeblack@google.com    sc_time t4 = sc_time::from_value( v );
6012855Sgabeblack@google.com    cout << t4 << endl;
6112855Sgabeblack@google.com
6212855Sgabeblack@google.com    v *= 10000;
6312855Sgabeblack@google.com    sc_time t5 = sc_time::from_value( v );
6412855Sgabeblack@google.com    cout << t5 << endl;
6512855Sgabeblack@google.com
6612855Sgabeblack@google.com    v *= 100;
6712855Sgabeblack@google.com    sc_time t6 = sc_time::from_value( v );
6812855Sgabeblack@google.com    cout << t6 << endl;
6912855Sgabeblack@google.com
7012855Sgabeblack@google.com    v *= 10000;
7112855Sgabeblack@google.com    sc_time t7 = sc_time::from_value( v );
7212855Sgabeblack@google.com    cout << t7 << endl;
7312855Sgabeblack@google.com}
7412855Sgabeblack@google.com
7512855Sgabeblack@google.comvoid
7612855Sgabeblack@google.comtest_constructors()
7712855Sgabeblack@google.com{
7812855Sgabeblack@google.com    cout << "test_constructors" << endl;
7912855Sgabeblack@google.com
8012855Sgabeblack@google.com    sc_time t1;
8112855Sgabeblack@google.com    cout << t1 << endl;
8212855Sgabeblack@google.com
8312855Sgabeblack@google.com    sc_time t2a( 0, SC_SEC );
8412855Sgabeblack@google.com    cout << t2a << endl;
8512855Sgabeblack@google.com
8612855Sgabeblack@google.com    sc_time t2b( 1.2345, SC_NS );
8712855Sgabeblack@google.com    cout << t2b << endl;
8812855Sgabeblack@google.com    sc_time t2c( 1.2341, SC_NS );
8912855Sgabeblack@google.com    cout << t2c << endl;
9012855Sgabeblack@google.com
9112855Sgabeblack@google.com    sc_time t2d( 1, SC_FS );
9212855Sgabeblack@google.com    cout << t2d << endl;
9312855Sgabeblack@google.com
9412855Sgabeblack@google.com    sc_time t2e( -1.2345, SC_NS );
9512855Sgabeblack@google.com    cout << t2e << endl;
9612855Sgabeblack@google.com    sc_time t2f( -1.2341, SC_NS );
9712855Sgabeblack@google.com    cout << t2f << endl;
9812855Sgabeblack@google.com
9912855Sgabeblack@google.com    char v1 = 1;
10012855Sgabeblack@google.com    signed char v2 = 2;
10112855Sgabeblack@google.com    unsigned char v3 = 3;
10212855Sgabeblack@google.com    short v4 = 4;
10312855Sgabeblack@google.com    unsigned short v5 = 5;
10412855Sgabeblack@google.com    int v6 = 6;
10512855Sgabeblack@google.com    unsigned int v7 = 7;
10612855Sgabeblack@google.com    long v8 = 8;
10712855Sgabeblack@google.com    unsigned long v9 = 9;
10812855Sgabeblack@google.com    float v10 = 10;
10912855Sgabeblack@google.com    double v11 = 11;
11012855Sgabeblack@google.com
11112855Sgabeblack@google.com    sc_time t2g( v1, SC_NS );
11212855Sgabeblack@google.com    cout << t2g << endl;
11312855Sgabeblack@google.com    sc_time t2h( v2, SC_NS );
11412855Sgabeblack@google.com    cout << t2h << endl;
11512855Sgabeblack@google.com    sc_time t2i( v3, SC_NS );
11612855Sgabeblack@google.com    cout << t2i << endl;
11712855Sgabeblack@google.com    sc_time t2j( v4, SC_NS );
11812855Sgabeblack@google.com    cout << t2j << endl;
11912855Sgabeblack@google.com    sc_time t2k( v5, SC_NS );
12012855Sgabeblack@google.com    cout << t2k << endl;
12112855Sgabeblack@google.com    sc_time t2l( v6, SC_NS );
12212855Sgabeblack@google.com    cout << t2l << endl;
12312855Sgabeblack@google.com    sc_time t2m( v7, SC_NS );
12412855Sgabeblack@google.com    cout << t2m << endl;
12512855Sgabeblack@google.com    sc_time t2n( v8, SC_NS );
12612855Sgabeblack@google.com    cout << t2n << endl;
12712855Sgabeblack@google.com    sc_time t2o( v9, SC_NS );
12812855Sgabeblack@google.com    cout << t2o << endl;
12912855Sgabeblack@google.com    sc_time t2p( v10, SC_NS );
13012855Sgabeblack@google.com    cout << t2p << endl;
13112855Sgabeblack@google.com    sc_time t2q( v11, SC_NS );
13212855Sgabeblack@google.com    cout << t2q << endl;
13312855Sgabeblack@google.com
13412855Sgabeblack@google.com    sc_time t3a( 0, SC_SEC );
13512855Sgabeblack@google.com    cout << t3a << endl;
13612855Sgabeblack@google.com
13712855Sgabeblack@google.com    sc_time t3b( 1.2341, true );
13812855Sgabeblack@google.com    cout << t3b << endl;
13912855Sgabeblack@google.com    sc_time t3c( 1.2345, true );
14012855Sgabeblack@google.com    cout << t3c << endl;
14112855Sgabeblack@google.com    sc_time t3d( -1.2341, true );
14212855Sgabeblack@google.com    cout << t3d << endl;
14312855Sgabeblack@google.com    sc_time t3e( -1.2345, true );
14412855Sgabeblack@google.com    cout << t3e << endl;
14512855Sgabeblack@google.com
14612855Sgabeblack@google.com    sc_time t3f( 1.2345, false );
14712855Sgabeblack@google.com    cout << t3f << endl;
14812855Sgabeblack@google.com    sc_time t3g( 1.5432, false );
14912855Sgabeblack@google.com    cout << t3g << endl;
15012855Sgabeblack@google.com    sc_time t3h( -1.2345, false );
15112855Sgabeblack@google.com    cout << t3h << endl;
15212855Sgabeblack@google.com    sc_time t3i( -1.5432, false );
15312855Sgabeblack@google.com    cout << t3i << endl;
15412855Sgabeblack@google.com
15512855Sgabeblack@google.com#if !defined( _MSC_VER )
15612855Sgabeblack@google.com    sc_time t4a( 0ull, true );
15712855Sgabeblack@google.com    cout << t4a << endl;
15812855Sgabeblack@google.com    sc_time t4b( 25ull, true );
15912855Sgabeblack@google.com    cout << t4b << endl;
16012855Sgabeblack@google.com    sc_time t4c( 25ull, false );
16112855Sgabeblack@google.com    cout << t4c << endl;
16212855Sgabeblack@google.com#else
16312855Sgabeblack@google.com    sc_time t4a( 0ui64, true );
16412855Sgabeblack@google.com    cout << t4a << endl;
16512855Sgabeblack@google.com    sc_time t4b( 25ui64, true );
16612855Sgabeblack@google.com    cout << t4b << endl;
16712855Sgabeblack@google.com    sc_time t4c( 25ui64, false );
16812855Sgabeblack@google.com    cout << t4c << endl;
16912855Sgabeblack@google.com#endif
17012855Sgabeblack@google.com
17112855Sgabeblack@google.com    sc_time t5( t4c );
17212855Sgabeblack@google.com    cout << t5 << endl;
17312855Sgabeblack@google.com}
17412855Sgabeblack@google.com
17512855Sgabeblack@google.comvoid
17612855Sgabeblack@google.comtest_assignment()
17712855Sgabeblack@google.com{
17812855Sgabeblack@google.com    cout << "test_assignment" << endl;
17912855Sgabeblack@google.com
18012855Sgabeblack@google.com    sc_time t1;
18112855Sgabeblack@google.com
18212855Sgabeblack@google.com    sc_time t2;
18312855Sgabeblack@google.com    t1 = t2;
18412855Sgabeblack@google.com    cout << t1 << endl;
18512855Sgabeblack@google.com
18612855Sgabeblack@google.com    sc_time t3( 1.2345, SC_NS );
18712855Sgabeblack@google.com    t1 = t3;
18812855Sgabeblack@google.com    cout << t1 << endl;
18912855Sgabeblack@google.com
19012855Sgabeblack@google.com    sc_time t4( -1.5432, SC_NS );
19112855Sgabeblack@google.com    t1 = t4;
19212855Sgabeblack@google.com    cout << t1 << endl;
19312855Sgabeblack@google.com}
19412855Sgabeblack@google.com
19512855Sgabeblack@google.comvoid
19612855Sgabeblack@google.comtest_conversion()
19712855Sgabeblack@google.com{
19812855Sgabeblack@google.com    cout << "test_conversion" << endl;
19912855Sgabeblack@google.com
20012855Sgabeblack@google.com    sc_time t1;
20112855Sgabeblack@google.com    cout << t1.value() << endl;
20212855Sgabeblack@google.com    cout << t1.to_double() << endl;
20312855Sgabeblack@google.com    cout << t1 << endl;
20412855Sgabeblack@google.com    cout << t1.to_seconds() << endl;
20512855Sgabeblack@google.com
20612855Sgabeblack@google.com    sc_time t2( 1.2345, SC_US );
20712855Sgabeblack@google.com    cout << t2.value() << endl;
20812855Sgabeblack@google.com    cout << t2.to_double() << endl;
20912855Sgabeblack@google.com    cout << t2 << endl;
21012855Sgabeblack@google.com    cout << t2.to_seconds() << endl;
21112855Sgabeblack@google.com
21212855Sgabeblack@google.com    sc_time t3( -1.5432, SC_NS );
21312855Sgabeblack@google.com    cout << t3.value() << endl;
21412855Sgabeblack@google.com    cout << t3.to_double() << endl;
21512855Sgabeblack@google.com    cout << t3 << endl;
21612855Sgabeblack@google.com    cout << t3.to_seconds() << endl;
21712855Sgabeblack@google.com}
21812855Sgabeblack@google.com
21912855Sgabeblack@google.comvoid
22012855Sgabeblack@google.comtest_relational()
22112855Sgabeblack@google.com{
22212855Sgabeblack@google.com    cout << "test_relational" << endl;
22312855Sgabeblack@google.com
22412855Sgabeblack@google.com    sc_time t1;
22512855Sgabeblack@google.com    sc_time t2( 1, SC_FS );
22612855Sgabeblack@google.com    sc_time t3( 1.2345, SC_NS );
22712855Sgabeblack@google.com    sc_time t4( 1.2341, SC_NS );
22812855Sgabeblack@google.com    sc_time t5( -1.5432, SC_NS );
22912855Sgabeblack@google.com
23012855Sgabeblack@google.com    cout << ( t1 == t2 ) << endl;
23112855Sgabeblack@google.com    cout << ( t1 != t2 ) << endl;
23212855Sgabeblack@google.com    cout << ( t1 <  t2 ) << endl;
23312855Sgabeblack@google.com    cout << ( t1 <= t2 ) << endl;
23412855Sgabeblack@google.com    cout << ( t1 >  t2 ) << endl;
23512855Sgabeblack@google.com    cout << ( t1 >= t2 ) << endl;
23612855Sgabeblack@google.com
23712855Sgabeblack@google.com    cout << ( t3 == t4 ) << endl;
23812855Sgabeblack@google.com    cout << ( t3 != t4 ) << endl;
23912855Sgabeblack@google.com    cout << ( t3 <  t4 ) << endl;
24012855Sgabeblack@google.com    cout << ( t3 <= t4 ) << endl;
24112855Sgabeblack@google.com    cout << ( t3 >  t4 ) << endl;
24212855Sgabeblack@google.com    cout << ( t3 >= t4 ) << endl;
24312855Sgabeblack@google.com
24412855Sgabeblack@google.com    cout << ( t1 == t5 ) << endl;
24512855Sgabeblack@google.com    cout << ( t1 != t5 ) << endl;
24612855Sgabeblack@google.com    cout << ( t1 <  t5 ) << endl;
24712855Sgabeblack@google.com    cout << ( t1 <= t5 ) << endl;
24812855Sgabeblack@google.com    cout << ( t1 >  t5 ) << endl;
24912855Sgabeblack@google.com    cout << ( t1 >= t5 ) << endl;
25012855Sgabeblack@google.com}
25112855Sgabeblack@google.com
25212855Sgabeblack@google.comvoid
25312855Sgabeblack@google.comtest_arithmetic()
25412855Sgabeblack@google.com{
25512855Sgabeblack@google.com    cout << "test_arithmetic" << endl;
25612855Sgabeblack@google.com
25712855Sgabeblack@google.com    sc_time t1;
25812855Sgabeblack@google.com    sc_time t2( 1, SC_FS );
25912855Sgabeblack@google.com    sc_time t3( 1.2345, SC_NS );
26012855Sgabeblack@google.com    sc_time t4( 1.2341, SC_NS );
26112855Sgabeblack@google.com    sc_time t5( -1.5432, SC_NS );
26212855Sgabeblack@google.com
26312855Sgabeblack@google.com    cout << ( t1 + t2 ) << endl;
26412855Sgabeblack@google.com    cout << ( t1 + t3 ) << endl;
26512855Sgabeblack@google.com    cout << ( t1 + t5 ) << endl;
26612855Sgabeblack@google.com    cout << ( t3 + t2 ) << endl;
26712855Sgabeblack@google.com    cout << ( t3 + t4 ) << endl;
26812855Sgabeblack@google.com    cout << ( t3 + t5 ) << endl;
26912855Sgabeblack@google.com    cout << ( t5 + t5 ) << endl;
27012855Sgabeblack@google.com
27112855Sgabeblack@google.com    cout << ( t1 - t2 ) << endl;
27212855Sgabeblack@google.com    cout << ( t1 - t3 ) << endl;
27312855Sgabeblack@google.com    cout << ( t1 - t5 ) << endl;
27412855Sgabeblack@google.com    cout << ( t3 - t4 ) << endl;
27512855Sgabeblack@google.com    cout << ( t3 - t5 ) << endl;
27612855Sgabeblack@google.com    cout << ( t5 - t5 ) << endl;
27712855Sgabeblack@google.com
27812855Sgabeblack@google.com    cout << ( t1 * 1.2345 ) << endl;
27912855Sgabeblack@google.com    cout << ( 1.2345 * t3 ) << endl;
28012855Sgabeblack@google.com    cout << ( t4 * 2 ) << endl;
28112855Sgabeblack@google.com
28212855Sgabeblack@google.com    cout << ( t1 / 1.2345 ) << endl;
28312855Sgabeblack@google.com    cout << ( t4 / 2 ) << endl;
28412855Sgabeblack@google.com    cout << ( t3 / t4 ) << endl;
28512855Sgabeblack@google.com
28612855Sgabeblack@google.com    cout << ( t2 += t3 ) << endl;
28712855Sgabeblack@google.com    cout << ( t2 -= t4 ) << endl;
28812855Sgabeblack@google.com    cout << ( t2 *= 1.2345 ) << endl;
28912855Sgabeblack@google.com    cout << ( t2 /= 2 ) << endl;
29012855Sgabeblack@google.com}
29112855Sgabeblack@google.com
29212855Sgabeblack@google.comvoid
29312855Sgabeblack@google.comtest_SC_ZERO_TIME()
29412855Sgabeblack@google.com{
29512855Sgabeblack@google.com    cout << "test_SC_ZERO_TIME" << endl;
29612855Sgabeblack@google.com
29712855Sgabeblack@google.com    cout << SC_ZERO_TIME << endl;
29812855Sgabeblack@google.com}
29912855Sgabeblack@google.com
30012855Sgabeblack@google.comint
30112855Sgabeblack@google.comsc_main( int, char*[] )
30212855Sgabeblack@google.com{
30312855Sgabeblack@google.com#if defined(_MSC_VER) && _MSC_VER < 1900
30412855Sgabeblack@google.com     _set_output_format(_TWO_DIGIT_EXPONENT);
30512855Sgabeblack@google.com#endif
30612855Sgabeblack@google.com    test_print();
30712855Sgabeblack@google.com    test_constructors();
30812855Sgabeblack@google.com    test_assignment();
30912855Sgabeblack@google.com    test_conversion();
31012855Sgabeblack@google.com    test_relational();
31112855Sgabeblack@google.com    test_arithmetic();
31212855Sgabeblack@google.com    test_SC_ZERO_TIME();
31312855Sgabeblack@google.com
31412855Sgabeblack@google.com    return 0;
31512855Sgabeblack@google.com}
316