/********************************************************************/
/*		Test byte and word classes.  Copyright Joe Schell 1989.      */
/********************************************************************/

#include <byte.hpp>

#define comp(c,i)	( ((c) == int(i)) ? "okay.\n" : "not okay.\n")

void test_init(int c)  {cout << "   Initialization is " << comp(c,3);}
void test_inc(int c)   { cout << "   Increment is " << comp(c,4); }
void test_dec(int c)   { cout << "   Decrement is " << comp(c,3); }
void test_eql(int c)   { cout << "   Equal for int is " << comp(c,3);}


main()
{
	cout << "Testing byte and word class.\n";

	byte b, c=3, *d;
	char *test_byte = "abc";

	cout << "Byte:( should be 03, result=" << c.make_string() << ")\n";
	test_init(c);
	c++;	test_inc(c);
	c--;	test_dec(c);
	b=c;	test_eql(b);
	c=4;
	cout << "   Setting equal to integer is " << comp(c,4);

    b=c;
    c++;
	cout << "   Comparison of bytes is "
		 << ((b!=c) ? "okay." : "not okay.") << "\n";
	d = (byte*)test_byte;
	cout << "   Pointing is " << comp(*d,*test_byte);
	d++;
	cout << "   Incrementing pointer is " << comp(*d,*(test_byte+1));


	word x, y=3, *z;
	int test_word=8;
	cout << "\nWord:( should be 0003, result=" 
		 << y.make_string() << ")\n";
	test_init(y);
	y++;	test_inc(y);
	y--;	test_dec(y);
	x=y;	test_eql(x);
	y++;
	cout << "   Comparison of words is "
		<< ((x!=y) ? "okay." : "not okay.") << "\n";
	z = (word*)(&test_word);
	cout << "   Pointer to word is " << comp(*z,test_word);
	(*z)++;
	cout << "   Dereference and increment is " << comp(*z,9);

	// The next two lines should cause 'Illegal values' when
    // not commented.
	// b=UCHAR_MAX + 1;
	// x=(long)UINT_MAX + 1;

	cout << "\nTest is finished.\n";
}

