test03.cpp revision 12855:588919e0e4aa
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 test03.cpp -- 23 24 Original Author: Martin Janssen, Synopsys, Inc., 2002-03-19 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 *****************************************************************************/ 37 38// test of sc_length_param and sc_length_context and their use in the datatype 39// base classes. 40 41#include "systemc.h" 42 43void 44test_sc_length_param() 45{ 46 cout << "\n*** test_sc_length_param ***" << endl; 47 48 sc_length_param a; 49 cout << a << endl; 50 51 sc_length_param b( 5 ); 52 cout << b << endl; 53 54 try { 55 sc_length_param c( -1 ); 56 cout << c << endl; 57 } catch( sc_report x ) { 58 cout << "\nException caught" << endl; 59 cout << x.what() << endl; 60 } 61 62 sc_length_param d( b ); 63 cout << d << endl; 64 65 sc_dt::sc_without_context foo; 66 sc_length_param e( foo ); 67 cout << e << endl; 68 69 e = b; 70 cout << e << endl; 71 72 cout << (e == b) << endl; 73 cout << (e != b) << endl; 74 75 cout << e.len() << endl; 76 e.len( 42 ); 77 cout << e.len() << endl; 78 79 cout << e.to_string() << endl; 80 81 e.print(); 82 cout << endl; 83 e.dump(); 84} 85 86#define TEST_DEFAULT_CTOR(tp) \ 87{ \ 88 cout << "\n" << #tp << endl; \ 89 \ 90 tp a; \ 91 cout << a.length() << endl; \ 92 \ 93 sc_length_context con1( sc_length_param( 5 ) ); \ 94 tp b; \ 95 cout << b.length() << endl; \ 96 \ 97 sc_length_context con2( sc_length_param( 42 ) ); \ 98 tp c; \ 99 cout << c.length() << endl; \ 100 \ 101 con2.end(); \ 102 tp d; \ 103 cout << d.length() << endl; \ 104 \ 105 con1.end(); \ 106 tp e; \ 107 cout << e.length() << endl; \ 108} 109 110void 111test_default_ctors() 112{ 113 cout << "\n*** test_default_ctors ***" << endl; 114 115 TEST_DEFAULT_CTOR(sc_bv_base); 116 TEST_DEFAULT_CTOR(sc_lv_base); 117 118 TEST_DEFAULT_CTOR(sc_int_base); 119 TEST_DEFAULT_CTOR(sc_uint_base); 120 TEST_DEFAULT_CTOR(sc_signed); 121 TEST_DEFAULT_CTOR(sc_unsigned); 122} 123 124int 125sc_main( int, char*[] ) 126{ 127 test_sc_length_param(); 128 test_default_ctors(); 129 130 return 0; 131} 132