// ------------------------------- //
// -------- Start of File -------- //
// ------------------------------- //
// ----------------------------------------------------------- // 
// C++ Source Code File Name: testu32.cpp 
// Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
// Produced By: Doug Gaer   
// File Creation Date: 09/05/1997  
// Date Last Modified: 03/17/1999
// Copyright (c) 1997 Douglas M. Gaer
// ----------------------------------------------------------- // 
// ------------- Program Description and Details ------------- // 
// ----------------------------------------------------------- // 
/*
This is a test program for the UINT32 class.

The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
All those who put this code or its derivatives in a commercial
product MUST mention this copyright in their documentation for
users of the products in which this code or its derivative
classes are used. Otherwise, you have the freedom to redistribute
verbatim copies of this source code, adapt it to your specific
needs, or improve the code and release your improvements to the
public provided that the modified files carry prominent notices
stating that you changed the files and the date of any change.

THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
CORRECTION.
*/
// ----------------------------------------------------------- // 
#include <iostream.h>
#include "uint32.h"

void pause()
{
  cout << endl;
  cout << "Press enter to continue..." << endl;
  cin.get();
}

void SkipToEol(istream &s)
// Used to clear istream
{
  char c;
  s.clear();
  while(s.get(c) && c != '\n') { ; }
}

template<class TYPEX, class TYPEY>
inline void OperatorTest(TYPEX x, TYPEY y)
{
  char *tf[2] = {"FALSE", "TRUE"};
  cout << endl;
  cout << "Value x = " << x << ", Value y = " << y << endl;
  TYPEX z;
  cout << x << " += " << y << " = "; z = x; z += y; cout << z << endl;
  cout << x << " -= " << y << " = "; z = x; z -= y; cout << z << endl;
  cout << x << " *= " << y << " = "; z = x; z *= y; cout << z << endl;
  cout << x << " /= " << y << " = "; z = x; z /= y; cout << z << endl;
  cout << x << " * " << y << " = " ; z = (x * y); cout << z << endl;
  cout << x << " / " << y << " = " ; z = (x / y); cout << z << endl;
  cout << x << " + " << y << " = " ; z = (x + y); cout << z << endl;
  cout << x << " - " << y << " = " ; z = (x - y); cout << z << endl;
  cout << x << " == " << y << " = " << tf[(x == y)] << endl;
  cout << x << " != " << y << " = " << tf[(x != y)] << endl;
  cout << x << " <= " << y << " = " << tf[(x <= y)] << endl;
  cout << x << " >= " << y << " = " << tf[(x >= y)] << endl;
  cout << x << " < " << y << " = " << tf[(x < y)] << endl;
  cout << x << " > " << y << " = " << tf[(x > y)] << endl;
  cout << x << "++ = "; z = x; z++; cout << z << endl;
  cout << x << "-- = "; z = x; z--; cout << z << endl; 
  cout << "++" << x << " = "; z = x; ++z; cout << z << endl;
  cout << "--" << x << " = "; z = x; --z; cout << z << endl;
}

int main()
{
  UINT32 a = LWORDPositiveLimit;
  UINT32 b(LWORDNegitiveLimit);
  UINT32 c;

  c = ULWORDLimit;
  cout << "Assigning UINT32 unsigned limit: " << c << endl;

  pause();
  
  cout << "Testing UINT32 copy consturctor..." << endl;
  UINT32 d(a);
  cout << d << endl;

  cout << endl;
  cout << "Testing UINT32 assignment operator..." << endl;
  UINT32 e;
  e = a;
  cout << e << endl;

  pause();

  cout << "Testing overloaded operators (UINT32, UINT32)..." << endl;
  __ULWORD__ buf1, buf2, al, bl;
  
  cout << "Enter first integer: ";
  cin >> buf1;
  if(cin) {
    a = buf1;
    al = buf1;
    cout << "Enter second integer: ";
    cin >> buf2;
  }
  else {
    cout << "Input stream broken. Exiting..." << endl;
    return 0;
  }
  if(cin) {
    b = buf2;
    bl = buf2;
  }
  else {
    cout << "Input stream broken. Exiting..." << endl;
    return 0;
  }

  SkipToEol(cin);
    
  cout << endl;
  
  OperatorTest(a, b);

  pause();

  cout << "Testing overloaded operators (UINT32, __ULWORD__)..." << endl;
  OperatorTest(a, bl);

  pause();

  cout << "Testing overloaded operators (__ULWORD__, UINT32)..." << endl;
  OperatorTest(al, b);
  
  pause();

  cout << "Testing overloaded operators (UINT32, __WORD__)..." << endl;
  OperatorTest(a, (__WORD__)bl);

  pause();

  cout << "Testing overloaded operators (__WORD__, UINT32)..." << endl;
  OperatorTest((__WORD__)al, b);

  pause();

  cout << "Testing overloaded operators (UINT32, __SWORD__)..." << endl;
  OperatorTest(a, (__SWORD__)bl);

  pause();

  cout << "Testing overloaded operators (__SWORD__, UINT32)..." << endl;
  OperatorTest((__SWORD__)al, b);

  pause();
  
  cout << "Testing overloaded operators (UINT32, __UWORD__)..." << endl;
  OperatorTest(a, (__UWORD__)bl);

  pause();

  cout << "Testing overloaded operators (__UWORD__, UINT32)..." << endl;
  OperatorTest((__UWORD__)al, b);

  pause();

  cout << "Testing overloaded operators (UINT32, __USWORD__)..." << endl;
  OperatorTest(a, (__USWORD__)bl);

  pause();

  cout << "Testing overloaded operators (__USWORD__, UINT32)..." << endl;
  OperatorTest((__USWORD__)al, b);

  pause();
  
  cout << "Testing overloaded operators (UINT32, __SBYTE__)..." << endl;
  OperatorTest(a, 'B');

  pause();

  cout << "Testing overloaded operators (__SBYTE__, UINT32)..." << endl;
  OperatorTest('A', b);

  return 0;
}
// ----------------------------------------------------------- //
// ------------------------------- //
// --------- End of File --------- //
// ------------------------------- //


