// testEndian.cc   P. Conrad  for lab4b, Fall 2005
// an example of what your main for lab4bs2.cc might look like
// test whether the function toLittleEndian works or not

// We'll use the number

// 0x01020408 to see if the bytes get swapped ok
// if they do, the number should come out 0x08040201


#include <iostream>
using std::cout;
using std::endl;

#include "endian.h"

int main(void)
{


  int x = 0x01020408;

  int xShouldBeAfterSwapping = 0x08040201;

  // better style would be to swap the 
  // if and else parts, and eliminate the ! symbol...

  if (systemIsLittleEndian())
    {
      // on a little endian, there should
      // be no change in the result, so
      // test for that...

      int result = convertToLittleEndian(x);

      if ( result == x)
	  cout << " it worked and system is little endian" << endl;
      else
	  cout << " its broken " << endl;
    }
  else
    {
      int result = convertToLittleEndian(x);

      if ( result == xShouldBeAfterSwapping)
	  cout << " it worked and system is big Endian" << endl;
      else
	  cout << " its broken " << endl;
    }

}  


